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: 2007/01/30 20:56:08 $
00007   Version:   $Revision: 1.9 $
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   }
00150 
00152   virtual ~ImageReverseConstIterator() {};
00153 
00156   ImageReverseConstIterator(const Self& it)
00157   {
00158     m_Image = it.m_Image;     // copy the smart pointer
00159 
00160     m_Region = it.m_Region;
00161     
00162     m_Buffer = it.m_Buffer;
00163     m_Offset = it.m_Offset;
00164     m_BeginOffset = it.m_BeginOffset;
00165     m_EndOffset = it.m_EndOffset;
00166     m_PixelAccessor = it.m_PixelAccessor;
00167     m_PixelAccessorFunctor = it.m_PixelAccessorFunctor;
00168     m_PixelAccessorFunctor.SetBegin( m_Buffer );
00169   }
00170 
00173   ImageReverseConstIterator(ImageType *ptr,
00174                 const RegionType &region)
00175   {
00176     unsigned long offset;
00177     m_Image = ptr;
00178     m_Buffer = m_Image->GetBufferPointer();
00179     m_Region = region;
00181 
00182     // Compute the end offset, one pixel before the first pixel
00183     offset = m_Image->ComputeOffset( m_Region.GetIndex() );
00184     m_EndOffset = offset-1;
00185     
00186     // Compute the begin offset, the last pixel in the region
00187     IndexType ind(m_Region.GetIndex());
00188     SizeType size(m_Region.GetSize());
00189     for (unsigned int i=0; i < TImage::ImageDimension; ++i)
00190       {
00191       ind[i] += (size[i] - 1);
00192       }
00193     m_BeginOffset = m_Image->ComputeOffset( ind );
00194     m_Offset = m_BeginOffset;
00195 
00196     m_PixelAccessor = ptr->GetPixelAccessor();
00197     m_PixelAccessorFunctor.SetPixelAccessor( m_PixelAccessor );
00198     m_PixelAccessorFunctor.SetBegin( m_Buffer );
00199   }
00200   
00208   ImageReverseConstIterator( const ImageConstIterator<TImage> &it)
00209   {
00210     m_Image = it.GetImage();
00211     m_Region = it.GetRegion();
00212     m_Buffer = m_Image->GetBufferPointer();
00214 
00215     IndexType ind = it.GetIndex();
00216 
00217     m_Offset = m_Image->ComputeOffset( ind );
00218 
00219     // Compute the end offset, one pixel before the first pixel
00220     m_EndOffset = m_Image->ComputeOffset( m_Region.GetIndex() ) - 1;
00221     
00222     // Compute the begin offset, the last pixel in the region
00223     IndexType regInd(m_Region.GetIndex());
00224     SizeType regSize(m_Region.GetSize());
00225     for (unsigned int i=0; i < TImage::ImageDimension; ++i)
00226       {
00227       regInd[i] += (regSize[i] - 1);
00228       }
00229     m_BeginOffset = m_Image->ComputeOffset( regInd );
00230     
00231     m_PixelAccessor = m_Image->GetPixelAccessor();
00232     m_PixelAccessorFunctor.SetPixelAccessor( m_PixelAccessor );
00233     m_PixelAccessorFunctor.SetBegin( m_Buffer );
00234   }
00235 
00238   Self &operator=(const Self& it)
00239   {
00240     m_Image = it.m_Image;     // copy the smart pointer
00241     m_Region = it.m_Region;
00242 
00243     m_Buffer = it.m_Buffer;
00244     m_Offset = it.m_Offset;
00245     m_BeginOffset = it.m_BeginOffset;
00246     m_EndOffset = it.m_EndOffset;
00247     m_PixelAccessor = it.m_PixelAccessor;
00248     m_PixelAccessorFunctor.SetPixelAccessor( m_PixelAccessor );
00249     m_PixelAccessorFunctor.SetBegin( m_Buffer );
00250     return *this;
00251   }
00252   
00255   Self &operator=(const ImageConstIterator<TImage>& it)
00256   {
00257     m_Image = it.GetImage();
00258     m_Region = it.GetRegion();
00259     m_Buffer = m_Image->GetBufferPointer();
00261 
00262     IndexType ind = it.GetIndex();
00263 
00264     m_Offset = m_Image->ComputeOffset( ind );
00265 
00266     // Compute the end offset, one pixel before the first pixel
00267     m_EndOffset = m_Image->ComputeOffset( m_Region.GetIndex() ) - 1;
00268     
00269     // Compute the begin offset, the last pixel in the region
00270     IndexType regInd(m_Region.GetIndex());
00271     SizeType regSize(m_Region.GetSize());
00272     for (unsigned int i=0; i < TImage::ImageDimension; ++i)
00273       {
00274       regInd[i] += (regSize[i] - 1);
00275       }
00276     m_BeginOffset = m_Image->ComputeOffset( regInd );
00277     
00278     m_PixelAccessor = m_Image->GetPixelAccessor();
00279     m_PixelAccessorFunctor.SetPixelAccessor( m_PixelAccessor );
00280     m_PixelAccessorFunctor.SetBegin( m_Buffer );
00281     
00282     return *this;
00283   }
00284   
00286   static unsigned int GetImageIteratorDimension() 
00287     {return TImage::ImageDimension;}
00288 
00291   bool
00292   operator!=(const Self &it) const
00293     {
00294     // two iterators are the same if they "point to" the same memory location
00295     return (m_Buffer + m_Offset) != (it.m_Buffer + it.m_Offset);
00296     };
00298 
00301   bool
00302   operator==(const Self &it) const
00303     {
00304     // two iterators are the same if they "point to" the same memory location
00305     return (m_Buffer + m_Offset) == (it.m_Buffer + it.m_Offset);
00306     };
00308 
00309 #if 0
00310 
00316   bool
00317   operator<=(const Self &it) const
00318     {
00319     // an iterator is "less than" another if it "points to" a lower
00320     // memory location
00321     return (m_Buffer + m_Offset) <= (it.m_Buffer + it.m_Offset);
00322     };
00324 
00327   bool
00328   operator<(const Self &it) const
00329     {
00330     // an iterator is "less than" another if it "points to" a lower
00331     // memory location
00332     return (m_Buffer + m_Offset) < (it.m_Buffer + it.m_Offset);
00333     };
00335 
00338   bool
00339   operator>=(const Self &it) const
00340     {
00341     // an iterator is "greater than" another if it "points to" a higher
00342     // memory location
00343     return (m_Buffer + m_Offset) >= (it.m_Buffer + it.m_Offset);
00344     };
00346 
00349   bool
00350   operator>(const Self &it) const
00351     {
00352     // an iterator is "greater than" another if it "points to" a higher
00353     // memory location
00354     return (m_Buffer + m_Offset) > (it.m_Buffer + it.m_Offset);
00355     };
00356 #endif
00357 
00358 
00359   
00364   const IndexType GetIndex()
00365     { return m_Image->ComputeIndex( m_Offset );  }
00366 
00369   virtual void SetIndex(const IndexType &ind)
00370     { m_Offset = m_Image->ComputeOffset( ind ); }
00371 
00372 
00375   const RegionType& GetRegion() const
00376     { return m_Region; };
00377 
00379   const PixelType Get(void) const  
00380     { return m_PixelAccessorFunctor.Get(*(m_Buffer+m_Offset)); }
00381 
00383   void Set( const PixelType & value) const  
00384     { 
00385     this->m_PixelAccessorFunctor.Set(*(const_cast<InternalPixelType *>(
00386             this->m_Buffer+this->m_Offset)),value);
00387     }
00388 
00392   const PixelType & Value(void) const  
00393     { return *(m_Buffer+m_Offset); }
00394 
00398   const PixelType & Value(void) 
00399     { return *(m_Buffer+m_Offset); }
00400 
00404   Self Begin() const;
00405 
00408   void GoToBegin()
00409     {
00410     m_Offset = m_BeginOffset;
00411     };
00412 
00416   Self End() const;
00417 
00420   void GoToEnd()
00421     {
00422     m_Offset = m_EndOffset;
00423     };
00424 
00427   bool IsAtBegin()
00428     {
00429     return (m_Offset == m_BeginOffset);
00430     }
00431 
00434   bool IsAtEnd()
00435     {
00436     return (m_Offset == m_EndOffset);
00437     }
00438 
00439 protected: //made protected so other iterators can access 
00440   typename ImageType::ConstWeakPointer    m_Image;
00441   RegionType                          m_Region;      // region to iterate over
00442   
00443   unsigned long  m_Offset;
00444   unsigned long  m_BeginOffset; // offset to last pixel in region
00445   unsigned long  m_EndOffset;   // offset to one pixel before first pixel
00446 
00447   const InternalPixelType        *m_Buffer;
00448 
00449   AccessorType                    m_PixelAccessor;
00450   AccessorFunctorType             m_PixelAccessorFunctor;
00451 };
00452 
00453 } // end namespace itk
00454 
00455 // Define instantiation macro for this template.
00456 #define ITK_TEMPLATE_ImageReverseConstIterator(_, EXPORT, x, y) namespace itk { \
00457   _(1(class EXPORT ImageReverseConstIterator< ITK_TEMPLATE_1 x >)) \
00458   namespace Templates { typedef ImageReverseConstIterator< ITK_TEMPLATE_1 x > ImageReverseConstIterator##y; } \
00459   }
00460 
00461 #if ITK_TEMPLATE_EXPLICIT
00462 # include "Templates/itkImageReverseConstIterator+-.h"
00463 #endif
00464 
00465 #if ITK_TEMPLATE_TXX
00466 # include "itkImageReverseConstIterator.txx"
00467 #endif
00468 
00469 #endif 
00470 

Generated at Tue Jul 29 20:43:50 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000