ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkBinaryMorphologyImageFilter.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 __itkBinaryMorphologyImageFilter_h
00019 #define __itkBinaryMorphologyImageFilter_h
00020 
00021 #include <vector>
00022 #include <queue>
00023 #include "itkKernelImageFilter.h"
00024 #include "itkNeighborhoodIterator.h"
00025 #include "itkImageBoundaryCondition.h"
00026 #include "itkImageRegionIterator.h"
00027 #include "itkConceptChecking.h"
00028 
00029 namespace itk
00030 {
00102 template< class TInputImage, class TOutputImage, class TKernel >
00103 class ITK_EXPORT BinaryMorphologyImageFilter:
00104   public KernelImageFilter< TInputImage, TOutputImage, TKernel >
00105 {
00106 public:
00107 
00109   itkStaticConstMacro(InputImageDimension, unsigned int,
00110                       TInputImage::ImageDimension);
00111   itkStaticConstMacro(OutputImageDimension, unsigned int,
00112                       TOutputImage::ImageDimension);
00114 
00116   itkStaticConstMacro(KernelDimension, unsigned int,
00117                       TKernel::NeighborhoodDimension);
00118 
00120   typedef TInputImage  InputImageType;
00121   typedef TOutputImage OutputImageType;
00122 
00124   typedef BinaryMorphologyImageFilter                                   Self;
00125   typedef KernelImageFilter< InputImageType, OutputImageType, TKernel > Superclass;
00126   typedef SmartPointer< Self >                                          Pointer;
00127   typedef SmartPointer< const Self >                                    ConstPointer;
00128 
00130   itkNewMacro(Self);
00131 
00133   itkTypeMacro(BinaryMorphologyImageFilter, ImageToImageFilter);
00134 
00136   typedef TKernel KernelType;
00137 
00139   typedef typename KernelType::ConstIterator KernelIteratorType;
00140 
00142   typedef typename InputImageType::PixelType                 InputPixelType;
00143   typedef typename OutputImageType::PixelType                OutputPixelType;
00144   typedef typename NumericTraits< InputPixelType >::RealType InputRealType;
00145   typedef typename InputImageType::OffsetType                OffsetType;
00146   typedef typename InputImageType::IndexType                 IndexType;
00147   typedef typename InputImageType::IndexValueType            IndexValueType;
00148 
00149   typedef typename InputImageType::RegionType    InputImageRegionType;
00150   typedef typename OutputImageType::RegionType   OutputImageRegionType;
00151   typedef typename InputImageType::SizeType      InputSizeType;
00152   typedef typename InputImageType::SizeValueType InputSizeValueType;
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 
00170   itkSetMacro(ForegroundValue, InputPixelType);
00171 
00174   itkGetConstMacro(ForegroundValue, InputPixelType);
00175 
00180   itkSetMacro(BackgroundValue, OutputPixelType);
00181 
00186   itkGetConstMacro(BackgroundValue, OutputPixelType);
00187 
00190   itkSetMacro(BoundaryToForeground, bool);
00191   itkGetConstReferenceMacro(BoundaryToForeground, bool);
00192   itkBooleanMacro(BoundaryToForeground);
00194 
00196   void SetKernel(const KernelType & kernel);
00197 
00198 protected:
00199   BinaryMorphologyImageFilter();
00200   virtual ~BinaryMorphologyImageFilter(){}
00201   void PrintSelf(std::ostream & os, Indent indent) const;
00202 
00205   void AnalyzeKernel();
00206 
00208   typedef std::vector< OffsetType > NeighborIndexContainer;
00209 
00211   typedef std::vector< NeighborIndexContainer > NeighborIndexContainerContainer;
00212 
00214   typedef std::vector< OffsetType > ComponentVectorType;
00215 
00217   typedef typename ComponentVectorType::const_iterator
00218   ComponentVectorConstIterator;
00219 
00222   NeighborIndexContainer & GetDifferenceSet(unsigned int code)
00223   { return m_KernelDifferenceSets[code]; }
00224 
00227   ComponentVectorConstIterator KernelCCVectorBegin()
00228   { return m_KernelCCVector.begin(); }
00229 
00232   ComponentVectorConstIterator KernelCCVectorEnd()
00233   { return m_KernelCCVector.end(); }
00234 
00235   bool m_BoundaryToForeground;
00236 private:
00237   BinaryMorphologyImageFilter(const Self &); //purposely not implemented
00238   void operator=(const Self &);              //purposely not implemented
00239 
00241   InputPixelType m_ForegroundValue;
00242 
00244   OutputPixelType m_BackgroundValue;
00245 
00247   NeighborIndexContainerContainer m_KernelDifferenceSets;
00248 
00252   std::vector< OffsetType > m_KernelCCVector;
00253 };
00254 } // end namespace itk
00255 
00256 #ifndef ITK_MANUAL_INSTANTIATION
00257 #include "itkBinaryMorphologyImageFilter.hxx"
00258 #endif
00259 
00260 #endif
00261