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: 2005/10/09 23:24:21 $
00007   Version:   $Revision: 1.19 $
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   }
00172 
00179   ImageRegionConstIterator( const ImageIterator<TImage> &it)
00180   {
00181     this->ImageIterator<TImage>::operator=(it);
00182     IndexType ind = this->GetIndex();
00183     m_SpanEndOffset = this->m_Offset + static_cast<long>(this->m_Region.GetSize()[0]) 
00184       - (ind[0] - this->m_Region.GetIndex()[0]);
00185     m_SpanBeginOffset = m_SpanEndOffset
00186       - static_cast<long>(this->m_Region.GetSize()[0]);
00187   }
00188 
00195   ImageRegionConstIterator( const ImageConstIterator<TImage> &it)
00196   {
00197     this->ImageConstIterator<TImage>::operator=(it);
00198     IndexType ind = this->GetIndex();
00199     m_SpanEndOffset = this->m_Offset + static_cast<long>(this->m_Region.GetSize()[0]) 
00200       - (ind[0] - this->m_Region.GetIndex()[0]);
00201     m_SpanBeginOffset = m_SpanEndOffset
00202       - static_cast<long>(this->m_Region.GetSize()[0]);
00203   }
00204 
00207   void GoToBegin()
00208   {
00209     Superclass::GoToBegin();
00210 
00211     // reset the span offsets
00212     m_SpanBeginOffset = this->m_BeginOffset;
00213     m_SpanEndOffset   = this->m_BeginOffset
00214       + static_cast<long>(this->m_Region.GetSize()[0]);
00215   };
00216   
00219   void GoToEnd()
00220   {
00221     Superclass::GoToEnd();
00222     
00223     // reset the span offsets
00224     m_SpanEndOffset = this->m_EndOffset;
00225     m_SpanBeginOffset = m_SpanEndOffset
00226       - static_cast<long>(this->m_Region.GetSize()[0]);
00227   };
00228 
00232   Self Begin(void) const;
00233 
00237   Self End(void) const;
00238 
00239 
00243   void SetIndex(const IndexType &ind)
00244   { Superclass::SetIndex(ind);
00245     m_SpanEndOffset = this->m_Offset + static_cast<long>(this->m_Region.GetSize()[0]) 
00246       - (ind[0] - this->m_Region.GetIndex()[0]);
00247     m_SpanBeginOffset = m_SpanEndOffset
00248       - static_cast<long>(this->m_Region.GetSize()[0]);
00249   }
00250   
00258   Self &
00259   operator++()
00260   {
00261     if (++this->m_Offset >= m_SpanEndOffset)
00262       {
00263       this->Increment();
00264       }
00265     return *this;
00266   }
00267 
00275   Self & operator--()
00276   {
00277     if (--this->m_Offset < m_SpanBeginOffset)
00278       {
00279       this->Decrement();
00280       }
00281     return *this;
00282   }
00283 
00284 private:
00285   void Increment(); // advance in a direction other than the fastest moving
00286   void Decrement(); // go back in a direction other than the fastest moving
00287   
00288 protected:
00289   unsigned long m_SpanBeginOffset;  // one pixel before the beginning of the span (row)
00290   unsigned long m_SpanEndOffset;  // one pixel past the end of the span (row)
00291        
00292 };
00293 
00294 } // end namespace itk
00295 
00296 #ifndef ITK_MANUAL_INSTANTIATION
00297 #include "itkImageRegionConstIterator.txx"
00298 #endif
00299 
00300 #if defined(_MSC_VER)
00301 #undef ITK_LEAN_AND_MEAN
00302 #endif
00303 
00304 #endif 

Generated at Wed May 24 23:22:47 2006 for ITK by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2000