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: 2008-10-18 21:13:25 $
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 __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, 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 - static_cast<long>(this->m_Region.GetSize()[0]);
00220     }
00221   
00224   void GoToEnd()
00225     {
00226     Superclass::GoToEnd();
00227 
00228     // reset the span offsets
00229     m_SpanEndOffset = this->m_EndOffset;
00230     m_SpanBeginOffset = m_SpanEndOffset + static_cast<long>(this->m_Region.GetSize()[0]);
00231     }
00232 
00236   Self Begin(void) const;
00237 
00242   Self End(void) const;
00243 
00244 
00248   void SetIndex(const IndexType &ind)
00249     {
00250     Superclass::SetIndex(ind);
00251     m_SpanBeginOffset = this->m_Offset + static_cast<long>(this->m_Region.GetSize()[0]) 
00252       - (ind[0] - this->m_Region.GetIndex()[0]);
00253     m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(this->m_Region.GetSize()[0]);
00254     }
00256 
00265   Self &
00266   operator++()
00267     {
00268     if (--this->m_Offset <= m_SpanEndOffset)
00269       {
00270       // We have past the beginning of the span (row), need to wrap around.
00271 
00272       // First move forward one pixel, because we are going to use a different
00273       // algorithm to compute the next pixel
00274       this->m_Offset++;
00275       
00276       // Get the index of the first pixel on the span (row)
00277       typename ImageConstIterator<TImage>::IndexType
00278         ind = this->m_Image->ComputeIndex( static_cast<OffsetValueType>(this->m_Offset) );
00279 
00280       const typename ImageConstIterator<TImage>::IndexType&
00281         startIndex = this->m_Region.GetIndex();
00282       const typename ImageConstIterator<TImage>::SizeType&
00283         size = this->m_Region.GetSize();
00284 
00285       // Deccrement along a row, then wrap at the beginning of the region row.
00286       bool done;
00287       unsigned int dim;
00288 
00289       // Check to see if we are past the first pixel in the region
00290       // Note that --ind[0] moves to the previous pixel along the row.
00291       done = (--ind[0] == startIndex[0] - 1);
00292       for (unsigned int i=1; done && i < ImageIteratorDimension; i++)
00293         {
00294         done = (ind[i] == startIndex[i]);
00295         }
00296       
00297       // if the iterator is outside the region (but not past region begin) then
00298       // we need to wrap around the region
00299       dim = 0;
00300       if (!done)
00301         {
00302         while ( (dim < ImageIteratorDimension - 1)
00303                 && (ind[dim] < startIndex[dim]) )
00304           {
00305           ind[dim] = startIndex[dim] + static_cast<long>(size[dim]) - 1;
00306           ind[++dim]--;
00307           }
00308         }
00309       this->m_Offset = this->m_Image->ComputeOffset( ind );
00310       m_SpanBeginOffset = this->m_Offset;
00311       m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(size[0]);
00312       }
00313     return *this;
00314     }
00315 
00324   Self & operator--()
00325     {
00326     if (++this->m_Offset >= m_SpanBeginOffset)
00327       {
00328       // We have reached the end of the span (row), need to wrap around.
00329 
00330       // First back up one pixel, because we are going to use a different
00331       // algorithm to compute the next pixel
00332       --this->m_Offset;
00333       
00334       // Get the index of the last pixel on the span (row)
00335       typename ImageConstIterator<TImage>::IndexType
00336         ind = this->m_Image->ComputeIndex( static_cast<OffsetValueType>(this->m_Offset) );
00337 
00338       const typename ImageIterator<TImage>::IndexType&
00339         startIndex = this->m_Region.GetIndex();
00340       const typename ImageIterator<TImage>::SizeType&
00341         size = this->m_Region.GetSize();
00342 
00343       // Increment along a row, then wrap at the end of the region row.
00344       bool done;
00345       unsigned int dim;
00346 
00347       // Check to see if we are past the last pixel in the region
00348       // Note that ++ind[0] moves to the next pixel along the row.
00349       done = (++ind[0] == startIndex[0] + static_cast<long>(size[0]));
00350       for (unsigned int i=1; done && i < ImageIteratorDimension; i++)
00351         {
00352         done = (ind[i] == startIndex[i] + static_cast<long>(size[i]) - 1);
00353         }
00354       
00355       // if the iterator is outside the region (but not past region end) then
00356       // we need to wrap around the region
00357       dim = 0;
00358       if (!done)
00359         {
00360         while ( (dim < ImageIteratorDimension - 1)
00361                 && (ind[dim] > startIndex[dim] + static_cast<long>(size[dim]) - 1) )
00362           {
00363           ind[dim] = startIndex[dim];
00364           ind[++dim]++;
00365           }
00366         }
00367       this->m_Offset = this->m_Image->ComputeOffset( ind );
00368       m_SpanBeginOffset = this->m_Offset;
00369       m_SpanEndOffset = this->m_Offset - static_cast<long>(size[0]);
00370       }
00371     return *this;
00372     }
00373 
00374 protected:
00375   unsigned long m_SpanBeginOffset;  // offset to last pixel in the row
00376   unsigned long m_SpanEndOffset;  // offset to one pixel before the row
00377        
00378 };
00379 
00380 } // end namespace itk
00381 
00382 // Define instantiation macro for this template.
00383 #define ITK_TEMPLATE_ImageRegionReverseConstIterator(_, EXPORT, x, y) namespace itk { \
00384   _(1(class EXPORT ImageRegionReverseConstIterator< ITK_TEMPLATE_1 x >)) \
00385   namespace Templates { typedef ImageRegionReverseConstIterator< ITK_TEMPLATE_1 x > ImageRegionReverseConstIterator##y; } \
00386   }
00387 
00388 #if ITK_TEMPLATE_EXPLICIT
00389 # include "Templates/itkImageRegionReverseConstIterator+-.h"
00390 #endif
00391 
00392 #if ITK_TEMPLATE_TXX
00393 # include "itkImageRegionReverseConstIterator.txx"
00394 #endif
00395 
00396 #endif 
00397 

Generated at Sat Feb 28 12:45:21 2009 for ITK by doxygen 1.5.6 written by Dimitri van Heesch, © 1997-2000