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

itkImageConstIteratorWithIndex.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkImageConstIteratorWithIndex.h,v $
00005   Language:  C++
00006   Date:      $Date: 2007/01/30 20:56:08 $
00007   Version:   $Revision: 1.24 $
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 __itkImageConstIteratorWithIndex_h
00018 #define __itkImageConstIteratorWithIndex_h
00019 
00020 #include "itkIndex.h"
00021 #include "itkImage.h"
00022 #include <memory>
00023 
00024 namespace itk
00025 {
00026 
00090 template<typename TImage>
00091 class ITK_EXPORT ImageConstIteratorWithIndex
00092 {
00093 public:
00095   typedef ImageConstIteratorWithIndex Self;
00096 
00101   itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension);
00102 
00104   typedef typename TImage::IndexType          IndexType;
00105   typedef typename IndexType::IndexValueType  IndexValueType;
00106 
00108   typedef typename TImage::SizeType           SizeType;
00109   typedef typename SizeType::SizeValueType    SizeValueType;
00110 
00112   typedef typename TImage::RegionType         RegionType;
00113 
00115   typedef TImage   ImageType;
00116 
00120   typedef typename TImage::PixelContainer PixelContainer;
00121   typedef typename PixelContainer::Pointer PixelContainerPointer;
00122 
00124   typedef typename TImage::InternalPixelType   InternalPixelType;
00125 
00127   typedef typename TImage::PixelType   PixelType;
00128 
00131   typedef typename TImage::AccessorType            AccessorType;
00132   typedef typename TImage::AccessorFunctorType     AccessorFunctorType;
00133 
00135   typedef typename TImage::OffsetType           OffsetType;
00136   typedef typename OffsetType::OffsetValueType  OffsetValueType;
00137 
00140   ImageConstIteratorWithIndex();
00141 
00144   ImageConstIteratorWithIndex(const Self& it);
00145 
00148   ImageConstIteratorWithIndex( const TImage *ptr,
00149                                const RegionType& region );
00150 
00153   Self &operator=(const Self& it);
00154 
00156   static unsigned int GetImageDimension() 
00157     {return ImageDimension;}
00158 
00161   bool
00162   operator!=(const Self &it) const
00163     {
00164     // two iterators are the same if they "point to" the same memory location
00165     return (m_Position) != (it.m_Position);
00166     };
00168 
00171   bool
00172   operator==(const Self &it) const
00173     {
00174     // two iterators are the same if they "point to" the same memory location
00175     return (m_Position) == (it.m_Position);
00176     };
00178 
00181   bool
00182   operator<=(const Self &it) const
00183     {
00184     // an iterator is "less than" another if it "points to" a lower
00185     // memory location
00186     return (m_Position) <= (it.m_Position);
00187     };
00189 
00192   bool
00193   operator<(const Self &it) const
00194     {
00195     // an iterator is "less than" another if it "points to" a lower
00196     // memory location
00197     return (m_Position) < (it.m_Position);
00198     };
00200 
00203   bool
00204   operator>=(const Self &it) const
00205     {
00206     // an iterator is "greater than" another if it "points to" a higher
00207     // memory location
00208     return (m_Position) >= (it.m_Position);
00209     };
00211 
00214   bool
00215   operator>(const Self &it) const
00216     {
00217     // an iterator is "greater than" another if it "points to" a higher
00218     // memory location
00219     return (m_Position) > (it.m_Position);
00220     };
00222 
00225   const IndexType & GetIndex() const
00226     { return m_PositionIndex; }
00227 
00230   const RegionType& GetRegion() const
00231     { return m_Region; };
00232 
00235   void SetIndex(const IndexType &ind)
00236   { m_Position = m_Image->GetBufferPointer() + m_Image->ComputeOffset( ind ); 
00237       m_PositionIndex = ind;  }
00239 
00241   PixelType Get(void) const  
00242     { return m_PixelAccessorFunctor.Get(*m_Position); }
00243 
00247   const PixelType & Value(void) const  
00248     { return *m_Position; }
00249 
00252   Self Begin(void) const;
00253 
00255   void GoToBegin(void);
00256 
00259   Self End(void) const;
00260 
00262   void GoToReverseBegin(void);
00263 
00265   bool IsAtReverseEnd(void) const
00266     {
00267       return !m_Remaining;
00268     }
00269 
00271   bool IsAtEnd(void) const
00272     {
00273       return !m_Remaining;
00274     }
00275 
00277   bool Remaining()
00278     {
00279     return m_Remaining;
00280     }
00281 
00282 protected: //made protected so other iterators can access 
00283   typename TImage::ConstWeakPointer     m_Image;
00284   
00285   IndexType    m_PositionIndex;     // Index where we currently are
00286   IndexType    m_BeginIndex;        // Index to start iterating over
00287   IndexType    m_EndIndex;          // Index to finish iterating:
00288                                     // one pixel past the end of each
00289                                     // row, col, slice, etc....
00290 
00291   RegionType   m_Region;            // region to iterate over
00292 
00293   unsigned long          m_OffsetTable[ ImageDimension + 1 ]; 
00294   
00295   const InternalPixelType     *m_Position;
00296   const InternalPixelType     *m_Begin;
00297   const InternalPixelType     *m_End;
00298 
00299   bool                         m_Remaining;
00300 
00301   AccessorType           m_PixelAccessor;
00302   AccessorFunctorType    m_PixelAccessorFunctor;
00303 
00304 };
00305 
00306 } // end namespace itk
00307 
00308 // Define instantiation macro for this template.
00309 #define ITK_TEMPLATE_ImageConstIteratorWithIndex(_, EXPORT, x, y) namespace itk { \
00310   _(1(class EXPORT ImageConstIteratorWithIndex< ITK_TEMPLATE_1 x >)) \
00311   namespace Templates { typedef ImageConstIteratorWithIndex< ITK_TEMPLATE_1 x > ImageConstIteratorWithIndex##y; } \
00312   }
00313 
00314 
00315 #if ITK_TEMPLATE_EXPLICIT
00316 # include "Templates/itkImageConstIteratorWithIndex+-.h"
00317 #endif
00318 
00319 #if ITK_TEMPLATE_TXX
00320 # include "itkImageConstIteratorWithIndex.txx"
00321 #endif
00322 
00323 #endif 
00324 

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