From 5009e64c5fab57a49b6efe3eff173055aabbe8fd Mon Sep 17 00:00:00 2001 From: Cyrille Valladeau <cyrille.valladeau@c-s.fr> Date: Wed, 23 Dec 2009 09:24:33 +0100 Subject: [PATCH] ENH : TSX calib evolution --- Code/IO/otbTerraSarImageMetadataInterface.cxx | 313 ++++++++++++++- Code/IO/otbTerraSarImageMetadataInterface.h | 33 +- .../otbTerraSarBrightnessImageFilter.h | 11 +- .../otbTerraSarBrightnessImageFilter.txx | 29 +- Code/Radiometry/otbTerraSarFunctors.txx | 2 +- .../IO/otbTerraSarImageMetadataInterface.cxx | 30 ++ Testing/Code/Radiometry/CMakeLists.txt | 12 + .../otbTerraSarBrightnessImageFilterTest.cxx | 9 +- .../ossim/ossimTerraSarModel.cpp | 357 ++++++++++-------- .../ossim/ossimTerraSarModel.h | 5 + .../ossim/ossimTerraSarProductDoc.cpp | 16 +- .../ossim/ossimTerraSarProductDoc.h | 3 + 12 files changed, 621 insertions(+), 199 deletions(-) diff --git a/Code/IO/otbTerraSarImageMetadataInterface.cxx b/Code/IO/otbTerraSarImageMetadataInterface.cxx index 8a1519f61c..9d06582dde 100644 --- a/Code/IO/otbTerraSarImageMetadataInterface.cxx +++ b/Code/IO/otbTerraSarImageMetadataInterface.cxx @@ -29,6 +29,7 @@ #include "itkMetaDataObject.h" #include "otbVectorDataKeywordlist.h" +#include "base/ossimDate.h" namespace otb { @@ -48,9 +49,10 @@ TerraSarImageMetadataInterface::GetSensorID( const MetaDataDictionaryType & dict { itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, ImageKeywordlist); } + ossimKeywordlist kwl; ImageKeywordlist.convertToOSSIMKeywordlist(kwl); - + kwl.print(std::cout); std::string key= "sensor"; ossimString keywordString = kwl.find(key.c_str()); std::string output(keywordString.chars()); @@ -351,7 +353,7 @@ TerraSarImageMetadataInterface::GetCalibrationFactor( const MetaDataDictionaryTy { if( !this->CanRead( dict ) ) { - itkExceptionMacro(<<"Invalid Metadata, no TerraSar Image"); + itkExceptionMacro(<<"Invalid Metadata, no TerraSar Image"); } ImageKeywordlistType imageKeywordlist; @@ -371,4 +373,311 @@ TerraSarImageMetadataInterface::GetCalibrationFactor( const MetaDataDictionaryTy } +ossimplugins::Noise * +TerraSarImageMetadataInterface::GetNoise( const MetaDataDictionaryType & dict ) const +{ + if( !this->CanRead( dict ) ) + { + itkExceptionMacro(<<"Invalid Metadata, no TerraSar Image"); + } + + ImageKeywordlistType imageKeywordlist; + + if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey)) + { + itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist); + } + + ossimKeywordlist kwl; + imageKeywordlist.convertToOSSIMKeywordlist(kwl); + + ossimplugins::Noise * noise = new ossimplugins::Noise(); + noise->loadState( kwl, ""); + + + return noise; +} + + +unsigned int +TerraSarImageMetadataInterface::GetNumberOfNoiseRecords( const MetaDataDictionaryType & dict ) const +{ + ossimplugins::Noise * noise = this->GetNoise( dict ); + + ImageKeywordlistType imageKeywordlist; + + if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey)) + { + itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist); + } + + ossimKeywordlist kwl; + imageKeywordlist.convertToOSSIMKeywordlist(kwl); + std::string key = "noise.numberOfNoiseRecords"; + ossimString nbRec = kwl.find(key.c_str()); + + + delete noise; + + return static_cast<unsigned int>(nbRec.toInt()); +} + + +TerraSarImageMetadataInterface::UIntVectorType +TerraSarImageMetadataInterface::GetNoisePolynomialDegrees( const MetaDataDictionaryType & dict ) const +{ + ossimplugins::Noise * noise = this->GetNoise( dict ); + + ImageKeywordlistType imageKeywordlist; + + if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey)) + { + itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist); + } + + ossimKeywordlist kwl; + imageKeywordlist.convertToOSSIMKeywordlist(kwl); + + UIntVectorType polDeg; + itk::OStringStream oss; + + unsigned int nbRec = this->GetNumberOfNoiseRecords(dict); + for(unsigned int i=0; i<nbRec; i++) + { + oss.str(""); + oss << "noise[" << i << "]imageNoise.noiseEstimate.polynomialDegree"; + ossimString tempVal = kwl.find(oss.str().c_str()); + polDeg.push_back( static_cast<unsigned int>(tempVal.toInt()) ); + } + + delete noise; + + return polDeg; +} + +TerraSarImageMetadataInterface::DoubleVectorVectorType +TerraSarImageMetadataInterface::GetNoisePolynomialCoefficientsList( const MetaDataDictionaryType & dict ) const +{ + ImageKeywordlistType imageKeywordlist; + + if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey)) + { + itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist); + } + + ossimKeywordlist kwl; + imageKeywordlist.convertToOSSIMKeywordlist(kwl); + + ossimplugins::Noise * noise = this->GetNoise( dict ); + unsigned int nbRec = this->GetNumberOfNoiseRecords(dict); + UIntVectorType polDegs = this->GetNoisePolynomialDegrees(dict); + + DoubleVectorVectorType polCoefList; + DoubleVectorType polCoef; + itk::OStringStream oss; + + for(unsigned int i=0; i<nbRec; i++) + { + polCoef.clear(); + // set <= condition because degree N means N+1 coeff + for(unsigned int j=0; j<=polDegs.size(); j++) + { + oss.str(""); + oss << "noise[" << i << "]imageNoise.noiseEstimate.coefficient[" << j <<"]"; + ossimString tempVal = kwl.find(oss.str().c_str()); + polCoef.push_back( static_cast<double>(tempVal.toDouble()) ); + } + polCoefList.push_back(polCoef); + } + + delete noise; + + return polCoefList; +} + + +TerraSarImageMetadataInterface::DoubleVectorType +TerraSarImageMetadataInterface::GetNoiseTimeUTCList( const MetaDataDictionaryType & dict ) const +{ + ossimplugins::Noise * noise = this->GetNoise( dict ); + + ImageKeywordlistType imageKeywordlist; + + if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey)) + { + itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist); + } + + ossimKeywordlist kwl; + imageKeywordlist.convertToOSSIMKeywordlist(kwl); + + DoubleVectorType timeList; + itk::OStringStream oss; + ossimString separatorList = "-T:Z"; + std::vector<ossimString> splittedDate; + + int year, month, day, hour, minu, sec; + double secDec, julianDay; + unsigned int nbRec = this->GetNumberOfNoiseRecords(dict); + for(unsigned int i=0; i<nbRec; i++) + { + oss.str(""); + oss << "noise[" << i << "]imageNoise.timeUTC"; + ossimString tempVal = kwl.find(oss.str().c_str()); + splittedDate = tempVal.split(separatorList); + + year = splittedDate[0].toInt(); + month = splittedDate[1].toInt(); + day = splittedDate[2].toInt(); + hour = splittedDate[3].toInt(); + minu = splittedDate[4].toInt(); + double secFull = splittedDate[5].toDouble(); + sec = static_cast<int>(vcl_floor(secFull)); + // store the decimal second value + secDec = secFull - vcl_floor(secFull); + ossimDate myDate(month, day, year); + myDate.setHour(hour); + myDate.setMin(minu); + myDate.setSec(sec); + + std::cout<<secDec*1e-5/0.864<<std::endl; + julianDay = myDate.getJulian(); + // add the decimal second to the julian day (0.00001 <-> 0.864s) + julianDay += secDec*1e-5/0.864; + + + timeList.push_back( julianDay ); + } + + delete noise; + + return timeList; +} + + +TerraSarImageMetadataInterface::DoubleVectorType +TerraSarImageMetadataInterface::GetNoiseValidityRangeMaxList( const MetaDataDictionaryType & dict ) const +{ + ossimplugins::Noise * noise = this->GetNoise( dict ); + + ImageKeywordlistType imageKeywordlist; + + if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey)) + { + itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist); + } + + ossimKeywordlist kwl; + imageKeywordlist.convertToOSSIMKeywordlist(kwl); + + DoubleVectorType maxList; + itk::OStringStream oss; + + unsigned int nbRec = this->GetNumberOfNoiseRecords(dict); + for(unsigned int i=0; i<nbRec; i++) + { + oss.str(""); + oss << "noise[" << i << "]imageNoise.noiseEstimate.validityRangeMax"; + ossimString tempVal = kwl.find(oss.str().c_str()); + maxList.push_back( tempVal.toDouble() ); + } + + delete noise; + + return maxList; +} + + + +TerraSarImageMetadataInterface::DoubleVectorType +TerraSarImageMetadataInterface::GetNoiseValidityRangeMinList( const MetaDataDictionaryType & dict ) const +{ + ossimplugins::Noise * noise = this->GetNoise( dict ); + + ImageKeywordlistType imageKeywordlist; + + if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey)) + { + itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist); + } + + ossimKeywordlist kwl; + imageKeywordlist.convertToOSSIMKeywordlist(kwl); + + DoubleVectorType minList; + itk::OStringStream oss; + + unsigned int nbRec = this->GetNumberOfNoiseRecords(dict); + for(unsigned int i=0; i<nbRec; i++) + { + oss.str(""); + oss << "noise[" << i << "]imageNoise.noiseEstimate.validityRangeMin"; + ossimString tempVal = kwl.find(oss.str().c_str()); + + minList.push_back( tempVal.toDouble() ); + } + + delete noise; + + return minList; +} + +TerraSarImageMetadataInterface::DoubleVectorType +TerraSarImageMetadataInterface::GetNoiseReferencePointList( const MetaDataDictionaryType & dict ) const +{ + ossimplugins::Noise * noise = this->GetNoise( dict ); + + ImageKeywordlistType imageKeywordlist; + + if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey)) + { + itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist); + } + + ossimKeywordlist kwl; + imageKeywordlist.convertToOSSIMKeywordlist(kwl); + + DoubleVectorType refPointList; + itk::OStringStream oss; + + unsigned int nbRec = this->GetNumberOfNoiseRecords(dict); + for(unsigned int i=0; i<nbRec; i++) + { + oss.str(""); + oss << "noise[" << i << "]imageNoise.noiseEstimate.referencePoint"; + ossimString tempVal = kwl.find(oss.str().c_str()); + + refPointList.push_back( tempVal.toDouble() ); + } + + delete noise; + + return refPointList; +} + + +double +TerraSarImageMetadataInterface::GetRadarFrequency( const MetaDataDictionaryType & dict ) const +{ + if( !this->CanRead( dict ) ) + { + itkExceptionMacro(<<"Invalid Metadata, no TerraSar Image"); + } + + ImageKeywordlistType imageKeywordlist; + + if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey)) + { + itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist); + } + + ossimKeywordlist kwl; + imageKeywordlist.convertToOSSIMKeywordlist(kwl); + + ossimString tempVal = kwl.find("radarFrequency"); + double freq = tempVal.toDouble(); + + return freq; +} + } // end namespace otb diff --git a/Code/IO/otbTerraSarImageMetadataInterface.h b/Code/IO/otbTerraSarImageMetadataInterface.h index 9ac96ad82f..645e977047 100644 --- a/Code/IO/otbTerraSarImageMetadataInterface.h +++ b/Code/IO/otbTerraSarImageMetadataInterface.h @@ -29,6 +29,7 @@ #include "otbMetaDataKey.h" #include "otbImageKeywordlist.h" #include "itkImageBase.h" +#include <otb/Noise.h> #include <string> namespace otb @@ -59,6 +60,9 @@ public: typedef MetaDataKey::VectorType VectorType; typedef MetaDataKey::VariableLengthVectorType VariableLengthVectorType; typedef ImageKeywordlist ImageKeywordlistType; + typedef std::vector<double> DoubleVectorType; + typedef std::vector<DoubleVectorType> DoubleVectorVectorType; + typedef std::vector<unsigned int> UIntVectorType; /** Set the image used to get the metadata */ itkSetObjectMacro(Image,ImageType); @@ -93,7 +97,34 @@ public: /** Get the calibration.calFactor : generationTime variable */ double GetCalibrationFactor( const MetaDataDictionaryType & ) const; - bool CanRead( const MetaDataDictionaryType & ) const; + /** Get the noise structure */ + ossimplugins::Noise * GetNoise( const MetaDataDictionaryType & ) const; + + /** Get the number of noise records */ + unsigned int GetNumberOfNoiseRecords( const MetaDataDictionaryType & ) const; + + /** Get the polynomial degree list */ + UIntVectorType GetNoisePolynomialDegrees( const MetaDataDictionaryType & ) const; + + /** Get the polynomial coefficient list */ + DoubleVectorVectorType GetNoisePolynomialCoefficientsList( const MetaDataDictionaryType & ) const; + + /** Get timeUTC noise acquisition list in Julian day */ + DoubleVectorType GetNoiseTimeUTCList( const MetaDataDictionaryType & ) const; + + /** Get noise minimum validity range list */ + DoubleVectorType GetNoiseValidityRangeMinList( const MetaDataDictionaryType & ) const; + + /** Get noise maximum validity range list */ + DoubleVectorType GetNoiseValidityRangeMaxList( const MetaDataDictionaryType & ) const; + + /** Get noise reference point list */ + DoubleVectorType GetNoiseReferencePointList( const MetaDataDictionaryType & ) const; + + /** Get the radar frequency */ + double GetRadarFrequency( const MetaDataDictionaryType & ) const; + + bool CanRead( const MetaDataDictionaryType & ) const; protected: TerraSarImageMetadataInterface(); diff --git a/Code/Radiometry/otbTerraSarBrightnessImageFilter.h b/Code/Radiometry/otbTerraSarBrightnessImageFilter.h index 432f702889..ad90b24285 100644 --- a/Code/Radiometry/otbTerraSarBrightnessImageFilter.h +++ b/Code/Radiometry/otbTerraSarBrightnessImageFilter.h @@ -74,17 +74,18 @@ public: typedef std::vector<DoubleVectorType> DoubleVectorVectorType; /** Accessors */ - void SetCalFactor(double pCalFactor){ - this->GetFunctor().SetCalFactor( pCalFactor ); - this->Modified(); - } + void SetCalFactor(double pCalFactor) + { + this->GetFunctor().SetCalFactor( pCalFactor ); + this->Modified(); + } double GetCalFactor(){ return this->GetFunctor().GetCalFactor(); } protected: /** Constructor */ - TerraSarBrightnessImageFilter(); + TerraSarBrightnessImageFilter(){}; /** Destructor */ virtual ~TerraSarBrightnessImageFilter() {}; diff --git a/Code/Radiometry/otbTerraSarBrightnessImageFilter.txx b/Code/Radiometry/otbTerraSarBrightnessImageFilter.txx index 1e786dad8a..86095a183f 100644 --- a/Code/Radiometry/otbTerraSarBrightnessImageFilter.txx +++ b/Code/Radiometry/otbTerraSarBrightnessImageFilter.txx @@ -19,29 +19,32 @@ #define __otbTerraSarBrightnessImageFilter_txx #include "otbTerraSarBrightnessImageFilter.h" -#include "otbImageMetadataInterfaceFactory.h" -#include "otbImageMetadataInterfaceBase.h" - +//#include "otbImageMetadataInterfaceFactory.h" +//#include "otbImageMetadataInterfaceBase.h" +#include "otbTerraSarImageMetadataInterface.h" namespace otb { -/** - * Constructor - */ -template <class TInputImage, class TOutputImage> -TerraSarBrightnessImageFilter<TInputImage,TOutputImage> -::TerraSarBrightnessImageFilter() -{ -// m_CalFactor = 1.; -} - template <class TInputImage, class TOutputImage> void TerraSarBrightnessImageFilter<TInputImage,TOutputImage> ::BeforeThreadedGenerateData() { Superclass::BeforeThreadedGenerateData(); + + // If the user doesn't set it AND the metadata is available, set calFactor using image metadata + std::cout<<this->GetCalFactor()<<std::endl; + if (this->GetCalFactor() == itk::NumericTraits<double>::min()) + { + /** TODO : use a factory for RADAR image metadata interface */ + TerraSarImageMetadataInterface::Pointer lImageMetadata = otb::TerraSarImageMetadataInterface::New(); + if( !lImageMetadata->CanRead(this->GetInput()->GetMetaDataDictionary()) ) + { + itkExceptionMacro(<<"Invalid input image. Only TerraSar images are supproted"); + } + this->SetCalFactor( lImageMetadata->GetCalibrationFactor(this->GetInput()->GetMetaDataDictionary()) ); + } } } diff --git a/Code/Radiometry/otbTerraSarFunctors.txx b/Code/Radiometry/otbTerraSarFunctors.txx index 20ee8aab46..f59941b2f4 100644 --- a/Code/Radiometry/otbTerraSarFunctors.txx +++ b/Code/Radiometry/otbTerraSarFunctors.txx @@ -33,7 +33,7 @@ template <class TInput, class TOutput> TerraSarBrightnessImageFunctor<TInput, TOutput> ::TerraSarBrightnessImageFunctor() { - m_CalFactor = 1.; + m_CalFactor = itk::NumericTraits<double>::min(); } diff --git a/Testing/Code/IO/otbTerraSarImageMetadataInterface.cxx b/Testing/Code/IO/otbTerraSarImageMetadataInterface.cxx index 26f4652b52..40bc04bed5 100644 --- a/Testing/Code/IO/otbTerraSarImageMetadataInterface.cxx +++ b/Testing/Code/IO/otbTerraSarImageMetadataInterface.cxx @@ -37,12 +37,42 @@ int otbTerraSarImageMetadataInterface (int argc, char* argv[]) typedef otb::VectorImage< double, 2 > InputImageType; typedef otb::ImageFileReader< InputImageType > ImageReaderType; + typedef std::vector<double> DoubleVectorType; + typedef std::vector<DoubleVectorType> DoubleVectorVectorType; + typedef std::vector<unsigned int> UIntVectorType; + + ImageReaderType::Pointer reader = ImageReaderType::New(); reader->SetFileName( inputFilename ); reader->UpdateOutputInformation(); otb::TerraSarImageMetadataInterface::Pointer lImageMetadata = otb::TerraSarImageMetadataInterface::New(); + lImageMetadata->GetNoise(reader->GetOutput()->GetMetaDataDictionary())->print(std::cout); + std::cout<<lImageMetadata->GetNumberOfNoiseRecords(reader->GetOutput()->GetMetaDataDictionary())<<std::endl; + UIntVectorType deg = lImageMetadata->GetNoisePolynomialDegrees(reader->GetOutput()->GetMetaDataDictionary()); + DoubleVectorVectorType coeffs = lImageMetadata->GetNoisePolynomialCoefficientsList(reader->GetOutput()->GetMetaDataDictionary()); + + DoubleVectorType mins = lImageMetadata->GetNoiseValidityRangeMinList(reader->GetOutput()->GetMetaDataDictionary()); + DoubleVectorType maxs = lImageMetadata->GetNoiseValidityRangeMaxList(reader->GetOutput()->GetMetaDataDictionary()); + DoubleVectorType ref = lImageMetadata->GetNoiseReferencePointList(reader->GetOutput()->GetMetaDataDictionary()); + DoubleVectorType time = lImageMetadata->GetNoiseTimeUTCList(reader->GetOutput()->GetMetaDataDictionary()); + + for( unsigned int i=0; i<deg.size(); i++ ) + { + std::cout<<"~~~~~~~ Polynome "<<i<<" ( degree: "<<deg[i]<<")"<<std::endl; + for( unsigned int j=0; j<coeffs[i].size(); j++ ) + { + std::cout<<coeffs[i][j]<<" "; + } + std::cout<<std::endl; + std::cout<<mins[i]<<std::endl; + std::cout<<maxs[i]<<std::endl; + std::cout<<ref[i]<<std::endl; + std::cout<<time[i]<<std::endl; + } + std::cout<<lImageMetadata->GetRadarFrequency(reader->GetOutput()->GetMetaDataDictionary())<<std::endl; + std::ofstream file; file.open(outputFilename); file<<"GetSensorID: "<<lImageMetadata->GetSensorID(reader->GetOutput()->GetMetaDataDictionary())<<std::endl; diff --git a/Testing/Code/Radiometry/CMakeLists.txt b/Testing/Code/Radiometry/CMakeLists.txt index 599ea0d7f7..b3bba93307 100644 --- a/Testing/Code/Radiometry/CMakeLists.txt +++ b/Testing/Code/Radiometry/CMakeLists.txt @@ -1076,8 +1076,20 @@ ADD_TEST(raTvTerraSarBrightnessImageFilterTest ${RADIOMETRY_TESTS9} otbTerraSarBrightnessImageFilterTest ${INPUTDATA}/ExtractIMAGE_HH_SRA_strip_012.tif ${TEMP}/raTvTerraSarBrightnessImageFilterTest.tif + 1 # set calfactor ) +IF(OTB_DATA_USE_LARGEINPUT) +ADD_TEST(raTvTerraSarBrightnessImageFilterUPSALA ${RADIOMETRY_TESTS9} + --compare-image ${EPSILON} + ${BASELINE}//raTvTerraSarBrightnessImageFilter_UPSALA.tif + ${TEMP}//raTvTerraSarBrightnessImageFilter_UPSALA.tif + otbTerraSarBrightnessImageFilterTest + ${LARGEINPUT}/TERRASARX/UPSALA_GLACIER/TSX1_SAR__MGD/IMAGEDATA/IMAGE_HH_SRA_strip_012.tif + ${TEMP}/raTvTerraSarBrightnessImageFilter_UPSALA.tif + 0 # don't set calfactor +) +ENDIF(OTB_DATA_USE_LARGEINPUT) # A enrichir diff --git a/Testing/Code/Radiometry/otbTerraSarBrightnessImageFilterTest.cxx b/Testing/Code/Radiometry/otbTerraSarBrightnessImageFilterTest.cxx index 165a922924..26c5c9bfa1 100644 --- a/Testing/Code/Radiometry/otbTerraSarBrightnessImageFilterTest.cxx +++ b/Testing/Code/Radiometry/otbTerraSarBrightnessImageFilterTest.cxx @@ -44,15 +44,14 @@ int otbTerraSarBrightnessImageFilterTest(int argc, char * argv[]) reader->UpdateOutputInformation(); - std::cout<<reader->GetOutput()->GetNumberOfComponentsPerPixel()<<std::endl; - - - filter->SetCalFactor( 10 ); + //std::cout<<reader->GetOutput()->GetNumberOfComponentsPerPixel()<<std::endl; + if( atoi(argv[3]) == 1 ) + filter->SetCalFactor( 10 ); filter->SetInput(reader->GetOutput()); writer->SetInput(filter->GetOutput()); - writer->SetNumberOfStreamDivisions(1); + writer->Update(); return EXIT_SUCCESS; diff --git a/Utilities/otbossimplugins/ossim/ossimTerraSarModel.cpp b/Utilities/otbossimplugins/ossim/ossimTerraSarModel.cpp index 7ac33e4b9d..5d49f2b907 100644 --- a/Utilities/otbossimplugins/ossim/ossimTerraSarModel.cpp +++ b/Utilities/otbossimplugins/ossim/ossimTerraSarModel.cpp @@ -53,6 +53,8 @@ static const char POL_LAYER[] = "polLayer"; static const char CALIBRATION_CALFACTOR[] = "calibration.calibrationConstant.calFactor"; +static const char RADAR_FREQUENCY[] = "radarFrequency"; + using ::ossimString; using ::ossimXmlDocument; @@ -84,9 +86,10 @@ ossimplugins::ossimTerraSarModel::ossimTerraSarModel() _polLayer(), _noise(0), _calFactor(0.), + _radarFrequency(0.), _azStartTime(), _azStopTime(), - _generationTime(), + _generationTime(), theProductXmlFile() { } @@ -109,6 +112,7 @@ ossimplugins::ossimTerraSarModel::ossimTerraSarModel( _polLayer(rhs._polLayer), _noise(rhs._noise), _calFactor(rhs._calFactor), + _radarFrequency(rhs._radarFrequency), _azStartTime(rhs._azStartTime), _azStopTime(rhs._azStopTime), _generationTime(rhs._generationTime), @@ -149,183 +153,184 @@ double ossimplugins::ossimTerraSarModel::getSlantRangeFromGeoreferenced(double c bool ossimplugins::ossimTerraSarModel::open(const ossimFilename& file) { - static const char MODULE[] = "ossimplugins::ossimTerraSarModel::open"; - - bool debug = false; - - if (debug) - cout << "Opening file" << endl; - - if (traceDebug()) - { + static const char MODULE[] = "ossimplugins::ossimTerraSarModel::open"; + + bool debug = false; + + if (debug) + cout << "Opening file" << endl; + + if (traceDebug()) + { ossimNotify(ossimNotifyLevel_DEBUG) - << MODULE << " entered...\n" - << "file: " << file << "\n"; - } - - bool result = false; - ossimFilename xmlfile; - bool findMeatadataFile = findTSXLeader(file, xmlfile); - - if(findMeatadataFile) - { + << MODULE << " entered...\n" + << "file: " << file << "\n"; + } + + bool result = false; + ossimFilename xmlfile; + bool findMeatadataFile = findTSXLeader(file, xmlfile); + + if(findMeatadataFile) + { //--- // Instantiate the XML parser: //--- ossimXmlDocument* xdoc = new ossimXmlDocument(); if ( xdoc->openFile(xmlfile) ) - { - - ossimTerraSarProductDoc tsDoc; - - result = tsDoc.isTerraSarX(xdoc); - if (debug) - cout << "result of IsTSX " << result << endl; - - if (result) - { - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG) - << "isTerraSarX...\n"; - } - - // Set the base class number of lines and samples - result = tsDoc.initImageSize(xdoc, theImageSize); - - if (debug) - cout << "result of initImageSize" << result << endl; - - - if (result) - { - - // Set the base class clip rect. - theImageClipRect = ossimDrect( - 0, 0, - theImageSize.x-1, theImageSize.y-1); - } - - // Set the sub image offset. tmp hard coded (drb). - theSubImageOffset.x = 0.0; - theSubImageOffset.y = 0.0; - - // Set the image ID to the scene ID. - if (result) - { - result = tsDoc.getSceneId(xdoc, theImageID); - if (debug) - cout << "result of getting SceneID" << result << endl; - } - - // Set the sensor ID to the mission ID. - if (result) - { - result = tsDoc.getMission(xdoc, theSensorID); - - if (debug) - cout << "result of getting MissionID...." << result << endl; - } - - // Set the base class gsd: - result = tsDoc.initGsd(xdoc, theGSD); - - if (debug) - cout << "result of getting GSD...." << result << endl; - - if (result) - { - theMeanGSD = (theGSD.x + theGSD.y)/2.0; - } - - if (result) - { - /*result = */initSRGR(xdoc, tsDoc); - - if (debug) - cout << "result of initSRGR.... " << result << endl; - - if (result) - { - result = initPlatformPosition(xdoc, tsDoc); - - if (debug) - cout << "result of initPlatformPosition.... " << result << endl; - - if (result) - { - result = initSensorParams(xdoc, tsDoc); - - if (debug) - cout << "result of initSensorParams.... " << result << endl; - - if (result) - { - result = initRefPoint(xdoc, tsDoc); - if (debug) - cout << "result of initRefPoint.... " << result << endl; - - 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(); - if (result) - { - result = tsDoc.getAzimuthStartTime(xdoc, _azStartTime); - if (result) - { - result = tsDoc.getAzimuthStopTime(xdoc, _azStopTime); - if (result) - { - result = tsDoc.getGenerationTime(xdoc, _generationTime); - } - } - } - } - } - } - } - } - } - } - } - } - } - - - } // matches: if ( xdoc->openFile(file) ) + { + ossimTerraSarProductDoc tsDoc; + + result = tsDoc.isTerraSarX(xdoc); + if (debug) + cout << "result of IsTSX " << result << endl; + + if (result) + { + if (traceDebug()) + { + ossimNotify(ossimNotifyLevel_DEBUG) + << "isTerraSarX...\n"; + } + + // Set the base class number of lines and samples + result = tsDoc.initImageSize(xdoc, theImageSize); + + if (debug) + cout << "result of initImageSize" << result << endl; + + + if (result) + { + // Set the base class clip rect. + theImageClipRect = ossimDrect(0, 0, theImageSize.x-1, theImageSize.y-1); + } + + // Set the sub image offset. tmp hard coded (drb). + theSubImageOffset.x = 0.0; + theSubImageOffset.y = 0.0; + + // Set the image ID to the scene ID. + if (result) + { + result = tsDoc.getSceneId(xdoc, theImageID); + if (debug) + cout << "result of getting SceneID" << result << endl; + } + + // Set the sensor ID to the mission ID. + if (result) + { + result = tsDoc.getMission(xdoc, theSensorID); + + if (debug) + cout << "result of getting MissionID...." << result << endl; + } + + // Set the base class gsd: + result = tsDoc.initGsd(xdoc, theGSD); + + if (debug) + cout << "result of getting GSD...." << result << endl; + + if (result) + { + theMeanGSD = (theGSD.x + theGSD.y)/2.0; + } + + if (result) + { + /*result = */initSRGR(xdoc, tsDoc); + + if (debug) + cout << "result of initSRGR.... " << result << endl; + + if (result) + { + result = initPlatformPosition(xdoc, tsDoc); + + if (debug) + cout << "result of initPlatformPosition.... " << result << endl; + + if (result) + { + result = initSensorParams(xdoc, tsDoc); + + if (debug) + cout << "result of initSensorParams.... " << result << endl; + + if (result) + { + result = initRefPoint(xdoc, tsDoc); + if (debug) + cout << "result of initRefPoint.... " << result << endl; + + 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(); + if (result) + { + result = tsDoc.getRadarFrequency(xdoc, s); + _radarFrequency= s.toFloat64(); + if (result) + { + result = tsDoc.getAzimuthStartTime(xdoc, _azStartTime); + if (result) + { + result = tsDoc.getAzimuthStopTime(xdoc, _azStopTime); + if (result) + { + result = tsDoc.getGenerationTime(xdoc, _generationTime); + } + } + } + } + } + } + } + } + } + } + } + } + } + } + + + } // matches: if ( xdoc->openFile(file) ) delete xdoc; xdoc = 0; - } // matches: if ( file.exists() ) - - - if (debug) - cout << "Initialized values...." << endl; - - - if (result) - { + } // matches: if ( file.exists() ) + + + if (debug) + cout << "Initialized values...." << endl; + + + if (result) + { theProductXmlFile = xmlfile; - + if (debug) - cout << "theProductXmlFile : " << xmlfile << endl; - + cout << "theProductXmlFile : " << xmlfile << endl; + // Assign the ossimSensorModel::theBoundGndPolygon ossimGpt ul; ossimGpt ur; @@ -436,6 +441,7 @@ bool ossimplugins::ossimTerraSarModel::saveState(ossimKeywordlist& kwl, _noise->saveState(kwl,prefix); kwl.add(prefix, CALIBRATION_CALFACTOR, ossimString::toString(_calFactor).c_str()); + kwl.add(prefix, RADAR_FREQUENCY, ossimString::toString(_radarFrequency).c_str()); kwl.add(prefix, AZ_START_TIME, _azStartTime.c_str()); kwl.add(prefix, AZ_STOP_TIME, _azStopTime.c_str()); kwl.add(prefix, GENERATION_TIME, _generationTime.c_str()); @@ -746,6 +752,24 @@ bool ossimplugins::ossimTerraSarModel::loadState (const ossimKeywordlist &kwl, result = false; } + lookup = kwl.find(prefix, RADAR_FREQUENCY); + if (lookup) + { + s = lookup; + _radarFrequency= s.toDouble(); + } + else + { + if (traceDebug()) + { + ossimNotify(ossimNotifyLevel_WARN) + << MODULE + << "\nRequired keyword not found: " + << RADAR_FREQUENCY << "\n"; + } + result = false; + } + lookup = kwl.find(prefix, AZ_START_TIME); if (lookup) { @@ -860,6 +884,7 @@ std::ostream& ossimplugins::ossimTerraSarModel::print(std::ostream& out) const } out << CALIBRATION_CALFACTOR << ": " << _calFactor << "\n"; + out << RADAR_FREQUENCY << ": " << _radarFrequency<< "\n"; out << AZ_START_TIME << ": " << _azStartTime << "\n"; out << AZ_STOP_TIME << ": " << _azStopTime << "\n"; out << GENERATION_TIME << ": " << _generationTime << "\n"; diff --git a/Utilities/otbossimplugins/ossim/ossimTerraSarModel.h b/Utilities/otbossimplugins/ossim/ossimTerraSarModel.h index 3e2125527a..32106085a1 100644 --- a/Utilities/otbossimplugins/ossim/ossimTerraSarModel.h +++ b/Utilities/otbossimplugins/ossim/ossimTerraSarModel.h @@ -239,6 +239,11 @@ namespace ossimplugins */ double _calFactor; + /** + * @brief centerFrequency (instrument node). + */ + double _radarFrequency; + /** * @brief Azimuthal Start Time (Start acquisition time). */ diff --git a/Utilities/otbossimplugins/ossim/ossimTerraSarProductDoc.cpp b/Utilities/otbossimplugins/ossim/ossimTerraSarProductDoc.cpp index c60045bf72..0aa3227bcd 100644 --- a/Utilities/otbossimplugins/ossim/ossimTerraSarProductDoc.cpp +++ b/Utilities/otbossimplugins/ossim/ossimTerraSarProductDoc.cpp @@ -718,8 +718,8 @@ bool ossimplugins::ossimTerraSarProductDoc::getRadiometricCorrection( } - bool ossimplugins::ossimTerraSarProductDoc::getReferencePoint( - const ossimXmlDocument* xdoc, ossimString& s) const +bool ossimplugins::ossimTerraSarProductDoc::getReferencePoint( + const ossimXmlDocument* xdoc, ossimString& s) const { ossimString path = "/level1Product/productSpecific/projectedImageInfo/slantToGroundRangeProjection/referencePoint"; return ossim::getPath(path, xdoc, s); @@ -869,7 +869,6 @@ bool ossimplugins::ossimTerraSarProductDoc::getAzimuthStartTime( bool ossimplugins::ossimTerraSarProductDoc::getAzimuthStopTime( const ossimXmlDocument* xdoc, ossimString& s) const { - std::cout<<"getAzimuthStopTimegetAzimuthStopTimegetAzimuthStopTimegetAzimuthStopTimegetAzimuthStopTimeres"<<std::endl; ossimString path = "/level1Product/productInfo/sceneInfo/stop/timeUTC"; @@ -881,9 +880,8 @@ bool ossimplugins::ossimTerraSarProductDoc::getAzimuthStopTime( { ossimNotify(ossimNotifyLevel_DEBUG)<< "Node \"/level1Product/productInfo/sceneInfo/stop/timeUTC\" invalid, trying \"/level1Product/instrument/settings/rxGainSetting/stopTimeUTC\"...\n"; } - path = "/level1Product/instrument/settings/settingRecord/dataSegment segmentID/stopTimeUTC";// rxGainSetting/stopTimeUTC"; + path = "/level1Product/instrument/settings/settingRecord/dataSegment segmentID/stopTimeUTC"; res = ossim::getPath(path, xdoc, s); - std::cout<<res<<std::endl; } return res; @@ -1057,7 +1055,13 @@ bool ossimplugins::ossimTerraSarProductDoc::getCalFactor( "/level1Product/calibration/calibrationConstant/calFactor"; return ossim::getPath(path, xdoc, s); } - +bool ossimplugins::ossimTerraSarProductDoc::getRadarFrequency( + const ossimXmlDocument* xdoc, ossimString& s) const +{ + ossimString path = + "/level1Product/instrument/radarParameters/centerFrequency"; + return ossim::getPath(path, xdoc, s); +} bool ossimplugins::ossimTerraSarProductDoc::initNoise( const ossimXmlDocument* xdoc, ossimplugins::Noise* noise) const { diff --git a/Utilities/otbossimplugins/ossim/ossimTerraSarProductDoc.h b/Utilities/otbossimplugins/ossim/ossimTerraSarProductDoc.h index 0f4f1b727d..9a9c1fd3da 100644 --- a/Utilities/otbossimplugins/ossim/ossimTerraSarProductDoc.h +++ b/Utilities/otbossimplugins/ossim/ossimTerraSarProductDoc.h @@ -218,6 +218,9 @@ namespace ossimplugins ossimString& s) const; bool getCalFactor(const ossimXmlDocument* xdoc, ossimString& s) const; + bool getRadarFrequency(const ossimXmlDocument* xdoc, + ossimString& s) const; + /** * @brief Method to initialize Noise object from -- GitLab