ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkKernelImageFilter.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkKernelImageFilter_h
00019 #define __itkKernelImageFilter_h
00020 
00021 #include "itkBoxImageFilter.h"
00022 #include "itkFlatStructuringElement.h"
00023 
00024 namespace itk
00025 {
00039 template< class TInputImage, class TOutputImage, class TKernel /*=Neighborhood<bool,
00040                                                                  TInputImage::ImageDimension>*/                     >
00041 class ITK_EXPORT KernelImageFilter:
00042   public BoxImageFilter< TInputImage, TOutputImage >
00043 {
00044 public:
00046   typedef KernelImageFilter                           Self;
00047   typedef BoxImageFilter< TInputImage, TOutputImage > Superclass;
00048   typedef SmartPointer< Self >                        Pointer;
00049   typedef SmartPointer< const Self >                  ConstPointer;
00050 
00052   itkNewMacro(Self);
00053 
00055   itkTypeMacro(KernelImageFilter,
00056                BoxImageFilter);
00057 
00059   typedef TInputImage                      InputImageType;
00060   typedef typename TInputImage::RegionType RegionType;
00061   typedef typename TInputImage::SizeType   SizeType;
00062   typedef typename TInputImage::IndexType  IndexType;
00063   typedef typename TInputImage::OffsetType OffsetType;
00064 
00065   typedef typename TInputImage::PixelType InputPixelType;
00066 
00067   typedef TOutputImage                     OutputImageType;
00068   typedef typename TOutputImage::PixelType OutputPixelType;
00069 
00070   typedef TKernel KernelType;
00071 
00073   itkStaticConstMacro(ImageDimension, unsigned int,
00074                       TInputImage::ImageDimension);
00075 
00077   typedef FlatStructuringElement< itkGetStaticConstMacro(ImageDimension) >
00078   FlatKernelType;
00079 
00081   typedef typename TInputImage::SizeType RadiusType;
00082 
00084   virtual void SetKernel(const KernelType & kernel);
00085 
00086   itkGetConstReferenceMacro(Kernel, KernelType);
00087 
00089   virtual void SetRadius(const RadiusType & radius);
00090 
00091   virtual void SetRadius(const SizeValueType & radius)
00092   {
00093     // needed because of the overloading of the method
00094     Superclass::SetRadius(radius);
00095   }
00096 
00097 protected:
00098   KernelImageFilter();
00099   ~KernelImageFilter() {}
00100 
00101   void PrintSelf(std::ostream & os, Indent indent) const;
00102 
00104   KernelType m_Kernel;
00105 private:
00106   KernelImageFilter(const Self &); //purposely not implemented
00107   void operator=(const Self &);    //purposely not implemented
00109 
00110   template<class T> void MakeKernel( const RadiusType & radius, T & kernel )
00111   {
00112     kernel.SetRadius( radius );
00113     for( typename T::Iterator kit=kernel.Begin(); kit != kernel.End(); kit++ )
00114       {
00115       *kit = 1;
00116       }
00117   }
00118 
00119   void MakeKernel( const RadiusType & radius, FlatKernelType & kernel )
00120   {
00121     // set up a decomposable box structuring element which is
00122     // much efficient with van Herk / Gil Werman filters
00123     kernel = FlatKernelType::Box( radius );
00124     assert( kernel.GetDecomposable() );
00125   }
00126 };
00127 }
00128 
00129 #ifndef ITK_MANUAL_INSTANTIATION
00130 #include "itkKernelImageFilter.hxx"
00131 #endif
00132 
00133 #endif
00134