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: 2005/08/14 19:25:18 $
00007   Version:   $Revision: 1.8 $
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 __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 
00086 template<typename TImage>
00087 class ITK_EXPORT ImageReverseConstIterator
00088 {
00089 public:
00091   typedef ImageReverseConstIterator Self;
00092   
00097   itkStaticConstMacro(ImageIteratorDimension, unsigned int,
00098                       TImage::ImageDimension);
00099 
00101   typedef typename TImage::IndexType        IndexType;
00102   typedef typename TImage::IndexValueType   IndexValueType;
00103     
00105   typedef typename TImage::SizeType         SizeType;
00106   typedef typename TImage::SizeValueType    SizeValueType;
00107   
00109   typedef typename TImage::OffsetType       OffsetType;
00110   typedef typename TImage::OffsetValueType  OffsetValueType;
00111   
00113   typedef typename TImage::RegionType       RegionType;
00114 
00116   typedef TImage   ImageType;
00117 
00121   typedef typename TImage::PixelContainer PixelContainer;
00122   typedef typename PixelContainer::Pointer PixelContainerPointer;
00123   
00125   typedef typename TImage::InternalPixelType   InternalPixelType;
00126 
00128   typedef typename TImage::PixelType   PixelType;
00129 
00132   typedef typename TImage::AccessorType     AccessorType;
00133 
00135   typedef typename TImage::AccessorFunctorType     AccessorFunctorType;
00136 
00139   ImageReverseConstIterator()
00140     :m_PixelAccessor(),
00141      m_PixelAccessorFunctor()
00142   {
00143     m_Buffer = 0;
00144     m_Offset = 0;
00145     m_BeginOffset = 0;
00146     m_EndOffset = 0;
00147     m_PixelAccessorFunctor.SetBegin( m_Buffer );
00148   }
00149 
00151   virtual ~ImageReverseConstIterator() {};
00152 
00155   ImageReverseConstIterator(const Self& it)
00156   {
00157     m_Image = it.m_Image;     // copy the smart pointer
00158 
00159     m_Region = it.m_Region;
00160     
00161     m_Buffer = it.m_Buffer;
00162     m_Offset = it.m_Offset;
00163     m_BeginOffset = it.m_BeginOffset;
00164     m_EndOffset = it.m_EndOffset;
00165     m_PixelAccessor = it.m_PixelAccessor;
00166     m_PixelAccessorFunctor = it.m_PixelAccessorFunctor;
00167     m_PixelAccessorFunctor.SetBegin( m_Buffer );
00168   }
00169 
00172   ImageReverseConstIterator(ImageType *ptr,
00173                 const RegionType &region)
00174   {
00175     unsigned long offset;
00176     m_Image = ptr;
00177     m_Buffer = m_Image->GetBufferPointer();
00178     m_Region = region;
00179 
00180     // Compute the end offset, one pixel before the first pixel
00181     offset = m_Image->ComputeOffset( m_Region.GetIndex() );
00182     m_EndOffset = offset-1;
00183     
00184     // Compute the begin offset, the last pixel in the region
00185     IndexType ind(m_Region.GetIndex());
00186     SizeType size(m_Region.GetSize());
00187     for (unsigned int i=0; i < TImage::ImageDimension; ++i)
00188       {
00189       ind[i] += (size[i] - 1);
00190       }
00191     m_BeginOffset = m_Image->ComputeOffset( ind );
00192     m_Offset = m_BeginOffset;
00193 
00194     m_PixelAccessor = ptr->GetPixelAccessor();
00195     m_PixelAccessorFunctor.SetPixelAccessor( m_PixelAccessor );
00196     m_PixelAccessorFunctor.SetBegin( m_Buffer );
00197   }
00198   
00206   ImageReverseConstIterator( const ImageConstIterator<TImage> &it)
00207   {
00208     m_Image = it.GetImage();
00209     m_Region = it.GetRegion();
00210     m_Buffer = m_Image->GetBufferPointer();
00211     
00212     IndexType ind = it.GetIndex();
00213 
00214     m_Offset = m_Image->ComputeOffset( ind );
00215 
00216     // Compute the end offset, one pixel before the first pixel
00217     m_EndOffset = m_Image->ComputeOffset( m_Region.GetIndex() ) - 1;
00218     
00219     // Compute the begin offset, the last pixel in the region
00220     IndexType regInd(m_Region.GetIndex());
00221     SizeType regSize(m_Region.GetSize());
00222     for (unsigned int i=0; i < TImage::ImageDimension; ++i)
00223       {
00224       regInd[i] += (regSize[i] - 1);
00225       }
00226     m_BeginOffset = m_Image->ComputeOffset( regInd );
00227     
00228     m_PixelAccessor = m_Image->GetPixelAccessor();
00229     m_PixelAccessorFunctor.SetPixelAccessor( m_PixelAccessor );
00230     m_PixelAccessorFunctor.SetBegin( m_Buffer );
00231   }
00232 
00235   Self &operator=(const Self& it)
00236   {
00237     m_Image = it.m_Image;     // copy the smart pointer
00238     m_Region = it.m_Region;
00239     
00240     m_Buffer = it.m_Buffer;
00241     m_Offset = it.m_Offset;
00242     m_BeginOffset = it.m_BeginOffset;
00243     m_EndOffset = it.m_EndOffset;
00244     m_PixelAccessor = it.m_PixelAccessor;
00245     m_PixelAccessorFunctor.SetPixelAccessor( m_PixelAccessor );
00246     m_PixelAccessorFunctor.SetBegin( m_Buffer );
00247     return *this;
00248   }
00249   
00252   Self &operator=(const ImageConstIterator<TImage>& it)
00253   {
00254     m_Image = it.GetImage();
00255     m_Region = it.GetRegion();
00256     m_Buffer = m_Image->GetBufferPointer();
00257     
00258     IndexType ind = it.GetIndex();
00259 
00260     m_Offset = m_Image->ComputeOffset( ind );
00261 
00262     // Compute the end offset, one pixel before the first pixel
00263     m_EndOffset = m_Image->ComputeOffset( m_Region.GetIndex() ) - 1;
00264     
00265     // Compute the begin offset, the last pixel in the region
00266     IndexType regInd(m_Region.GetIndex());
00267     SizeType regSize(m_Region.GetSize());
00268     for (unsigned int i=0; i < TImage::ImageDimension; ++i)
00269       {
00270       regInd[i] += (regSize[i] - 1);
00271       }
00272     m_BeginOffset = m_Image->ComputeOffset( regInd );
00273     
00274     m_PixelAccessor = m_Image->GetPixelAccessor();
00275     m_PixelAccessorFunctor.SetPixelAccessor( m_PixelAccessor );
00276     m_PixelAccessorFunctor.SetBegin( m_Buffer );
00277     
00278     return *this;
00279   }
00280   
00282   static unsigned int GetImageIteratorDimension() 
00283     {return TImage::ImageDimension;}
00284 
00287   bool
00288   operator!=(const Self &it) const
00289     {
00290     // two iterators are the same if they "point to" the same memory location
00291     return (m_Buffer + m_Offset) != (it.m_Buffer + it.m_Offset);
00292     };
00293 
00296   bool
00297   operator==(const Self &it) const
00298     {
00299     // two iterators are the same if they "point to" the same memory location
00300     return (m_Buffer + m_Offset) == (it.m_Buffer + it.m_Offset);
00301     };
00302   
00303 #if 0
00304 
00310   bool
00311   operator<=(const Self &it) const
00312     {
00313     // an iterator is "less than" another if it "points to" a lower
00314     // memory location
00315     return (m_Buffer + m_Offset) <= (it.m_Buffer + it.m_Offset);
00316     };
00317 
00320   bool
00321   operator<(const Self &it) const
00322     {
00323     // an iterator is "less than" another if it "points to" a lower
00324     // memory location
00325     return (m_Buffer + m_Offset) < (it.m_Buffer + it.m_Offset);
00326     };
00327 
00330   bool
00331   operator>=(const Self &it) const
00332     {
00333     // an iterator is "greater than" another if it "points to" a higher
00334     // memory location
00335     return (m_Buffer + m_Offset) >= (it.m_Buffer + it.m_Offset);
00336     };
00337 
00340   bool
00341   operator>(const Self &it) const
00342     {
00343     // an iterator is "greater than" another if it "points to" a higher
00344     // memory location
00345     return (m_Buffer + m_Offset) > (it.m_Buffer + it.m_Offset);
00346     };
00347 #endif
00348 
00349   
00354   const IndexType GetIndex()
00355     { return m_Image->ComputeIndex( m_Offset );  }
00356 
00359   virtual void SetIndex(const IndexType &ind)
00360     { m_Offset = m_Image->ComputeOffset( ind ); }
00361 
00362 
00365   const RegionType& GetRegion() const
00366     { return m_Region; };
00367 
00369   const PixelType Get(void) const  
00370     { return m_PixelAccessorFunctor.Get(*(m_Buffer+m_Offset)); }
00371   
00373   void Set( const PixelType & value) const  
00374     { m_PixelAccessorFunctor.Set(*(m_Buffer+m_Offset),value); }
00375 
00379   const PixelType & Value(void) const  
00380     { return *(m_Buffer+m_Offset); }
00381  
00385   PixelType & Value(void) 
00386     { return *(m_Buffer+m_Offset); }
00387 
00391   Self Begin() const;
00392 
00395   void GoToBegin()
00396     {
00397     m_Offset = m_BeginOffset;
00398     };
00399 
00403   Self End() const;
00404 
00407   void GoToEnd()
00408     {
00409     m_Offset = m_EndOffset;
00410     };
00411 
00414   bool IsAtBegin()
00415     {
00416     return (m_Offset == m_BeginOffset);
00417     }
00418 
00421   bool IsAtEnd()
00422     {
00423     return (m_Offset == m_EndOffset);
00424     }
00425   
00426 protected: //made protected so other iterators can access 
00427   typename ImageType::ConstWeakPointer    m_Image;
00428   RegionType                          m_Region;      // region to iterate over
00429   
00430   unsigned long  m_Offset;
00431   unsigned long  m_BeginOffset; // offset to last pixel in region
00432   unsigned long  m_EndOffset;   // offset to one pixel before first pixel
00433 
00434   const InternalPixelType        *m_Buffer;
00435 
00436   AccessorType                    m_PixelAccessor;
00437   AccessorFunctorType             m_PixelAccessorFunctor;
00438 };
00439 
00440 } // end namespace itk
00441 
00442 #ifndef ITK_MANUAL_INSTANTIATION
00443 #include "itkImageReverseConstIterator.txx"
00444 #endif
00445 
00446 #endif 

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