diff --git a/Testing/Code/IO/CMakeLists.txt b/Testing/Code/IO/CMakeLists.txt index 0440ce9b80a70ae7cf813c8505873d69e40b458f..aee6220453e2477c6403948703624e280017c638 100644 --- a/Testing/Code/IO/CMakeLists.txt +++ b/Testing/Code/IO/CMakeLists.txt @@ -2455,6 +2455,18 @@ ADD_TEST(ioTvImageKeywordlistRadarSat1 ${IO_TESTS18} ${TEMP}/ioTvImageKeywordlistRadarSat1_saveState_loadState.txt ) +ADD_TEST(ioTvImageKeywordlistRadarSat1_vdf ${IO_TESTS18} + --ignore-order --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/VDF_DAT.001 + ${TEMP}/ioTvImageKeywordlistRadarSat1.txt + ${TEMP}/ioTvImageKeywordlistRadarSat1_saveState_loadState.txt +) + ADD_TEST(ioTvImageKeywordlistSardegnaRadarSat1 ${IO_TESTS18} --ignore-order --compare-n-ascii ${NOTOL} 2 ${BASELINE_FILES}/ioTvImageKeywordlistSardegnaRadarSat1.txt @@ -2467,6 +2479,18 @@ ADD_TEST(ioTvImageKeywordlistSardegnaRadarSat1 ${IO_TESTS18} ${TEMP}/ioTvImageKeywordlistSardegnaRadarSat1_saveState_loadState.txt ) +ADD_TEST(ioTvImageKeywordlistSardegnaRadarSat1_vdf ${IO_TESTS18} + --ignore-order --compare-n-ascii ${NOTOL} 2 + ${BASELINE_FILES}/ioTvImageKeywordlistSardegnaRadarSat1.txt + ${TEMP}/ioTvImageKeywordlistSardegnaRadarSat1.txt + ${BASELINE_FILES}/ioTvImageKeywordlistSardegnaRadarSat1.txt + ${TEMP}/ioTvImageKeywordlistSardegnaRadarSat1_saveState_loadState.txt + otbImageKeywordlist + ${LARGEDATA}/RADARSAT1/SARDEGNA/scene01/vdf_dat.001 + ${TEMP}/ioTvImageKeywordlistSardegnaRadarSat1.txt + ${TEMP}/ioTvImageKeywordlistSardegnaRadarSat1_saveState_loadState.txt +) + ADD_TEST(ioTvImageKeywordlistRadarSat2 ${IO_TESTS18} --ignore-order --compare-n-ascii ${NOTOL} 2 ${BASELINE_FILES}/ioTvImageKeywordlistRadarSat2.txt diff --git a/Testing/Code/IO/otbImageKeywordlist.cxx b/Testing/Code/IO/otbImageKeywordlist.cxx index 6cbdc45df0661d5e8c832c21aa28d7dfa9a44fae..09c0a9488c3e824154a44ff3e59f2d314627fa19 100644 --- a/Testing/Code/IO/otbImageKeywordlist.cxx +++ b/Testing/Code/IO/otbImageKeywordlist.cxx @@ -83,7 +83,18 @@ int otbImageKeywordlist(int argc, char* argv[]) otb_kwl.convertToOSSIMKeywordlist(geom_kwl2); hasMetaData = projection->loadState(geom_kwl2); + if (!hasMetaData) + { + std::cerr << "ERROR: projection loadState return with a false flag !" << std::endl; + return EXIT_FAILURE; + } hasMetaData = projection->saveState(geom_kwl3); + if (!hasMetaData) + { + std::cerr << "ERROR: projection saveState return with a false flag !" << std::endl; + return EXIT_FAILURE; + } + otb::ImageKeywordlist otb_kwl2; otb_kwl2.SetKeywordlist(geom_kwl3); diff --git a/Utilities/otbossimplugins/ossim/ossimRadarSatModel.cpp b/Utilities/otbossimplugins/ossim/ossimRadarSatModel.cpp index 92693b57d286d020dea48b76ed12a19acc5aed8d..cadfd1f502949622f2178789cd1e1c56d1b84a8a 100644 --- a/Utilities/otbossimplugins/ossim/ossimRadarSatModel.cpp +++ b/Utilities/otbossimplugins/ossim/ossimRadarSatModel.cpp @@ -30,6 +30,10 @@ #include <RadarSat/Data/DataFactory.h> #include <RadarSat/Data/ImageOptionsFileDescriptor.h> + +#include <RadarSat/VolumeDir/VolumeDescriptorRecord.h> +#include <RadarSat/VolumeDir/VolumeDirFactory.h> + #include <RadarSat/Data/ProcessedDataRecord.h> #include <RadarSat/CommonRecord/ProcessingParameters.h> #include <RadarSat/Leader/PlatformPositionData.h> @@ -123,9 +127,42 @@ bool ossimRadarSatModel::open(const ossimFilename& file) bool retValue = true; ossimFilename tempFilename = file; + /* - * Creation of the class allowing to store the metadata from the Volume Directory File + * Detect if we use vdf file or dat file */ + ossimFilename dataFilePath; + ossimFilename volumeDirectoryFilePath; + std::string input_file = file; + string::size_type loc_DAT = input_file.find( "DAT_01", 0 ); + string::size_type loc_dat = input_file.find( "dat_01", 0 ); + if ( (loc_DAT != string::npos ) || ( loc_dat != string::npos ) ) + { + dataFilePath = input_file.c_str(); + if (loc_DAT != string::npos ) input_file.replace(loc_DAT, 6, "VDF_DAT"); + if (loc_dat != string::npos ) input_file.replace(loc_dat, 6, "vdf_dat"); + volumeDirectoryFilePath = input_file.c_str(); + } + else + { + string::size_type loc_VDF = input_file.find( "VDF_DAT", 0 ); + string::size_type loc_vdf = input_file.find( "vdf_dat", 0 ); + if ( (loc_VDF != string::npos ) || ( loc_vdf != string::npos ) ) + { + volumeDirectoryFilePath = input_file.c_str(); + if (loc_VDF != string::npos ) input_file.replace(loc_VDF, 7, "DAT_01"); + if (loc_vdf != string::npos ) input_file.replace(loc_vdf, 7, "dat_01"); + dataFilePath = input_file.c_str(); + } + else + { + ossimNotify(ossimNotifyLevel_DEBUG) + << "File Name not coherent (searching for *DAT_01* or *dat_01* or *vdf_dat* or *VDF_DAT* ) : " << file << std::endl; + return false; + } + } + + //Creation of the class allowing to store the metadata from the Volume Directory File if (_volumeDir != NULL) { delete _volumeDir; @@ -133,9 +170,7 @@ bool ossimRadarSatModel::open(const ossimFilename& file) } _volumeDir = new VolumeDir(); - /* - * Creation of the class allowing to store the metadata from the Data file - */ + //Creation of the class allowing to store the metadata from the Data file if (_data != NULL) { delete _data; @@ -143,9 +178,7 @@ bool ossimRadarSatModel::open(const ossimFilename& file) } _data = new Data(); - /* - * Creation of the class allowing to store the metadata from the Leader file - */ + //Creation of the class allowing to store the metadata from the Leader file if(_leader != NULL) { delete _leader; @@ -153,9 +186,7 @@ bool ossimRadarSatModel::open(const ossimFilename& file) } _leader = new Leader(); - /* - * Creation of the class allowing to store the metadata from the Trailer file - */ + // Creation of the class allowing to store the metadata from the Trailer file if(_trailer != NULL) { delete _trailer; @@ -163,57 +194,105 @@ bool ossimRadarSatModel::open(const ossimFilename& file) } _trailer = new Trailer(); - RadarSatRecordHeader header; - DataFactory factory; - ifstream dataFile (tempFilename, ios::in|ios::binary); - dataFile>>header; - if(dataFile.eof()) + + RadarSatRecordHeader headerVDF; + VolumeDirFactory factoryVDF; + ifstream volumeDirFile (volumeDirectoryFilePath, ios::in|ios::binary); + volumeDirFile>>headerVDF; + if(volumeDirFile.eof()) { - dataFile.close(); + volumeDirFile.close(); retValue = false; } else { if(traceDebug()) { - ossimNotify(ossimNotifyLevel_DEBUG) - << "Begin reading DAT file" << std::endl; + ossimNotify(ossimNotifyLevel_DEBUG) << "Begin reading VDF file" << std::endl; } - RadarSatRecord* record = factory.Instanciate(header.get_rec_seq()); - if (record != NULL && header.get_rec_seq() == 1) + RadarSatRecord* recordVDF = factoryVDF.Instanciate(headerVDF.get_rec_seq()); + if (recordVDF != NULL && headerVDF.get_rec_seq() == 1) { - record->Read(dataFile); - /* - * Tests if the input File is a valid Radarsat DAT file - */ - if ( (((ImageOptionsFileDescriptor*)record)->get_file_name()).substr(0,10) == "RSAT-1-SAR" ) - { - /*m_SubProduct = (((ImageOptionsFileDescriptor*)record)->get_file_name()).substr(11,3); - std::cout << "m_SubProduct: " << m_SubProduct << std::endl;*/ - /* - * Reading of the remaining of the data file - */ - dataFile.close(); - dataFile.open(tempFilename, ios::in|ios::binary); - - dataFile>>*_data; - - // insertion dans le container de type map - _data->InsertRecord(header.get_rec_seq(), record); + recordVDF->Read(volumeDirFile); - dataFile.close(); + //Test if the input File is a valid Radarsat VDF file + if ((((VolumeDescriptorRecord*) recordVDF)->get_logvol_id()).substr(0, 10) == "RSAT-1-SAR") + { + std::string subProduct = (((VolumeDescriptorRecord*) recordVDF)->get_logvol_id()).substr(11, 3); + if (subProduct == "RAW") + std::cout << "FATAL_ERROR: RAW format is not supported" <<std::endl; + else if (subProduct == "SCN") + std::cout << "WARNING: SCN format is supported but not tested" <<std::endl; + else if (subProduct == "SCW") + std::cout << "MSG: SCW format is supported and tested" <<std::endl; + else if (subProduct == "SGF") + std::cout << "MSG: SGF format is supported and tested" <<std::endl; + else if (subProduct == "SGX") + std::cout << "WARNING: SGX format is supported but not tested" <<std::endl; + else if (subProduct == "SLC") + std::cout << "WARNING: SLC format is supported but not tested" <<std::endl; + else if (subProduct == "SPG") + std::cout << "FATAL_ERROR: SPG format is not supported" <<std::endl; + else if (subProduct == "SSG") + std::cout << "FATAL_ERROR: SSG format is not supported" <<std::endl; + + + + //Reading of the remaining of the volume directory file + + volumeDirFile.close(); + volumeDirFile.open(volumeDirectoryFilePath, ios::in | ios::binary); + volumeDirFile >> *_volumeDir; + volumeDirFile.close(); + + if (traceDebug()) + { + ossimNotify(ossimNotifyLevel_DEBUG) << "End reading VDF file" << std::endl; + } - if(traceDebug()) + RadarSatRecordHeader headerDAT; + DataFactory factoryDAT; + ifstream dataFile (dataFilePath, ios::in|ios::binary); + dataFile>>headerDAT; + if(dataFile.eof()) { - ossimNotify(ossimNotifyLevel_DEBUG) - << "End reading DAT file" << std::endl; + dataFile.close(); + retValue = false; } + else + { + if(traceDebug()) + { + ossimNotify(ossimNotifyLevel_DEBUG)<< "Begin reading DAT file" << std::endl; + } + + RadarSatRecord* recordDAT = factoryDAT.Instanciate(headerDAT.get_rec_seq()); + if (recordDAT != NULL && headerDAT.get_rec_seq() == 1) + { + recordDAT->Read(dataFile); + dataFile.close(); + /* + * Reading the remaining of the data file + */ + dataFile.open(dataFilePath, ios::in|ios::binary); + dataFile>>*_data; + dataFile.close(); + + _data->InsertRecord(headerDAT.get_rec_seq(), recordDAT); + + if(traceDebug()) + { + ossimNotify(ossimNotifyLevel_DEBUG) << "End reading DAT file" << std::endl; + } + } // TODO move to end + }// TODO move to end + /* * Leader file path construction from the DAT file path * Warning : the filename case has to be homogenous */ - std::string leader_file = file; + std::string leader_file = dataFilePath; string::size_type loc = leader_file.find( "DAT_01", 0 ); if( loc != string::npos ) leader_file.replace(loc, 6, "LEA_01" ); // upper case test else @@ -222,24 +301,20 @@ bool ossimRadarSatModel::open(const ossimFilename& file) if( loc != string::npos ) leader_file.replace(loc, 6, "lea_01" ); // lower case test else { - ossimNotify(ossimNotifyLevel_DEBUG) - << "File Name not coherent (searching for *DAT_01* or *dat_01*) : " << file << std::endl; + ossimNotify(ossimNotifyLevel_DEBUG) << "File Name not coherent (searching for *DAT_01* or *dat_01*) : " << file << std::endl; } } ossimFilename leaderFilePath(leader_file); - if (!leaderFilePath.exists()) { - ossimNotify(ossimNotifyLevel_DEBUG) - << "Leader file not found (searching for *lea_01* coherent with *dat_01*) : " << file << std::endl; + ossimNotify(ossimNotifyLevel_DEBUG) << "Leader file not found (searching for *lea_01* coherent with *dat_01*) : " << file << std::endl; retValue = false; } else { if(traceDebug()) { - ossimNotify(ossimNotifyLevel_DEBUG) - << "Begin reading Leader file" << std::endl; + ossimNotify(ossimNotifyLevel_DEBUG) << "Begin reading Leader file" << std::endl; } /* * Leader file data reading @@ -249,15 +324,15 @@ bool ossimRadarSatModel::open(const ossimFilename& file) leaderFile.close(); if(traceDebug()) { - ossimNotify(ossimNotifyLevel_DEBUG) - << "End reading Leader file" << std::endl; + ossimNotify(ossimNotifyLevel_DEBUG) << "End reading Leader file" << std::endl; } } + /* * Trailer file path construction from the DAT file path * Warning : the filename case has to be homogenous */ - std::string trailer_file = file; + std::string trailer_file = dataFilePath; loc = trailer_file.find( "DAT_01", 0 ); if( loc != string::npos ) trailer_file.replace(loc, 6, "TRA_01" ); // upper case test else @@ -266,24 +341,20 @@ bool ossimRadarSatModel::open(const ossimFilename& file) if( loc != string::npos ) trailer_file.replace(loc, 6, "tra_01" ); // lower case test else { - ossimNotify(ossimNotifyLevel_DEBUG) - << "File Name not coherent (searching for *DAT_01* or *dat_01*) : " << file << std::endl; + ossimNotify(ossimNotifyLevel_DEBUG) << "File Name not coherent (searching for *DAT_01* or *dat_01*) : " << file << std::endl; } } ossimFilename trailerFilePath(trailer_file); - if (!trailerFilePath.exists()) { - ossimNotify(ossimNotifyLevel_DEBUG) - << "Trailer file not found (searching for *tra_01* coherent with *dat_01*) : " << file << std::endl; - retValue = false; + ossimNotify(ossimNotifyLevel_DEBUG) << "Trailer file not found (searching for *tra_01* coherent with *dat_01*) : " << file << std::endl; + retValue = false; } else { if(traceDebug()) { - ossimNotify(ossimNotifyLevel_DEBUG) - << "Begin reading Trailer file" << std::endl; + ossimNotify(ossimNotifyLevel_DEBUG) << "Begin reading Trailer file" << std::endl; } /* * Trailer file data reading @@ -293,29 +364,28 @@ bool ossimRadarSatModel::open(const ossimFilename& file) trailerFile.close(); if(traceDebug()) { - ossimNotify(ossimNotifyLevel_DEBUG) - << "End reading Trailer file" << std::endl; + ossimNotify(ossimNotifyLevel_DEBUG) << "End reading Trailer file" << std::endl; } } } else { - dataFile.close(); + volumeDirFile.close(); retValue = false; } } else { - dataFile.close(); + volumeDirFile.close(); retValue = false; } } if(traceDebug()) { - ossimNotify(ossimNotifyLevel_DEBUG) - << "ossimRadarSatTileSource::open() DEBUG: returning..." << std::endl; + ossimNotify(ossimNotifyLevel_DEBUG) << "ossimRadarSatTileSource::open() DEBUG: returning..." << std::endl; } + return retValue; }