OTB  9.0.0
Orfeo Toolbox
otbGridResampleImageFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 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"
26 #include "itkLinearInterpolateImageFunction.h"
27 #include "itkDefaultConvertPixelTraits.h"
28 
29 #include "otbMacro.h"
30 
31 namespace otb
32 {
33 
60 template <typename TInputImage, typename TOutputImage, typename TInterpolatorPrecision = double>
61 class ITK_EXPORT GridResampleImageFilter : public itk::ImageToImageFilter<TInputImage, TOutputImage>
62 {
63 public:
66  typedef itk::ImageToImageFilter<TInputImage, TOutputImage> Superclass;
67  typedef itk::SmartPointer<Self> Pointer;
68  typedef itk::SmartPointer<const Self> ConstPointer;
69 
71  itkNewMacro(Self);
72 
74  itkTypeMacro(GridResampleImageFilter, itk::ImageToImageFilter);
75 
77  itkStaticConstMacro(ImageDimension, unsigned int, TOutputImage::ImageDimension);
78  itkStaticConstMacro(InputImageDimension, unsigned int, TInputImage::ImageDimension);
80 
82  typedef TInputImage InputImageType;
83  typedef TOutputImage OutputImageType;
84  typedef typename OutputImageType::RegionType OutputImageRegionType;
85  typedef typename TOutputImage::PixelType OutputPixelType;
86 
87 
88  typedef itk::DefaultConvertPixelTraits<OutputPixelType> OutputPixelConvertType;
89  typedef typename OutputPixelConvertType::ComponentType OutputPixelComponentType;
90 
92  typedef itk::InterpolateImageFunction<InputImageType, TInterpolatorPrecision> InterpolatorType;
93  typedef typename InterpolatorType::Pointer InterpolatorPointerType;
94  typedef itk::LinearInterpolateImageFunction<InputImageType, TInterpolatorPrecision> DefaultInterpolatorType;
95  typedef typename InterpolatorType::OutputType InterpolatorOutputType;
96  typedef itk::DefaultConvertPixelTraits<InterpolatorOutputType> InterpolatorConvertType;
97  typedef typename InterpolatorConvertType::ComponentType InterpolatorComponentType;
98 
100  typedef typename itk::ContinuousIndex<double, InputImageDimension> ContinuousInputIndexType;
101 
103  typedef itk::ImageBase<OutputImageType::ImageDimension> ImageBaseType;
104  typedef typename ImageBaseType::SpacingType SpacingType;
105  typedef typename ImageBaseType::SizeType SizeType;
106  typedef typename ImageBaseType::PointType PointType;
107  typedef typename ImageBaseType::IndexType IndexType;
108 
109  itkSetMacro(OutputStartIndex, IndexType);
110  itkGetConstReferenceMacro(OutputStartIndex, IndexType);
111 
112  itkSetMacro(OutputSize, SizeType);
113  itkGetConstReferenceMacro(OutputSize, SizeType);
114 
115  itkSetMacro(OutputOrigin, PointType);
116  itkGetConstReferenceMacro(OutputOrigin, PointType);
117 
118  itkSetMacro(OutputSpacing, SpacingType);
119  itkGetConstReferenceMacro(OutputSpacing, SpacingType);
120 
121  itkSetMacro(EdgePaddingValue, OutputPixelType);
122  itkGetConstReferenceMacro(EdgePaddingValue, OutputPixelType);
123 
124  itkSetMacro(CheckOutputBounds, bool);
125  itkGetMacro(CheckOutputBounds, bool);
126  itkBooleanMacro(CheckOutputBounds);
127 
128  itkSetMacro(InterpolationMargin, double);
129  itkGetMacro(InterpolationMargin, double);
130 
131  itkSetObjectMacro(Interpolator, InterpolatorType);
132  itkGetObjectMacro(Interpolator, InterpolatorType);
133 
135  void SetOutputParametersFromImage(const ImageBaseType* image);
136 
138  itk::ModifiedTimeType GetMTime(void) const override;
139 
140 protected:
142 
145 
146  void GenerateOutputInformation() override;
147 
148  void GenerateInputRequestedRegion() override;
149 
150  void BeforeThreadedGenerateData() override;
151 
152  void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId) override;
153 
154  void AfterThreadedGenerateData() override;
155 
156  inline void CastPixelWithBoundsChecking(const InterpolatorOutputType& value, const InterpolatorComponentType& minComponent,
157  const InterpolatorComponentType& maxComponent, OutputPixelType& outputValue) const
158  {
159  // Method imported from itk::ResampleImageFilter
160  const unsigned int nComponents = InterpolatorConvertType::GetNumberOfComponents(value);
161 
162  itk::NumericTraits<OutputPixelType>::SetLength(outputValue, nComponents);
163 
164  for (unsigned int n = 0; n < nComponents; n++)
165  {
166  InterpolatorComponentType component = InterpolatorConvertType::GetNthComponent(n, value);
167 
168  if (m_CheckOutputBounds && component < minComponent)
169  {
170  OutputPixelConvertType::SetNthComponent(n, outputValue, static_cast<OutputPixelComponentType>(minComponent));
171  }
172  else if (m_CheckOutputBounds && component > maxComponent)
173  {
174  OutputPixelConvertType::SetNthComponent(n, outputValue, static_cast<OutputPixelComponentType>(maxComponent));
175  }
176  else
177  {
178  OutputPixelConvertType::SetNthComponent(n, outputValue, static_cast<OutputPixelComponentType>(component));
179  }
180  }
181  }
182 
183 
184  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
185 
186 private:
187  GridResampleImageFilter(const Self&) = delete;
188  void operator=(const Self&) = delete;
189 
190  IndexType m_OutputStartIndex; // output image start index
191  SizeType m_OutputSize; // output image size
192  PointType m_OutputOrigin; // output image origin
193  SpacingType m_OutputSpacing; // output image spacing
194 
195  OutputPixelType m_EdgePaddingValue; // Default pixel value
196 
198 
199  bool m_CheckOutputBounds; // Shall we check
200  // output bounds when
201  // casting?
202 
204  // for resampling
205 
207  // variable for
208  // speed-up. Computed
209  // in BeforeThreadedGenerateData
210 };
211 
212 } // namespace otb
213 
214 #ifndef OTB_MANUAL_INSTANTIATION
216 #endif
217 
218 #endif
otb::GridResampleImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbGridResampleImageFilter.h:67
otb::GridResampleImageFilter::PointType
ImageBaseType::PointType PointType
Definition: otbGridResampleImageFilter.h:106
otb::GridResampleImageFilter::m_Interpolator
InterpolatorPointerType m_Interpolator
Definition: otbGridResampleImageFilter.h:203
otb::GridResampleImageFilter::OutputImageType
TOutputImage OutputImageType
Definition: otbGridResampleImageFilter.h:83
otb::GridResampleImageFilter::InterpolatorType
itk::InterpolateImageFunction< InputImageType, TInterpolatorPrecision > InterpolatorType
Definition: otbGridResampleImageFilter.h:92
otb::GridResampleImageFilter::SpacingType
ImageBaseType::SpacingType SpacingType
Definition: otbGridResampleImageFilter.h:104
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::GridResampleImageFilter::m_OutputOrigin
PointType m_OutputOrigin
Definition: otbGridResampleImageFilter.h:192
otb::GridResampleImageFilter::OutputPixelConvertType
itk::DefaultConvertPixelTraits< OutputPixelType > OutputPixelConvertType
Definition: otbGridResampleImageFilter.h:88
otb::GridResampleImageFilter::m_ReachableOutputRegion
OutputImageRegionType m_ReachableOutputRegion
Definition: otbGridResampleImageFilter.h:206
otbMacro.h
otb::GridResampleImageFilter::InterpolatorPointerType
InterpolatorType::Pointer InterpolatorPointerType
Definition: otbGridResampleImageFilter.h:93
otb::GridResampleImageFilter::DefaultInterpolatorType
itk::LinearInterpolateImageFunction< InputImageType, TInterpolatorPrecision > DefaultInterpolatorType
Definition: otbGridResampleImageFilter.h:94
otb::GridResampleImageFilter::InterpolatorOutputType
InterpolatorType::OutputType InterpolatorOutputType
Definition: otbGridResampleImageFilter.h:95
otbGridResampleImageFilter.hxx
otb::GridResampleImageFilter::Superclass
itk::ImageToImageFilter< TInputImage, TOutputImage > Superclass
Definition: otbGridResampleImageFilter.h:66
otb::mpl::GetNumberOfComponents
unsigned int GetNumberOfComponents(PixelType const &pix)
Definition: otbArrayTraits.h:215
otb::GridResampleImageFilter::~GridResampleImageFilter
~GridResampleImageFilter() override
Definition: otbGridResampleImageFilter.h:144
otb::GridResampleImageFilter::IndexType
ImageBaseType::IndexType IndexType
Definition: otbGridResampleImageFilter.h:107
otb::GridResampleImageFilter::m_OutputSize
SizeType m_OutputSize
Definition: otbGridResampleImageFilter.h:191
otb::GridResampleImageFilter::m_OutputStartIndex
IndexType m_OutputStartIndex
Definition: otbGridResampleImageFilter.h:190
otb::GridResampleImageFilter::Self
GridResampleImageFilter Self
Definition: otbGridResampleImageFilter.h:65
otb::GridResampleImageFilter::InputImageType
TInputImage InputImageType
Definition: otbGridResampleImageFilter.h:82
otb::GridResampleImageFilter::InterpolatorConvertType
itk::DefaultConvertPixelTraits< InterpolatorOutputType > InterpolatorConvertType
Definition: otbGridResampleImageFilter.h:96
otb::GridResampleImageFilter::m_EdgePaddingValue
OutputPixelType m_EdgePaddingValue
Definition: otbGridResampleImageFilter.h:195
otb::GridResampleImageFilter::m_InterpolationMargin
double m_InterpolationMargin
Definition: otbGridResampleImageFilter.h:197
otb::GridResampleImageFilter::m_CheckOutputBounds
bool m_CheckOutputBounds
Definition: otbGridResampleImageFilter.h:199
otb::GridResampleImageFilter::m_OutputSpacing
SpacingType m_OutputSpacing
Definition: otbGridResampleImageFilter.h:193
otb::GridResampleImageFilter::CastPixelWithBoundsChecking
void CastPixelWithBoundsChecking(const InterpolatorOutputType &value, const InterpolatorComponentType &minComponent, const InterpolatorComponentType &maxComponent, OutputPixelType &outputValue) const
Definition: otbGridResampleImageFilter.h:156
otb::GridResampleImageFilter::OutputImageRegionType
OutputImageType::RegionType OutputImageRegionType
Definition: otbGridResampleImageFilter.h:84
otb::GridResampleImageFilter::ContinuousInputIndexType
itk::ContinuousIndex< double, InputImageDimension > ContinuousInputIndexType
Definition: otbGridResampleImageFilter.h:100
otb::GridResampleImageFilter::InterpolatorComponentType
InterpolatorConvertType::ComponentType InterpolatorComponentType
Definition: otbGridResampleImageFilter.h:97
otb::GridResampleImageFilter
Resample input image on a new origin/spacing/size grid.
Definition: otbGridResampleImageFilter.h:61
otb::GridResampleImageFilter::SizeType
ImageBaseType::SizeType SizeType
Definition: otbGridResampleImageFilter.h:105
otb::GridResampleImageFilter::OutputPixelType
TOutputImage::PixelType OutputPixelType
Definition: otbGridResampleImageFilter.h:85
otb::GridResampleImageFilter::ImageBaseType
itk::ImageBase< OutputImageType::ImageDimension > ImageBaseType
Definition: otbGridResampleImageFilter.h:103
otb::GridResampleImageFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbGridResampleImageFilter.h:68
otb::GridResampleImageFilter::OutputPixelComponentType
OutputPixelConvertType::ComponentType OutputPixelComponentType
Definition: otbGridResampleImageFilter.h:89