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

itkLabelContourImageFilter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkLabelContourImageFilter.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-02-14 22:00:53 $
00007   Version:   $Revision: 1.1 $
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 __itkLabelContourImageFilter_h
00019 #define __itkLabelContourImageFilter_h
00020 
00021 #include "itkInPlaceImageFilter.h"
00022 #include "itkImage.h"
00023 #include "itkConceptChecking.h"
00024 #include <vector>
00025 #include <map>
00026 #include "itkProgressReporter.h"
00027 #include "itkBarrier.h"
00028 
00029 namespace itk
00030 {
00031 
00052 template <class TInputImage, class TOutputImage>
00053 class ITK_EXPORT LabelContourImageFilter : 
00054     public InPlaceImageFilter< TInputImage, TOutputImage > 
00055 {
00056 public:
00060   typedef LabelContourImageFilter                         Self;
00061   typedef InPlaceImageFilter< TInputImage, TOutputImage > Superclass;
00062 
00066   typedef typename Superclass::InputImagePointer InputImagePointer;
00067 
00072   typedef typename TOutputImage::PixelType         OutputPixelType;
00073   typedef typename TOutputImage::InternalPixelType OutputInternalPixelType;
00074   typedef typename TInputImage::PixelType          InputPixelType;
00075   typedef typename TInputImage::InternalPixelType  InputInternalPixelType;
00076 
00077   itkStaticConstMacro(ImageDimension, unsigned int,
00078                       TOutputImage::ImageDimension);
00079   itkStaticConstMacro(OutputImageDimension, unsigned int,
00080                       TOutputImage::ImageDimension);
00081   itkStaticConstMacro(InputImageDimension, unsigned int,
00082                       TInputImage::ImageDimension);
00083   
00087   typedef TInputImage                       InputImageType;
00088   typedef typename TInputImage::IndexType   IndexType;
00089   typedef typename TInputImage::SizeType    SizeType;
00090   typedef typename TInputImage::OffsetType  OffsetType;
00091   typedef typename TInputImage::PixelType   InputImagePixelType;
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   typedef typename TOutputImage::PixelType  OutputImagePixelType;
00099 
00100   typedef std::list<IndexType>              ListType;
00101 
00105   typedef SmartPointer<Self>        Pointer;
00106   typedef SmartPointer<const Self>  ConstPointer;
00107 
00111   itkTypeMacro(LabelContourImageFilter, ImageToImageFilter);
00112 
00116   itkNewMacro(Self);
00117 
00124   itkSetMacro(FullyConnected, bool);
00125   itkGetConstReferenceMacro(FullyConnected, bool);
00126   itkBooleanMacro(FullyConnected);
00128 
00129   // Concept checking -- input and output dimensions must be the same
00130   itkConceptMacro(SameDimension,
00131     (Concept::SameDimension<itkGetStaticConstMacro(InputImageDimension),
00132        itkGetStaticConstMacro(OutputImageDimension)>));
00133 
00138   itkSetMacro(BackgroundValue, OutputImagePixelType);
00139   itkGetMacro(BackgroundValue, OutputImagePixelType);
00141 
00142 protected:
00143   LabelContourImageFilter() 
00144     {
00145     m_FullyConnected = false;
00146     m_BackgroundValue = NumericTraits< OutputImagePixelType >::Zero;
00147     m_NumberOfThreads = 0;
00148     this->SetInPlace( false );
00149     }
00150   virtual ~LabelContourImageFilter() {}
00151   LabelContourImageFilter(const Self&) {}
00152   void PrintSelf(std::ostream& os, Indent indent) const;
00153 
00157   void BeforeThreadedGenerateData ();
00158   void AfterThreadedGenerateData ();
00159   void ThreadedGenerateData (const RegionType& outputRegionForThread, int threadId);
00161 
00165   void GenerateInputRequestedRegion();
00166 
00171   void EnlargeOutputRequestedRegion(DataObject *itkNotUsed(output));
00172 
00173 private:
00174   OutputImagePixelType m_BackgroundValue;
00175   bool                 m_FullyConnected;
00176   
00177   // some additional types
00178   typedef typename TOutputImage::RegionType::SizeType OutSizeType;
00179 
00180   // types to support the run length encoding of lines
00181   class runLength
00182     {
00183     public:
00184     // run length information - may be a more type safe way of doing this
00185     long int length;
00186     typename InputImageType::IndexType where; // Index of the start of the run
00187     InputImagePixelType label;
00188     };
00189 
00190   typedef std::vector<runLength> lineEncoding;
00191 
00192   // the map storing lines
00193   typedef std::vector<lineEncoding> LineMapType;
00194   
00195   typedef std::vector<long> OffsetVec;
00196 
00197   // the types to support union-find operations
00198   typedef std::vector<unsigned long int> UnionFindType;
00199 
00200   bool CheckNeighbors(const OutputIndexType &A, 
00201                       const OutputIndexType &B);
00202 
00203   void CompareLines(lineEncoding &current, const lineEncoding &Neighbour);
00204 
00205 
00206   void SetupLineOffsets(OffsetVec &LineOffsets);
00207 
00208   void Wait()
00209     {
00210     if( m_NumberOfThreads > 1 )
00211       {
00212       m_Barrier->Wait();
00213       }
00214     }
00215 
00216   typename Barrier::Pointer m_Barrier;
00217   LineMapType               m_LineMap;
00218   long                      m_NumberOfThreads;
00219 };
00220   
00221 } // end namespace itk
00222 
00223 #ifndef ITK_MANUAL_INSTANTIATION
00224 #include "itkLabelContourImageFilter.txx"
00225 #endif
00226 
00227 #endif
00228 

Generated at Sat Feb 28 12:54:16 2009 for ITK by doxygen 1.5.6 written by Dimitri van Heesch, © 1997-2000