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-07-22 16:57:52 $
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 
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   typedef typename TInputImage::SizeValueType   SizeValueType;
00093   typedef typename TInputImage::OffsetValueType OffsetValueType;
00094 
00095   typedef TOutputImage                      OutputImageType;
00096   typedef typename TOutputImage::RegionType RegionType;
00097   typedef typename TOutputImage::IndexType  OutputIndexType;
00098   typedef typename TOutputImage::SizeType   OutputSizeType;
00099   typedef typename TOutputImage::OffsetType OutputOffsetType;
00100   typedef typename TOutputImage::PixelType  OutputImagePixelType;
00101 
00102   typedef std::list<IndexType>              ListType;
00103 
00107   typedef SmartPointer<Self>        Pointer;
00108   typedef SmartPointer<const Self>  ConstPointer;
00109 
00113   itkTypeMacro(LabelContourImageFilter, ImageToImageFilter);
00114 
00118   itkNewMacro(Self);
00119 
00126   itkSetMacro(FullyConnected, bool);
00127   itkGetConstReferenceMacro(FullyConnected, bool);
00128   itkBooleanMacro(FullyConnected);
00130 
00131   // Concept checking -- input and output dimensions must be the same
00132   itkConceptMacro(SameDimension,
00133     (Concept::SameDimension<itkGetStaticConstMacro(InputImageDimension),
00134        itkGetStaticConstMacro(OutputImageDimension)>));
00135 
00140   itkSetMacro(BackgroundValue, OutputImagePixelType);
00141   itkGetConstMacro(BackgroundValue, OutputImagePixelType);
00143 
00144 protected:
00145   LabelContourImageFilter() 
00146     {
00147     m_FullyConnected = false;
00148     m_BackgroundValue = NumericTraits< OutputImagePixelType >::Zero;
00149     m_NumberOfThreads = 0;
00150     this->SetInPlace( false );
00151     }
00152   virtual ~LabelContourImageFilter() {}
00153   LabelContourImageFilter(const Self&) {}
00154   void PrintSelf(std::ostream& os, Indent indent) const;
00155 
00159   void BeforeThreadedGenerateData ();
00160   void AfterThreadedGenerateData ();
00161   void ThreadedGenerateData (const RegionType& outputRegionForThread, int threadId);
00163 
00167   void GenerateInputRequestedRegion();
00168 
00173   void EnlargeOutputRequestedRegion(DataObject *itkNotUsed(output));
00174 
00175 private:
00176   OutputImagePixelType m_BackgroundValue;
00177   bool                 m_FullyConnected;
00178   
00179   // some additional types
00180   typedef typename TOutputImage::RegionType::SizeType OutSizeType;
00181 
00182   // types to support the run length encoding of lines
00183   class runLength
00184     {
00185     public:
00186     // run length information - may be a more type safe way of doing this
00187     long int length;
00188     typename InputImageType::IndexType where; // Index of the start of the run
00189     InputImagePixelType label;
00190     };
00191 
00192   typedef std::vector<runLength> lineEncoding;
00193 
00194   // the map storing lines
00195   typedef std::vector<lineEncoding> LineMapType;
00196   
00197   typedef std::vector<long> OffsetVec;
00198 
00199   // the types to support union-find operations
00200   typedef std::vector<unsigned long int> UnionFindType;
00201 
00202   bool CheckNeighbors(const OutputIndexType &A, 
00203                       const OutputIndexType &B);
00204 
00205   void CompareLines(lineEncoding &current, const lineEncoding &Neighbour);
00206 
00207 
00208   void SetupLineOffsets(OffsetVec &LineOffsets);
00209 
00210   void Wait()
00211     {
00212     if( m_NumberOfThreads > 1 )
00213       {
00214       m_Barrier->Wait();
00215       }
00216     }
00217 
00218   typename Barrier::Pointer m_Barrier;
00219   LineMapType               m_LineMap;
00220   long                      m_NumberOfThreads;
00221 };
00222   
00223 } // end namespace itk
00224 
00225 #ifndef ITK_MANUAL_INSTANTIATION
00226 #include "itkLabelContourImageFilter.txx"
00227 #endif
00228 
00229 #endif
00230 

Generated at Fri Apr 16 18:50:25 2010 for ITK by doxygen 1.6.1 written by Dimitri van Heesch, © 1997-2000