Skip to content
Snippets Groups Projects
Commit 7112b7b5 authored by Otmane Lahlou's avatar Otmane Lahlou
Browse files

ENH : add support for input rpc model estimation

parent 2b965b2b
No related branches found
No related tags found
No related merge requests found
......@@ -20,17 +20,28 @@
#include "itkImageToImageFilter.h"
#include "otbOptResampleImageFilter.h"
#include "otbPhysicalToRPCSensorModelImageFilter.h"
#include "otbGenericRSTransform.h"
namespace otb
{
/** \class GenericRSResampleImageFilter
* \brief This class is a composite filter
*
* \brief This class is a composite filter that allows you to project
* an input image from any coordinate system to any other one. The
* coordinate systems can be defined by their projection reference,
* the keyword list or a meta data dictionary.
*
*
* This class uses the otb::StreamingResampleImageFilter. It defines
* and uses a otb::GenericRSTransform using the input/output coordinate
* system informations listed below. This class can resample the input to an
* output image with the Size/Origin/Spacing/StartIndex defined by
* the user. Note that there are no default values for all the
* parmeters, so it is mandatory to set correct parameters to have a
* correct result.
*
*
*
* \ingroup Projection
*
......@@ -69,6 +80,10 @@ public:
typedef typename ResamplerType::IndexType IndexType;
typedef typename ResamplerType::RegionType RegionType;
typedef typename ResamplerType::InterpolatorType InterpolatorType;
/** Estimate the rpc model */
typedef PhysicalToRPCSensorModelImageFilter<InputImageType> RpcModelEstimatorType;
typedef typename RpcModelEstimatorType::Pointer RpcModelEstimatorPointerType;
/** Specialisation of OptResampleFilter with a remote
* sensing transform
......@@ -110,7 +125,6 @@ public:
otbSetObjectMemberMacro(Resampler,OutputSpacing,SpacingType);
otbGetObjectMemberConstReferenceMacro(Resampler,OutputSpacing,SpacingType);
/** Methods to Set/Get the interpolator */
void SetInterpolator(InterpolatorType * interpolator)
{
......@@ -119,20 +133,33 @@ public:
}
otbGetObjectMemberConstMacro(Resampler, Interpolator, const InterpolatorType *);
/** Set/Get for input and output projections. */
/**
* Set/Get input & output projections.
* Set/Get input & output keywordlist
* The macro are not used here cause the input and the output are
* inversed.
*/
void SetInputProjectionRef(const std::string& ref)
{
m_Transform->SetOutputProjectionRef(ref);
this->Modified();
}
otbGetObjectMemberMacro(Transform,InputProjectionRef,std::string);
std::string GetInputProjectionRef()
{
return m_Transform->GetOutputProjectionRef();
}
void SetOutputProjectionRef(const std::string& ref)
{
m_Transform->SetInputProjectionRef(ref);
this->Modified();
}
otbGetObjectMemberMacro(Transform,OutputProjectionRef,std::string);
std::string GetOutputProjectionRef()
{
return m_Transform->GetInputProjectionRef();
}
/** Set/Get Input Keywordlist*/
void SetInputKeywordList(const ImageKeywordlist& kwl)
......@@ -140,7 +167,10 @@ public:
m_Transform->SetOutputKeywordList(kwl);
this->Modified();
}
otbGetObjectMemberConstMacro(Transform,InputKeywordList,ImageKeywordlist);
const ImageKeywordlist GetInputKeywordList()
{
return m_Transform->GetOutputKeywordList();
}
/** Set/Get output Keywordlist*/
void SetOutputKeywordList(const ImageKeywordlist& kwl)
......@@ -148,7 +178,11 @@ public:
m_Transform->SetInputKeywordList(kwl);
this->Modified();
}
otbGetObjectMemberConstMacro(Transform,OutputKeywordList,ImageKeywordlist);
ImageKeywordlist GetOutputKeywordList()
{
return m_Transform->GetInputKeywordList();
}
/** Set/Get the DEMDirectory*/
void SetDEMDirectory(const std::string& dem)
......@@ -157,9 +191,19 @@ public:
this->Modified();
}
otbGetObjectMemberConstMacro(Transform,DEMDirectory,std::string);
/** Useful to set the output parameters from an existing image*/
void SetOutputParametersFromImage(const InputImageType * image);
/** Macro to Set/Get the grid spacing for rpc estimator*/
otbSetObjectMemberMacro(InputRpcEstimator,GridSpacing,unsigned int);
otbGetObjectMemberConstMacro(InputRpcEstimator,GridSpacing,unsigned int);
// Macro to tune the EstimateInputRpcModel flag
itkSetMacro(EstimateInputRpcModel, bool);
itkGetMacro(EstimateInputRpcModel, bool);
itkBooleanMacro(EstimateInputRpcModel);
protected:
GenericRSResampleImageFilter();
/** Destructor */
......@@ -173,9 +217,13 @@ private:
GenericRSResampleImageFilter(const Self &); //purposely not implemented
void operator =(const Self&); //purposely not implemented
// boolean that allow the estimation of the input rpc model
bool m_EstimateInputRpcModel;
// Filters pointers
ResamplerPointerType m_Resampler;
GenericRSTransformPointerType m_Transform;
ResamplerPointerType m_Resampler;
RpcModelEstimatorPointerType m_InputRpcEstimator;
GenericRSTransformPointerType m_Transform;
};
} // namespace otb
......
......@@ -30,12 +30,13 @@ namespace otb
template <class TInputImage, class TOutputImage, class TDeformationField>
GenericRSResampleImageFilter<TInputImage, TOutputImage, TDeformationField>
::GenericRSResampleImageFilter()
::GenericRSResampleImageFilter():m_EstimateInputRpcModel(false)
{
// internal filters instanciation
m_Resampler = ResamplerType::New();
m_Transform = GenericRSTransformType::New();
m_Resampler = ResamplerType::New();
m_InputRpcEstimator = RpcModelEstimatorType::New();
m_Transform = GenericRSTransformType::New();
// Initialize the deformation field spacing
SpacingType initSpacing;
initSpacing[0]= 2.;
......@@ -43,8 +44,6 @@ GenericRSResampleImageFilter<TInputImage, TOutputImage, TDeformationField>
this->SetDeformationFieldSpacing(initSpacing);
}
template <class TInputImage, class TOutputImage, class TDeformationField>
void
GenericRSResampleImageFilter<TInputImage, TOutputImage, TDeformationField>
......@@ -80,12 +79,16 @@ GenericRSResampleImageFilter<TInputImage, TOutputImage, TDeformationField>
outputPtr->SetLargestPossibleRegion(region);
// Expose the input metadata to the output
// Encapsulate the output metadata
itk::MetaDataDictionary& dict = this->GetOutput()->GetMetaDataDictionary();
// GetInputProjectionRef is used here cause the RS transform is
// inversed : Output -> Input
itk::EncapsulateMetaData<std::string>(dict, MetaDataKey::ProjectionRefKey,
this->GetInputProjectionRef());
this->GetOutputProjectionRef());
if(this->GetOutputKeywordList().GetSize() > 0)
{
itk::EncapsulateMetaData<ImageKeywordlist>(dict, MetaDataKey::OSSIMKeywordlistKey,
this->GetOutputKeywordList());
}
outputPtr->SetMetaDataDictionary(dict);
}
......@@ -112,7 +115,15 @@ GenericRSResampleImageFilter<TInputImage, TOutputImage, TDeformationField>
m_Transform->InstanciateTransform();
// Generate input requested region
m_Resampler->SetInput(inputPtr);
if (m_EstimateInputRpcModel)
{
m_InputRpcEstimator->SetInput(this->GetInput());
m_Resampler->SetInput(m_InputRpcEstimator->GetOutput());
}
else
{
m_Resampler->SetInput(this->GetInput());
}
m_Resampler->SetTransform(m_Transform);
m_Resampler->SetDeformationFieldSpacing(this->GetDeformationFieldSpacing());
m_Resampler->GetOutput()->UpdateOutputInformation();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment