21 #ifndef otbGenericRSResampleImageFilter_hxx
22 #define otbGenericRSResampleImageFilter_hxx
26 #include "itkMetaDataObject.h"
28 #include "itkProgressAccumulator.h"
32 #include "ogr_spatialref.h"
41 template <
class TInputImage,
class TOutputImage>
45 m_EstimateInputRpcModel(false),
46 m_EstimateOutputRpcModel(false),
47 m_RpcEstimationUpdated(false),
60 template <
class TInputImage,
class TOutputImage>
64 typename itk::ProgressAccumulator::Pointer progress = itk::ProgressAccumulator::New();
65 progress->SetMiniPipelineFilter(
this);
66 progress->RegisterInternalFilter(m_Resampler, 1.f);
68 m_Resampler->GraftOutput(this->GetOutput());
69 m_Resampler->UpdateOutputData(m_Resampler->GetOutput());
70 this->GraftOutput(m_Resampler->GetOutput());
79 template <
class TInputImage,
class TOutputImage>
83 if (m_EstimateOutputRpcModel)
84 this->EstimateOutputRpcModel();
87 if (m_EstimateInputRpcModel && !m_RpcEstimationUpdated)
89 this->EstimateInputRpcModel();
93 this->UpdateTransform();
95 m_Resampler->SetInput(this->GetInput());
96 m_Resampler->SetTransform(m_Transform);
97 m_Resampler->SetDisplacementFieldSpacing(this->GetDisplacementFieldSpacing());
98 m_Resampler->GraftOutput(this->GetOutput());
99 m_Resampler->UpdateOutputInformation();
100 this->GraftOutput(m_Resampler->GetOutput());
103 if (this->GetOutputImageMetadata() !=
nullptr)
104 this->GetOutput()->m_Imd.Merge(*(this->GetOutputImageMetadata()));
111 template <
class TInputImage,
class TOutputImage>
116 typename OutputImageType::Pointer tempPtr = OutputImageType::New();
118 typename OutputImageType::RegionType region;
119 region.SetSize(this->GetOutputSize());
120 region.SetIndex(this->GetOutputStartIndex());
121 tempPtr->SetRegions(region);
125 tempPtr->SetImageMetadata(*(this->GetOutputImageMetadata()));
128 m_OutputRpcEstimator->SetInput(tempPtr);
129 m_OutputRpcEstimator->UpdateOutputInformation();
132 m_Transform->SetInputImageMetadata(&(m_OutputRpcEstimator->GetOutput()->GetImageMetadata()));
139 template <
class TInputImage,
class TOutputImage>
142 if (!m_EstimateInputRpcModel)
144 m_Transform->SetOutputImageMetadata(&(this->GetInput()->GetImageMetadata()));
145 m_Transform->SetOutputProjectionRef(this->GetInput()->GetProjectionRef());
147 m_Transform->InstantiateTransform();
151 template <
class TInputImage,
class TOutputImage>
154 if (this->m_Updating)
158 m_Resampler->GetOutput()->SetRequestedRegion(output);
159 m_Resampler->GetOutput()->PropagateRequestedRegion();
168 template <
class TInputImage,
class TOutputImage>
173 typename InputImageType::Pointer tempPtr = InputImageType::New();
174 tempPtr->SetRegions(this->GetInput()->GetLargestPossibleRegion());
175 tempPtr->CopyInformation(this->GetInput());
179 m_InputRpcEstimator->SetInput(tempPtr);
180 m_InputRpcEstimator->UpdateOutputInformation();
183 m_Transform->SetOutputImageMetadata(&(m_InputRpcEstimator->GetOutput()->GetImageMetadata()));
187 m_RpcEstimationUpdated =
true;
194 template <
class TInputImage,
class TOutputImage>
199 this->SetOutputOrigin(src->GetOrigin());
200 this->SetOutputSpacing(src->GetSignedSpacing());
201 this->SetOutputStartIndex(src->GetLargestPossibleRegion().GetIndex());
202 this->SetOutputSize(src->GetLargestPossibleRegion().GetSize());
203 this->SetOutputProjectionRef(src->GetProjectionRef());
204 this->GetOutput()->SetImageMetadata(src->GetImageMetadata());
211 template <
class TInputImage,
class TOutputImage>
212 template <
class TImageType>
215 this->SetOutputOrigin(image->GetOrigin());
216 this->SetOutputSpacing(image->GetSignedSpacing());
217 this->SetOutputStartIndex(image->GetLargestPossibleRegion().GetIndex());
218 this->SetOutputSize(image->GetLargestPossibleRegion().GetSize());
219 this->SetOutputProjectionRef(image->GetProjectionRef());
220 this->GetOutput()->SetImageMetadata(image->GetImageMetadata());
230 template <
class TInputImage,
class TOutputImage>
239 this->UpdateTransform();
242 std::string projectionRef;
245 m_Transform->GetInverse(invTransform);
251 typedef itk::Point<double, 2> GeoPointType;
255 typename InputImageType::PointType pSrc;
257 GeoPointType geoPoint;
258 index[0] = input->GetLargestPossibleRegion().GetIndex()[0];
259 index[1] = input->GetLargestPossibleRegion().GetIndex()[1];
260 input->TransformIndexToPhysicalPoint(index, pSrc);
263 geoPoint = invTransform->GetTransform()->GetFirstTransform()->TransformPoint(pSrc);
266 unsigned int zone(0);
272 projectionRef = oSRS.
ToWkt();
274 else if (map ==
"WGS84")
280 itkExceptionMacro(
"The output map " << map <<
"is not supported, please try UTM or WGS84");
285 typename OutputParametersEstimatorType::Pointer genericRSEstimator = OutputParametersEstimatorType::New();
287 genericRSEstimator->SetInput(input);
288 genericRSEstimator->SetOutputProjectionRef(projectionRef);
289 genericRSEstimator->ForceSpacingTo(spacing);
290 genericRSEstimator->Compute();
293 this->SetOutputProjectionRef(projectionRef);
294 this->SetOutputOrigin(genericRSEstimator->GetOutputOrigin());
295 this->SetOutputSpacing(genericRSEstimator->GetOutputSpacing());
296 this->SetOutputSize(genericRSEstimator->GetOutputSize());
297 this->UpdateTransform();
306 template <
class TInputImage,
class TOutputImage>
313 typename OutputParametersEstimatorType::Pointer genericRSEstimator = OutputParametersEstimatorType::New();
315 genericRSEstimator->SetInput(input);
316 genericRSEstimator->SetOutputProjectionRef(projectionRef);
317 genericRSEstimator->Compute();
320 this->SetOutputProjectionRef(projectionRef);
321 this->SetOutputOrigin(genericRSEstimator->GetOutputOrigin());
322 this->SetOutputSpacing(genericRSEstimator->GetOutputSpacing());
323 this->SetOutputSize(genericRSEstimator->GetOutputSize());
324 this->UpdateTransform();
327 template <
class TInputImage,
class TOutputImage>
330 Superclass::PrintSelf(os, indent);
331 os << indent <<
"EstimateInputRpcModel:" << (m_EstimateInputRpcModel ?
"On" :
"Off") << std::endl;
332 os << indent <<
"EstimateOutputRpcModel:" << (m_EstimateOutputRpcModel ?
"On" :
"Off") << std::endl;
333 os << indent <<
"RpcEstimationUpdated:" << (m_RpcEstimationUpdated ?
"True" :
"False") << std::endl;
334 os << indent <<
"OutputOrigin: " << m_Resampler->GetOutputOrigin() << std::endl;
335 os << indent <<
"OutputSpacing: " << m_Resampler->GetOutputSpacing() << std::endl;
336 os << indent <<
"OutputStartIndex: " << m_Resampler->GetOutputStartIndex() << std::endl;
337 os << indent <<
"OutputSize: " << m_Resampler->GetOutputSize() << std::endl;
338 os << indent <<
"GenericRSTransform: " << std::endl;
339 m_Transform->Print(os, indent.GetNextIndent());