OTB  5.0.0
Orfeo Toolbox
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 {
63 template <class TInputImage, class TOutputImage, class TBoundaryCondition =
66 class ITK_EXPORT ConvolutionImageFilter :
67  public itk::ImageToImageFilter<TInputImage, TOutputImage>
68 {
69 public:
71  itkStaticConstMacro(InputImageDimension, unsigned int,
72  TInputImage::ImageDimension);
73  itkStaticConstMacro(OutputImageDimension, unsigned int,
74  TOutputImage::ImageDimension);
76 
78  typedef TInputImage InputImageType;
79  typedef TOutputImage OutputImageType;
80 
86 
88  itkNewMacro(Self);
89 
91  itkTypeMacro(ConvolutionImageFilter, ImageToImageFilter);
92 
94  typedef typename InputImageType::PixelType InputPixelType;
95  typedef typename OutputImageType::PixelType OutputPixelType;
97  typedef typename InputImageType::RegionType InputImageRegionType;
98  typedef typename OutputImageType::RegionType OutputImageRegionType;
99  typedef typename InputImageType::SizeType InputSizeType;
100  typedef TFilterPrecision FilterPrecisionType;
102  typedef TBoundaryCondition BoundaryConditionType;
103 
105  virtual void SetRadius(const InputSizeType rad)
106  {
107  itkDebugMacro("setting radius to " << rad);
108  if (this->m_Radius != rad)
109  {
110  this->m_Radius = rad;
111  unsigned int arraySize = 1;
112  for (unsigned int i = 0; i < m_Radius.GetSizeDimension(); ++i)
113  {
114  arraySize *= 2 * this->m_Radius[i] + 1;
115  }
116  this->m_Filter.SetSize(arraySize);
117  this->m_Filter.Fill(1);
118  this->Modified();
119  }
120  }
122 
124  itkGetConstReferenceMacro(Radius, InputSizeType);
125 
127  virtual void SetFilter(ArrayType filter)
128  {
129  if (filter.Size() != m_Filter.Size())
130  {
131  itkExceptionMacro(
132  "Error in SetFilter, invalid filter size:" << filter.Size() <<
133  " instead of (2*m_Radius[0]+1)*(2*m_Radius[1]+1): " << m_Filter.Size());
134  }
135  else
136  {
137  m_Filter = filter;
138  }
139  this->Modified();
140  }
141  itkGetConstReferenceMacro(Filter, ArrayType);
143 
147  itkSetMacro(NormalizeFilter, bool);
148  itkGetMacro(NormalizeFilter, bool);
149  itkBooleanMacro(NormalizeFilter);
151 
152 #ifdef ITK_USE_CONCEPT_CHECKING
153 
154  itkConceptMacro(InputHasNumericTraitsCheck,
156 
158 #endif
159 
160 protected:
163  void PrintSelf(std::ostream& os, itk::Indent indent) const;
164 
175  void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,
176  itk::ThreadIdType threadId);
177 
184  virtual void GenerateInputRequestedRegion()
185  throw(itk::InvalidRequestedRegionError);
186 
187 private:
188  ConvolutionImageFilter(const Self &); //purposely not implemented
189  void operator =(const Self&); //purposely not implemented
190 
192  InputSizeType m_Radius;
193 
195  ArrayType m_Filter;
196 
198  bool m_NormalizeFilter;
199 };
200 
201 } // end namespace itk
202 
203 #ifndef OTB_MANUAL_INSTANTIATION
205 #endif
206 
207 #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