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

itkImageReverseConstIterator.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkImageReverseConstIterator.h,v $
00005   Language:  C++
00006   Date:      $Date: 2002/09/30 12:41:11 $
00007   Version:   $Revision: 1.1 $
00008 
00009   Copyright (c) 2002 Insight 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 __itkImageReverseConstIterator_h
00018 #define __itkImageReverseConstIterator_h
00019 
00020 #include "itkIndex.h"
00021 #include "itkSize.h"
00022 #include "itkImage.h"
00023 #include "itkImageConstIterator.h"
00024 #include <memory>
00025 
00026 namespace itk
00027 {
00028 
00059 template<typename TImage>
00060 class ImageReverseConstIterator {
00061 public:
00063   typedef ImageReverseConstIterator Self;
00064   
00069   itkStaticConstMacro(ImageIteratorDimension, unsigned int,
00070                       TImage::ImageDimension);
00071 
00073   typedef typename TImage::IndexType        IndexType;
00074   typedef typename TImage::IndexValueType   IndexValueType;
00075     
00077   typedef typename TImage::SizeType         SizeType;
00078   typedef typename TImage::SizeValueType    SizeValueType;
00079   
00081   typedef typename TImage::OffsetType       OffsetType;
00082   typedef typename TImage::OffsetValueType  OffsetValueType;
00083   
00085   typedef typename TImage::RegionType       RegionType;
00086 
00088   typedef TImage   ImageType;
00089 
00093   typedef typename TImage::PixelContainer PixelContainer;
00094   typedef typename PixelContainer::Pointer PixelContainerPointer;
00095   
00097   typedef typename TImage::InternalPixelType   InternalPixelType;
00098 
00100   typedef typename TImage::PixelType   PixelType;
00101 
00104   typedef typename TImage::AccessorType     AccessorType;
00105 
00108   ImageReverseConstIterator()
00109     :m_PixelAccessor()
00110   {
00111     m_Buffer = 0;
00112     m_Offset = 0;
00113     m_BeginOffset = 0;
00114     m_EndOffset = 0;
00115   }
00116 
00118   virtual ~ImageReverseConstIterator() {};
00119 
00122   ImageReverseConstIterator(const Self& it)
00123   {
00124     m_Image = it.m_Image;     // copy the smart pointer
00125 
00126     m_Region = it.m_Region;
00127     
00128     m_Buffer = it.m_Buffer;
00129     m_Offset = it.m_Offset;
00130     m_BeginOffset = it.m_BeginOffset;
00131     m_EndOffset = it.m_EndOffset;
00132     m_PixelAccessor = it.m_PixelAccessor;
00133   }
00134 
00137   ImageReverseConstIterator(ImageType *ptr,
00138                 const RegionType &region)
00139   {
00140     unsigned long offset;
00141     m_Image = ptr;
00142     m_Buffer = m_Image->GetBufferPointer();
00143     m_Region = region;
00144 
00145     // Compute the end offset, one pixel before the first pixel
00146     offset = m_Image->ComputeOffset( m_Region.GetIndex() );
00147     m_EndOffset = offset-1;
00148     
00149     // Compute the begin offset, the last pixel in the region
00150     IndexType ind(m_Region.GetIndex());
00151     SizeType size(m_Region.GetSize());
00152     for (unsigned int i=0; i < TImage::ImageDimension; ++i)
00153       {
00154       ind[i] += (size[i] - 1);
00155       }
00156     m_BeginOffset = m_Image->ComputeOffset( ind );
00157     m_Offset = m_BeginOffset;
00158 
00159     m_PixelAccessor = ptr->GetPixelAccessor();
00160   }
00161   
00169   ImageReverseConstIterator( const ImageConstIterator<TImage> &it)
00170   {
00171     m_Image = it.GetImage();
00172     m_Region = it.GetRegion();
00173     m_Buffer = m_Image->GetBufferPointer();
00174     
00175     IndexType ind = it.GetIndex();
00176 
00177     m_Offset = m_Image->ComputeOffset( ind );
00178 
00179     // Compute the end offset, one pixel before the first pixel
00180     m_EndOffset = m_Image->ComputeOffset( m_Region.GetIndex() ) - 1;
00181     
00182     // Compute the begin offset, the last pixel in the region
00183     IndexType regInd(m_Region.GetIndex());
00184     SizeType regSize(m_Region.GetSize());
00185     for (unsigned int i=0; i < TImage::ImageDimension; ++i)
00186       {
00187       regInd[i] += (regSize[i] - 1);
00188       }
00189     m_BeginOffset = m_Image->ComputeOffset( regInd );
00190     
00191     m_PixelAccessor = m_Image->GetPixelAccessor();
00192   }
00193 
00196   Self &operator=(const Self& it)
00197   {
00198     m_Image = it.m_Image;     // copy the smart pointer
00199     m_Region = it.m_Region;
00200     
00201     m_Buffer = it.m_Buffer;
00202     m_Offset = it.m_Offset;
00203     m_BeginOffset = it.m_BeginOffset;
00204     m_EndOffset = it.m_EndOffset;
00205     m_PixelAccessor = it.m_PixelAccessor;
00206     return *this;
00207   }
00208   
00211   Self &operator=(const ImageConstIterator<TImage>& it)
00212   {
00213     m_Image = it.GetImage();
00214     m_Region = it.GetRegion();
00215     m_Buffer = m_Image->GetBufferPointer();
00216     
00217     IndexType ind = it.GetIndex();
00218 
00219     m_Offset = m_Image->ComputeOffset( ind );
00220 
00221     // Compute the end offset, one pixel before the first pixel
00222     m_EndOffset = m_Image->ComputeOffset( m_Region.GetIndex() ) - 1;
00223     
00224     // Compute the begin offset, the last pixel in the region
00225     IndexType regInd(m_Region.GetIndex());
00226     SizeType regSize(m_Region.GetSize());
00227     for (unsigned int i=0; i < TImage::ImageDimension; ++i)
00228       {
00229       regInd[i] += (regSize[i] - 1);
00230       }
00231     m_BeginOffset = m_Image->ComputeOffset( regInd );
00232     
00233     m_PixelAccessor = m_Image->GetPixelAccessor();
00234     
00235     return *this;
00236   }
00237   
00239   static unsigned int GetImageIteratorDimension() 
00240     {return TImage::ImageDimension;}
00241 
00244   bool
00245   operator!=(const Self &it) const
00246     {
00247     // two iterators are the same if they "point to" the same memory location
00248     return (m_Buffer + m_Offset) != (it.m_Buffer + it.m_Offset);
00249     };
00250 
00253   bool
00254   operator==(const Self &it) const
00255     {
00256     // two iterators are the same if they "point to" the same memory location
00257     return (m_Buffer + m_Offset) == (it.m_Buffer + it.m_Offset);
00258     };
00259   
00260 #if 0
00261 
00267   bool
00268   operator<=(const Self &it) const
00269     {
00270     // an iterator is "less than" another if it "points to" a lower
00271     // memory location
00272     return (m_Buffer + m_Offset) <= (it.m_Buffer + it.m_Offset);
00273     };
00274 
00277   bool
00278   operator<(const Self &it) const
00279     {
00280     // an iterator is "less than" another if it "points to" a lower
00281     // memory location
00282     return (m_Buffer + m_Offset) < (it.m_Buffer + it.m_Offset);
00283     };
00284 
00287   bool
00288   operator>=(const Self &it) const
00289     {
00290     // an iterator is "greater than" another if it "points to" a higher
00291     // memory location
00292     return (m_Buffer + m_Offset) >= (it.m_Buffer + it.m_Offset);
00293     };
00294 
00297   bool
00298   operator>(const Self &it) const
00299     {
00300     // an iterator is "greater than" another if it "points to" a higher
00301     // memory location
00302     return (m_Buffer + m_Offset) > (it.m_Buffer + it.m_Offset);
00303     };
00304 #endif
00305 
00306   
00311   const IndexType GetIndex()
00312     { return m_Image->ComputeIndex( m_Offset );  }
00313 
00316   virtual void SetIndex(const IndexType &ind)
00317     { m_Offset = m_Image->ComputeOffset( ind ); }
00318 
00319 
00322   const RegionType& GetRegion() const
00323     { return m_Region; };
00324 
00326   PixelType & Get(void) const  
00327     { return m_PixelAccessor.Get(*(m_Buffer+m_Offset)); }
00328   
00330   void Set( const PixelType & value) const  
00331     { m_PixelAccessor.Set(*(m_Buffer+m_Offset),value); }
00332 
00336   const PixelType & Value(void) const  
00337     { return *(m_Buffer+m_Offset); }
00338  
00342   PixelType & Value(void) 
00343     { return *(m_Buffer+m_Offset); }
00344 
00348   Self Begin() const;
00349 
00352   void GoToBegin()
00353     {
00354     m_Offset = m_BeginOffset;
00355     };
00356 
00360   Self End() const;
00361 
00364   void GoToEnd()
00365     {
00366     m_Offset = m_EndOffset;
00367     };
00368 
00371   bool IsAtBegin()
00372     {
00373     return (m_Offset == m_BeginOffset);
00374     }
00375 
00378   bool IsAtEnd()
00379     {
00380     return (m_Offset == m_EndOffset);
00381     }
00382   
00383 protected: //made protected so other iterators can access 
00384   typename ImageType::ConstPointer    m_Image;
00385   RegionType                          m_Region;      // region to iterate over
00386   
00387   unsigned long  m_Offset;
00388   unsigned long  m_BeginOffset; // offset to last pixel in region
00389   unsigned long  m_EndOffset;   // offset to one pixel before first pixel
00390 
00391   const InternalPixelType        *m_Buffer;
00392 
00393   AccessorType                    m_PixelAccessor;
00394 };
00395 
00396 } // end namespace itk
00397 
00398 #ifndef ITK_MANUAL_INSTANTIATION
00399 #include "itkImageReverseConstIterator.txx"
00400 #endif
00401 
00402 #endif 

Generated at Wed Mar 12 01:13:02 2003 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000