OTB  9.0.0
Orfeo Toolbox
otbConvolutionImageFilter.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 otbConvolutionImageFilter_h
22 #define otbConvolutionImageFilter_h
23 
24 #include "itkImageToImageFilter.h"
25 #include "itkImage.h"
26 #include "itkNumericTraits.h"
27 #include "itkArray.h"
28 #include "itkZeroFluxNeumannBoundaryCondition.h"
29 
30 namespace otb
31 {
66 template <class TInputImage, class TOutputImage, class TBoundaryCondition = itk::ZeroFluxNeumannBoundaryCondition<TInputImage>,
67  class TFilterPrecision = typename itk::NumericTraits<typename TInputImage::InternalPixelType>::RealType>
68 class ITK_EXPORT ConvolutionImageFilter : public itk::ImageToImageFilter<TInputImage, TOutputImage>
69 {
70 public:
72  itkStaticConstMacro(InputImageDimension, unsigned int, TInputImage::ImageDimension);
73  itkStaticConstMacro(OutputImageDimension, unsigned int, TOutputImage::ImageDimension);
75 
77  typedef TInputImage InputImageType;
78  typedef TOutputImage OutputImageType;
79 
82  typedef itk::ImageToImageFilter<InputImageType, OutputImageType> Superclass;
83  typedef itk::SmartPointer<Self> Pointer;
84  typedef itk::SmartPointer<const Self> ConstPointer;
85 
87  itkNewMacro(Self);
88 
90  itkTypeMacro(ConvolutionImageFilter, ImageToImageFilter);
91 
93  typedef typename InputImageType::PixelType InputPixelType;
94  typedef typename OutputImageType::PixelType OutputPixelType;
95  typedef typename itk::NumericTraits<InputPixelType>::RealType InputRealType;
96  typedef typename InputImageType::RegionType InputImageRegionType;
97  typedef typename OutputImageType::RegionType OutputImageRegionType;
98  typedef typename InputImageType::SizeType InputSizeType;
99  typedef TFilterPrecision FilterPrecisionType;
100  typedef typename itk::Array<FilterPrecisionType> ArrayType;
101  typedef TBoundaryCondition BoundaryConditionType;
102 
104  virtual void SetRadius(const InputSizeType rad)
105  {
106  itkDebugMacro("setting radius to " << rad);
107  if (this->m_Radius != rad)
108  {
109  this->m_Radius = rad;
110  unsigned int arraySize = 1;
111  for (unsigned int i = 0; i < m_Radius.GetSizeDimension(); ++i)
112  {
113  arraySize *= 2 * this->m_Radius[i] + 1;
114  }
115  this->m_Filter.SetSize(arraySize);
116  this->m_Filter.Fill(1);
117  this->Modified();
118  }
119  }
121 
123  itkGetConstReferenceMacro(Radius, InputSizeType);
124 
126  virtual void SetFilter(ArrayType filter)
127  {
128  if (filter.Size() != m_Filter.Size())
129  {
130  itkExceptionMacro("Error in SetFilter, invalid filter size:" << filter.Size() << " instead of (2*m_Radius[0]+1)*(2*m_Radius[1]+1): " << m_Filter.Size());
131  }
132  else
133  {
134  m_Filter = filter;
135  }
136  this->Modified();
137  }
138  itkGetConstReferenceMacro(Filter, ArrayType);
140 
144  itkSetMacro(NormalizeFilter, bool);
145  itkGetMacro(NormalizeFilter, bool);
146  itkBooleanMacro(NormalizeFilter);
148 
149 #ifdef ITK_USE_CONCEPT_CHECKING
150 
151  itkConceptMacro(InputHasNumericTraitsCheck, (itk::Concept::HasNumericTraits<InputPixelType>));
152 
154 #endif
155 
156 protected:
159  {
160  }
161  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
162 
173  void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId) override;
174 
181  void GenerateInputRequestedRegion() override;
182 
183 private:
184  ConvolutionImageFilter(const Self&) = delete;
185  void operator=(const Self&) = delete;
186 
189 
192 
195 };
196 
197 } // end namespace itk
198 
199 #ifndef OTB_MANUAL_INSTANTIATION
201 #endif
202 
203 #endif
otb::ConvolutionImageFilter::~ConvolutionImageFilter
~ConvolutionImageFilter() override
Definition: otbConvolutionImageFilter.h:158
otb::ConvolutionImageFilter::m_Radius
InputSizeType m_Radius
Definition: otbConvolutionImageFilter.h:188
otb::ConvolutionImageFilter::InputSizeType
InputImageType::SizeType InputSizeType
Definition: otbConvolutionImageFilter.h:98
otb::ConvolutionImageFilter
Applies a convolution filter to a mono channel image.
Definition: otbConvolutionImageFilter.h:68
otb::ConvolutionImageFilter::InputRealType
itk::NumericTraits< InputPixelType >::RealType InputRealType
Definition: otbConvolutionImageFilter.h:95
otb::ConvolutionImageFilter::ArrayType
itk::Array< FilterPrecisionType > ArrayType
Definition: otbConvolutionImageFilter.h:100
otb::ConvolutionImageFilter::FilterPrecisionType
TFilterPrecision FilterPrecisionType
Definition: otbConvolutionImageFilter.h:99
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::ConvolutionImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbConvolutionImageFilter.h:83
otbConvolutionImageFilter.hxx
otb::Wrapper::Tags::Filter
static const std::string Filter
Definition: otbWrapperTags.h:39
otb::ConvolutionImageFilter::Self
ConvolutionImageFilter Self
Definition: otbConvolutionImageFilter.h:81
otb::ConvolutionImageFilter::SetFilter
virtual void SetFilter(ArrayType filter)
Definition: otbConvolutionImageFilter.h:126
otb::ConvolutionImageFilter::Superclass
itk::ImageToImageFilter< InputImageType, OutputImageType > Superclass
Definition: otbConvolutionImageFilter.h:82
otb::ConvolutionImageFilter::InputImageType
TInputImage InputImageType
Definition: otbConvolutionImageFilter.h:77
otb::ConvolutionImageFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbConvolutionImageFilter.h:84
otb::ConvolutionImageFilter::OutputImageRegionType
OutputImageType::RegionType OutputImageRegionType
Definition: otbConvolutionImageFilter.h:97
otb::ConvolutionImageFilter::InputImageRegionType
InputImageType::RegionType InputImageRegionType
Definition: otbConvolutionImageFilter.h:96
otb::ConvolutionImageFilter::OutputPixelType
OutputImageType::PixelType OutputPixelType
Definition: otbConvolutionImageFilter.h:94
otb::ConvolutionImageFilter::OutputImageType
TOutputImage OutputImageType
Definition: otbConvolutionImageFilter.h:78
otb::ConvolutionImageFilter::m_Filter
ArrayType m_Filter
Definition: otbConvolutionImageFilter.h:191
otb::ConvolutionImageFilter::SetRadius
virtual void SetRadius(const InputSizeType rad)
Definition: otbConvolutionImageFilter.h:104
otb::ConvolutionImageFilter::m_NormalizeFilter
bool m_NormalizeFilter
Definition: otbConvolutionImageFilter.h:194
otb::ConvolutionImageFilter::BoundaryConditionType
TBoundaryCondition BoundaryConditionType
Definition: otbConvolutionImageFilter.h:101
otb::ConvolutionImageFilter::InputPixelType
InputImageType::PixelType InputPixelType
Definition: otbConvolutionImageFilter.h:90