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

itkBinaryContourImageFilter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkBinaryContourImageFilter.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-04-23 03:43:41 $
00007   Version:   $Revision: 1.2 $
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 __itkBinaryContourImageFilter_h
00019 #define __itkBinaryContourImageFilter_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 
00051 template <class TInputImage, class TOutputImage>
00052 class ITK_EXPORT BinaryContourImageFilter : 
00053     public InPlaceImageFilter< TInputImage, TOutputImage > 
00054 {
00055 public:
00059   typedef BinaryContourImageFilter                        Self;
00060   typedef InPlaceImageFilter< 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 
00076   itkStaticConstMacro(ImageDimension, unsigned int,
00077                       TOutputImage::ImageDimension);
00078   itkStaticConstMacro(OutputImageDimension, unsigned int,
00079                       TOutputImage::ImageDimension);
00080   itkStaticConstMacro(InputImageDimension, unsigned int,
00081                       TInputImage::ImageDimension);
00082   
00086   typedef TInputImage                       InputImageType;
00087   typedef typename TInputImage::IndexType   IndexType;
00088   typedef typename TInputImage::SizeType    SizeType;
00089   typedef typename TInputImage::OffsetType  OffsetType;
00090   typedef typename TInputImage::PixelType   InputImagePixelType;
00091 
00092   typedef TOutputImage                      OutputImageType;
00093   typedef typename TOutputImage::RegionType RegionType;
00094   typedef typename TOutputImage::IndexType  OutputIndexType;
00095   typedef typename TOutputImage::SizeType   OutputSizeType;
00096   typedef typename TOutputImage::OffsetType OutputOffsetType;
00097   typedef typename TOutputImage::PixelType  OutputImagePixelType;
00098 
00099   typedef std::list<IndexType>              ListType;
00100 
00104   typedef SmartPointer<Self>        Pointer;
00105   typedef SmartPointer<const Self>  ConstPointer;
00106 
00110   itkTypeMacro(BinaryContourImageFilter, ImageToImageFilter);
00111 
00115   itkNewMacro(Self);
00116 
00123   itkSetMacro(FullyConnected, bool);
00124   itkGetConstReferenceMacro(FullyConnected, bool);
00125   itkBooleanMacro(FullyConnected);
00127 
00128   // Concept checking -- input and output dimensions must be the same
00129   itkConceptMacro(SameDimension,
00130     (Concept::SameDimension<itkGetStaticConstMacro(InputImageDimension),
00131        itkGetStaticConstMacro(OutputImageDimension)>));
00132 
00137   itkSetMacro(BackgroundValue, OutputImagePixelType);
00138   itkGetConstMacro(BackgroundValue, OutputImagePixelType);
00140 
00145   itkSetMacro(ForegroundValue, InputImagePixelType);
00146   itkGetConstMacro(ForegroundValue, InputImagePixelType);
00148 
00149 protected:
00150   BinaryContourImageFilter() 
00151     {
00152     m_FullyConnected = false;
00153     m_ForegroundValue = NumericTraits< InputImagePixelType >::max();
00154     m_BackgroundValue = NumericTraits< OutputImagePixelType >::Zero;
00155     m_NumberOfThreads = 0;
00156     this->SetInPlace( false );
00157     }
00158   virtual ~BinaryContourImageFilter() {}
00159   BinaryContourImageFilter(const Self&) {}
00160   void PrintSelf(std::ostream& os, Indent indent) const;
00161 
00165   void BeforeThreadedGenerateData ();
00166   void AfterThreadedGenerateData ();
00167   void ThreadedGenerateData (const RegionType& outputRegionForThread, int threadId);
00169 
00173   void GenerateInputRequestedRegion();
00174 
00179   void EnlargeOutputRequestedRegion(DataObject *itkNotUsed(output));
00180 
00181 private:
00182   InputImagePixelType  m_ForegroundValue;
00183   OutputImagePixelType m_BackgroundValue;
00184   bool                 m_FullyConnected;
00185   
00186   // some additional types
00187   typedef typename TOutputImage::RegionType::SizeType OutSizeType;
00188 
00189   // types to support the run length encoding of lines
00190   class runLength
00191     {
00192     public:
00193     // run length information - may be a more type safe way of doing this
00194     long int length;
00195     typename InputImageType::IndexType where; // Index of the start of the run
00196     };
00197 
00198   typedef std::vector<runLength> lineEncoding;
00199 
00200   // the map storing lines
00201   typedef std::vector<lineEncoding> LineMapType;
00202   
00203   typedef std::vector<long> OffsetVec;
00204 
00205   // the types to support union-find operations
00206   typedef std::vector<unsigned long int> UnionFindType;
00207 
00208   bool CheckNeighbors(const OutputIndexType &A, 
00209                       const OutputIndexType &B);
00210 
00211   void CompareLines(lineEncoding &current, const lineEncoding &Neighbour);
00212 
00213 
00214   void SetupLineOffsets(OffsetVec &LineOffsets);
00215 
00216   void Wait()
00217     {
00218     if( m_NumberOfThreads > 1 )
00219       {
00220       m_Barrier->Wait();
00221       }
00222     }
00223 
00224   typename Barrier::Pointer m_Barrier;
00225   LineMapType               m_ForegroundLineMap;
00226   LineMapType               m_BackgroundLineMap;
00227   long                      m_NumberOfThreads;
00228 };
00229   
00230 } // end namespace itk
00231 
00232 #ifndef ITK_MANUAL_INSTANTIATION
00233 #include "itkBinaryContourImageFilter.txx"
00234 #endif
00235 
00236 #endif
00237 

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