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: 2005/08/17 14:34:58 $
00007   Version:   $Revision: 1.23 $
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     };
00167 
00170   bool
00171   operator==(const Self &it) const
00172     {
00173     // two iterators are the same if they "point to" the same memory location
00174     return (m_Position) == (it.m_Position);
00175     };
00176   
00179   bool
00180   operator<=(const Self &it) const
00181     {
00182     // an iterator is "less than" another if it "points to" a lower
00183     // memory location
00184     return (m_Position) <= (it.m_Position);
00185     };
00186 
00189   bool
00190   operator<(const Self &it) const
00191     {
00192     // an iterator is "less than" another if it "points to" a lower
00193     // memory location
00194     return (m_Position) < (it.m_Position);
00195     };
00196 
00199   bool
00200   operator>=(const Self &it) const
00201     {
00202     // an iterator is "greater than" another if it "points to" a higher
00203     // memory location
00204     return (m_Position) >= (it.m_Position);
00205     };
00206 
00209   bool
00210   operator>(const Self &it) const
00211     {
00212     // an iterator is "greater than" another if it "points to" a higher
00213     // memory location
00214     return (m_Position) > (it.m_Position);
00215     };
00216 
00219   const IndexType & GetIndex() const
00220     { return m_PositionIndex; }
00221 
00224   const RegionType& GetRegion() const
00225     { return m_Region; };
00226 
00229   void SetIndex(const IndexType &ind)
00230   { m_Position = m_Image->GetBufferPointer() + m_Image->ComputeOffset( ind ); 
00231       m_PositionIndex = ind;  }
00232 
00234   PixelType Get(void) const  
00235     { return m_PixelAccessorFunctor.Get(*m_Position); }
00236   
00240   const PixelType & Value(void) const  
00241     { return *m_Position; }
00242  
00245   Self Begin(void) const;
00246 
00248   void GoToBegin(void);
00249 
00252   Self End(void) const;
00253 
00255   void GoToReverseBegin(void);
00256 
00258   bool IsAtReverseEnd(void) const
00259     {
00260       return !m_Remaining;
00261     }
00262 
00264   bool IsAtEnd(void) const
00265     {
00266       return !m_Remaining;
00267     }
00268   
00270   bool Remaining()
00271     {
00272     return m_Remaining;
00273     }
00274   
00275 protected: //made protected so other iterators can access 
00276   typename TImage::ConstWeakPointer     m_Image;
00277   
00278   IndexType    m_PositionIndex;     // Index where we currently are
00279   IndexType    m_BeginIndex;        // Index to start iterating over
00280   IndexType    m_EndIndex;          // Index to finish iterating:
00281                                     // one pixel past the end of each
00282                                     // row, col, slice, etc....
00283 
00284   RegionType   m_Region;            // region to iterate over
00285 
00286   unsigned long          m_OffsetTable[ ImageDimension + 1 ]; 
00287   
00288   const InternalPixelType     *m_Position;
00289   const InternalPixelType     *m_Begin;
00290   const InternalPixelType     *m_End;
00291 
00292   bool                         m_Remaining;
00293 
00294   AccessorType           m_PixelAccessor;
00295   AccessorFunctorType    m_PixelAccessorFunctor;
00296 
00297 };
00298 
00299 } // end namespace itk
00300 
00301 #ifndef ITK_MANUAL_INSTANTIATION
00302 #include "itkImageConstIteratorWithIndex.txx"
00303 #endif
00304 
00305 #endif 

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