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: 2004/11/01 21:16:31 $
00007   Version:   $Revision: 1.20 $
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 
00134   typedef typename TImage::OffsetType           OffsetType;
00135   typedef typename OffsetType::OffsetValueType  OffsetValueType;
00136 
00139   ImageConstIteratorWithIndex();
00140 
00143   ImageConstIteratorWithIndex(const Self& it);
00144 
00147   ImageConstIteratorWithIndex( const TImage *ptr,
00148                                const RegionType& region );
00149 
00152   Self &operator=(const Self& it);
00153   
00155   static unsigned int GetImageDimension() 
00156     {return ImageDimension;}
00157 
00160   bool
00161   operator!=(const Self &it) const
00162     {
00163     // two iterators are the same if they "point to" the same memory location
00164     return (m_Position) != (it.m_Position);
00165     };
00166 
00169   bool
00170   operator==(const Self &it) const
00171     {
00172     // two iterators are the same if they "point to" the same memory location
00173     return (m_Position) == (it.m_Position);
00174     };
00175   
00178   bool
00179   operator<=(const Self &it) const
00180     {
00181     // an iterator is "less than" another if it "points to" a lower
00182     // memory location
00183     return (m_Position) <= (it.m_Position);
00184     };
00185 
00188   bool
00189   operator<(const Self &it) const
00190     {
00191     // an iterator is "less than" another if it "points to" a lower
00192     // memory location
00193     return (m_Position) < (it.m_Position);
00194     };
00195 
00198   bool
00199   operator>=(const Self &it) const
00200     {
00201     // an iterator is "greater than" another if it "points to" a higher
00202     // memory location
00203     return (m_Position) >= (it.m_Position);
00204     };
00205 
00208   bool
00209   operator>(const Self &it) const
00210     {
00211     // an iterator is "greater than" another if it "points to" a higher
00212     // memory location
00213     return (m_Position) > (it.m_Position);
00214     };
00215 
00218   const IndexType GetIndex()
00219     { return m_PositionIndex; }
00220 
00223   const RegionType& GetRegion() const
00224     { return m_Region; };
00225 
00228   void SetIndex(const IndexType &ind)
00229     { m_Position = m_Begin + m_Image->ComputeOffset( ind ); 
00230       m_PositionIndex = ind;  }
00231 
00233   PixelType Get(void) const  
00234     { return m_PixelAccessor.Get(*m_Position); }
00235   
00239   const PixelType & Value(void) const  
00240     { return *m_Position; }
00241  
00244   Self Begin(void) const;
00245 
00247   void GoToBegin(void);
00248 
00251   Self End(void) const;
00252 
00254   void GoToReverseBegin(void);
00255 
00257   bool IsAtReverseEnd(void) const
00258     {
00259       return !m_Remaining;
00260     }
00261 
00263   bool IsAtEnd(void) const
00264     {
00265       return !m_Remaining;
00266     }
00267   
00269   bool Remaining()
00270     {
00271     return m_Remaining;
00272     }
00273   
00274 protected: //made protected so other iterators can access 
00275   typename TImage::ConstWeakPointer     m_Image;
00276   
00277   IndexType    m_PositionIndex;     // Index where we currently are
00278   IndexType    m_BeginIndex;        // Index to start iterating over
00279   IndexType    m_EndIndex;          // Index to finish iterating:
00280                                     // one pixel past the end of each
00281                                     // row, col, slice, etc....
00282 
00283   RegionType   m_Region;            // region to iterate over
00284 
00285   unsigned long          m_OffsetTable[ ImageDimension + 1 ]; 
00286   
00287   const InternalPixelType     *m_Position;
00288   const InternalPixelType     *m_Begin;
00289   const InternalPixelType     *m_End;
00290 
00291   bool                         m_Remaining;
00292 
00293   AccessorType           m_PixelAccessor;
00294 
00295 };
00296 
00297 } // end namespace itk
00298 
00299 #ifndef ITK_MANUAL_INSTANTIATION
00300 #include "itkImageConstIteratorWithIndex.txx"
00301 #endif
00302 
00303 #endif 

Generated at Tue Mar 29 23:54:34 2005 for ITK by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2000