21 #ifndef otbStreamingShrinkImageFilter_hxx
22 #define otbStreamingShrinkImageFilter_hxx
25 #include "itkImageRegionIteratorWithIndex.h"
27 #include "itkProgressReporter.h"
32 template <
class TImage>
37 template <
class TImage>
42 template <
class TImage>
46 TileSplitterType::Pointer splitter = TileSplitterType::New();
47 splitter->SetShrinkFactor(m_ShrinkFactor);
48 this->m_Splitter = splitter;
50 unsigned long nbDivisions = this->EstimateOptimalNumberOfDivisions(input, region, 0);
51 this->m_ComputedNumberOfSplits = this->m_Splitter->GetNumberOfSplits(region, nbDivisions);
52 otbMsgDevMacro(<<
"Number of split : " << this->m_ComputedNumberOfSplits)
55 this->m_Region = region;
60 template <
class TInputImage,
class TOutputImage>
63 this->SetNumberOfRequiredInputs(1);
64 this->SetNumberOfRequiredOutputs(1);
69 template <
class TInputImage,
class TOutputImage>
74 template <
class TInputImage,
class TOutputImage>
77 Superclass::GenerateOutputInformation();
85 output->CopyInformation(input);
86 output->SetLargestPossibleRegion(input->GetLargestPossibleRegion());
88 if (output->GetRequestedRegion().GetNumberOfPixels() == 0)
90 output->SetRequestedRegion(output->GetLargestPossibleRegion());
95 template <
class TInputImage,
class TOutputImage>
106 template <
class TInputImage,
class TOutputImage>
111 inputPtr->UpdateOutputInformation();
113 m_ShrunkOutput = OutputImageType::New();
114 m_ShrunkOutput->CopyInformation(inputPtr);
116 const typename InputImageType::SpacingType& inputSpacing = inputPtr->GetSignedSpacing();
117 const typename InputImageType::SizeType& inputSize = inputPtr->GetLargestPossibleRegion().GetSize();
118 const typename InputImageType::IndexType& inputIndex = inputPtr->GetLargestPossibleRegion().GetIndex();
119 typename InputImageType::IndexType startIndex;
121 typename OutputImageType::SpacingType shrunkOutputSpacing;
122 typename OutputImageType::RegionType shrunkOutputLargestPossibleRegion;
123 typename OutputImageType::SizeType shrunkOutputSize;
124 typename OutputImageType::IndexType shrunkOutputStartIndex;
125 typename OutputImageType::PointType shrunkOutputOrigin;
127 for (
unsigned int i = 0; i < OutputImageType::ImageDimension; ++i)
129 startIndex[i] = inputIndex[i] + (m_ShrinkFactor - 1) / 2;
130 if (m_ShrinkFactor > inputSize[i])
131 startIndex[i] = inputIndex[i] + (inputSize[i] - 1) / 2;
132 m_Offset[i] = startIndex[i] % m_ShrinkFactor;
133 shrunkOutputSpacing[i] = inputSpacing[i] *
static_cast<double>(m_ShrinkFactor);
134 shrunkOutputSize[i] = inputSize[i] > m_ShrinkFactor ? inputSize[i] / m_ShrinkFactor : 1;
136 shrunkOutputOrigin[i] = inputPtr->GetOrigin()[i] + inputSpacing[i] * startIndex[i];
140 shrunkOutputStartIndex[i] = 0;
143 m_ShrunkOutput->SetSignedSpacing(shrunkOutputSpacing);
144 m_ShrunkOutput->SetOrigin(shrunkOutputOrigin);
146 shrunkOutputLargestPossibleRegion.SetSize(shrunkOutputSize);
147 shrunkOutputLargestPossibleRegion.SetIndex(shrunkOutputStartIndex);
149 m_ShrunkOutput->SetRegions(shrunkOutputLargestPossibleRegion);
150 m_ShrunkOutput->Allocate();
153 template <
class TInputImage,
class TOutputImage>
158 template <
class TInputImage,
class TOutputImage>
163 template <
class TInputImage,
class TOutputImage>
167 itk::ProgressReporter progress(
this, threadId, outputRegionForThread.GetNumberOfPixels());
170 itk::ImageRegionConstIteratorWithIndex<InputImageType> inIt(inputPtr, outputRegionForThread);
171 for (inIt.GoToBegin(); !inIt.IsAtEnd(); ++inIt, progress.CompletedPixel())
173 const IndexType& inIndex = inIt.GetIndex();
175 if ((inIndex[0] - m_Offset[0]) % m_ShrinkFactor == 0 && (inIndex[1] - m_Offset[1]) % m_ShrinkFactor == 0)
178 shrunkIndex[0] = (inIndex[0] - m_Offset[0]) / m_ShrinkFactor;
179 shrunkIndex[1] = (inIndex[1] - m_Offset[1]) / m_ShrinkFactor;
180 if (m_ShrunkOutput->GetLargestPossibleRegion().IsInside(shrunkIndex))
181 m_ShrunkOutput->SetPixel(shrunkIndex, inIt.Get());
186 template <
class TInputImage,
class TOutputImage>
191 template <
class TImage,
class TOutputImage>
194 Superclass::PrintSelf(os, indent);
195 os << indent <<
"Shrink factor: " << m_ShrinkFactor << std::endl;