Commit 0b158238 authored by Thomas Feuvrier's avatar Thomas Feuvrier
Browse files

ENH: Improve reading TerraSarX keywordlist

parent ad43342b
......@@ -1982,102 +1982,135 @@ ADD_TEST(ioTvTerraSarImageMetadataInterface ${IO_TESTS18}
ADD_TEST(ioTvImageKeywordlistSpot5 ${IO_TESTS18}
--compare-ascii ${NOTOL}
--compare-n-ascii ${NOTOL} 2
${BASELINE_FILES}/ioTvImageKeywordlistSpot5.txt
${TEMP}/ioTvImageKeywordlistSpot5.txt
${BASELINE_FILES}/ioTvImageKeywordlistSpot5.txt
${TEMP}/ioTvImageKeywordlistSpot5_saveState_loadState.txt
--ignore-lines-with 1 support_data.metadata_file
otbImageKeywordlist
${LARGEDATA}/SPOT5/TEHERAN/IMAGERY.TIF
${TEMP}/ioTvImageKeywordlistSpot5.txt
${TEMP}/ioTvImageKeywordlistSpot5_saveState_loadState.txt
)
ADD_TEST(ioTvImageKeywordlistQuickbird ${IO_TESTS18}
--compare-ascii ${NOTOL}
--compare-n-ascii ${NOTOL} 2
${BASELINE_FILES}/ioTvImageKeywordlistQuickbird.txt
${TEMP}/ioTvImageKeywordlistQuickbird.txt
${BASELINE_FILES}/ioTvImageKeywordlistQuickbird.txt
${TEMP}/ioTvImageKeywordlistQuickbird_saveState_loadState.txt
otbImageKeywordlist
${LARGEDATA}/QUICKBIRD/TOULOUSE/000000128955_01_P001_PAN/02APR01105228-P1BS-000000128955_01_P001.TIF
${TEMP}/ioTvImageKeywordlistQuickbird.txt
${TEMP}/ioTvImageKeywordlistQuickbird_saveState_loadState.txt
)
ADD_TEST(ioTvImageKeywordlistIkonos ${IO_TESTS18}
--compare-ascii ${NOTOL}
--compare-n-ascii ${NOTOL} 2
${BASELINE_FILES}/ioTvImageKeywordlistIkonos.txt
${TEMP}/ioTvImageKeywordlistIkonos.txt
${BASELINE_FILES}/ioTvImageKeywordlistIkonos.txt
${TEMP}/ioTvImageKeywordlistIkonos_saveState_loadState.txt
otbImageKeywordlist
${LARGEDATA}/IKONOS/BLOSSEVILLE/po_2619900_pan_0000000.tif
${TEMP}/ioTvImageKeywordlistIkonos.txt
${TEMP}/ioTvImageKeywordlistIkonos_saveState_loadState.txt
)
ADD_TEST(ioTvImageKeywordlistRapidEye ${IO_TESTS18}
--compare-ascii ${NOTOL}
--compare-n-ascii ${NOTOL} 2
${BASELINE_FILES}/ioTvImageKeywordlistRapidEye.txt
${TEMP}/ioTvImageKeywordlistRapidEye.txt
${BASELINE_FILES}/ioTvImageKeywordlistRapidEye.txt
${TEMP}/ioTvImageKeywordlistRapidEye_saveState_loadState.txt
otbImageKeywordlist
${LARGEDATA}/RAPIDEYE/level1B/2008-12-25T005918_RE3_1B-NAC_397971_12345_band3.ntf
${TEMP}/ioTvImageKeywordlistRapidEye.txt
${TEMP}/ioTvImageKeywordlistRapidEye_saveState_loadState.txt
)
ADD_TEST(ioTvImageKeywordlistEnvisatAsar ${IO_TESTS18}
--compare-ascii ${NOTOL}
--compare-n-ascii ${NOTOL} 2
${BASELINE_FILES}/ioTvImageKeywordlistEnvisatAsar.txt
${TEMP}/ioTvImageKeywordlistEnvisatAsar.txt
${BASELINE_FILES}/ioTvImageKeywordlistEnvisatAsar.txt
${TEMP}/ioTvImageKeywordlistEnvisatAsar_saveState_loadState.txt
otbImageKeywordlist
${LARGEDATA}/ENVISAT_ASAR_SCENE01/ASA_APS_1PNDPA20030821_7713.N1
${TEMP}/ioTvImageKeywordlistEnvisatAsar.txt
${TEMP}/ioTvImageKeywordlistEnvisatAsar_saveState_loadState.txt
)
ADD_TEST(ioTvImageKeywordlistAlosPalsar ${IO_TESTS18}
--compare-ascii ${NOTOL}
--compare-n-ascii ${NOTOL} 2
${BASELINE_FILES}/ioTvImageKeywordlistAlosPalsar.txt
${TEMP}/ioTvImageKeywordlistAlosPalsar.txt
${BASELINE_FILES}/ioTvImageKeywordlistAlosPalsar.txt
${TEMP}/ioTvImageKeywordlistAlosPalsar_saveState_loadState.txt
otbImageKeywordlist
${LARGEDATA}/PALSAR/200801280007/l1data/VOL-ALPSRP037120700-H1.1__A
${TEMP}/ioTvImageKeywordlistAlosPalsar.txt
${TEMP}/ioTvImageKeywordlistAlosPalsar_saveState_loadState.txt
)
ADD_TEST(ioTvImageKeywordlistRadarSat1 ${IO_TESTS18}
--compare-ascii ${NOTOL}
--compare-n-ascii ${NOTOL} 2
${BASELINE_FILES}/ioTvImageKeywordlistRadarSat1.txt
${TEMP}/ioTvImageKeywordlistRadarSat1.txt
${BASELINE_FILES}/ioTvImageKeywordlistRadarSat1.txt
${TEMP}/ioTvImageKeywordlistRadarSat1_saveState_loadState.txt
otbImageKeywordlist
${LARGEDATA}/RADARSAT1/GOMA/SCENE01/DAT_01.001
${TEMP}/ioTvImageKeywordlistRadarSat1.txt
${TEMP}/ioTvImageKeywordlistRadarSat1_saveState_loadState.txt
)
ADD_TEST(ioTvImageKeywordlistRadarSat2 ${IO_TESTS18}
--compare-ascii ${NOTOL}
--compare-n-ascii ${NOTOL} 2
${BASELINE_FILES}/ioTvImageKeywordlistRadarSat2.txt
${TEMP}/ioTvImageKeywordlistRadarSat2.txt
${BASELINE_FILES}/ioTvImageKeywordlistRadarSat2.txt
${TEMP}/ioTvImageKeywordlistRadarSat2_saveState_loadState.txt
otbImageKeywordlist
${LARGEDATA}/RADARSAT2/ALTONA/Fine_Quad-Pol_Dataset/PK6621_DK406_FQ9_20080405_124900_HH_VV_HV_VH_SLC_Altona/product.xml
${TEMP}/ioTvImageKeywordlistRadarSat2.txt
${TEMP}/ioTvImageKeywordlistRadarSat2_saveState_loadState.txt
)
ADD_TEST(ioTvImageKeywordlistTerraSarX ${IO_TESTS18}
--compare-ascii ${NOTOL}
--compare-n-ascii ${NOTOL} 2
${BASELINE_FILES}/ioTvImageKeywordlistTerraSarX.txt
${TEMP}/ioTvImageKeywordlistTerraSarX.txt
${BASELINE_FILES}/ioTvImageKeywordlistTerraSarX.txt
${TEMP}/ioTvImageKeywordlistTerraSarX_saveState_loadState.txt
otbImageKeywordlist
${LARGEDATA}/TERRASARX/dims/TSX-1.SAR.L1B/TSX1_SAR__SSC/TSX1_SAR__SSC.xml
${TEMP}/ioTvImageKeywordlistTerraSarX.txt
${TEMP}/ioTvImageKeywordlistTerraSarX_saveState_loadState.txt
)
ADD_TEST(ioTvImageKeywordlistTerraSarX_Upsala ${IO_TESTS18}
--compare-ascii ${NOTOL}
--compare-n-ascii ${NOTOL} 2
${BASELINE_FILES}/ioTvImageKeywordlistTerraSarX_Upsala.txt
${TEMP}/ioTvImageKeywordlistTerraSarX_Upsala.txt
${BASELINE_FILES}/ioTvImageKeywordlistTerraSarX_Upsala.txt
${TEMP}/ioTvImageKeywordlistTerraSarX_Upsala_saveState_loadState.txt
otbImageKeywordlist
${LARGEDATA}/TERRASARX/UPSALA_GLACIER/TSX1_SAR__MGD/TSX1_SAR__MGD.xml
${TEMP}/ioTvImageKeywordlistTerraSarX_Upsala.txt
${TEMP}/ioTvImageKeywordlistTerraSarX_Upsala_saveState_loadState.txt
)
ADD_TEST(ioTvImageKeywordlistTerraSarX_Toronto ${IO_TESTS18}
--compare-ascii ${NOTOL}
--compare-n-ascii ${NOTOL} 2
${BASELINE_FILES}/ioTvImageKeywordlistTerraSarX_Toronto.txt
${TEMP}/ioTvImageKeywordlistTerraSarX_Toronto.txt
${BASELINE_FILES}/ioTvImageKeywordlistTerraSarX_Toronto.txt
${TEMP}/ioTvImageKeywordlistTerraSarX_Toronto_saveState_loadState.txt
otbImageKeywordlist
${LARGEDATA}/TERRASARX/TORONTO/TSX1_SAR__SSC/TSX1_SAR__SSC.xml
${TEMP}/ioTvImageKeywordlistTerraSarX_Toronto.txt
${TEMP}/ioTvImageKeywordlistTerraSarX_Toronto_saveState_loadState.txt
)
ADD_TEST(ioTvImageKeywordlistErs ${IO_TESTS18}
......@@ -2087,6 +2120,7 @@ ADD_TEST(ioTvImageKeywordlistErs ${IO_TESTS18}
otbImageKeywordlist
${LARGEDATA}/SAR_ERS2_SLCI_SCENE1/DAT_01.001
${TEMP}/ioTvImageKeywordlistErs.txt
${TEMP}/ioTvImageKeywordlistErs_saveState_loadState.txt
)
ENDIF(OTB_DATA_USE_LARGEINPUT)
......
......@@ -20,14 +20,22 @@ PURPOSE. See the above copyright notices for more information.
#endif
#include <iostream>
#include "otbVectorImage.h"
#include "otbImageFileReader.h"
#
#include <iomanip>
#include <fstream>
#include "otbMacro.h"
#include "otbImageKeywordlist.h"
#include "base/ossimKeywordlist.h"
#include "projection/ossimProjection.h"
#include "projection/ossimProjectionFactoryRegistry.h"
#include "ossim/ossimPluginProjectionFactory.h"
int otbImageKeywordlist( int argc, char* argv[] )
{
if (argc!=3)
if (argc!=4)
{
std::cout << argv[0] <<" <input filename> <output filename>"
std::cout << argv[0] <<" <input filename> <output filename> <output filename2>"
<< std::endl;
return EXIT_FAILURE;
......@@ -35,21 +43,50 @@ int otbImageKeywordlist( int argc, char* argv[] )
char * filename = argv[1];
char * outFilename = argv[2];
char * outFilename2 = argv[3];
std::ofstream file;
file.open(outFilename);
file << std::setprecision(15);
std::ofstream file2;
file2.open(outFilename2);
file2 << std::setprecision(15);
bool hasMetaData = false;
ossimKeywordlist geom_kwl, geom_kwl2, geom_kwl3;
ossimProjectionFactoryRegistry::instance()->registerFactory(ossimplugins::ossimPluginProjectionFactory::instance());
ossimProjection * projection = ossimProjectionFactoryRegistry::instance()
->createProjection(ossimFilename(filename),0);
if (!projection)
{
otbMsgDevMacro( <<"OSSIM Instanciate projection FAILED ! ");
return EXIT_FAILURE;
}
hasMetaData = projection->saveState(geom_kwl);
std::cout << "geom_kwl:"<<geom_kwl<<std::endl;
otb::ImageKeywordlist otb_kwl;
otb_kwl.SetKeywordlist( geom_kwl );
typedef otb::VectorImage<double, 2> ImageType;
typedef otb::ImageFileReader<ImageType> ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(filename);
reader->UpdateOutputInformation();
otb_kwl.convertToOSSIMKeywordlist( geom_kwl2 );
std::cout << "geom_kwl2:"<<geom_kwl2<<std::endl;
hasMetaData = projection->loadState(geom_kwl2);
hasMetaData = projection->saveState(geom_kwl3);
otb::ImageKeywordlist otb_kwl2;
otb_kwl2.SetKeywordlist( geom_kwl3 );
std::cout << "geom_kwl3:"<<geom_kwl3<<std::endl;
file << "*** KEYWORD LIST ***\n";
file << reader->GetOutput()->GetImageKeywordlist();
file << otb_kwl;
file2 << "*** KEYWORD LIST ***\n";
file2 << otb_kwl2;
file.close();
file2.close();
return EXIT_SUCCESS;
}
......@@ -37,6 +37,18 @@ static const char SR_GR_SF_KW[] = "sc_gr_sf";
static const char ALT_SR_GR_COEFFICIENT0_KW[] = "alt_sr_gr_coeff0";
static const char ALT_SR_GR_COEFFICIENT1_KW[] = "alt_sr_gr_coeff1";
static const char ALT_SR_GR_COEFFICIENT2_KW[] = "alt_sr_gr_coeff2";
static const char PRODUCT_TYPE[] = "product_type";
static const char RADIOMETRIC_CORRECTION[] = "radiometricCorrection";
static const char ACQUISITION_INFO[] = "acquisitionInfo.";
static const char IMAGING_MODE[] = "imagingMode";
static const char SENSOR[] = "sensor";
static const char LOOK_DIRECTION[] = "lookDirection";
static const char POLARISATION_MODE[] = "polarisationMode";
static const char POL_LAYER[] = "polLayer";
static const char CALIBRATION_CALFACTOR[] = "calibration.calibrationConstant.calFactor";
using ::ossimString;
using ::ossimXmlDocument;
......@@ -59,6 +71,15 @@ ossimplugins::ossimTerraSarModel::ossimTerraSarModel()
_sceneCenterRangeTime(0.0),
_SrToGr_scaling_factor(0.0),
_alt_srgr_coefset(3),
_productType(),
_radiometricCorrection(),
_imagingMode(),
_acquisitionSensor(),
_lookDirection(),
_polarisationMode(),
_polLayer(),
_noise(0),
_calFactor(0.),
theProductXmlFile()
{
}
......@@ -72,12 +93,26 @@ ossimplugins::ossimTerraSarModel::ossimTerraSarModel(
_sceneCenterRangeTime(rhs._sceneCenterRangeTime),
_SrToGr_scaling_factor(rhs._SrToGr_scaling_factor),
_alt_srgr_coefset(rhs._alt_srgr_coefset),
_productType(rhs._productType),
_radiometricCorrection(rhs._radiometricCorrection),
_imagingMode(rhs._imagingMode),
_acquisitionSensor(rhs._acquisitionSensor),
_lookDirection(rhs._lookDirection),
_polarisationMode(rhs._polarisationMode),
_polLayer(rhs._polLayer),
_noise(rhs._noise),
_calFactor(rhs._calFactor),
theProductXmlFile(rhs.theProductXmlFile)
{
}
ossimplugins::ossimTerraSarModel::~ossimTerraSarModel()
{
if (_noise != 0)
{
delete _noise;
}
}
ossimString ossimplugins::ossimTerraSarModel::getClassName() const
......@@ -184,11 +219,39 @@ bool ossimplugins::ossimTerraSarModel::open(const ossimFilename& file)
if (result)
{
result = initRefPoint(xdoc, tsDoc);
if (result)
{
result = tsDoc.getProductType(xdoc, _productType);
if (result)
{
result = tsDoc.getRadiometricCorrection(xdoc, _radiometricCorrection);
if (result)
{
result = initAcquisitionInfo(xdoc, tsDoc);
if (result)
{
result = initNoise(xdoc, tsDoc);
if (result)
{
ossimString s;
result = tsDoc.getCalFactor(xdoc, s);
_calFactor = s.toFloat64();
}
}
}
}
}
}
}
}
}
}
} // matches: if ( xdoc->openFile(file) )
......@@ -282,7 +345,26 @@ bool ossimplugins::ossimTerraSarModel::saveState(ossimKeywordlist& kwl,
{
// kwl.add(prefix, LOAD_FROM_PRODUCT_FILE_KW, "true");
}
kwl.add(prefix, PRODUCT_TYPE, _productType.c_str());
kwl.add(prefix, RADIOMETRIC_CORRECTION, _radiometricCorrection.c_str());
ossimString kw = ACQUISITION_INFO;
ossimString kw2 = kw + IMAGING_MODE;
kwl.add(prefix, kw2, _imagingMode.c_str());
kw2 = kw + SENSOR;
kwl.add(prefix, kw2, _acquisitionSensor.c_str());
kw2 = kw + LOOK_DIRECTION;
kwl.add(prefix, kw2, _lookDirection.c_str());
kw2 = kw + POLARISATION_MODE;
kwl.add(prefix, kw2, _polarisationMode.c_str());
kw2 = kw + POL_LAYER;
kwl.add(prefix, kw2, _polLayer.c_str());
_noise->saveState(kwl,prefix);
kwl.add(prefix, CALIBRATION_CALFACTOR, ossimString::toString(_calFactor).c_str());
if (traceDebug())
{
ossimNotify(ossimNotifyLevel_DEBUG)
......@@ -554,6 +636,40 @@ bool ossimplugins::ossimTerraSarModel::loadState (const ossimKeywordlist &kwl,
} // matches: if (result)
// Load the base class.
if ( !_noise)
{
_noise = new Noise();
}
if ( _noise->loadState(kwl, prefix) == false )
{
if (traceDebug())
{
ossimNotify(ossimNotifyLevel_WARN)
<< MODULE
<< "\n_noise->loadState failed!\n";
}
result = false;
}
lookup = kwl.find(prefix, CALIBRATION_CALFACTOR);
if (lookup)
{
s = lookup;
_calFactor = s.toDouble();
}
else
{
if (traceDebug())
{
ossimNotify(ossimNotifyLevel_WARN)
<< MODULE
<< "\nRequired keyword not found: "
<< CALIBRATION_CALFACTOR << "\n";
}
result = false;
}
if (traceDebug())
{
ossimNotify(ossimNotifyLevel_DEBUG)
......@@ -566,6 +682,7 @@ bool ossimplugins::ossimTerraSarModel::loadState (const ossimKeywordlist &kwl,
std::ostream& ossimplugins::ossimTerraSarModel::print(std::ostream& out) const
{
static const char MODULE[] = "ossimplugins::ossimTerraSarModel::print";
// Capture the original flags.
std::ios_base::fmtflags f = out.flags();
......@@ -604,7 +721,34 @@ std::ostream& ossimplugins::ossimTerraSarModel::print(std::ostream& out) const
ossimGeometricSarSensorModel::print(out);
if ( _noise->print(out) == false )
{
if (traceDebug())
{
ossimNotify(ossimNotifyLevel_WARN)
<< MODULE
<< "\n_noise->print failed!\n";
}
}
out << CALIBRATION_CALFACTOR << ": " << _calFactor << "\n";
// Reset flags.
ossimString kw = ACQUISITION_INFO;
ossimString kw2 = kw + IMAGING_MODE;
out << kw2 << ": " << _imagingMode.c_str()<< "\n";
kw2 = kw + SENSOR;
out << kw2<< ": " << _acquisitionSensor.c_str()<< "\n";
kw2 = kw + LOOK_DIRECTION;
out << kw2<< ": " << _lookDirection.c_str()<< "\n";
kw2 = kw + POLARISATION_MODE;
out << kw2<< ": " << _polarisationMode.c_str()<< "\n";
kw2 = kw + POL_LAYER;
out << kw2<< ": " << _polLayer.c_str()<< "\n";
out.setf(f);
return out;
......@@ -1407,5 +1551,76 @@ bool ossimplugins::ossimTerraSarModel::initRefPoint(
return true;
}
bool ossimplugins::ossimTerraSarModel::initAcquisitionInfo(
const ossimXmlDocument* xdoc, const ossimTerraSarProductDoc& tsDoc)
{
static const char MODULE[] = "ossimplugins::ossimTerraSarModel::initAcquisitionInfo";
if (traceDebug())
{
ossimNotify(ossimNotifyLevel_DEBUG)<< MODULE << " entered...\n";
}
bool result = tsDoc.getImagingMode(xdoc, _imagingMode);
if( result )
{
result = tsDoc.getAcquisitionSensor(xdoc, _acquisitionSensor);
if( result )
{
result = tsDoc.getLookDirection(xdoc, _lookDirection);
if( result )
{
result = tsDoc.getPolarisationMode(xdoc, _polarisationMode);
if( result )
{
result = tsDoc.getPolLayer(xdoc, _polLayer);
}
}
}
}
if (traceDebug())
{
ossimNotify(ossimNotifyLevel_DEBUG)
<< MODULE << " exit status = " << (result?"true":"false\n")
<< std::endl;
}
return result;
}
bool ossimplugins::ossimTerraSarModel::initNoise(
const ossimXmlDocument* xdoc, const ossimTerraSarProductDoc& tsDoc)
{
static const char MODULE[] = "ossimplugins::ossimTerraSarModel::initNoise";
if (traceDebug())
{
ossimNotify(ossimNotifyLevel_DEBUG)<< MODULE << " entered...\n";
}
// Initialize the platform position interpolator.
if (_noise)
{
delete _noise;
}
_noise = new Noise();
bool result = tsDoc.initNoise(xdoc, _noise);
if (traceDebug())
{
ossimNotify(ossimNotifyLevel_DEBUG)
<< MODULE << " exit status = " << (result?"true":"false\n")
<< std::endl;
}
return result;
}
......@@ -24,6 +24,7 @@
#include <list>
#include <otb/CivilDateTime.h>
#include <otb/Noise.h>
// Forward class declarations outside of namespace ossimplugins.
class ossimXmlDocument;
......@@ -137,6 +138,24 @@ namespace ossimplugins
*/
bool initRefPoint(const ossimXmlDocument* xdoc,
const ossimTerraSarProductDoc& rsDoc);
/**
* @brief Method to initialize AcquisitionInfo parameters from
* TerraSAR product xml file.
* @param xdoc Opened product xml file.
* @return true on success, false on error.
*/
bool initAcquisitionInfo( const ossimXmlDocument* xdoc,
const ossimTerraSarProductDoc& tsDoc);
/**
* @brief Method to initialize ImageNoise parameters from
* TerraSAR product xml file.
* @param xdoc Opened product xml file.
* @return true on success, false on error.
*/
bool initNoise(
const ossimXmlDocument* xdoc, const ossimTerraSarProductDoc& tsDoc);
/**
* @brief Slant Range TO Ground Range Projection reference point
......@@ -167,6 +186,51 @@ namespace ossimplugins
*/
std::vector<double> _alt_srgr_coefset;
/**
* @brief ProductType.
*/
ossimString _productType;
/**
* @brief RadiometricCorrection.
*/
ossimString _radiometricCorrection;
/**
* @brief ImagingMode (AcquisitionInfo node).
*/
ossimString _imagingMode;
/**
* @brief Sensor (AcquisitionInfo node).
*/
ossimString _acquisitionSensor;
/**
* @brief LookDirection (AcquisitionInfo node).
*/
ossimString _lookDirection;
/**
* @brief PolarisationMode (AcquisitionInfo node).
*/
ossimString _polarisationMode;
/**
* @brief PolLayer (AcquisitionInfo node).
*/
ossimString _polLayer;
/**
* @brief Noise (Noise node).
*/
Noise *_noise;
/**
* @brief CalFactor (Calibration node).
*/
double _calFactor;