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: 2007/01/30 20:56:08 $
00007   Version:   $Revision: 1.7 $
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 #include "itkImageRegionIterator.h"
00022 
00023 namespace itk
00024 {
00025 
00100 template<typename TImage>
00101 class ITK_EXPORT ImageRegionReverseConstIterator : public ImageReverseConstIterator<TImage>
00102 {
00103 public:
00104 
00106   typedef ImageRegionReverseConstIterator Self;
00107   typedef ImageReverseConstIterator<TImage>  Superclass;
00108 
00113   enum { ImageIteratorDimension = Superclass::ImageIteratorDimension };
00114 
00117   typedef typename Superclass::IndexType IndexType;
00118   typedef typename Superclass::IndexValueType IndexValueType;
00119 
00122   typedef typename Superclass::SizeType SizeType;
00123   typedef typename Superclass::SizeValueType SizeValueType;
00124 
00127   typedef typename Superclass::OffsetType OffsetType;
00128   typedef typename Superclass::OffsetValueType OffsetValueType;
00129 
00131   typedef typename Superclass::RegionType   RegionType;
00132 
00135   typedef typename Superclass::ImageType ImageType;
00136 
00140   typedef typename Superclass::PixelContainer PixelContainer;
00141   typedef typename PixelContainer::Pointer PixelContainerPointer;
00142 
00144   typedef typename Superclass::InternalPixelType   InternalPixelType;
00145 
00147   typedef typename Superclass::PixelType   PixelType;
00148 
00151   typedef typename Superclass::AccessorType     AccessorType;
00152 
00154   itkTypeMacro(ImageRegionReverseConstIterator, ImageReverseConstIterator);
00155 
00157   ImageRegionReverseConstIterator() : Superclass()
00158   {
00159     m_SpanBeginOffset = 0;
00160     m_SpanEndOffset = 0;
00161   }
00162 
00165   ImageRegionReverseConstIterator(ImageType *ptr,
00166                       const RegionType &region)
00167     : Superclass(ptr, region)
00168   {
00169     m_SpanBeginOffset = this->m_BeginOffset;
00170     m_SpanEndOffset = this->m_BeginOffset - static_cast<long>(this->m_Region.GetSize()[0]);
00171   }
00173 
00181   ImageRegionReverseConstIterator( const ImageConstIterator<TImage> &it):Superclass(it)
00182   {
00183     IndexType ind = this->GetIndex();
00184     m_SpanBeginOffset = this->m_Offset + static_cast<long>(this->m_Region.GetSize()[0]) 
00185       - (ind[0] - this->m_Region.GetIndex()[0]);
00186     m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(this->m_Region.GetSize()[0]);
00187   }
00189 
00192   ImageRegionReverseConstIterator( const ImageReverseConstIterator<TImage> &it):Superclass(it)
00193   {
00194     IndexType ind = this->GetIndex();
00195     m_SpanBeginOffset = this->m_Offset + static_cast<long>(this->m_Region.GetSize()[0]) 
00196       - (ind[0] - this->m_Region.GetIndex()[0]);
00197     m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(this->m_Region.GetSize()[0]);
00198   }
00200 
00203   ImageRegionReverseConstIterator( const ImageRegionIterator<TImage> &it):Superclass(it)
00204   {
00205     IndexType ind = this->GetIndex();
00206     m_SpanBeginOffset = this->m_Offset + static_cast<long>(this->m_Region.GetSize()[0]) 
00207       - (ind[0] - this->m_Region.GetIndex()[0]);
00208     m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(this->m_Region.GetSize()[0]);
00209   }
00211 
00214   void GoToBegin()
00215   {
00216     Superclass::GoToBegin();
00217 
00218     // reset the span offsets
00219     m_SpanBeginOffset = this->m_BeginOffset;
00220     m_SpanEndOffset   = this->m_BeginOffset
00221       - static_cast<long>(this->m_Region.GetSize()[0]);
00222   };
00223   
00226   void GoToEnd()
00227   {
00228     Superclass::GoToEnd();
00229 
00230     // reset the span offsets
00231     m_SpanEndOffset = this->m_EndOffset;
00232     m_SpanBeginOffset = m_SpanEndOffset
00233       + static_cast<long>(this->m_Region.GetSize()[0]);
00234   };
00235 
00239   Self Begin(void) const;
00240 
00245   Self End(void) const;
00246 
00247 
00251   void SetIndex(const IndexType &ind)
00252   { Superclass::SetIndex(ind);
00253     m_SpanBeginOffset = this->m_Offset + static_cast<long>(this->m_Region.GetSize()[0]) 
00254       - (ind[0] - this->m_Region.GetIndex()[0]);
00255     m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(this->m_Region.GetSize()[0]);
00256   }
00258 
00267   Self &
00268   operator++()
00269   {
00270     if (--this->m_Offset <= m_SpanEndOffset)
00271       {
00272       // We have past the beginning of the span (row), need to wrap around.
00273 
00274       // First move forward one pixel, because we are going to use a different
00275       // algorithm to compute the next pixel
00276       this->m_Offset++;
00277       
00278       // Get the index of the first pixel on the span (row)
00279       typename ImageConstIterator<TImage>::IndexType
00280         ind = this->m_Image->ComputeIndex( static_cast<OffsetValueType>(this->m_Offset) );
00281 
00282       const typename ImageConstIterator<TImage>::IndexType&
00283         startIndex = this->m_Region.GetIndex();
00284       const typename ImageConstIterator<TImage>::SizeType&
00285         size = this->m_Region.GetSize();
00286 
00287       // Deccrement along a row, then wrap at the beginning of the region row.
00288       bool done;
00289       unsigned int dim;
00290 
00291       // Check to see if we are past the first pixel in the region
00292       // Note that --ind[0] moves to the previous pixel along the row.
00293       done = (--ind[0] == startIndex[0] - 1);
00294       for (unsigned int i=1; done && i < ImageIteratorDimension; i++)
00295         {
00296         done = (ind[i] == startIndex[i]);
00297         }
00298       
00299       // if the iterator is outside the region (but not past region begin) then
00300       // we need to wrap around the region
00301       dim = 0;
00302       if (!done)
00303         {
00304         while ( (dim < ImageIteratorDimension - 1)
00305                 && (ind[dim] < startIndex[dim]) )
00306           {
00307           ind[dim] = startIndex[dim] + static_cast<long>(size[dim]) - 1;
00308           ind[++dim]--;
00309           }
00310         }
00311       this->m_Offset = this->m_Image->ComputeOffset( ind );
00312       m_SpanBeginOffset = this->m_Offset;
00313       m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(size[0]);
00314       }
00315     return *this;
00316   }
00317 
00326   Self & operator--()
00327   {
00328     if (++this->m_Offset >= m_SpanBeginOffset)
00329       {
00330       // We have reached the end of the span (row), need to wrap around.
00331 
00332       // First back up one pixel, because we are going to use a different
00333       // algorithm to compute the next pixel
00334       --this->m_Offset;
00335       
00336       // Get the index of the last pixel on the span (row)
00337       typename ImageConstIterator<TImage>::IndexType
00338         ind = this->m_Image->ComputeIndex( static_cast<OffsetValueType>(this->m_Offset) );
00339 
00340       const typename ImageIterator<TImage>::IndexType&
00341         startIndex = this->m_Region.GetIndex();
00342       const typename ImageIterator<TImage>::SizeType&
00343         size = this->m_Region.GetSize();
00344 
00345       // Increment along a row, then wrap at the end of the region row.
00346       bool done;
00347       unsigned int dim;
00348 
00349       // Check to see if we are past the last pixel in the region
00350       // Note that ++ind[0] moves to the next pixel along the row.
00351       done = (++ind[0] == startIndex[0] + static_cast<long>(size[0]));
00352       for (unsigned int i=1; done && i < ImageIteratorDimension; i++)
00353         {
00354         done = (ind[i] == startIndex[i] + static_cast<long>(size[i]) - 1);
00355         }
00356       
00357       // if the iterator is outside the region (but not past region end) then
00358       // we need to wrap around the region
00359       dim = 0;
00360       if (!done)
00361         {
00362         while ( (dim < ImageIteratorDimension - 1)
00363                 && (ind[dim] > startIndex[dim] + static_cast<long>(size[dim]) - 1) )
00364           {
00365           ind[dim] = startIndex[dim];
00366           ind[++dim]++;
00367           }
00368         }
00369       this->m_Offset = this->m_Image->ComputeOffset( ind );
00370       m_SpanBeginOffset = this->m_Offset;
00371       m_SpanEndOffset = this->m_Offset - static_cast<long>(size[0]);
00372       }
00373     return *this;
00374   }
00375 
00376 protected:
00377   unsigned long m_SpanBeginOffset;  // offset to last pixel in the row
00378   unsigned long m_SpanEndOffset;  // offset to one pixel before the row
00379        
00380 };
00381 
00382 } // end namespace itk
00383 
00384 // Define instantiation macro for this template.
00385 #define ITK_TEMPLATE_ImageRegionReverseConstIterator(_, EXPORT, x, y) namespace itk { \
00386   _(1(class EXPORT ImageRegionReverseConstIterator< ITK_TEMPLATE_1 x >)) \
00387   namespace Templates { typedef ImageRegionReverseConstIterator< ITK_TEMPLATE_1 x > ImageRegionReverseConstIterator##y; } \
00388   }
00389 
00390 #if ITK_TEMPLATE_EXPLICIT
00391 # include "Templates/itkImageRegionReverseConstIterator+-.h"
00392 #endif
00393 
00394 #if ITK_TEMPLATE_TXX
00395 # include "itkImageRegionReverseConstIterator.txx"
00396 #endif
00397 
00398 #endif 
00399 

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