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/01/28 21:52:18 $
00007   Version:   $Revision: 1.17 $
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 namespace itk
00024 {
00025 
00103 template<typename TImage>
00104 class ITK_EXPORT ImageRegionConstIterator : public ImageConstIterator<TImage>
00105 {
00106 public:
00108   typedef ImageRegionConstIterator Self;
00109   typedef ImageConstIterator<TImage>  Superclass;
00110   
00115   itkStaticConstMacro(ImageIteratorDimension, unsigned int,
00116                       Superclass::ImageIteratorDimension);
00117 
00120   typedef typename Superclass::IndexType IndexType;
00121 
00124   typedef typename Superclass::SizeType SizeType;
00125 
00127   typedef typename Superclass::RegionType   RegionType;
00128 
00131   typedef typename Superclass::ImageType ImageType;
00132 
00136   typedef typename Superclass::PixelContainer         PixelContainer;
00137   typedef typename Superclass::PixelContainerPointer  PixelContainerPointer;
00138   
00140   typedef typename Superclass::InternalPixelType   InternalPixelType;
00141 
00143   typedef typename Superclass::PixelType   PixelType;
00144 
00147   typedef typename Superclass::AccessorType     AccessorType;
00148 
00150   itkTypeMacro(ImageRegionConstIterator, ImageIterator);
00151 
00153   ImageRegionConstIterator() : ImageConstIterator<TImage>()
00154   {
00155     m_SpanBeginOffset = 0;
00156     m_SpanEndOffset = 0;
00157   }
00158   
00161   ImageRegionConstIterator(const ImageType *ptr,
00162                       const RegionType &region)
00163     : ImageConstIterator<TImage>(ptr, region)
00164   {
00165     m_SpanBeginOffset = this->m_BeginOffset;
00166     m_SpanEndOffset   = this->m_BeginOffset + static_cast<long>(this->m_Region.GetSize()[0]);
00167   }
00168 
00175   ImageRegionConstIterator( const ImageIterator<TImage> &it)
00176   {
00177     this->ImageIterator<TImage>::operator=(it);
00178     IndexType ind = this->GetIndex();
00179     m_SpanEndOffset = this->m_Offset + static_cast<long>(this->m_Region.GetSize()[0]) 
00180       - (ind[0] - this->m_Region.GetIndex()[0]);
00181     m_SpanBeginOffset = m_SpanEndOffset
00182       - static_cast<long>(this->m_Region.GetSize()[0]);
00183   }
00184 
00191   ImageRegionConstIterator( const ImageConstIterator<TImage> &it)
00192   {
00193     this->ImageConstIterator<TImage>::operator=(it);
00194     IndexType ind = this->GetIndex();
00195     m_SpanEndOffset = this->m_Offset + static_cast<long>(this->m_Region.GetSize()[0]) 
00196       - (ind[0] - this->m_Region.GetIndex()[0]);
00197     m_SpanBeginOffset = m_SpanEndOffset
00198       - static_cast<long>(this->m_Region.GetSize()[0]);
00199   }
00200 
00203   void GoToBegin()
00204   {
00205     Superclass::GoToBegin();
00206 
00207     // reset the span offsets
00208     m_SpanBeginOffset = this->m_BeginOffset;
00209     m_SpanEndOffset   = this->m_BeginOffset
00210       + static_cast<long>(this->m_Region.GetSize()[0]);
00211   };
00212   
00215   void GoToEnd()
00216   {
00217     Superclass::GoToEnd();
00218     
00219     // reset the span offsets
00220     m_SpanEndOffset = this->m_EndOffset;
00221     m_SpanBeginOffset = m_SpanEndOffset
00222       - static_cast<long>(this->m_Region.GetSize()[0]);
00223   };
00224 
00228   Self Begin(void) const;
00229 
00233   Self End(void) const;
00234 
00235 
00239   void SetIndex(const IndexType &ind)
00240   { Superclass::SetIndex(ind);
00241     m_SpanEndOffset = this->m_Offset + static_cast<long>(this->m_Region.GetSize()[0]) 
00242       - (ind[0] - this->m_Region.GetIndex()[0]);
00243     m_SpanBeginOffset = m_SpanEndOffset
00244       - static_cast<long>(this->m_Region.GetSize()[0]);
00245   }
00246   
00254   Self &
00255   operator++()
00256   {
00257     if (++this->m_Offset >= m_SpanEndOffset)
00258       {
00259       this->Increment();
00260       }
00261     return *this;
00262   }
00263 
00271   Self & operator--()
00272   {
00273     if (--this->m_Offset < m_SpanBeginOffset)
00274       {
00275       this->Decrement();
00276       }
00277     return *this;
00278   }
00279 
00280 private:
00281   void Increment(); // advance in a direction other than the fastest moving
00282   void Decrement(); // go back in a direction other than the fastest moving
00283   
00284 protected:
00285   unsigned long m_SpanBeginOffset;  // one pixel before the beginning of the span (row)
00286   unsigned long m_SpanEndOffset;  // one pixel past the end of the span (row)
00287        
00288 };
00289 
00290 } // end namespace itk
00291 
00292 #ifndef ITK_MANUAL_INSTANTIATION
00293 #include "itkImageRegionConstIterator.txx"
00294 #endif
00295 
00296 #endif 

Generated at Tue Mar 29 23:56:36 2005 for ITK by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2000