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

itkShapedFloodFilledFunctionConditionalConstIterator.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkShapedFloodFilledFunctionConditionalConstIterator.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-04-28 16:16:25 $
00007   Version:   $Revision: 1.2 $
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 __itkShapedFloodFilledFunctionConditionalConstIterator_h
00018 #define __itkShapedFloodFilledFunctionConditionalConstIterator_h
00019 
00020 #include <queue>
00021 #include <vector>
00022 
00023 #include "itkIndex.h"
00024 #include "itkSize.h"
00025 #include "itkConditionalConstIterator.h"
00026 #include "itkShapedNeighborhoodIterator.h"
00027 #include "itkConnectedComponentAlgorithm.h"
00028 #include "itkImage.h"
00029 
00030 namespace itk
00031 {
00032 
00043 template<class TImage, class TFunction>
00044 class ITK_EXPORT ShapedFloodFilledFunctionConditionalConstIterator:
00045     public ConditionalConstIterator<TImage>
00046 {
00047 public:
00048 
00050   typedef ShapedFloodFilledFunctionConditionalConstIterator Self;
00051 
00053   typedef TFunction FunctionType;
00054 
00056   typedef typename TFunction::InputType FunctionInputType;
00057 
00059   typedef typename TImage::IndexType IndexType;
00060 
00062   typedef typename TImage::OffsetType OffsetType;
00063 
00065   typedef typename TImage::SizeType SizeType;
00066 
00068   typedef typename TImage::RegionType RegionType;
00069 
00071   typedef TImage ImageType;
00072 
00074   typedef typename TImage::InternalPixelType InternalPixelType;
00075 
00077   typedef typename TImage::PixelType   PixelType;  
00078 
00080   typedef typename itk::ShapedNeighborhoodIterator<ImageType> NeighborhoodIteratorType;
00081 
00086   itkStaticConstMacro(NDimensions, unsigned int, TImage::ImageDimension);
00087 
00091   ShapedFloodFilledFunctionConditionalConstIterator(const ImageType *imagePtr,
00092                                      FunctionType *fnPtr,
00093                                      IndexType startIndex);
00094 
00098   ShapedFloodFilledFunctionConditionalConstIterator(const ImageType *imagePtr,
00099                                      FunctionType *fnPtr,
00100                                      std::vector<IndexType> & startIndices);
00101 
00105   ShapedFloodFilledFunctionConditionalConstIterator(const ImageType *imagePtr,
00106                                               FunctionType *fnPtr);
00107 
00112   void FindSeedPixel();
00113 
00115   void FindSeedPixels();
00116 
00118   void InitializeIterator();
00119 
00121   virtual ~ShapedFloodFilledFunctionConditionalConstIterator() {};
00122 
00124   virtual bool IsPixelIncluded(const IndexType & index) const = 0;
00125 
00128   Self &operator=(const Self& it)
00129     {
00130     this->m_Image = it.m_Image;     // copy the smart pointer
00131     this->m_Region = it.m_Region;
00132     return *this;
00133     } 
00134 
00136   static unsigned int GetIteratorDimension() 
00137     {return TImage::ImageDimension;}
00138 
00143   const IndexType GetIndex()
00144     { return m_IndexStack.front();}
00145 
00147   const PixelType & Get(void) const
00148     { return this->m_Image->GetPixel(m_IndexStack.front() ); }
00149 
00151   bool IsAtEnd()
00152     { return this->m_IsAtEnd; }
00153 
00155   void AddSeed ( const IndexType seed )
00156     {
00157     m_StartIndices.push_back ( seed );
00158     }
00159 
00161   void ClearSeeds ()
00162     {
00163     m_StartIndices.clear();
00164     }
00165 
00168   void GoToBegin()
00169     {
00170     // Clear the queue
00171     while (!m_IndexStack.empty())
00172       {
00173       m_IndexStack.pop();
00174       }
00175 
00176     this->m_IsAtEnd = true;
00177     // Initialize the temporary image
00178     m_TempPtr->FillBuffer(
00179       NumericTraits<ITK_TYPENAME TTempImage::PixelType>::Zero
00180       );
00181     
00182     for ( unsigned int i = 0; i < m_StartIndices.size(); i++ )
00183       {
00184       if( this->m_Image->GetBufferedRegion().IsInside ( m_StartIndices[i] ) &&
00185           this->IsPixelIncluded(m_StartIndices[i]) )
00186         {
00187         // Push the seed onto the queue
00188         m_IndexStack.push(m_StartIndices[i]);
00189         
00190         // Obviously, we're at the beginning
00191         this->m_IsAtEnd = false;
00192         
00193         // Mark the start index in the temp image as inside the
00194         // function, neighbor check incomplete
00195         m_TempPtr->SetPixel(m_StartIndices[i], 2);
00196         }
00197       }
00198     }
00199 
00201   void operator++()
00202     { this->DoFloodStep(); }
00203 
00204   void DoFloodStep();
00205   
00206   virtual SmartPointer<FunctionType> GetFunction() const
00207     {
00208     return m_Function;
00209     }
00210     
00215   void SetFullyConnected(const bool _arg);
00216   bool GetFullyConnected() const;
00217   itkBooleanMacro(FullyConnected);
00219 
00220 
00221 protected: //made protected so other iterators can access 
00223   SmartPointer<FunctionType> m_Function;
00224 
00230   typedef Image<unsigned char, itkGetStaticConstMacro(NDimensions)> TTempImage;
00231 
00232   typename TTempImage::Pointer m_TempPtr;
00233   
00235   std::vector<IndexType> m_StartIndices;
00236 
00238   typename ImageType::PointType m_ImageOrigin;
00239 
00241   typename ImageType::SpacingType m_ImageSpacing;
00242 
00244   NeighborhoodIteratorType m_NeighborhoodIterator;
00245 
00247   RegionType   m_ImageRegion;
00248 
00250   std::queue<IndexType> m_IndexStack;
00251 
00253   FunctionInputType m_LocationVector;
00254 
00257   bool m_FoundUncheckedNeighbor;
00258 
00260   bool m_IsValidIndex;
00261 
00267   bool m_FullyConnected;
00268 };
00270 
00271 } // end namespace itk
00272 
00273 #ifndef ITK_MANUAL_INSTANTIATION
00274 #include "itkShapedFloodFilledFunctionConditionalConstIterator.txx"
00275 #endif
00276 
00277 #endif 
00278 

Generated at Mon Jul 12 2010 19:49:02 for ITK by doxygen 1.7.1 written by Dimitri van Heesch, © 1997-2000