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/10/01 17:48:09 $
00007   Version:   $Revision: 1.7 $
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 
00022 #include "itkIndex.h"
00023 #include "itkSize.h"
00024 #include "itkConditionalConstIterator.h"
00025 #include "itkImage.h"
00026 
00027 namespace itk
00028 {
00029 
00037 template<class TImage, class TFunction>
00038 class FloodFilledFunctionConditionalConstIterator: public ConditionalConstIterator<TImage>
00039 {
00040 public:
00042   typedef FloodFilledFunctionConditionalConstIterator Self;
00043 
00045   typedef TFunction FunctionType;
00046 
00048   typedef typename TFunction::InputType FunctionInputType;
00049 
00051   typedef typename TImage::IndexType  IndexType;
00052 
00054   typedef typename TImage::SizeType    SizeType;
00055 
00057   typedef typename TImage::RegionType    RegionType;
00058 
00060   typedef TImage   ImageType;
00061 
00063   typedef typename TImage::InternalPixelType   InternalPixelType;
00064 
00066   typedef typename TImage::PixelType   PixelType;
00067 
00072   itkStaticConstMacro(NDimensions, unsigned int, TImage::ImageDimension);
00073 
00077   FloodFilledFunctionConditionalConstIterator(const ImageType *imagePtr,
00078                                      FunctionType *fnPtr,
00079                                      IndexType startIndex);
00080 
00084   FloodFilledFunctionConditionalConstIterator(const ImageType *imagePtr,
00085                                               FunctionType *fnPtr);
00086 
00091   void FindSeedPixel();
00092 
00094   void InitializeIterator();
00095 
00097   virtual ~FloodFilledFunctionConditionalConstIterator() {};
00098 
00100   virtual bool IsPixelIncluded(const IndexType & index) const = 0;
00101   
00104   Self &operator=(const Self& it)
00105   {
00106     m_Image = it.m_Image;     // copy the smart pointer
00107     m_Region = it.m_Region;
00108   }
00109   
00111   static unsigned int GetIteratorDimension() 
00112     {return TImage::ImageDimension;}
00113 
00118   const IndexType GetIndex()
00119     { return m_IndexStack.top();}
00120 
00122   const PixelType & Get(void) const
00123     { return m_Image->GetPixel(m_IndexStack.top() ); }
00124  
00126   bool IsAtEnd()
00127     { return m_IsAtEnd; };
00128 
00131   void GoToBegin()
00132     {
00133     // Clear the stack
00134     while (!m_IndexStack.empty())
00135       {
00136       m_IndexStack.pop();
00137       }
00138     
00139     if( m_Image->GetBufferedRegion().IsInside ( m_StartIndex ) &&
00140         this->IsPixelIncluded(m_StartIndex) )
00141       {
00142       // Push the seed onto the stack
00143       m_IndexStack.push(m_StartIndex);
00144       
00145       // Obviously, we're at the beginning
00146       m_IsAtEnd = false;
00147 
00148       // Initialize the temporary image
00149       tempPtr->FillBuffer(NumericTraits<ITK_TYPENAME TTempImage::PixelType>::Zero);
00150 
00151       // Mark the start index in the temp image as inside the function, neighbor check incomplete
00152       tempPtr->SetPixel(m_StartIndex, 2);
00153       }
00154     else
00155       {
00156       // If the start index is not included, we're done
00157       m_IsAtEnd = true;
00158       }    
00159     };
00160 
00162   void operator++()
00163     { this->DoFloodStep(); }
00164 
00165   void DoFloodStep();
00166   
00167 protected: //made protected so other iterators can access 
00169   SmartPointer<FunctionType> m_Function;
00170 
00176   typedef Image<unsigned char, itkGetStaticConstMacro(NDimensions)> TTempImage;
00177   typename TTempImage::Pointer tempPtr;
00178   
00180   IndexType m_StartIndex;
00181 
00183   const double* m_ImageOrigin;
00184   
00186   const double* m_ImageSpacing;
00187 
00189   const unsigned long int* m_ImageSize;
00190 
00192   std::stack<IndexType> m_IndexStack;
00193 
00195   FunctionInputType m_LocationVector;
00196 
00198   bool m_FoundUncheckedNeighbor;
00199 
00201   bool m_IsValidIndex;
00202 };
00203 
00204 } // end namespace itk
00205 
00206 #ifndef ITK_MANUAL_INSTANTIATION
00207 #include "itkFloodFilledFunctionConditionalConstIterator.txx"
00208 #endif
00209 
00210 #endif 

Generated at Wed Mar 12 01:12:57 2003 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000