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: 2008-10-17 01:41:59 $
00007   Version:   $Revision: 1.25 $
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     {
00231     m_Position = m_Image->GetBufferPointer() + m_Image->ComputeOffset( ind );
00232     m_PositionIndex = ind;
00233     }
00235 
00237   PixelType Get(void) const
00238     { return m_PixelAccessorFunctor.Get(*m_Position); }
00239 
00243   const PixelType & Value(void) const
00244     { return *m_Position; }
00245 
00248   Self Begin(void) const;
00249 
00251   void GoToBegin(void);
00252 
00255   Self End(void) const;
00256 
00258   void GoToReverseBegin(void);
00259 
00261   bool IsAtReverseEnd(void) const
00262     {
00263     return !m_Remaining;
00264     }
00265 
00267   bool IsAtEnd(void) const
00268     {
00269     return !m_Remaining;
00270     }
00271 
00273   bool Remaining()
00274     {
00275     return m_Remaining;
00276     }
00277 
00278 protected: //made protected so other iterators can access
00279   typename TImage::ConstWeakPointer     m_Image;
00280 
00281   IndexType    m_PositionIndex;     // Index where we currently are
00282   IndexType    m_BeginIndex;        // Index to start iterating over
00283   IndexType    m_EndIndex;          // Index to finish iterating:
00284                                     // one pixel past the end of each
00285                                     // row, col, slice, etc....
00286 
00287   RegionType   m_Region;            // region to iterate over
00288 
00289   unsigned long          m_OffsetTable[ ImageDimension + 1 ];
00290 
00291   const InternalPixelType     *m_Position;
00292   const InternalPixelType     *m_Begin;
00293   const InternalPixelType     *m_End;
00294 
00295   bool                         m_Remaining;
00296 
00297   AccessorType           m_PixelAccessor;
00298   AccessorFunctorType    m_PixelAccessorFunctor;
00299 
00300 };
00301 
00302 } // end namespace itk
00303 
00304 // Define instantiation macro for this template.
00305 #define ITK_TEMPLATE_ImageConstIteratorWithIndex(_, EXPORT, x, y) namespace itk { \
00306   _(1(class EXPORT ImageConstIteratorWithIndex< ITK_TEMPLATE_1 x >)) \
00307   namespace Templates { typedef ImageConstIteratorWithIndex< ITK_TEMPLATE_1 x > ImageConstIteratorWithIndex##y; } \
00308   }
00309 
00310 
00311 #if ITK_TEMPLATE_EXPLICIT
00312 # include "Templates/itkImageConstIteratorWithIndex+-.h"
00313 #endif
00314 
00315 #if ITK_TEMPLATE_TXX
00316 # include "itkImageConstIteratorWithIndex.txx"
00317 #endif
00318 
00319 #endif
00320 

Generated at Thu May 28 10:15:59 2009 for ITK by doxygen 1.5.5 written by Dimitri van Heesch, © 1997-2000