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

itkBinaryImageToLabelMapFilter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkBinaryImageToLabelMapFilter.h,v $
00005   Language:  C++
00006   Date:      $Date: 2010-02-27 22:02:33 $
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 
00018 #ifndef __itkBinaryImageToLabelMapFilter_h
00019 #define __itkBinaryImageToLabelMapFilter_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 #include "itkBarrier.h"
00028 #include "itkLabelMap.h"
00029 #include "itkLabelObject.h"
00030 
00031 namespace itk
00032 {
00033 
00054 template <class TInputImage, 
00055   class TOutputImage = 
00056     LabelMap< LabelObject< unsigned long, ::itk::GetImageDimension<TInputImage>::ImageDimension> > >
00057 class ITK_EXPORT BinaryImageToLabelMapFilter : 
00058     public ImageToImageFilter< TInputImage, TOutputImage > 
00059 {
00060 public:
00064   typedef BinaryImageToLabelMapFilter                       Self;
00065   typedef ImageToImageFilter< TInputImage, TOutputImage >   Superclass;
00066   typedef SmartPointer<Self>                                Pointer;
00067   typedef SmartPointer<const Self>                          ConstPointer;
00068 
00072   itkNewMacro(Self);
00073 
00077   itkTypeMacro(BinaryImageToLabelMapFilter, ImageToImageFilter);
00078 
00082   typedef typename Superclass::InputImagePointer InputImagePointer;
00083 
00088   typedef typename TOutputImage::PixelType        OutputPixelType;
00089   typedef typename TInputImage::PixelType         InputPixelType;
00090   typedef typename TInputImage::SizeValueType     SizeValueType;
00091   typedef typename TInputImage::OffsetValueType   OffsetValueType;
00092   itkStaticConstMacro(ImageDimension, unsigned int, TOutputImage::ImageDimension);
00093   itkStaticConstMacro(OutputImageDimension, unsigned int, TOutputImage::ImageDimension);
00094   itkStaticConstMacro(InputImageDimension, unsigned int, TInputImage::ImageDimension);
00096 
00100   typedef TInputImage                       InputImageType;
00101   typedef typename TInputImage::IndexType   IndexType;
00102   typedef typename TInputImage::SizeType    SizeType;
00103   typedef typename TInputImage::OffsetType  OffsetType;
00104 
00105   typedef TOutputImage                      OutputImageType;
00106   typedef typename TOutputImage::RegionType RegionType;
00107   typedef typename TOutputImage::IndexType  OutputIndexType;
00108   typedef typename TOutputImage::SizeType   OutputSizeType;
00109   typedef typename TOutputImage::OffsetType OutputOffsetType;
00110   typedef typename TOutputImage::PixelType  OutputImagePixelType;
00111 
00112   typedef std::list<IndexType>              ListType;
00113 
00120   itkSetMacro(FullyConnected, bool);
00121   itkGetConstReferenceMacro(FullyConnected, bool);
00122   itkBooleanMacro(FullyConnected);
00124 
00125   // only set after completion
00126   itkGetConstReferenceMacro( NumberOfObjects, unsigned long);
00127 
00132   itkSetMacro(OutputBackgroundValue, OutputPixelType);
00133   itkGetConstMacro(OutputBackgroundValue, OutputPixelType);
00135 
00140   itkSetMacro(InputForegroundValue, InputPixelType);
00141   itkGetConstMacro(InputForegroundValue, InputPixelType);
00143 
00144 
00145 #ifdef ITK_USE_CONCEPT_CHECKING
00146   // Concept checking -- input and output dimensions must be the same
00147   itkConceptMacro(SameDimension,
00148     (Concept::SameDimension<itkGetStaticConstMacro(InputImageDimension),
00149        itkGetStaticConstMacro(OutputImageDimension)>));
00150 #endif
00151 
00152 
00153 protected:
00154   BinaryImageToLabelMapFilter();
00155   virtual ~BinaryImageToLabelMapFilter() {}
00156   void PrintSelf(std::ostream& os, Indent indent) const;
00157 
00161   void BeforeThreadedGenerateData ();
00162   void AfterThreadedGenerateData ();
00163   void ThreadedGenerateData (const RegionType& outputRegionForThread, int threadId);
00165 
00169   void GenerateInputRequestedRegion();
00170 
00175   void EnlargeOutputRequestedRegion(DataObject *itkNotUsed(output));
00176 
00177 private:
00178   BinaryImageToLabelMapFilter(const Self&); //purposely not implemented
00179   void operator=(const Self&); //purposely not implemented
00180 
00181   // some additional types
00182   typedef typename TOutputImage::RegionType::SizeType OutSizeType;
00183 
00184   // types to support the run length encoding of lines
00185   class runLength
00186     {
00187     public:
00188     // run length information - may be a more type safe way of doing this
00189     long int length;
00190     typename InputImageType::IndexType where; // Index of the start of the run
00191     unsigned long int label; // the initial label of the run
00192     };
00193 
00194   typedef std::vector<runLength> lineEncoding;
00195 
00196   // the map storing lines
00197   typedef std::vector<lineEncoding> LineMapType;
00198   
00199   typedef std::vector<long>         OffsetVectorType;
00200 
00201   // the types to support union-find operations
00202   typedef std::vector<unsigned long int> UnionFindType;
00203   UnionFindType m_UnionFind;
00204   UnionFindType m_Consecutive;
00205   // functions to support union-find operations
00206   void InitUnion(const unsigned long int size) 
00207     {
00208     m_UnionFind = UnionFindType(size + 1);
00209     }
00210 
00211   void InsertSet(const unsigned long int label);
00212   unsigned long int LookupSet(const unsigned long int label);
00213   void LinkLabels(const unsigned long int lab1, const unsigned long int lab2);
00214   unsigned long int CreateConsecutive();
00216   bool CheckNeighbors(const OutputIndexType &A, 
00217                       const OutputIndexType &B);
00218 
00219   void CompareLines(lineEncoding &current, const lineEncoding &Neighbour);
00220 
00221   void FillOutput(const LineMapType &LineMap,
00222                   ProgressReporter &progress);
00223 
00224   void SetupLineOffsets( OffsetVectorType & LineOffsets );
00225 
00226   void Wait()
00227     {
00228     // use m_NumberOfLabels.size() to get the number of thread used
00229     if( m_NumberOfLabels.size() > 1 )
00230       {
00231       m_Barrier->Wait();
00232       }
00233     }
00234 
00235   OutputPixelType                   m_OutputBackgroundValue;
00236   InputPixelType                    m_InputForegroundValue;
00237 
00238   SizeValueType                     m_NumberOfObjects;
00239 
00240   bool                              m_FullyConnected;
00241   
00242   typename std::vector< SizeValueType >   m_NumberOfLabels;
00243   typename std::vector< SizeValueType >   m_FirstLineIdToJoin;
00244   typename Barrier::Pointer               m_Barrier;
00245 
00246 #if !defined(CABLE_CONFIGURATION)
00247   LineMapType                       m_LineMap;
00248 #endif
00249 };
00250   
00251 } // end namespace itk
00252 
00253 #ifndef ITK_MANUAL_INSTANTIATION
00254 #if !defined(CABLE_CONFIGURATION)
00255 #include "itkBinaryImageToLabelMapFilter.txx"
00256 #endif
00257 #endif
00258 
00259 #endif
00260 

Generated at Mon Jul 12 2010 17:47:51 for ITK by doxygen 1.7.1 written by Dimitri van Heesch, © 1997-2000