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: 2006/06/22 13:06:54 $
00007   Version:   $Revision: 1.22 $
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
00217       + static_cast<long>(this->m_Region.GetSize()[0]);
00218   };
00219   
00222   void GoToEnd()
00223   {
00224     Superclass::GoToEnd();
00225 
00226     // reset the span offsets
00227     m_SpanEndOffset = this->m_EndOffset;
00228     m_SpanBeginOffset = m_SpanEndOffset
00229       - static_cast<long>(this->m_Region.GetSize()[0]);
00230   };
00231 
00235   Self Begin(void) const;
00236 
00240   Self End(void) const;
00241 
00242 
00246   void SetIndex(const IndexType &ind)
00247   { Superclass::SetIndex(ind);
00248     m_SpanEndOffset = this->m_Offset + static_cast<long>(this->m_Region.GetSize()[0]) 
00249       - (ind[0] - this->m_Region.GetIndex()[0]);
00250     m_SpanBeginOffset = m_SpanEndOffset
00251       - static_cast<long>(this->m_Region.GetSize()[0]);
00252   }
00254 
00262   Self &
00263   operator++()
00264   {
00265     if (++this->m_Offset >= m_SpanEndOffset)
00266       {
00267       this->Increment();
00268       }
00269     return *this;
00270   }
00272 
00280   Self & operator--()
00281   {
00282     if (--this->m_Offset < m_SpanBeginOffset)
00283       {
00284       this->Decrement();
00285       }
00286     return *this;
00287   }
00289 
00290 private:
00291   void Increment(); // advance in a direction other than the fastest moving
00292   void Decrement(); // go back in a direction other than the fastest moving
00293   
00294 protected:
00295   unsigned long m_SpanBeginOffset;  // one pixel before the beginning of the span (row)
00296   unsigned long m_SpanEndOffset;  // one pixel past the end of the span (row)
00297        
00298 };
00299 
00300 } // end namespace itk
00301 
00302 // Define instantiation macro for this template.
00303 #define ITK_TEMPLATE_ImageRegionConstIterator(_, EXPORT, x, y) namespace itk { \
00304   _(1(class EXPORT ImageRegionConstIterator< ITK_TEMPLATE_1 x >)) \
00305   namespace Templates { typedef ImageRegionConstIterator< ITK_TEMPLATE_1 x > ImageRegionConstIterator##y; } \
00306   }
00307 
00308 
00309 #if ITK_TEMPLATE_EXPLICIT
00310 # include "Templates/itkImageRegionConstIterator+-.h"
00311 #endif
00312 
00313 #if ITK_TEMPLATE_TXX
00314 # include "itkImageRegionConstIterator.txx"
00315 #endif
00316 
00317 #if defined(_MSC_VER)
00318 #undef ITK_LEAN_AND_MEAN
00319 #endif
00320 
00321 #endif 
00322 

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