ITK  4.2.0
Insight Segmentation and Registration Toolkit
itkKernelImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkKernelImageFilter_h
19 #define __itkKernelImageFilter_h
20 
21 #include "itkBoxImageFilter.h"
23 
24 namespace itk
25 {
39 template< class TInputImage, class TOutputImage, class TKernel /*=Neighborhood<bool,
40  TInputImage::ImageDimension>*/ >
41 class ITK_EXPORT KernelImageFilter:
42  public BoxImageFilter< TInputImage, TOutputImage >
43 {
44 public:
50 
52  itkNewMacro(Self);
53 
55  itkTypeMacro(KernelImageFilter,
57 
59  typedef TInputImage InputImageType;
60  typedef typename TInputImage::RegionType RegionType;
61  typedef typename TInputImage::SizeType SizeType;
62  typedef typename TInputImage::IndexType IndexType;
63  typedef typename TInputImage::OffsetType OffsetType;
64 
65  typedef typename TInputImage::PixelType InputPixelType;
66 
67  typedef TOutputImage OutputImageType;
68  typedef typename TOutputImage::PixelType OutputPixelType;
69 
70  typedef TKernel KernelType;
71 
73  itkStaticConstMacro(ImageDimension, unsigned int,
74  TInputImage::ImageDimension);
75 
79 
81  typedef typename TInputImage::SizeType RadiusType;
82 
84  virtual void SetKernel(const KernelType & kernel);
85 
86  itkGetConstReferenceMacro(Kernel, KernelType);
87 
89  virtual void SetRadius(const RadiusType & radius);
90 
91  virtual void SetRadius(const SizeValueType & radius)
92  {
93  // needed because of the overloading of the method
94  Superclass::SetRadius(radius);
95  }
96 
97 protected:
100 
101  void PrintSelf(std::ostream & os, Indent indent) const;
102 
105 private:
106  KernelImageFilter(const Self &); //purposely not implemented
107  void operator=(const Self &); //purposely not implemented
109 
110  template<class T> void MakeKernel( const RadiusType & radius, T & kernel )
111  {
112  kernel.SetRadius( radius );
113  for( typename T::Iterator kit=kernel.Begin(); kit != kernel.End(); kit++ )
114  {
115  *kit = 1;
116  }
117  }
118 
119  void MakeKernel( const RadiusType & radius, FlatKernelType & kernel )
120  {
121  // set up a decomposable box structuring element which is
122  // much efficient with van Herk / Gil Werman filters
123  kernel = FlatKernelType::Box( radius );
124  assert( kernel.GetDecomposable() );
125  }
126 };
127 }
128 
129 #ifndef ITK_MANUAL_INSTANTIATION
130 #include "itkKernelImageFilter.hxx"
131 #endif
132 
133 #endif
134