OTB  6.1.0
Orfeo Toolbox
otbConvolutionImageFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2017 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"
29 
30 namespace otb
31 {
66 template <class TInputImage, class TOutputImage, class TBoundaryCondition =
69 class ITK_EXPORT ConvolutionImageFilter :
70  public itk::ImageToImageFilter<TInputImage, TOutputImage>
71 {
72 public:
74  itkStaticConstMacro(InputImageDimension, unsigned int,
75  TInputImage::ImageDimension);
76  itkStaticConstMacro(OutputImageDimension, unsigned int,
77  TOutputImage::ImageDimension);
79 
81  typedef TInputImage InputImageType;
82  typedef TOutputImage OutputImageType;
83 
89 
91  itkNewMacro(Self);
92 
94  itkTypeMacro(ConvolutionImageFilter, ImageToImageFilter);
95 
97  typedef typename InputImageType::PixelType InputPixelType;
98  typedef typename OutputImageType::PixelType OutputPixelType;
100  typedef typename InputImageType::RegionType InputImageRegionType;
101  typedef typename OutputImageType::RegionType OutputImageRegionType;
103  typedef TFilterPrecision FilterPrecisionType;
105  typedef TBoundaryCondition BoundaryConditionType;
106 
108  virtual void SetRadius(const InputSizeType rad)
109  {
110  itkDebugMacro("setting radius to " << rad);
111  if (this->m_Radius != rad)
112  {
113  this->m_Radius = rad;
114  unsigned int arraySize = 1;
115  for (unsigned int i = 0; i < m_Radius.GetSizeDimension(); ++i)
116  {
117  arraySize *= 2 * this->m_Radius[i] + 1;
118  }
119  this->m_Filter.SetSize(arraySize);
120  this->m_Filter.Fill(1);
121  this->Modified();
122  }
123  }
125 
127  itkGetConstReferenceMacro(Radius, InputSizeType);
128 
130  virtual void SetFilter(ArrayType filter)
131  {
132  if (filter.Size() != m_Filter.Size())
133  {
134  itkExceptionMacro(
135  "Error in SetFilter, invalid filter size:" << filter.Size() <<
136  " instead of (2*m_Radius[0]+1)*(2*m_Radius[1]+1): " << m_Filter.Size());
137  }
138  else
139  {
140  m_Filter = filter;
141  }
142  this->Modified();
143  }
144  itkGetConstReferenceMacro(Filter, ArrayType);
146 
150  itkSetMacro(NormalizeFilter, bool);
151  itkGetMacro(NormalizeFilter, bool);
152  itkBooleanMacro(NormalizeFilter);
154 
155 #ifdef ITK_USE_CONCEPT_CHECKING
156 
157  itkConceptMacro(InputHasNumericTraitsCheck,
159 
161 #endif
162 
163 protected:
165  ~ConvolutionImageFilter() ITK_OVERRIDE {}
166  void PrintSelf(std::ostream& os, itk::Indent indent) const ITK_OVERRIDE;
167 
178  void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,
179  itk::ThreadIdType threadId) ITK_OVERRIDE;
180 
187  void GenerateInputRequestedRegion()
188  throw(itk::InvalidRequestedRegionError) ITK_OVERRIDE;
189 
190 private:
191  ConvolutionImageFilter(const Self &); //purposely not implemented
192  void operator =(const Self&); //purposely not implemented
193 
195  InputSizeType m_Radius;
196 
198  ArrayType m_Filter;
199 
201  bool m_NormalizeFilter;
202 };
203 
204 } // end namespace itk
205 
206 #ifndef OTB_MANUAL_INSTANTIATION
208 #endif
209 
210 #endif
itk::Size< Monteverdi_DIMENSION > SizeType
Definition: mvdTypes.h:146
InputImageType::RegionType InputImageRegionType
virtual void SetFilter(ArrayType filter)
virtual void SetRadius(const InputSizeType rad)
Applies a convolution filter to a mono channel image.
itk::NumericTraits< InputPixelType >::RealType InputRealType
static const std::string Filter
itk::Array< FilterPrecisionType > ArrayType
InputImageType::PixelType InputPixelType
itk::ImageToImageFilter< InputImageType, OutputImageType > Superclass
itk::SmartPointer< Self > Pointer
unsigned int ThreadIdType
SizeValueType Size(void) const
OutputImageType::RegionType OutputImageRegionType
#define itkConceptMacro(name, concept)
OutputImageType::PixelType OutputPixelType
InputImageType::SizeType InputSizeType
itk::SmartPointer< const Self > ConstPointer