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: 2004/12/11 20:29:18 $
00007   Version:   $Revision: 1.16 $
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: 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     this->m_Image = it.m_Image;     // copy the smart pointer
00118     this->m_Region = it.m_Region;
00119     return *this;
00120   }
00121   
00123   static unsigned int GetIteratorDimension() 
00124     {return TImage::ImageDimension;}
00125 
00130   const IndexType GetIndex()
00131     { return m_IndexStack.front();}
00132 
00134   const PixelType & Get(void) const
00135     { return this->m_Image->GetPixel(m_IndexStack.front() ); }
00136  
00138   bool IsAtEnd()
00139     { return this->m_IsAtEnd; };
00140 
00142   void AddSeed ( const IndexType seed )
00143   {
00144     m_StartIndices.push_back ( seed );
00145   };
00146 
00148   void ClearSeeds ()
00149   {
00150     m_StartIndices.clear();
00151   };
00152   
00155   void GoToBegin()
00156     {
00157     // Clear the queue
00158     while (!m_IndexStack.empty())
00159       {
00160       m_IndexStack.pop();
00161       }
00162 
00163     this->m_IsAtEnd = true;
00164     // Initialize the temporary image
00165     tempPtr->FillBuffer(NumericTraits<ITK_TYPENAME TTempImage::PixelType>::Zero);
00166     
00167     for ( unsigned int i = 0; i < m_StartIndices.size(); i++ )
00168       {
00169       if( this->m_Image->GetBufferedRegion().IsInside ( m_StartIndices[i] ) &&
00170           this->IsPixelIncluded(m_StartIndices[i]) )
00171         {
00172         // Push the seed onto the queue
00173         m_IndexStack.push(m_StartIndices[i]);
00174         
00175         // Obviously, we're at the beginning
00176         this->m_IsAtEnd = false;
00177         
00178         // Mark the start index in the temp image as inside the function, neighbor check incomplete
00179         tempPtr->SetPixel(m_StartIndices[i], 2);
00180         }
00181       }
00182     };
00183 
00185   void operator++()
00186     { this->DoFloodStep(); }
00187 
00188   void DoFloodStep();
00189   
00190   virtual SmartPointer<FunctionType> GetFunction() const
00191   {
00192     return m_Function;
00193   }
00194 
00195 
00196 protected: //made protected so other iterators can access 
00198   SmartPointer<FunctionType> m_Function;
00199 
00205   typedef Image<unsigned char, itkGetStaticConstMacro(NDimensions)> TTempImage;
00206   typename TTempImage::Pointer tempPtr;
00207   
00209   std::vector<IndexType> m_StartIndices;
00210 
00212   typename ImageType::PointType m_ImageOrigin;
00213   
00215   typename ImageType::SpacingType m_ImageSpacing;
00216 
00218   RegionType   m_ImageRegion;
00219 
00221   std::queue<IndexType> m_IndexStack;
00222 
00224   FunctionInputType m_LocationVector;
00225 
00227   bool m_FoundUncheckedNeighbor;
00228 
00230   bool m_IsValidIndex;
00231 };
00232 
00233 } // end namespace itk
00234 
00235 #ifndef ITK_MANUAL_INSTANTIATION
00236 #include "itkFloodFilledFunctionConditionalConstIterator.txx"
00237 #endif
00238 
00239 #endif 

Generated at Wed May 24 23:08:55 2006 for ITK by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2000