From 28140e6442592619316623c64644258ba1923842 Mon Sep 17 00:00:00 2001 From: Otmane Lahlou <otmane.lahlou@c-s.fr> Date: Mon, 13 Sep 2010 18:40:23 +0200 Subject: [PATCH] ENH : override the Modified Method --- .../otbPhysicalToRPCSensorModelImageFilter.h | 4 + ...otbPhysicalToRPCSensorModelImageFilter.txx | 97 +++++++++++-------- 2 files changed, 62 insertions(+), 39 deletions(-) diff --git a/Code/Projections/otbPhysicalToRPCSensorModelImageFilter.h b/Code/Projections/otbPhysicalToRPCSensorModelImageFilter.h index 3e89bc584c..17579714f6 100644 --- a/Code/Projections/otbPhysicalToRPCSensorModelImageFilter.h +++ b/Code/Projections/otbPhysicalToRPCSensorModelImageFilter.h @@ -103,6 +103,9 @@ public: { m_GridSize.Fill(inSize); } + + /** Reimplement the method Modified() */ + virtual void Modified(); protected: /** Constructor */ @@ -129,6 +132,7 @@ private: std::string m_DEMDirectory; double m_AverageElevation; SizeType m_GridSize; + bool m_OutputInformationGenerated; }; } // end of namespace otb diff --git a/Code/Projections/otbPhysicalToRPCSensorModelImageFilter.txx b/Code/Projections/otbPhysicalToRPCSensorModelImageFilter.txx index 60ba08c863..5cee5ff95d 100644 --- a/Code/Projections/otbPhysicalToRPCSensorModelImageFilter.txx +++ b/Code/Projections/otbPhysicalToRPCSensorModelImageFilter.txx @@ -40,6 +40,9 @@ PhysicalToRPCSensorModelImageFilter<TImage> // Initialize the gridSize : 16 points to have a correct estimation // of the model m_GridSize.Fill(4); + + // Flag initilalisation + m_OutputInformationGenerated = false; } template <class TImage> @@ -54,56 +57,72 @@ PhysicalToRPCSensorModelImageFilter<TImage> ::GenerateOutputInformation() { Superclass::GenerateOutputInformation(); + + if(!m_OutputInformationGenerated) + { - // Get the input - ImageType * input = const_cast<ImageType*>(this->GetInput()); + // Get the input + ImageType * input = const_cast<ImageType*>(this->GetInput()); - // Build the grid - // Generate GCPs from physical sensor model - RSTransformPointerType rsTransform = RSTransformType::New(); - rsTransform->SetInputKeywordList(input->GetImageKeywordlist()); + // Build the grid + // Generate GCPs from physical sensor model + RSTransformPointerType rsTransform = RSTransformType::New(); + rsTransform->SetInputKeywordList(input->GetImageKeywordlist()); - if(!m_DEMDirectory.empty()) - { - // Set the DEM & Average Elevation to the Remote Sensing Transform - rsTransform->SetDEMDirectory(m_DEMDirectory); - rsTransform->SetAverageElevation(m_AverageElevation); + if(!m_DEMDirectory.empty()) + { + // Set the DEM & Average Elevation to the Remote Sensing Transform + rsTransform->SetDEMDirectory(m_DEMDirectory); + rsTransform->SetAverageElevation(m_AverageElevation); - // Generate DEMHandler & set it to the GCP2sensorModel - typename DEMHandler::Pointer demHandler = DEMHandler::New(); - demHandler->OpenDEMDirectory(m_DEMDirectory.c_str()); - m_GCPsToSensorModelFilter->SetUseDEM(true); - m_GCPsToSensorModelFilter->SetDEMHandler(demHandler); - } + // Generate DEMHandler & set it to the GCP2sensorModel + typename DEMHandler::Pointer demHandler = DEMHandler::New(); + demHandler->OpenDEMDirectory(m_DEMDirectory.c_str()); + m_GCPsToSensorModelFilter->SetUseDEM(true); + m_GCPsToSensorModelFilter->SetDEMHandler(demHandler); + } - rsTransform->InstanciateTransform(); + rsTransform->InstanciateTransform(); - // Compute the size of the grid - typename ImageType::SizeType size = input->GetLargestPossibleRegion().GetSize(); - double gridSpacingX = size[0]/m_GridSize[0]; - double gridSpacingY = size[1]/m_GridSize[1]; + // Compute the size of the grid + typename ImageType::SizeType size = input->GetLargestPossibleRegion().GetSize(); + double gridSpacingX = size[0]/m_GridSize[0]; + double gridSpacingY = size[1]/m_GridSize[1]; - for(unsigned int px = 0; px<m_GridSize[0];++px) - { - for(unsigned int py = 0; py<m_GridSize[1];++py) + for(unsigned int px = 0; px<m_GridSize[0];++px) { - PointType inputPoint = input->GetOrigin(); - inputPoint[0]+= (px * gridSpacingX + 0.5) * input->GetSpacing()[0]; - inputPoint[1]+= (py * gridSpacingY + 0.5) * input->GetSpacing()[1]; - PointType outputPoint = rsTransform->TransformPoint(inputPoint); - m_GCPsToSensorModelFilter->AddGCP(inputPoint,outputPoint); + for(unsigned int py = 0; py<m_GridSize[1];++py) + { + PointType inputPoint = input->GetOrigin(); + inputPoint[0]+= (px * gridSpacingX + 0.5) * input->GetSpacing()[0]; + inputPoint[1]+= (py * gridSpacingY + 0.5) * input->GetSpacing()[1]; + PointType outputPoint = rsTransform->TransformPoint(inputPoint); + m_GCPsToSensorModelFilter->AddGCP(inputPoint,outputPoint); + } } - } - m_GCPsToSensorModelFilter->SetInput(input); - m_GCPsToSensorModelFilter->UpdateOutputInformation(); - std::cout<<"RPC model estimated. RMS ground error: "<<m_GCPsToSensorModelFilter->GetRMSGroundError() - <<", Mean error: "<<m_GCPsToSensorModelFilter->GetMeanError()<<std::endl; + m_GCPsToSensorModelFilter->SetInput(input); + m_GCPsToSensorModelFilter->UpdateOutputInformation(); + std::cout<<"RPC model estimated. RMS ground error: "<<m_GCPsToSensorModelFilter->GetRMSGroundError() + <<", Mean error: "<<m_GCPsToSensorModelFilter->GetMeanError()<<std::endl; - // Encapsulate the keywordlist - itk::MetaDataDictionary& dict = this->GetOutput()->GetMetaDataDictionary(); - itk::EncapsulateMetaData<ImageKeywordlist>(dict, MetaDataKey::OSSIMKeywordlistKey, - m_GCPsToSensorModelFilter->GetKeywordlist()); + // Encapsulate the keywordlist + itk::MetaDataDictionary& dict = this->GetOutput()->GetMetaDataDictionary(); + itk::EncapsulateMetaData<ImageKeywordlist>(dict, MetaDataKey::OSSIMKeywordlistKey, + m_GCPsToSensorModelFilter->GetKeywordlist()); + + // put the flag to true + m_OutputInformationGenerated = true; + } +} + +template <class TImage> +void +PhysicalToRPCSensorModelImageFilter<TImage> +::Modified() +{ + Superclass::Modified(); + m_OutputInformationGenerated= false; } template <class TImage> -- GitLab