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/01/25 16:09:29 $
00007   Version:   $Revision: 1.3 $
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 {
00107 template <class TInputImage, class TOutputImage, class TKernel>
00108 class ITK_EXPORT BinaryMorphologyImageFilter :
00109     public ImageToImageFilter< TInputImage, TOutputImage >
00110 {
00111 public:
00112 
00114   itkStaticConstMacro(InputImageDimension, unsigned int,
00115                       TInputImage::ImageDimension);
00116   itkStaticConstMacro(OutputImageDimension, unsigned int,
00117                       TOutputImage::ImageDimension);
00119 
00121   itkStaticConstMacro(KernelDimension, unsigned int,
00122                       TKernel::NeighborhoodDimension);
00123 
00125   typedef TInputImage  InputImageType;
00126   typedef TOutputImage OutputImageType;
00127 
00129   typedef BinaryMorphologyImageFilter                          Self;
00130   typedef ImageToImageFilter< InputImageType, OutputImageType> Superclass;
00131   typedef SmartPointer<Self>                                   Pointer;
00132   typedef SmartPointer<const Self>                             ConstPointer;
00133 
00135   itkNewMacro(Self);
00136 
00138   itkTypeMacro(BinaryMorphologyImageFilter, ImageToImageFilter);
00139 
00141   typedef TKernel KernelType;
00142 
00144   typedef typename KernelType::ConstIterator KernelIteratorType;
00145 
00147   typedef typename InputImageType::PixelType               InputPixelType;
00148   typedef typename OutputImageType::PixelType              OutputPixelType;
00149   typedef typename NumericTraits<InputPixelType>::RealType InputRealType;
00150   typedef typename InputImageType::OffsetType              OffsetType;
00151   typedef typename InputImageType::IndexType               IndexType;
00152 
00153   typedef typename InputImageType::RegionType  InputImageRegionType;
00154   typedef typename OutputImageType::RegionType OutputImageRegionType;
00155   typedef typename InputImageType::SizeType    InputSizeType;
00156 
00158   itkConceptMacro(ImageDimensionCheck,
00159       (Concept::SameDimension<itkGetStaticConstMacro(InputImageDimension),
00160                               itkGetStaticConstMacro(OutputImageDimension)>));
00161 
00162 // Cannot get this to work with gcc compiler
00163 #if 0
00164 
00165   itkConceptMacro(KernelDimensionCheck,
00166       (Concept::SameDimension<itkGetStaticConstMacro(KernelDimension),
00167                               itkGetStaticConstMacro(InputImageDimension)>));
00168 #endif
00169 
00171   void SetKernel( const KernelType& kernel );
00172 
00174   itkGetConstReferenceMacro(Kernel, KernelType);
00175 
00179   itkSetMacro(ForegroundValue, InputPixelType);
00180 
00183   itkGetConstMacro(ForegroundValue, InputPixelType);
00184 
00189   itkSetMacro(BackgroundValue, OutputPixelType);
00190 
00195   itkGetConstMacro(BackgroundValue, OutputPixelType);
00196 
00199   itkSetMacro(BoundaryToForeground, bool);
00200   itkGetConstReferenceMacro(BoundaryToForeground, bool);
00201   itkBooleanMacro(BoundaryToForeground);
00203 
00204 protected:
00205   BinaryMorphologyImageFilter();
00206   virtual ~BinaryMorphologyImageFilter(){}
00207   void PrintSelf(std::ostream& os, Indent indent) const;
00208 
00212   void AnalyzeKernel();
00213 
00222   void GenerateInputRequestedRegion() throw (InvalidRequestedRegionError);
00223 
00224   // type definition of container of neighbourhood index
00225   typedef std::vector< OffsetType > NeighborIndexContainer;
00226 
00227   // type definition of container of container of neighbourhood index
00228   typedef std::vector<NeighborIndexContainer> NeighborIndexContainerContainer;
00229 
00230   // type definition of the container for indices
00231   typedef std::vector< OffsetType > ComponentVectorType;
00232 
00233   // iterator for ComponentVectorType
00234   typedef typename ComponentVectorType::const_iterator
00235     ComponentVectorConstIterator;
00236 
00240   NeighborIndexContainer& GetDifferenceSet(unsigned int code)
00241     { return m_KernelDifferenceSets[code]; }
00242 
00246   ComponentVectorConstIterator KernelCCVectorBegin()
00247     { return m_KernelCCVector.begin(); }
00248 
00252   ComponentVectorConstIterator KernelCCVectorEnd()
00253     { return m_KernelCCVector.end(); }
00254 
00258   InputSizeType GetRadius() const
00259     { return m_Radius; }
00260 
00261   bool m_BoundaryToForeground;
00262 
00263 private:
00264   BinaryMorphologyImageFilter(const Self&); //purposely not implemented
00265   void operator=(const Self&); //purposely not implemented
00266 
00269   InputSizeType m_Radius;
00270 
00272   KernelType m_Kernel;
00273 
00275   InputPixelType m_ForegroundValue;
00276 
00278   OutputPixelType m_BackgroundValue;
00279 
00280   // Difference sets definition
00281   NeighborIndexContainerContainer m_KernelDifferenceSets;
00282 
00283   // For each Connected Component ( CC ) of structuring element we
00284   // store the position of one element, arbitrary chosen, which
00285   // belongs to the CC
00286   std::vector< OffsetType > m_KernelCCVector;
00287 };
00288 
00289 } // end namespace itk
00290 
00291 #ifndef ITK_MANUAL_INSTANTIATION
00292 #include "itkBinaryMorphologyImageFilter.txx"
00293 #endif
00294 
00295 #endif
00296 

Generated at Sun Mar 11 23:32:36 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000