OTB  6.7.0
Orfeo Toolbox
otbGridResampleImageFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbGridResampleImageFilter_h
22 #define otbGridResampleImageFilter_h
23 
24 
25 #include "itkImageToImageFilter.h"
28 
29 #include "otbMacro.h"
30 
31 namespace otb
32 {
33 
60 template <typename TInputImage, typename TOutputImage,
61  typename TInterpolatorPrecision = double>
62 class ITK_EXPORT GridResampleImageFilter :
63  public itk::ImageToImageFilter<TInputImage, TOutputImage>
64 {
65 public:
71 
73  itkNewMacro(Self);
74 
77 
79  itkStaticConstMacro(ImageDimension, unsigned int,
80  TOutputImage::ImageDimension);
81  itkStaticConstMacro(InputImageDimension, unsigned int,
82  TInputImage::ImageDimension);
84 
86  typedef TInputImage InputImageType;
87  typedef TOutputImage OutputImageType;
88  typedef typename OutputImageType::RegionType OutputImageRegionType;
89  typedef typename TOutputImage::PixelType OutputPixelType;
90 
91 
94 
97  TInterpolatorPrecision> InterpolatorType;
100  TInterpolatorPrecision> DefaultInterpolatorType;
104 
107 
114 
115  itkSetMacro(OutputStartIndex,IndexType);
116  itkGetConstReferenceMacro(OutputStartIndex,IndexType);
117 
118  itkSetMacro(OutputSize,SizeType);
119  itkGetConstReferenceMacro(OutputSize,SizeType);
120 
121  itkSetMacro(OutputOrigin,PointType);
122  itkGetConstReferenceMacro(OutputOrigin,PointType);
123 
124  itkSetMacro(OutputSpacing,SpacingType);
125  itkGetConstReferenceMacro(OutputSpacing,SpacingType);
126 
127  itkSetMacro(EdgePaddingValue,OutputPixelType);
128  itkGetConstReferenceMacro(EdgePaddingValue,OutputPixelType);
129 
130  itkSetMacro(CheckOutputBounds,bool);
131  itkGetMacro(CheckOutputBounds,bool);
132  itkBooleanMacro(CheckOutputBounds);
133 
134  itkSetObjectMacro(Interpolator,InterpolatorType);
135  itkGetObjectMacro(Interpolator,InterpolatorType);
136 
138  void SetOutputParametersFromImage(const ImageBaseType * image);
139 
141  itk::ModifiedTimeType GetMTime(void) const override;
142 
143 protected:
145 
148 
149  void GenerateOutputInformation() override;
150 
151  void GenerateInputRequestedRegion() override;
152 
153  void BeforeThreadedGenerateData() override;
154 
155  void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId) override;
156 
157  void AfterThreadedGenerateData() override;
158 
160  const InterpolatorComponentType& minComponent,
161  const InterpolatorComponentType& maxComponent,
162  OutputPixelType& outputValue ) const
163  {
164  // Method imported from itk::ResampleImageFilter
165  const unsigned int nComponents = InterpolatorConvertType::GetNumberOfComponents(value);
166 
167  itk::NumericTraits<OutputPixelType>::SetLength( outputValue, nComponents );
168 
169  for (unsigned int n=0; n<nComponents; n++)
170  {
171  InterpolatorComponentType component = InterpolatorConvertType::GetNthComponent( n, value );
172 
173  if ( m_CheckOutputBounds && component < minComponent )
174  {
175  OutputPixelConvertType::SetNthComponent( n, outputValue, static_cast<OutputPixelComponentType>( minComponent ) );
176  }
177  else if ( m_CheckOutputBounds && component > maxComponent )
178  {
179  OutputPixelConvertType::SetNthComponent( n, outputValue, static_cast<OutputPixelComponentType>( maxComponent ) );
180  }
181  else
182  {
183  OutputPixelConvertType::SetNthComponent(n, outputValue,
184  static_cast<OutputPixelComponentType>( component ) );
185  }
186  }
187  }
188 
189 
190  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
191 
192 private:
193  GridResampleImageFilter(const Self &) = delete;
194  void operator =(const Self&) = delete;
195 
196  IndexType m_OutputStartIndex; // output image start index
197  SizeType m_OutputSize; // output image size
198  PointType m_OutputOrigin; // output image origin
199  SpacingType m_OutputSpacing; // output image spacing
200 
201  OutputPixelType m_EdgePaddingValue; // Default pixel value
202 
203  bool m_CheckOutputBounds; // Shall we check
204  // output bounds when
205  // casting?
206 
208  // for resampling
209 
211  // variable for
212  // speed-up. Computed
213  // in BeforeThreadedGenerateData
214 
215 };
216 
217 } // namespace otb
218 
219 #ifndef OTB_MANUAL_INSTANTIATION
221 #endif
222 
223 #endif
itk::ImageBase< OutputImageType::ImageDimension > ImageBaseType
void CastPixelWithBoundsChecking(const InterpolatorOutputType &value, const InterpolatorComponentType &minComponent, const InterpolatorComponentType &maxComponent, OutputPixelType &outputValue) const
unsigned long ModifiedTimeType
itk::LinearInterpolateImageFunction< InputImageType, TInterpolatorPrecision > DefaultInterpolatorType
PixelType::ComponentType ComponentType
itk::ImageToImageFilter< TInputImage, TOutputImage > Superclass
Superclass::OutputType OutputType
OutputPixelConvertType::ComponentType OutputPixelComponentType
itk::DefaultConvertPixelTraits< InterpolatorOutputType > InterpolatorConvertType
OutputImageRegionType m_ReachableOutputRegion
ImageBaseType::SpacingType SpacingType
Resample input image on a new origin/spacing/size grid.
TInputImage InputImageType
static void SetLength(T &m, const unsigned int s)
OutputImageType::RegionType OutputImageRegionType
InterpolatorType::Pointer InterpolatorPointerType
unsigned int ThreadIdType
TOutputImage::PixelType OutputPixelType
InterpolatorConvertType::ComponentType InterpolatorComponentType
InterpolatorType::OutputType InterpolatorOutputType
OutputImageType::RegionType OutputImageRegionType
itk::SmartPointer< const Self > ConstPointer
itk::InterpolateImageFunction< InputImageType, TInterpolatorPrecision > InterpolatorType
itk::DefaultConvertPixelTraits< OutputPixelType > OutputPixelConvertType
itk::ContinuousIndex< double, InputImageDimension > ContinuousInputIndexType