diff --git a/app/otbSARMetadataCorrection.cxx b/app/otbSARMetadataCorrection.cxx index cf6833c6085ca7c033525a461b7132a75aa216f2..2c046fb51e4d6358fe7086fc558638e4c8143203 100644 --- a/app/otbSARMetadataCorrection.cxx +++ b/app/otbSARMetadataCorrection.cxx @@ -47,6 +47,15 @@ #endif +enum +{ + Mode_UserDefined, + Mode_GCP, + Mode_Orbits +}; + + + // Time/Date ossim typedef ossimplugins::time::ModifiedJulianDate TimeType; typedef ossimplugins::time::Duration DurationType; @@ -374,6 +383,18 @@ private: AddParameter(ParameterType_InputImage, "insar", "Input SAR image"); SetParameterDescription("insar", "SAR Image to extract initial metadata."); + // mode selection : gcp (auto) or fine orbits + AddParameter(ParameterType_Choice, "mode", "Parameters estimation modes"); + AddChoice("mode.auto", "User Defined"); + SetParameterDescription("mode.auto", "This mode allows you to fully modify default values : GCP corrections"); + AddChoice("mode.gcp", "GCP corrections"); + SetParameterDescription("mode.gcp", + "This mode allows you to automatically correct GCP into the output geom file"); + AddChoice("mode.orbits", "Fine orbits"); + SetParameterDescription("mode.orbits", + "This mode allows you to automatically retrieve the fine orbits and to save into a new geom file"); + + AddParameter(ParameterType_OutputFilename, "outkwl", "Write the OSSIM keywordlist to a geom file"); SetParameterDescription("outkwl", "This option allows extracting the OSSIM keywordlist of the image into a geom file."); MandatoryOff("outkwl"); @@ -386,7 +407,38 @@ private: void DoUpdateParameters() override { - // Nothing to do here : all parameters are independent + // Handle inputs following the mode + // chose by the user + switch (GetParameterInt("mode")) + { + case Mode_UserDefined: + { + EnableParameter("indem"); + EnableParameter("outkwl"); + + MandatoryOn("indem"); + MandatoryOff("outkwl"); + } + break; + case Mode_GCP: + { + EnableParameter("indem"); + EnableParameter("outkwl"); + + MandatoryOn("indem"); + MandatoryOff("outkwl"); + } + break; + case Mode_Orbits: + { + DisableParameter("indem"); + EnableParameter("outkwl"); + + MandatoryOff("indem"); + MandatoryOn("outkwl"); + } + break; + } // switch (GetParameterInt("mode") ) } void DoExecute() override @@ -400,129 +452,166 @@ private: // Get Sar keyWordList otb::ImageKeywordlist sar_kwl = SARPtr->GetImageKeywordlist(); + // Read information typedef otb::ImageMetadataInterfaceBase ImageMetadataInterfaceType; ImageMetadataInterfaceType::Pointer metadataInterface = ImageMetadataInterfaceFactory::CreateIMI(SARPtr->GetMetaDataDictionary()); - - // Change insar (???) - // SetParameterOutputImage("out", SARPtr); // Compilation error - // SARPtr->UpdateOutputInformation(); // Does not write (only for reader) - ////////// KyWordList (geom) ////////////// SARPtr->UpdateOutputInformation(); ImageKeywordlist outputKWL = SARPtr->GetImageKeywordlist(); + + bool doGcpCorrection = false; + bool doFineOrbits = false; + + // Get mode to adapt estimation according to user choice + switch (GetParameterInt("mode")) + { + case Mode_UserDefined: + { + doGcpCorrection = true; + } + break; + case Mode_GCP: + { + doGcpCorrection = true; + } + break; + case Mode_Orbits: + { + doFineOrbits = true; + } + break; + } // switch (GetParameterInt("mode") ) + + std::cout << "doGcpCorrection : " << doGcpCorrection << std::endl; + std::cout << "doFineOrbits : " << doFineOrbits << std::endl; + - // Check with metadataInterface and keyword List - int gcpcount = metadataInterface->GetGCPCount(); - if (gcpcount == 0) + if (doGcpCorrection) { - int gcpcount_kwl = std::atoi(outputKWL.GetMetadataByKey(GCP_NUMBER_KEY).c_str()); - if (gcpcount_kwl > 5) + std::cout << "Hello GCP correction !!" << std::endl; + + // Check with metadataInterface and keyword List + int gcpcount = metadataInterface->GetGCPCount(); + + if (gcpcount == 0) { - gcpcount = gcpcount_kwl; + int gcpcount_kwl = std::atoi(outputKWL.GetMetadataByKey(GCP_NUMBER_KEY).c_str()); + if (gcpcount_kwl > 5) + { + gcpcount = gcpcount_kwl; + } } - } - std::vector<double *> * vector_lonlat = new std::vector<double *>(); - std::vector<int *> * vector_colrow = new std::vector<int *>(); - std::vector<int> vector_ind; - std::vector<TimeType> vector_aziTime; - std::vector<double> vector_ranTime; + std::vector<double *> * vector_lonlat = new std::vector<double *>(); + std::vector<int *> * vector_colrow = new std::vector<int *>(); + std::vector<int> vector_ind; + std::vector<TimeType> vector_aziTime; + std::vector<double> vector_ranTime; - // Build the input (vector_lonlat) for GetClosestMNTHeight filter - if (gcpcount == 0) - { - // If no GCP => Retrieve Corners instead - // Get latitude and longitude for ur, ul, ll lr and center points - try + // Build the input (vector_lonlat) for GetClosestMNTHeight filter + if (gcpcount == 0) { - getCorners(metadataInterface->GetImageKeywordlist(), vector_lonlat, - vector_colrow, vector_ind, vector_aziTime, - vector_ranTime); + // If no GCP => Retrieve Corners instead + // Get latitude and longitude for ur, ul, ll lr and center points + try + { + getCorners(metadataInterface->GetImageKeywordlist(), vector_lonlat, + vector_colrow, vector_ind, vector_aziTime, + vector_ranTime); + } + catch (itk::ExceptionObject& /*err*/) + { + } } - catch (itk::ExceptionObject& /*err*/) - { + else + { + // If GCPs => Retrieve its + // Get latitude and longitude for each of its + getGCP(metadataInterface, gcpcount, outputKWL, vector_lonlat, vector_colrow, vector_ind); } - } - else - { - // If GCPs => Retrieve its - // Get latitude and longitude for each of its - getGCP(metadataInterface, gcpcount, outputKWL, vector_lonlat, vector_colrow, vector_ind); - } - ///// DEMClosestHgt filter to estimate accurate heights ///// - DEMClosestHgtFilterType::Pointer filterDEMClosestHgt = DEMClosestHgtFilterType::New(); - m_Ref.push_back(filterDEMClosestHgt.GetPointer()); + ///// DEMClosestHgt filter to estimate accurate heights ///// + DEMClosestHgtFilterType::Pointer filterDEMClosestHgt = DEMClosestHgtFilterType::New(); + m_Ref.push_back(filterDEMClosestHgt.GetPointer()); - // Set inputs : DEM and the vector_LonLat - filterDEMClosestHgt->SetInput(inputDEM); - filterDEMClosestHgt->SetVectorLonLat(vector_lonlat); + // Set inputs : DEM and the vector_LonLat + filterDEMClosestHgt->SetInput(inputDEM); + filterDEMClosestHgt->SetVectorLonLat(vector_lonlat); - // Init a vector for hgt - std::vector<double> * vector_hgt = new vector<double>(); - vector_hgt->resize(vector_lonlat->size()); // Same size than lon and lat + // Init a vector for hgt + std::vector<double> * vector_hgt = new vector<double>(); + vector_hgt->resize(vector_lonlat->size()); // Same size than lon and lat - for (unsigned int k = 0; k < vector_lonlat->size(); k++) - { - vector_hgt->at(k) = 0; - } + for (unsigned int k = 0; k < vector_lonlat->size(); k++) + { + vector_hgt->at(k) = 0; + } - // Launch our Persistent filter - filterDEMClosestHgt->Update(); - filterDEMClosestHgt->GetDEMHgt(vector_hgt); + // Launch our Persistent filter + filterDEMClosestHgt->Update(); + filterDEMClosestHgt->GetDEMHgt(vector_hgt); - // Add or update GCP into the output KWL (according to the sensor (GCPs already present or not)) - if (gcpcount == 0) - { - // Create GPCs with the four corners and center - createGCPAndUpdateKWL(vector_lonlat, vector_hgt, - vector_colrow, vector_ind, - vector_aziTime, - vector_ranTime, outputKWL); - } - else - { - // Just update heigths - updateGCPAndKWL(vector_hgt, gcpcount, outputKWL); - } + // Add or update GCP into the output KWL (according to the sensor (GCPs already present or not)) + if (gcpcount == 0) + { + // Create GPCs with the four corners and center + createGCPAndUpdateKWL(vector_lonlat, vector_hgt, + vector_colrow, vector_ind, + vector_aziTime, + vector_ranTime, outputKWL); + } + else + { + // Just update heigths + updateGCPAndKWL(vector_hgt, gcpcount, outputKWL); + } - // Display image information in the dedicated logger - otbAppLogINFO(<< ossOutput.str()); + // Display image information in the dedicated logger + otbAppLogINFO(<< ossOutput.str()); - // Free Memory - for (unsigned int itab = 0; itab < vector_lonlat->size(); itab++) - { - delete vector_lonlat->at(itab); - vector_lonlat->at(itab) = 0; - } - vector_lonlat->clear(); - delete vector_lonlat; - vector_lonlat = 0; + // Free Memory + for (unsigned int itab = 0; itab < vector_lonlat->size(); itab++) + { + delete vector_lonlat->at(itab); + vector_lonlat->at(itab) = 0; + } + vector_lonlat->clear(); + delete vector_lonlat; + vector_lonlat = 0; - vector_hgt->clear(); - delete vector_hgt; - vector_hgt = 0; + vector_hgt->clear(); + delete vector_hgt; + vector_hgt = 0; - for (unsigned int itab = 0; itab < vector_colrow->size(); itab++) - { - delete vector_colrow->at(itab); - vector_colrow->at(itab) = 0; + for (unsigned int itab = 0; itab < vector_colrow->size(); itab++) + { + delete vector_colrow->at(itab); + vector_colrow->at(itab) = 0; + } + vector_colrow->clear(); + delete vector_colrow; + vector_colrow = 0; + + vector_ind.clear(); + vector_aziTime.clear(); + vector_ranTime.clear(); } - vector_colrow->clear(); - delete vector_colrow; - vector_colrow = 0; - vector_ind.clear(); - vector_aziTime.clear(); - vector_ranTime.clear(); + if (doFineOrbits) + { + std::cout << "Hello Fine Orbits !!" << std::endl; + + double ullat = std::atof(outputKWL.GetMetadataByKey("ul_lat").c_str()); + std::cout << "ullat = " << ullat << std::endl; + } // Write output keywordlist with correct gcp (correction on heigth) if (IsParameterEnabled("outkwl") && HasValue("outkwl"))