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

itkImageRegionConstIterator.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkImageRegionConstIterator.h,v $
00005   Language:  C++
00006   Date:      $Date: 2008-10-18 21:13:25 $
00007   Version:   $Revision: 1.23 $
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 __itkImageRegionConstIterator_h
00018 #define __itkImageRegionConstIterator_h
00019 
00020 #include "itkImageConstIterator.h"
00021 #include "itkImageIterator.h"
00022 
00023 #if defined(_MSC_VER) && !defined(ITK_LEAN_AND_MEAN)
00024 #define ITK_LEAN_AND_MEAN
00025 #endif
00026 
00027 namespace itk
00028 {
00029 
00107 template<typename TImage>
00108 class ITK_EXPORT ImageRegionConstIterator : public ImageConstIterator<TImage>
00109 {
00110 public:
00112   typedef ImageRegionConstIterator    Self;
00113   typedef ImageConstIterator<TImage>  Superclass;
00114 
00119   itkStaticConstMacro(ImageIteratorDimension, unsigned int,
00120                       Superclass::ImageIteratorDimension);
00121 
00124   typedef typename Superclass::IndexType IndexType;
00125 
00128   typedef typename Superclass::SizeType SizeType;
00129 
00131   typedef typename Superclass::RegionType   RegionType;
00132 
00135   typedef typename Superclass::ImageType ImageType;
00136 
00140   typedef typename Superclass::PixelContainer         PixelContainer;
00141   typedef typename Superclass::PixelContainerPointer  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(ImageRegionConstIterator, ImageIterator);
00155 
00157   ImageRegionConstIterator() : ImageConstIterator<TImage>()
00158     {
00159     m_SpanBeginOffset = 0;
00160     m_SpanEndOffset = 0;
00161     }
00162 
00165   ImageRegionConstIterator(const ImageType *ptr,
00166                       const RegionType &region)
00167     : ImageConstIterator<TImage>(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 
00180   ImageRegionConstIterator( const ImageIterator<TImage> &it)
00181     {
00182     this->ImageConstIterator<TImage>::operator=(it);
00183     IndexType ind = this->GetIndex();
00184     m_SpanEndOffset = this->m_Offset + static_cast<long>(this->m_Region.GetSize()[0]) 
00185       - (ind[0] - this->m_Region.GetIndex()[0]);
00186     m_SpanBeginOffset = m_SpanEndOffset
00187       - static_cast<long>(this->m_Region.GetSize()[0]);
00188     }
00190 
00197   ImageRegionConstIterator( const ImageConstIterator<TImage> &it)
00198     {
00199     this->ImageConstIterator<TImage>::operator=(it);
00200     IndexType ind = this->GetIndex();
00201     m_SpanEndOffset = this->m_Offset + static_cast<long>(this->m_Region.GetSize()[0]) 
00202       - (ind[0] - this->m_Region.GetIndex()[0]);
00203     m_SpanBeginOffset = m_SpanEndOffset
00204       - static_cast<long>(this->m_Region.GetSize()[0]);
00205     }
00207 
00210   void GoToBegin()
00211     {
00212     Superclass::GoToBegin();
00213 
00214     // reset the span offsets
00215     m_SpanBeginOffset = this->m_BeginOffset;
00216     m_SpanEndOffset   = this->m_BeginOffset + static_cast<long>(this->m_Region.GetSize()[0]);
00217     }
00218   
00221   void GoToEnd()
00222     {
00223     Superclass::GoToEnd();
00224 
00225     // reset the span offsets
00226     m_SpanEndOffset = this->m_EndOffset;
00227     m_SpanBeginOffset = m_SpanEndOffset - static_cast<long>(this->m_Region.GetSize()[0]);
00228     }
00229 
00233   Self Begin(void) const;
00234 
00238   Self End(void) const;
00239 
00240 
00244   void SetIndex(const IndexType &ind)
00245     {
00246     Superclass::SetIndex(ind);
00247     m_SpanEndOffset = this->m_Offset + static_cast<long>(this->m_Region.GetSize()[0]) 
00248       - (ind[0] - this->m_Region.GetIndex()[0]);
00249     m_SpanBeginOffset = m_SpanEndOffset - static_cast<long>(this->m_Region.GetSize()[0]);
00250     }
00252 
00260   Self &
00261   operator++()
00262     {
00263     if (++this->m_Offset >= m_SpanEndOffset)
00264       {
00265       this->Increment();
00266       }
00267     return *this;
00268     }
00270 
00278   Self & operator--()
00279     {
00280     if (--this->m_Offset < m_SpanBeginOffset)
00281       {
00282       this->Decrement();
00283       }
00284     return *this;
00285     }
00287 
00288  
00289 protected:
00290   unsigned long m_SpanBeginOffset;  // one pixel before the beginning of the span (row)
00291   unsigned long m_SpanEndOffset;  // one pixel past the end of the span (row)
00292        
00293 private:
00294   void Increment(); // advance in a direction other than the fastest moving
00295   void Decrement(); // go back in a direction other than the fastest moving
00296  
00297 };
00298 
00299 } // end namespace itk
00300 
00301 // Define instantiation macro for this template.
00302 #define ITK_TEMPLATE_ImageRegionConstIterator(_, EXPORT, x, y) namespace itk { \
00303   _(1(class EXPORT ImageRegionConstIterator< ITK_TEMPLATE_1 x >)) \
00304   namespace Templates { typedef ImageRegionConstIterator< ITK_TEMPLATE_1 x > ImageRegionConstIterator##y; } \
00305   }
00306 
00307 
00308 #if ITK_TEMPLATE_EXPLICIT
00309 # include "Templates/itkImageRegionConstIterator+-.h"
00310 #endif
00311 
00312 #if ITK_TEMPLATE_TXX
00313 # include "itkImageRegionConstIterator.txx"
00314 #endif
00315 
00316 #if defined(_MSC_VER)
00317 #undef ITK_LEAN_AND_MEAN
00318 #endif
00319 
00320 #endif 
00321 

Generated at Mon Jul 12 2010 18:41:10 for ITK by doxygen 1.7.1 written by Dimitri van Heesch, © 1997-2000