21 #ifndef otbStreamingResampleImageFilter_hxx
22 #define otbStreamingResampleImageFilter_hxx
25 #include "itkProgressAccumulator.h"
31 template <
class TInputImage,
class TOutputImage,
class TInterpolatorPrecisionType>
35 m_DisplacementFilter = DisplacementFieldGeneratorType::New();
36 m_WarpFilter = WarpImageFilterType::New();
37 m_SignedOutputSpacing = m_DisplacementFilter->GetOutputSpacing();
40 this->SetDisplacementFieldSpacing(itk::NumericTraits<SpacingType>::ZeroValue());
43 m_WarpFilter->SetDisplacementField(m_DisplacementFilter->GetOutput());
46 template <
class TInputImage,
class TOutputImage,
class TInterpolatorPrecisionType>
50 typename itk::ProgressAccumulator::Pointer progress = itk::ProgressAccumulator::New();
51 progress->SetMiniPipelineFilter(
this);
52 progress->RegisterInternalFilter(m_WarpFilter, 1.f);
54 m_WarpFilter->GraftOutput(this->GetOutput());
55 m_WarpFilter->UpdateOutputData(m_WarpFilter->GetOutput());
56 this->GraftOutput(m_WarpFilter->GetOutput());
62 template <
class TInputImage,
class TOutputImage,
class TInterpolatorPrecisionType>
66 if (this->GetDisplacementFieldSpacing() == itk::NumericTraits<SpacingType>::ZeroValue())
68 this->SetDisplacementFieldSpacing(2. * this->GetOutputSpacing());
72 SizeType largestSize = this->GetOutputSize();
75 SizeType displacementFieldLargestSize;
77 for (
unsigned int dim = 0; dim < InputImageType::ImageDimension; ++dim)
85 displacementFieldLargestSize[dim] =
86 static_cast<unsigned int>(std::ceil(largestSize[dim] * std::abs(this->GetOutputSpacing()[dim] / this->GetDisplacementFieldSpacing()[dim]))) + 1;
88 m_DisplacementFilter->SetOutputSize(displacementFieldLargestSize);
89 m_DisplacementFilter->SetOutputIndex(this->GetOutputStartIndex());
91 m_WarpFilter->SetInput(this->GetInput());
92 m_WarpFilter->GraftOutput(this->GetOutput());
93 m_WarpFilter->UpdateOutputInformation();
94 this->GraftOutput(m_WarpFilter->GetOutput());
97 template <
class TInputImage,
class TOutputImage,
class TInterpolatorPrecisionType>
100 if (this->m_Updating)
103 m_WarpFilter->GetOutput()->SetRequestedRegion(output);
104 m_WarpFilter->GetOutput()->PropagateRequestedRegion();
111 template <
class TInputImage,
class TOutputImage,
class TInterpolatorPrecisionType>
114 this->SetOutputOrigin(image->GetOrigin());
116 this->SetOutputStartIndex(image->GetLargestPossibleRegion().GetIndex());
117 this->SetOutputSize(image->GetLargestPossibleRegion().GetSize());
121 template <
class TInputImage,
class TOutputImage,
class TInterpolatorPrecisionType>
124 m_SignedOutputSpacing = outputSpacing;
125 typename TInputImage::DirectionType direction = this->m_DisplacementFilter->GetOutputDirection();
126 for (
unsigned int i = 0; i < TInputImage::ImageDimension; ++i)
128 if (outputSpacing[i] < 0)
130 if (direction[i][i] > 0)
132 for (
unsigned int j = 0; j < TInputImage::ImageDimension; ++j)
134 direction[j][i] = -direction[j][i];
137 outputSpacing[i] = -outputSpacing[i];
140 this->m_DisplacementFilter->SetOutputSpacing(outputSpacing);
141 this->m_DisplacementFilter->SetOutputDirection(direction);
145 template <
class TInputImage,
class TOutputImage,
class TInterpolatorPrecisionType>
148 Superclass::PrintSelf(os, indent);
149 os << indent <<
"OutputOrigin: " << this->GetOutputOrigin() << std::endl;
150 os << indent <<
"OutputSpacing: " << this->GetOutputSpacing() << std::endl;
151 os << indent <<
"OutputStartIndex: " << this->GetOutputStartIndex() << std::endl;
152 os << indent <<
"OutputSize: " << this->GetOutputSize() << std::endl;