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

itkConnectedComponentImageFilter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkConnectedComponentImageFilter.h,v $
00005   Language:  C++
00006   Date:      $Date: 2007/10/05 10:31:58 $
00007   Version:   $Revision: 1.17 $
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 
00018 #ifndef __itkConnectedComponentImageFilter_h
00019 #define __itkConnectedComponentImageFilter_h
00020 
00021 #include "itkImageToImageFilter.h"
00022 #include "itkImage.h"
00023 #include "itkConceptChecking.h"
00024 #include <vector>
00025 #include <map>
00026 #include "itkProgressReporter.h"
00027 
00028 namespace itk
00029 {
00030 
00051 template <class TInputImage, class TOutputImage, class TMaskImage=TInputImage>
00052 class ITK_EXPORT ConnectedComponentImageFilter : 
00053     public ImageToImageFilter< TInputImage, TOutputImage > 
00054 {
00055 public:
00059   typedef ConnectedComponentImageFilter                   Self;
00060   typedef ImageToImageFilter< TInputImage, TOutputImage > Superclass;
00061 
00065   typedef typename Superclass::InputImagePointer InputImagePointer;
00066 
00071   typedef typename TOutputImage::PixelType         OutputPixelType;
00072   typedef typename TOutputImage::InternalPixelType OutputInternalPixelType;
00073   typedef typename TInputImage::PixelType          InputPixelType;
00074   typedef typename TInputImage::InternalPixelType  InputInternalPixelType;
00075   typedef typename TMaskImage::PixelType           MaskPixelType;
00076   itkStaticConstMacro(ImageDimension, unsigned int,
00077                       TOutputImage::ImageDimension);
00078   itkStaticConstMacro(OutputImageDimension, unsigned int,
00079                       TOutputImage::ImageDimension);
00080   itkStaticConstMacro(InputImageDimension, unsigned int,
00081                       TInputImage::ImageDimension);
00083 
00087   typedef TInputImage                       InputImageType;
00088   typedef TMaskImage                        MaskImageType;
00089   typedef typename TInputImage::IndexType   IndexType;
00090   typedef typename TInputImage::SizeType    SizeType;
00091   typedef typename TInputImage::OffsetType  OffsetType;
00092 
00093   typedef TOutputImage                      OutputImageType;
00094   typedef typename TOutputImage::RegionType RegionType;
00095   typedef typename TOutputImage::IndexType  OutputIndexType;
00096   typedef typename TOutputImage::SizeType   OutputSizeType;
00097   typedef typename TOutputImage::OffsetType OutputOffsetType;
00098 
00099   typedef std::list<IndexType>              ListType;
00100   typedef typename MaskImageType::Pointer   MaskImagePointer;
00101 
00105   typedef SmartPointer<Self>        Pointer;
00106   typedef SmartPointer<const Self>  ConstPointer;
00107 
00111   itkTypeMacro(ConnectedComponentImageFilter, ImageToImageFilter);
00112 
00116   itkNewMacro(Self);
00117 
00124   itkSetMacro(FullyConnected, bool);
00125   itkGetConstReferenceMacro(FullyConnected, bool);
00126   itkBooleanMacro(FullyConnected);
00128 
00129   // only set after completion
00130   itkGetConstReferenceMacro(ObjectCount, unsigned long);
00131 
00132   // Concept checking -- input and output dimensions must be the same
00133   itkConceptMacro(SameDimension,
00134     (Concept::SameDimension<itkGetStaticConstMacro(InputImageDimension),
00135        itkGetStaticConstMacro(OutputImageDimension)>));
00136 
00137 
00138   void SetMaskImage(TMaskImage* mask)
00139     {
00140     this->SetNthInput(1, const_cast<TMaskImage *>( mask ));
00141     }
00142 
00143   const TMaskImage* GetMaskImage() const
00144     {
00145     return (static_cast<const TMaskImage*>(this->ProcessObject::GetInput(1)));
00146     }
00147   
00148 protected:
00149   ConnectedComponentImageFilter() 
00150     {
00151     m_FullyConnected = false;
00152     m_ObjectCount = 0;
00153     }
00154   virtual ~ConnectedComponentImageFilter() {}
00155   ConnectedComponentImageFilter(const Self&) {}
00156   void PrintSelf(std::ostream& os, Indent indent) const;
00157 
00161   void GenerateData();
00162 
00166   void GenerateInputRequestedRegion();
00167 
00172   void EnlargeOutputRequestedRegion(DataObject *itkNotUsed(output));
00173 
00174   bool m_FullyConnected;
00175   
00176 private:
00177   unsigned long m_ObjectCount;
00178   // some additional types
00179   typedef typename TOutputImage::RegionType::SizeType OutSizeType;
00180 
00181   // types to support the run length encoding of lines
00182   class runLength
00183     {
00184     public:
00185     // run length information - may be a more type safe way of doing this
00186     long int length;
00187     typename InputImageType::IndexType where; // Index of the start of the run
00188     unsigned long int label; // the initial label of the run
00189     };
00190 
00191   typedef std::vector<runLength> lineEncoding;
00192 
00193   // the map storing lines
00194   typedef std::map<long, lineEncoding> LineMapType;
00195   
00196   typedef std::vector<long> OffsetVec;
00197 
00198   // the types to support union-find operations
00199   typedef std::vector<unsigned long int> UnionFindType;
00200   UnionFindType m_UnionFind;
00201   UnionFindType m_Consecutive;
00202   // functions to support union-find operations
00203   void InitUnion(const unsigned long int size) 
00204     {
00205     m_UnionFind = UnionFindType(size + 1);
00206     }
00207   void InsertSet(const unsigned long int label);
00208   unsigned long int LookupSet(const unsigned long int label);
00209   void LinkLabels(const unsigned long int lab1, const unsigned long int lab2);
00210   unsigned long int CreateConsecutive();
00212   bool CheckNeighbors(const OutputIndexType &A, 
00213                       const OutputIndexType &B);
00214 
00215   void CompareLines(lineEncoding &current, const lineEncoding &Neighbour);
00216 
00217   void FillOutput(const LineMapType &LineMap,
00218                   ProgressReporter &progress);
00219 
00220   void SetupLineOffsets(OffsetVec &LineOffsets);
00221 };
00222   
00223 } // end namespace itk
00224 
00225 #ifndef ITK_MANUAL_INSTANTIATION
00226 #include "itkConnectedComponentImageFilter.txx"
00227 #endif
00228 
00229 #endif
00230 

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