Orfeo ToolBox  4.2
Orfeo ToolBox is not a black box
otbConvolutionImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 #ifndef __otbConvolutionImageFilter_h
19 #define __otbConvolutionImageFilter_h
20 
21 #include "itkImageToImageFilter.h"
22 #include "itkImage.h"
23 #include "itkNumericTraits.h"
24 #include "itkArray.h"
26 
27 namespace otb
28 {
61 template <class TInputImage, class TOutputImage, class TBoundaryCondition =
64 class ITK_EXPORT ConvolutionImageFilter :
65  public itk::ImageToImageFilter<TInputImage, TOutputImage>
66 {
67 public:
69  itkStaticConstMacro(InputImageDimension, unsigned int,
70  TInputImage::ImageDimension);
71  itkStaticConstMacro(OutputImageDimension, unsigned int,
72  TOutputImage::ImageDimension);
73 
75  typedef TInputImage InputImageType;
76  typedef TOutputImage OutputImageType;
77 
83 
85  itkNewMacro(Self);
86 
88  itkTypeMacro(ConvolutionImageFilter, ImageToImageFilter);
89 
91  typedef typename InputImageType::PixelType InputPixelType;
92  typedef typename OutputImageType::PixelType OutputPixelType;
94  typedef typename InputImageType::RegionType InputImageRegionType;
95  typedef typename OutputImageType::RegionType OutputImageRegionType;
96  typedef typename InputImageType::SizeType InputSizeType;
97  typedef TFilterPrecision FilterPrecisionType;
99  typedef TBoundaryCondition BoundaryConditionType;
100 
102  virtual void SetRadius(const InputSizeType rad)
103  {
104  itkDebugMacro("setting radius to " << rad);
105  if (this->m_Radius != rad)
106  {
107  this->m_Radius = rad;
108  unsigned int arraySize = 1;
109  for (unsigned int i = 0; i < m_Radius.GetSizeDimension(); ++i)
110  {
111  arraySize *= 2 * this->m_Radius[i] + 1;
112  }
113  this->m_Filter.SetSize(arraySize);
114  this->m_Filter.Fill(1);
115  this->Modified();
116  }
117  }
118 
120  itkGetConstReferenceMacro(Radius, InputSizeType);
121 
123  virtual void SetFilter(ArrayType filter)
124  {
125  if (filter.Size() != m_Filter.Size())
126  {
127  itkExceptionMacro(
128  "Error in SetFilter, invalid filter size:" << filter.Size() <<
129  " instead of (2*m_Radius[0]+1)*(2*m_Radius[1]+1): " << m_Filter.Size());
130  }
131  else
132  {
133  m_Filter = filter;
134  }
135  this->Modified();
136  }
137  itkGetConstReferenceMacro(Filter, ArrayType);
138 
142  itkSetMacro(NormalizeFilter, bool);
143  itkGetMacro(NormalizeFilter, bool);
144  itkBooleanMacro(NormalizeFilter);
145 
146 #ifdef ITK_USE_CONCEPT_CHECKING
147 
148  itkConceptMacro(InputHasNumericTraitsCheck,
151 #endif
152 
153 protected:
156  void PrintSelf(std::ostream& os, itk::Indent indent) const;
157 
168  void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,
169  itk::ThreadIdType threadId);
170 
177  virtual void GenerateInputRequestedRegion()
178  throw(itk::InvalidRequestedRegionError);
179 
180 private:
181  ConvolutionImageFilter(const Self &); //purposely not implemented
182  void operator =(const Self&); //purposely not implemented
183 
185  InputSizeType m_Radius;
187  ArrayType m_Filter;
189  bool m_NormalizeFilter;
190 };
191 
192 } // end namespace itk
193 
194 #ifndef OTB_MANUAL_INSTANTIATION
196 #endif
197 
198 #endif
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
SizeValueType Size(void) const
OutputImageType::RegionType OutputImageRegionType
#define itkConceptMacro(name, concept)
OutputImageType::PixelType OutputPixelType
InputImageType::SizeType InputSizeType
itk::SmartPointer< const Self > ConstPointer
unsigned int ThreadIdType