OTB  9.0.0
Orfeo Toolbox
otbStreamingResampleImageFilter.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 otbStreamingResampleImageFilter_h
22 #define otbStreamingResampleImageFilter_h
23 
24 #include "itkImageToImageFilter.h"
26 #include "itkTransformToDisplacementFieldSource.h"
27 #include "itkLinearInterpolateImageFunction.h"
28 #include "otbImage.h"
29 #include "itkVector.h"
30 
31 #include "otbMacro.h"
32 
33 namespace otb
34 {
35 
58 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType = double>
59 class ITK_EXPORT StreamingResampleImageFilter : public itk::ImageToImageFilter<TInputImage, TOutputImage>
60 {
61 public:
64  typedef itk::ImageToImageFilter<TInputImage, TOutputImage> Superclass;
65  typedef itk::SmartPointer<Self> Pointer;
66  typedef itk::SmartPointer<const Self> ConstPointer;
67 
69  itkNewMacro(Self);
70 
72  itkTypeMacro(StreamingResampleImageFilter, itk::ImageToImageFilter);
73 
75  typedef TInputImage InputImageType;
76  typedef TOutputImage OutputImageType;
77 
79  typedef itk::Vector<double, TOutputImage::ImageDimension> DisplacementType;
81 
84 
86  typedef itk::TransformToDisplacementFieldSource<DisplacementFieldType, double> DisplacementFieldGeneratorType;
87  typedef typename DisplacementFieldGeneratorType::TransformType TransformType;
88  typedef typename DisplacementFieldGeneratorType::SizeType SizeType;
89  typedef typename DisplacementFieldGeneratorType::SpacingType SpacingType;
90  typedef typename DisplacementFieldGeneratorType::OriginType OriginType;
91  typedef typename DisplacementFieldGeneratorType::IndexType IndexType;
92  typedef typename DisplacementFieldGeneratorType::RegionType RegionType;
93 
95  typedef itk::InterpolateImageFunction<InputImageType, TInterpolatorPrecisionType> InterpolatorType;
96  typedef typename InterpolatorType::Pointer InterpolatorPointerType;
97  typedef itk::LinearInterpolateImageFunction<InputImageType, TInterpolatorPrecisionType> DefaultInterpolatorType;
98 
100  typedef itk::ImageBase<OutputImageType::ImageDimension> ImageBaseType;
101 
102 
104  void SetTransform(TransformType* transform)
105  {
106  m_DisplacementFilter->SetTransform(transform);
107  this->Modified();
108  }
109  otbGetObjectMemberConstMacro(DisplacementFilter, Transform, const TransformType*);
111 
113  void SetDisplacementFieldSpacing(SpacingType spacing);
114 
116  {
117  return m_SignedOutputSpacing;
118  };
119 
121  // Output Origin
122  void SetOutputOrigin(const OriginType& origin)
123  {
124  m_DisplacementFilter->SetOutputOrigin(origin);
125  m_WarpFilter->SetOutputOrigin(origin);
126  this->Modified();
127  }
128  otbGetObjectMemberConstReferenceMacro(WarpFilter, OutputOrigin, OriginType);
130 
131  // Output Start index
132  otbSetObjectMemberMacro(WarpFilter, OutputStartIndex, IndexType);
133  otbGetObjectMemberConstReferenceMacro(WarpFilter, OutputStartIndex, IndexType);
134 
135  // Output Size
136  otbSetObjectMemberMacro(WarpFilter, OutputSize, SizeType);
137  otbGetObjectMemberConstReferenceMacro(WarpFilter, OutputSize, SizeType);
138 
139  // Output Spacing
140  otbSetObjectMemberMacro(WarpFilter, OutputSpacing, SpacingType);
141  otbGetObjectMemberConstReferenceMacro(WarpFilter, OutputSpacing, SpacingType);
142 
144  void SetInterpolator(InterpolatorType* interpolator)
145  {
146  m_WarpFilter->SetInterpolator(interpolator);
147  this->Modified();
148  }
149  otbGetObjectMemberConstMacro(WarpFilter, Interpolator, const InterpolatorType*);
151 
153  otbSetObjectMemberMacro(WarpFilter, EdgePaddingValue, typename OutputImageType::PixelType);
154  otbGetObjectMemberMacro(WarpFilter, EdgePaddingValue, typename OutputImageType::PixelType);
156 
158  void SetOutputParametersFromImage(const ImageBaseType* image);
159 
160  /* Set number of threads for Deformation field generator*/
161  void SetDisplacementFilterNumberOfThreads(unsigned int nbThread)
162  {
163  m_DisplacementFilter->SetNumberOfThreads(nbThread);
164  }
165 
167  void PropagateRequestedRegion(itk::DataObject* output) override;
168 
169 protected:
171 
174 
175  void GenerateData() override;
176 
177  void GenerateOutputInformation() override;
178 
179  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
180 
181 private:
182  StreamingResampleImageFilter(const Self&) = delete;
183  void operator=(const Self&) = delete;
184 
185  // We need this to respect ConstRef macro and to be compliant with itk positive
186  // spacing
188 
189  typename DisplacementFieldGeneratorType::Pointer m_DisplacementFilter;
191 };
192 
193 } // namespace otb
194 
195 #ifndef OTB_MANUAL_INSTANTIATION
197 #endif
198 
199 #endif
otb::StreamingResampleImageFilter::DisplacementFieldType
otb::Image< DisplacementType > DisplacementFieldType
Definition: otbStreamingResampleImageFilter.h:80
otb::StreamingResampleImageFilter::DisplacementType
itk::Vector< double, TOutputImage::ImageDimension > DisplacementType
Definition: otbStreamingResampleImageFilter.h:79
otbStreamingResampleImageFilter.hxx
otb::StreamingResampleImageFilter::OriginType
DisplacementFieldGeneratorType::OriginType OriginType
Definition: otbStreamingResampleImageFilter.h:90
otbImage.h
otb::StreamingResampleImageFilter::SetTransform
void SetTransform(TransformType *transform)
Definition: otbStreamingResampleImageFilter.h:104
otb::StreamingResampleImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbStreamingResampleImageFilter.h:65
otb::StreamingResampleImageFilter::WarpImageFilterType
StreamingWarpImageFilter< InputImageType, OutputImageType, DisplacementFieldType > WarpImageFilterType
Definition: otbStreamingResampleImageFilter.h:83
otb::StreamingResampleImageFilter::m_DisplacementFilter
DisplacementFieldGeneratorType::Pointer m_DisplacementFilter
Definition: otbStreamingResampleImageFilter.h:189
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Image
Creation of an "otb" image which contains metadata.
Definition: otbImage.h:89
otb::StreamingResampleImageFilter::TransformType
DisplacementFieldGeneratorType::TransformType TransformType
Definition: otbStreamingResampleImageFilter.h:87
otb::StreamingResampleImageFilter::~StreamingResampleImageFilter
~StreamingResampleImageFilter() override
Definition: otbStreamingResampleImageFilter.h:173
otb::StreamingResampleImageFilter::m_WarpFilter
WarpImageFilterType::Pointer m_WarpFilter
Definition: otbStreamingResampleImageFilter.h:190
otb::StreamingResampleImageFilter::OutputImageType
TOutputImage OutputImageType
Definition: otbStreamingResampleImageFilter.h:76
otb::StreamingResampleImageFilter::SpacingType
DisplacementFieldGeneratorType::SpacingType SpacingType
Definition: otbStreamingResampleImageFilter.h:89
otb::StreamingResampleImageFilter::InputImageType
TInputImage InputImageType
Definition: otbStreamingResampleImageFilter.h:72
otbMacro.h
otb::StreamingResampleImageFilter::SetDisplacementFilterNumberOfThreads
void SetDisplacementFilterNumberOfThreads(unsigned int nbThread)
Definition: otbStreamingResampleImageFilter.h:161
otb::StreamingResampleImageFilter::ImageBaseType
itk::ImageBase< OutputImageType::ImageDimension > ImageBaseType
Definition: otbStreamingResampleImageFilter.h:100
otb::StreamingResampleImageFilter::SetOutputOrigin
void SetOutputOrigin(const OriginType &origin)
Definition: otbStreamingResampleImageFilter.h:122
otb::StreamingResampleImageFilter::Self
StreamingResampleImageFilter Self
Definition: otbStreamingResampleImageFilter.h:63
otb::StreamingResampleImageFilter::Superclass
itk::ImageToImageFilter< TInputImage, TOutputImage > Superclass
Definition: otbStreamingResampleImageFilter.h:64
otbStreamingWarpImageFilter.h
otb::StreamingResampleImageFilter
This class is a composite filter resampling an input image by setting a transform....
Definition: otbStreamingResampleImageFilter.h:59
otb::StreamingResampleImageFilter::IndexType
DisplacementFieldGeneratorType::IndexType IndexType
Definition: otbStreamingResampleImageFilter.h:91
otb::StreamingResampleImageFilter::InterpolatorType
itk::InterpolateImageFunction< InputImageType, TInterpolatorPrecisionType > InterpolatorType
Definition: otbStreamingResampleImageFilter.h:95
otb::StreamingResampleImageFilter::RegionType
DisplacementFieldGeneratorType::RegionType RegionType
Definition: otbStreamingResampleImageFilter.h:92
otb::StreamingWarpImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbStreamingWarpImageFilter.h:58
otb::Transform
Class to overload method passed to virtual pure in ITK V4.
Definition: otbTransform.h:39
otb::Wrapper::ImageBaseType
itk::ImageBase< 2 > ImageBaseType
Definition: otbWrapperTypes.h:180
otb::StreamingResampleImageFilter::SetInterpolator
void SetInterpolator(InterpolatorType *interpolator)
Definition: otbStreamingResampleImageFilter.h:144
otbGetObjectMemberConstReferenceMacro
#define otbGetObjectMemberConstReferenceMacro(object, name, type)
Definition: otbMacro.h:112
otb::StreamingResampleImageFilter::DisplacementFieldGeneratorType
itk::TransformToDisplacementFieldSource< DisplacementFieldType, double > DisplacementFieldGeneratorType
Definition: otbStreamingResampleImageFilter.h:86
otb::StreamingResampleImageFilter::m_SignedOutputSpacing
SpacingType m_SignedOutputSpacing
Definition: otbStreamingResampleImageFilter.h:187
otb::StreamingResampleImageFilter::GetDisplacementFieldSpacing
const SpacingType & GetDisplacementFieldSpacing() const
Definition: otbStreamingResampleImageFilter.h:115
otbGetObjectMemberConstMacro
#define otbGetObjectMemberConstMacro(object, name, type)
Definition: otbMacro.h:100
otb::StreamingResampleImageFilter::DefaultInterpolatorType
itk::LinearInterpolateImageFunction< InputImageType, TInterpolatorPrecisionType > DefaultInterpolatorType
Definition: otbStreamingResampleImageFilter.h:97
otb::StreamingResampleImageFilter::SizeType
DisplacementFieldGeneratorType::SizeType SizeType
Definition: otbStreamingResampleImageFilter.h:88
otbGetObjectMemberMacro
#define otbGetObjectMemberMacro(object, name, type)
Definition: otbMacro.h:89
otbSetObjectMemberMacro
#define otbSetObjectMemberMacro(object, name, type)
Definition: otbMacro.h:79
otb::StreamingResampleImageFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbStreamingResampleImageFilter.h:66
otb::StreamingResampleImageFilter::InterpolatorPointerType
InterpolatorType::Pointer InterpolatorPointerType
Definition: otbStreamingResampleImageFilter.h:96
otb::StreamingWarpImageFilter
This class acts like the itk::WarpImageFilter, but it does not request the largest possible region of...
Definition: otbStreamingWarpImageFilter.h:52