Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkBinaryMorphologyImageFilter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkBinaryMorphologyImageFilter.h,v $
00005   Language:  C++
00006   Date:      $Date: 2007/09/12 09:20:29 $
00007   Version:   $Revision: 1.4 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkBinaryMorphologyImageFilter_h
00018 #define __itkBinaryMorphologyImageFilter_h
00019 
00020 #include <vector>
00021 #include <queue>
00022 #include "itkImageToImageFilter.h"
00023 #include "itkImage.h"
00024 #include "itkNumericTraits.h"
00025 #include "itkNeighborhoodIterator.h"
00026 #include "itkConstNeighborhoodIterator.h"
00027 #include "itkNeighborhood.h"
00028 #include "itkImageBoundaryCondition.h"
00029 #include "itkImageRegionIterator.h"
00030 #include "itkConceptChecking.h"
00031 
00032 namespace itk
00033 {
00104 template <class TInputImage, class TOutputImage, class TKernel>
00105 class ITK_EXPORT BinaryMorphologyImageFilter :
00106     public ImageToImageFilter< TInputImage, TOutputImage >
00107 {
00108 public:
00109 
00111   itkStaticConstMacro(InputImageDimension, unsigned int,
00112                       TInputImage::ImageDimension);
00113   itkStaticConstMacro(OutputImageDimension, unsigned int,
00114                       TOutputImage::ImageDimension);
00116 
00118   itkStaticConstMacro(KernelDimension, unsigned int,
00119                       TKernel::NeighborhoodDimension);
00120 
00122   typedef TInputImage  InputImageType;
00123   typedef TOutputImage OutputImageType;
00124 
00126   typedef BinaryMorphologyImageFilter                          Self;
00127   typedef ImageToImageFilter< InputImageType, OutputImageType> Superclass;
00128   typedef SmartPointer<Self>                                   Pointer;
00129   typedef SmartPointer<const Self>                             ConstPointer;
00130 
00132   itkNewMacro(Self);
00133 
00135   itkTypeMacro(BinaryMorphologyImageFilter, ImageToImageFilter);
00136 
00138   typedef TKernel KernelType;
00139 
00141   typedef typename KernelType::ConstIterator KernelIteratorType;
00142 
00144   typedef typename InputImageType::PixelType               InputPixelType;
00145   typedef typename OutputImageType::PixelType              OutputPixelType;
00146   typedef typename NumericTraits<InputPixelType>::RealType InputRealType;
00147   typedef typename InputImageType::OffsetType              OffsetType;
00148   typedef typename InputImageType::IndexType               IndexType;
00149 
00150   typedef typename InputImageType::RegionType  InputImageRegionType;
00151   typedef typename OutputImageType::RegionType OutputImageRegionType;
00152   typedef typename InputImageType::SizeType    InputSizeType;
00153 
00155   itkConceptMacro(ImageDimensionCheck,
00156       (Concept::SameDimension<itkGetStaticConstMacro(InputImageDimension),
00157                               itkGetStaticConstMacro(OutputImageDimension)>));
00158 
00159 // Cannot get this to work with gcc compiler
00160 #if 0
00161 
00162   itkConceptMacro(KernelDimensionCheck,
00163       (Concept::SameDimension<itkGetStaticConstMacro(KernelDimension),
00164                               itkGetStaticConstMacro(InputImageDimension)>));
00165 #endif
00166 
00168   void SetKernel( const KernelType& kernel );
00169 
00171   itkGetConstReferenceMacro(Kernel, KernelType);
00172 
00176   itkSetMacro(ForegroundValue, InputPixelType);
00177 
00180   itkGetConstMacro(ForegroundValue, InputPixelType);
00181 
00186   itkSetMacro(BackgroundValue, OutputPixelType);
00187 
00192   itkGetConstMacro(BackgroundValue, OutputPixelType);
00193 
00196   itkSetMacro(BoundaryToForeground, bool);
00197   itkGetConstReferenceMacro(BoundaryToForeground, bool);
00198   itkBooleanMacro(BoundaryToForeground);
00200 
00201 protected:
00202   BinaryMorphologyImageFilter();
00203   virtual ~BinaryMorphologyImageFilter(){}
00204   void PrintSelf(std::ostream& os, Indent indent) const;
00205 
00209   void AnalyzeKernel();
00210 
00219   void GenerateInputRequestedRegion() throw (InvalidRequestedRegionError);
00220 
00221   // type definition of container of neighbourhood index
00222   typedef std::vector< OffsetType > NeighborIndexContainer;
00223 
00224   // type definition of container of container of neighbourhood index
00225   typedef std::vector<NeighborIndexContainer> NeighborIndexContainerContainer;
00226 
00227   // type definition of the container for indices
00228   typedef std::vector< OffsetType > ComponentVectorType;
00229 
00230   // iterator for ComponentVectorType
00231   typedef typename ComponentVectorType::const_iterator
00232     ComponentVectorConstIterator;
00233 
00237   NeighborIndexContainer& GetDifferenceSet(unsigned int code)
00238     { return m_KernelDifferenceSets[code]; }
00239 
00243   ComponentVectorConstIterator KernelCCVectorBegin()
00244     { return m_KernelCCVector.begin(); }
00245 
00249   ComponentVectorConstIterator KernelCCVectorEnd()
00250     { return m_KernelCCVector.end(); }
00251 
00255   InputSizeType GetRadius() const
00256     { return m_Radius; }
00257 
00258   bool m_BoundaryToForeground;
00259 
00260 private:
00261   BinaryMorphologyImageFilter(const Self&); //purposely not implemented
00262   void operator=(const Self&); //purposely not implemented
00263 
00266   InputSizeType m_Radius;
00267 
00269   KernelType m_Kernel;
00270 
00272   InputPixelType m_ForegroundValue;
00273 
00275   OutputPixelType m_BackgroundValue;
00276 
00277   // Difference sets definition
00278   NeighborIndexContainerContainer m_KernelDifferenceSets;
00279 
00280   // For each Connected Component ( CC ) of structuring element we
00281   // store the position of one element, arbitrary chosen, which
00282   // belongs to the CC
00283   std::vector< OffsetType > m_KernelCCVector;
00284 };
00285 
00286 } // end namespace itk
00287 
00288 #ifndef ITK_MANUAL_INSTANTIATION
00289 #include "itkBinaryMorphologyImageFilter.txx"
00290 #endif
00291 
00292 #endif
00293 

Generated at Tue Jul 29 19:13:13 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000