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

itkFloodFilledFunctionConditionalConstIterator.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkFloodFilledFunctionConditionalConstIterator.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-02-05 19:04:56 $
00007   Version:   $Revision: 1.20 $
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 #ifndef __itkFloodFilledFunctionConditionalConstIterator_h
00018 #define __itkFloodFilledFunctionConditionalConstIterator_h
00019 
00020 #include <queue>
00021 #include <vector>
00022 
00023 #include "itkIndex.h"
00024 #include "itkSize.h"
00025 #include "itkConditionalConstIterator.h"
00026 #include "itkImage.h"
00027 
00028 namespace itk
00029 {
00030 
00038 template<class TImage, class TFunction>
00039 class ITK_EXPORT FloodFilledFunctionConditionalConstIterator:
00040     public ConditionalConstIterator<TImage>
00041 {
00042 public:
00043 
00045   typedef FloodFilledFunctionConditionalConstIterator Self;
00046 
00048   typedef TFunction FunctionType;
00049 
00051   typedef typename TFunction::InputType FunctionInputType;
00052 
00054   typedef typename TImage::IndexType  IndexType;
00055 
00057   typedef typename TImage::SizeType    SizeType;
00058 
00060   typedef typename TImage::RegionType    RegionType;
00061 
00063   typedef TImage   ImageType;
00064 
00066   typedef typename TImage::InternalPixelType   InternalPixelType;
00067 
00069   typedef typename TImage::PixelType   PixelType;
00070 
00075   itkStaticConstMacro(NDimensions, unsigned int, TImage::ImageDimension);
00076 
00080   FloodFilledFunctionConditionalConstIterator(const ImageType *imagePtr,
00081                                      FunctionType *fnPtr,
00082                                      IndexType startIndex);
00083 
00087   FloodFilledFunctionConditionalConstIterator(const ImageType *imagePtr,
00088                                      FunctionType *fnPtr,
00089                                      std::vector<IndexType> & startIndices);
00090 
00094   FloodFilledFunctionConditionalConstIterator(const ImageType *imagePtr,
00095                                               FunctionType *fnPtr);
00096 
00101   void FindSeedPixel();
00102 
00104   void FindSeedPixels();
00105 
00107   void InitializeIterator();
00108 
00110   virtual ~FloodFilledFunctionConditionalConstIterator() {};
00111 
00113   virtual bool IsPixelIncluded(const IndexType & index) const = 0;
00114 
00117   Self &operator=(const Self& it)
00118     {
00119     this->m_Image = it.m_Image;     // copy the smart pointer
00120     this->m_Region = it.m_Region;
00121     return *this;
00122     } 
00123 
00125   static unsigned int GetIteratorDimension() 
00126     {return TImage::ImageDimension;}
00127 
00132   const IndexType GetIndex()
00133     { return m_IndexStack.front();}
00134 
00136   const PixelType & Get(void) const
00137     { return this->m_Image->GetPixel(m_IndexStack.front() ); }
00138 
00140   bool IsAtEnd()
00141     { return this->m_IsAtEnd; }
00142 
00144   void AddSeed ( const IndexType seed )
00145     {
00146     m_StartIndices.push_back ( seed );
00147     }
00148 
00150   void ClearSeeds ()
00151     {
00152     m_StartIndices.clear();
00153     }
00154 
00157   void GoToBegin()
00158     {
00159     // Clear the queue
00160     while (!m_IndexStack.empty())
00161       {
00162       m_IndexStack.pop();
00163       }
00164 
00165     this->m_IsAtEnd = true;
00166     // Initialize the temporary image
00167     m_TemporaryPointer->FillBuffer(
00168       NumericTraits<ITK_TYPENAME TTempImage::PixelType>::Zero
00169       );
00170     
00171     for ( unsigned int i = 0; i < m_StartIndices.size(); i++ )
00172       {
00173       if( this->m_Image->GetBufferedRegion().IsInside ( m_StartIndices[i] ) &&
00174           this->IsPixelIncluded(m_StartIndices[i]) )
00175         {
00176         // Push the seed onto the queue
00177         m_IndexStack.push(m_StartIndices[i]);
00178         
00179         // Obviously, we're at the beginning
00180         this->m_IsAtEnd = false;
00181         
00182         // Mark the start index in the temp image as inside the
00183         // function, neighbor check incomplete
00184         m_TemporaryPointer->SetPixel(m_StartIndices[i], 2);
00185         }
00186       }
00187     }
00188 
00190   void operator++()
00191     { this->DoFloodStep(); }
00192 
00193   void DoFloodStep();
00194   
00195   virtual SmartPointer<FunctionType> GetFunction() const
00196     {
00197     return m_Function;
00198     }
00199 
00200 
00201 protected: //made protected so other iterators can access 
00203   SmartPointer<FunctionType> m_Function;
00204 
00210   typedef Image<unsigned char, itkGetStaticConstMacro(NDimensions)> TTempImage;
00211   typename TTempImage::Pointer m_TemporaryPointer;
00212 
00214   std::vector<IndexType> m_StartIndices;
00215 
00217   typename ImageType::PointType m_ImageOrigin;
00218 
00220   typename ImageType::SpacingType m_ImageSpacing;
00221 
00223   RegionType   m_ImageRegion;
00224 
00226   std::queue<IndexType> m_IndexStack;
00227 
00229   FunctionInputType m_LocationVector;
00230 
00233   bool m_FoundUncheckedNeighbor;
00234 
00236   bool m_IsValidIndex;
00237 };
00238 
00239 } // end namespace itk
00240 
00241 // Define instantiation macro for this template.
00242 #define ITK_TEMPLATE_FloodFilledFunctionConditionalConstIterator(_, EXPORT, x, y) namespace itk { \
00243   _(2(class EXPORT FloodFilledFunctionConditionalConstIterator< ITK_TEMPLATE_2 x >)) \
00244   namespace Templates { typedef FloodFilledFunctionConditionalConstIterator< ITK_TEMPLATE_2 x > \
00245                         FloodFilledFunctionConditionalConstIterator##y; } \
00246   }
00247 
00248 #if ITK_TEMPLATE_EXPLICIT
00249 # include "Templates/itkFloodFilledFunctionConditionalConstIterator+-.h"
00250 #endif
00251 
00252 #if ITK_TEMPLATE_TXX
00253 # include "itkFloodFilledFunctionConditionalConstIterator.txx"
00254 #endif
00255 
00256 #endif 
00257 

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