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: 2007/02/05 13:35:52 $
00007   Version:   $Revision: 1.18 $
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     };
00149 
00151   void ClearSeeds ()
00152     {
00153     m_StartIndices.clear();
00154     };
00156 
00159   void GoToBegin()
00160     {
00161     // Clear the queue
00162     while (!m_IndexStack.empty())
00163       {
00164       m_IndexStack.pop();
00165       }
00166 
00167     this->m_IsAtEnd = true;
00168     // Initialize the temporary image
00169     tempPtr->FillBuffer(
00170       NumericTraits<ITK_TYPENAME TTempImage::PixelType>::Zero
00171       );
00172     
00173     for ( unsigned int i = 0; i < m_StartIndices.size(); i++ )
00174       {
00175       if( this->m_Image->GetBufferedRegion().IsInside ( m_StartIndices[i] ) &&
00176           this->IsPixelIncluded(m_StartIndices[i]) )
00177         {
00178         // Push the seed onto the queue
00179         m_IndexStack.push(m_StartIndices[i]);
00180         
00181         // Obviously, we're at the beginning
00182         this->m_IsAtEnd = false;
00183         
00184         // Mark the start index in the temp image as inside the
00185         // function, neighbor check incomplete
00186         tempPtr->SetPixel(m_StartIndices[i], 2);
00187         }
00188       }
00189     };
00190 
00192   void operator++()
00193     { this->DoFloodStep(); }
00194 
00195   void DoFloodStep();
00196   
00197   virtual SmartPointer<FunctionType> GetFunction() const
00198     {
00199     return m_Function;
00200     }
00201 
00202 
00203 protected: //made protected so other iterators can access 
00205   SmartPointer<FunctionType> m_Function;
00206 
00212   typedef Image<unsigned char, itkGetStaticConstMacro(NDimensions)> TTempImage;
00213   typename TTempImage::Pointer tempPtr;
00214 
00216   std::vector<IndexType> m_StartIndices;
00217 
00219   typename ImageType::PointType m_ImageOrigin;
00220 
00222   typename ImageType::SpacingType m_ImageSpacing;
00223 
00225   RegionType   m_ImageRegion;
00226 
00228   std::queue<IndexType> m_IndexStack;
00229 
00231   FunctionInputType m_LocationVector;
00232 
00235   bool m_FoundUncheckedNeighbor;
00236 
00238   bool m_IsValidIndex;
00239 };
00240 
00241 } // end namespace itk
00242 
00243 // Define instantiation macro for this template.
00244 #define ITK_TEMPLATE_FloodFilledFunctionConditionalConstIterator(_, EXPORT, x, y) namespace itk { \
00245   _(2(class EXPORT FloodFilledFunctionConditionalConstIterator< ITK_TEMPLATE_2 x >)) \
00246   namespace Templates { typedef FloodFilledFunctionConditionalConstIterator< ITK_TEMPLATE_2 x > \
00247                         FloodFilledFunctionConditionalConstIterator##y; } \
00248   }
00249 
00250 #if ITK_TEMPLATE_EXPLICIT
00251 # include "Templates/itkFloodFilledFunctionConditionalConstIterator+-.h"
00252 #endif
00253 
00254 #if ITK_TEMPLATE_TXX
00255 # include "itkFloodFilledFunctionConditionalConstIterator.txx"
00256 #endif
00257 
00258 #endif 
00259 

Generated at Tue Jul 29 20:04:44 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000