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: 2002/11/07 13:40:01 $
00007   Version:   $Revision: 1.8 $
00008 
00009   Copyright (c) 2002 Insight 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 <stack>
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 FloodFilledFunctionConditionalConstIterator: public ConditionalConstIterator<TImage>
00040 {
00041 public:
00043   typedef FloodFilledFunctionConditionalConstIterator Self;
00044 
00046   typedef TFunction FunctionType;
00047 
00049   typedef typename TFunction::InputType FunctionInputType;
00050 
00052   typedef typename TImage::IndexType  IndexType;
00053 
00055   typedef typename TImage::SizeType    SizeType;
00056 
00058   typedef typename TImage::RegionType    RegionType;
00059 
00061   typedef TImage   ImageType;
00062 
00064   typedef typename TImage::InternalPixelType   InternalPixelType;
00065 
00067   typedef typename TImage::PixelType   PixelType;
00068 
00073   itkStaticConstMacro(NDimensions, unsigned int, TImage::ImageDimension);
00074 
00078   FloodFilledFunctionConditionalConstIterator(const ImageType *imagePtr,
00079                                      FunctionType *fnPtr,
00080                                      IndexType startIndex);
00081 
00085   FloodFilledFunctionConditionalConstIterator(const ImageType *imagePtr,
00086                                      FunctionType *fnPtr,
00087                                      std::vector<IndexType> & startIndices);
00088 
00092   FloodFilledFunctionConditionalConstIterator(const ImageType *imagePtr,
00093                                               FunctionType *fnPtr);
00094 
00099   void FindSeedPixel();
00100 
00102   void FindSeedPixels();
00103 
00105   void InitializeIterator();
00106 
00108   virtual ~FloodFilledFunctionConditionalConstIterator() {};
00109 
00111   virtual bool IsPixelIncluded(const IndexType & index) const = 0;
00112   
00115   Self &operator=(const Self& it)
00116   {
00117     m_Image = it.m_Image;     // copy the smart pointer
00118     m_Region = it.m_Region;
00119   }
00120   
00122   static unsigned int GetIteratorDimension() 
00123     {return TImage::ImageDimension;}
00124 
00129   const IndexType GetIndex()
00130     { return m_IndexStack.top();}
00131 
00133   const PixelType & Get(void) const
00134     { return m_Image->GetPixel(m_IndexStack.top() ); }
00135  
00137   bool IsAtEnd()
00138     { return m_IsAtEnd; };
00139 
00141   void AddSeed ( const IndexType seed )
00142   {
00143     m_StartIndices.push_back ( seed );
00144   };
00145 
00147   void ClearSeeds ()
00148   {
00149     m_StartIndices.clear();
00150   };
00151   
00154   void GoToBegin()
00155     {
00156     // Clear the stack
00157     while (!m_IndexStack.empty())
00158       {
00159       m_IndexStack.pop();
00160       }
00161 
00162     m_IsAtEnd = true;
00163     for ( unsigned int i = 0; i < m_StartIndices.size(); i++ )
00164       {
00165       if( m_Image->GetBufferedRegion().IsInside ( m_StartIndices[i] ) &&
00166           this->IsPixelIncluded(m_StartIndices[i]) )
00167         {
00168         // Push the seed onto the stack
00169         m_IndexStack.push(m_StartIndices[i]);
00170         
00171         // Obviously, we're at the beginning
00172         m_IsAtEnd = false;
00173         
00174         // Initialize the temporary image
00175         tempPtr->FillBuffer(NumericTraits<ITK_TYPENAME TTempImage::PixelType>::Zero);
00176         
00177         // Mark the start index in the temp image as inside the function, neighbor check incomplete
00178         tempPtr->SetPixel(m_StartIndices[i], 2);
00179         }
00180       }
00181     };
00182 
00184   void operator++()
00185     { this->DoFloodStep(); }
00186 
00187   void DoFloodStep();
00188   
00189 protected: //made protected so other iterators can access 
00191   SmartPointer<FunctionType> m_Function;
00192 
00198   typedef Image<unsigned char, itkGetStaticConstMacro(NDimensions)> TTempImage;
00199   typename TTempImage::Pointer tempPtr;
00200   
00202   std::vector<IndexType> m_StartIndices;
00203 
00205   const double* m_ImageOrigin;
00206   
00208   const double* m_ImageSpacing;
00209 
00211   const unsigned long int* m_ImageSize;
00212 
00214   std::stack<IndexType> m_IndexStack;
00215 
00217   FunctionInputType m_LocationVector;
00218 
00220   bool m_FoundUncheckedNeighbor;
00221 
00223   bool m_IsValidIndex;
00224 };
00225 
00226 } // end namespace itk
00227 
00228 #ifndef ITK_MANUAL_INSTANTIATION
00229 #include "itkFloodFilledFunctionConditionalConstIterator.txx"
00230 #endif
00231 
00232 #endif 

Generated at Fri May 21 01:14:48 2004 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000