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

itkImageRegionReverseConstIterator.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkImageRegionReverseConstIterator.h,v $
00005   Language:  C++
00006   Date:      $Date: 2004/12/11 20:29:18 $
00007   Version:   $Revision: 1.6 $
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 __itkImageRegionReverseConstIterator_h
00018 #define __itkImageRegionReverseConstIterator_h
00019 
00020 #include "itkImageReverseConstIterator.h"
00021 
00022 namespace itk
00023 {
00024 
00099 template<typename TImage>
00100 class ITK_EXPORT ImageRegionReverseConstIterator : public ImageReverseConstIterator<TImage>
00101 {
00102 public:
00103 
00105   typedef ImageRegionReverseConstIterator Self;
00106   typedef ImageReverseConstIterator<TImage>  Superclass;
00107 
00112   enum { ImageIteratorDimension = Superclass::ImageIteratorDimension };
00113 
00116   typedef typename Superclass::IndexType IndexType;
00117   typedef typename Superclass::IndexValueType IndexValueType;
00118 
00121   typedef typename Superclass::SizeType SizeType;
00122   typedef typename Superclass::SizeValueType SizeValueType;
00123 
00126   typedef typename Superclass::OffsetType OffsetType;
00127   typedef typename Superclass::OffsetValueType OffsetValueType;
00128 
00130   typedef typename Superclass::RegionType   RegionType;
00131 
00134   typedef typename Superclass::ImageType ImageType;
00135 
00139   typedef typename Superclass::PixelContainer PixelContainer;
00140   typedef typename PixelContainer::Pointer PixelContainerPointer;
00141 
00143   typedef typename Superclass::InternalPixelType   InternalPixelType;
00144 
00146   typedef typename Superclass::PixelType   PixelType;
00147 
00150   typedef typename Superclass::AccessorType     AccessorType;
00151 
00153   itkTypeMacro(ImageRegionReverseConstIterator, ImageReverseConstIterator);
00154 
00156   ImageRegionReverseConstIterator() : Superclass()
00157   {
00158     m_SpanBeginOffset = 0;
00159     m_SpanEndOffset = 0;
00160   }
00161 
00164   ImageRegionReverseConstIterator(ImageType *ptr,
00165                       const RegionType &region)
00166     : Superclass(ptr, region)
00167   {
00168     m_SpanBeginOffset = this->m_BeginOffset;
00169     m_SpanEndOffset = this->m_BeginOffset - static_cast<long>(this->m_Region.GetSize()[0]);
00170   }
00172 
00180   ImageRegionReverseConstIterator( const ImageConstIterator<TImage> &it):Superclass(it)
00181   {
00182     IndexType ind = this->GetIndex();
00183     m_SpanBeginOffset = this->m_Offset + static_cast<long>(this->m_Region.GetSize()[0]) 
00184       - (ind[0] - this->m_Region.GetIndex()[0]);
00185     m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(this->m_Region.GetSize()[0]);
00186   }
00188 
00191   ImageRegionReverseConstIterator( const ImageReverseConstIterator<TImage> &it):Superclass(it)
00192   {
00193     IndexType ind = this->GetIndex();
00194     m_SpanBeginOffset = this->m_Offset + static_cast<long>(this->m_Region.GetSize()[0]) 
00195       - (ind[0] - this->m_Region.GetIndex()[0]);
00196     m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(this->m_Region.GetSize()[0]);
00197   }
00199 
00202   ImageRegionReverseConstIterator( const ImageRegionIterator<TImage> &it):Superclass(it)
00203   {
00204     IndexType ind = this->GetIndex();
00205     m_SpanBeginOffset = this->m_Offset + static_cast<long>(this->m_Region.GetSize()[0]) 
00206       - (ind[0] - this->m_Region.GetIndex()[0]);
00207     m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(this->m_Region.GetSize()[0]);
00208   }
00210 
00213   void GoToBegin()
00214   {
00215     Superclass::GoToBegin();
00216 
00217     // reset the span offsets
00218     m_SpanBeginOffset = this->m_BeginOffset;
00219     m_SpanEndOffset   = this->m_BeginOffset
00220       - static_cast<long>(this->m_Region.GetSize()[0]);
00221   };
00222   
00225   void GoToEnd()
00226   {
00227     Superclass::GoToEnd();
00228 
00229     // reset the span offsets
00230     m_SpanEndOffset = this->m_EndOffset;
00231     m_SpanBeginOffset = m_SpanEndOffset
00232       + static_cast<long>(this->m_Region.GetSize()[0]);
00233   };
00234 
00238   Self Begin(void) const;
00239 
00244   Self End(void) const;
00245 
00246 
00250   void SetIndex(const IndexType &ind)
00251   { Superclass::SetIndex(ind);
00252     m_SpanBeginOffset = this->m_Offset + static_cast<long>(this->m_Region.GetSize()[0]) 
00253       - (ind[0] - this->m_Region.GetIndex()[0]);
00254     m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(this->m_Region.GetSize()[0]);
00255   }
00257 
00266   Self &
00267   operator++()
00268   {
00269     if (--this->m_Offset <= m_SpanEndOffset)
00270       {
00271       // We have past the beginning of the span (row), need to wrap around.
00272 
00273       // First move forward one pixel, because we are going to use a different
00274       // algorithm to compute the next pixel
00275       this->m_Offset++;
00276       
00277       // Get the index of the first pixel on the span (row)
00278       typename ImageConstIterator<TImage>::IndexType
00279         ind = this->m_Image->ComputeIndex( static_cast<OffsetValueType>(this->m_Offset) );
00280 
00281       const typename ImageConstIterator<TImage>::IndexType&
00282         startIndex = this->m_Region.GetIndex();
00283       const typename ImageConstIterator<TImage>::SizeType&
00284         size = this->m_Region.GetSize();
00285 
00286       // Deccrement along a row, then wrap at the beginning of the region row.
00287       bool done;
00288       unsigned int dim;
00289 
00290       // Check to see if we are past the first pixel in the region
00291       // Note that --ind[0] moves to the previous pixel along the row.
00292       done = (--ind[0] == startIndex[0] - 1);
00293       for (unsigned int i=1; done && i < ImageIteratorDimension; i++)
00294         {
00295         done = (ind[i] == startIndex[i]);
00296         }
00297       
00298       // if the iterator is outside the region (but not past region begin) then
00299       // we need to wrap around the region
00300       dim = 0;
00301       if (!done)
00302         {
00303         while ( (dim < ImageIteratorDimension - 1)
00304                 && (ind[dim] < startIndex[dim]) )
00305           {
00306           ind[dim] = startIndex[dim] + static_cast<long>(size[dim]) - 1;
00307           ind[++dim]--;
00308           }
00309         }
00310       this->m_Offset = this->m_Image->ComputeOffset( ind );
00311       m_SpanBeginOffset = this->m_Offset;
00312       m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(size[0]);
00313       }
00314     return *this;
00315   }
00316 
00325   Self & operator--()
00326   {
00327     if (++this->m_Offset >= m_SpanBeginOffset)
00328       {
00329       // We have reached the end of the span (row), need to wrap around.
00330 
00331       // First back up one pixel, because we are going to use a different
00332       // algorithm to compute the next pixel
00333       --this->m_Offset;
00334       
00335       // Get the index of the last pixel on the span (row)
00336       typename ImageConstIterator<TImage>::IndexType
00337         ind = this->m_Image->ComputeIndex( static_cast<OffsetValueType>(this->m_Offset) );
00338 
00339       const typename ImageIterator<TImage>::IndexType&
00340         startIndex = this->m_Region.GetIndex();
00341       const typename ImageIterator<TImage>::SizeType&
00342         size = this->m_Region.GetSize();
00343 
00344       // Increment along a row, then wrap at the end of the region row.
00345       bool done;
00346       unsigned int dim;
00347 
00348       // Check to see if we are past the last pixel in the region
00349       // Note that ++ind[0] moves to the next pixel along the row.
00350       done = (++ind[0] == startIndex[0] + static_cast<long>(size[0]));
00351       for (unsigned int i=1; done && i < ImageIteratorDimension; i++)
00352         {
00353         done = (ind[i] == startIndex[i] + static_cast<long>(size[i]) - 1);
00354         }
00355       
00356       // if the iterator is outside the region (but not past region end) then
00357       // we need to wrap around the region
00358       dim = 0;
00359       if (!done)
00360         {
00361         while ( (dim < ImageIteratorDimension - 1)
00362                 && (ind[dim] > startIndex[dim] + static_cast<long>(size[dim]) - 1) )
00363           {
00364           ind[dim] = startIndex[dim];
00365           ind[++dim]++;
00366           }
00367         }
00368       this->m_Offset = this->m_Image->ComputeOffset( ind );
00369       m_SpanBeginOffset = this->m_Offset;
00370       m_SpanEndOffset = this->m_Offset - static_cast<long>(size[0]);
00371       }
00372     return *this;
00373   }
00374 
00375 protected:
00376   unsigned long m_SpanBeginOffset;  // offset to last pixel in the row
00377   unsigned long m_SpanEndOffset;  // offset to one pixel before the row
00378        
00379 };
00380 
00381 } // end namespace itk
00382 
00383 #ifndef ITK_MANUAL_INSTANTIATION
00384 #include "itkImageRegionReverseConstIterator.txx"
00385 #endif
00386 
00387 #endif 
00388 

Generated at Fri Sep 8 03:26:05 2006 for ITK by doxygen 1.4.7 written by Dimitri van Heesch, © 1997-2000