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

itkImageLinearConstIteratorWithIndex.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkImageLinearConstIteratorWithIndex.h,v $
00005   Language:  C++
00006   Date:      $Date: 2007-02-05 13:35:52 $
00007   Version:   $Revision: 1.16 $
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 __itkImageLinearConstIteratorWithIndex_h
00018 #define __itkImageLinearConstIteratorWithIndex_h
00019 
00020 #include "itkImageConstIteratorWithIndex.h"
00021 
00022 namespace itk
00023 {
00024 
00101 template<typename TImage>
00102 class ITK_EXPORT ImageLinearConstIteratorWithIndex : public ImageConstIteratorWithIndex<TImage>
00103 {
00104 public:
00106   typedef ImageLinearConstIteratorWithIndex Self;
00107   typedef ImageConstIteratorWithIndex<TImage>  Superclass;
00108 
00113   typedef typename TImage::IndexType   IndexType;
00114 
00119   typedef typename TImage::RegionType RegionType;
00120 
00125   typedef TImage ImageType;
00126 
00130   typedef typename TImage::PixelContainer PixelContainer;
00131   typedef typename PixelContainer::Pointer PixelContainerPointer;
00132 
00134   ImageLinearConstIteratorWithIndex() : ImageConstIteratorWithIndex<TImage>() {}
00135 
00138   ImageLinearConstIteratorWithIndex(const ImageType *ptr, const RegionType& region);
00139 
00146   ImageLinearConstIteratorWithIndex( const ImageConstIteratorWithIndex<TImage> &it)
00147     { this->ImageConstIteratorWithIndex<TImage>::operator=(it); }
00148 
00151   inline void NextLine(void);
00152 
00155   inline void PreviousLine(void);
00156 
00159   void GoToBeginOfLine(void);
00160 
00163   void GoToReverseBeginOfLine(void);
00164 
00167   void GoToEndOfLine(void);
00168 
00170   inline bool IsAtEndOfLine(void)
00171   {
00172     return this->m_PositionIndex[m_Direction] >= this->m_EndIndex[m_Direction];
00173   }
00174 
00176   inline bool IsAtReverseEndOfLine(void)
00177   {
00178     return this->m_PositionIndex[m_Direction] < this->m_BeginIndex[m_Direction];
00179   }
00180 
00182   inline void SetDirection(unsigned int direction)
00183   {
00184     if( direction >= TImage::ImageDimension )
00185       {
00186       itkGenericExceptionMacro(<<"In image of dimension " << TImage::ImageDimension <<" Direction " << direction << " sas selected");
00187       }
00188     m_Direction = direction;
00189     m_Jump = this->m_OffsetTable[ m_Direction ];
00190   }
00192 
00195   inline Self & operator++()
00196   {
00197     this->m_PositionIndex[m_Direction]++;
00198     this->m_Position += m_Jump;
00199     return *this;
00200   }
00202 
00205   inline Self & operator--()
00206   {
00207     this->m_PositionIndex[m_Direction]--;
00208     this->m_Position -= m_Jump;
00209     return *this;
00210   }
00212 
00213 private:
00214     unsigned long  m_Jump;
00215     unsigned int   m_Direction;
00216 };
00217 
00218   //----------------------------------------------------------------------
00219   //  Go to next line
00220   //----------------------------------------------------------------------
00221   template<class TImage>
00222   inline
00223   void 
00224   ImageLinearConstIteratorWithIndex<TImage>
00225   ::NextLine(void)
00226   {
00227 
00228     this->m_Position -=   this->m_OffsetTable[ m_Direction ] * 
00229       ( this->m_PositionIndex[ m_Direction ] - this->m_BeginIndex[ m_Direction ] ); 
00230   
00231     this->m_PositionIndex[m_Direction] = this->m_BeginIndex[m_Direction];     
00232 
00233     for( unsigned int n=0; n<TImage::ImageDimension; n++ )
00234       {
00235 
00236       this->m_Remaining = false;
00237     
00238       if( n == m_Direction ) 
00239         {
00240         continue;
00241         }
00242     
00243       this->m_PositionIndex[ n  ]++;
00244       if( this->m_PositionIndex[n] <  this->m_EndIndex[n] )
00245         {
00246         this->m_Position += this->m_OffsetTable[ n ];
00247         this->m_Remaining = true;
00248         break;
00249         }
00250       else 
00251         {
00252         this->m_Position -= this->m_OffsetTable[ n ] * ( this->m_Region.GetSize()[n]-1 );
00253         this->m_PositionIndex[ n ] = this->m_BeginIndex[ n ]; 
00254         }
00255       }
00256   }
00257 
00258 
00259 
00260   //----------------------------------------------------------------------
00261   //  Pass to the last pixel on the previous line
00262   //----------------------------------------------------------------------
00263   template<class TImage>
00264   inline
00265   void 
00266   ImageLinearConstIteratorWithIndex<TImage>
00267   ::PreviousLine(void)
00268   {
00269 
00270     this->m_Position +=   this->m_OffsetTable[ m_Direction ] * 
00271       ( this->m_EndIndex[ m_Direction ] - 1 - this->m_PositionIndex[ m_Direction ] ); 
00272   
00273     this->m_PositionIndex[m_Direction] = this->m_EndIndex[m_Direction]-1;   
00274 
00275 
00276     for( unsigned int n=0; n<TImage::ImageDimension; n++ )
00277       {
00278 
00279       this->m_Remaining = false;
00280     
00281       if( n == m_Direction ) 
00282         {
00283         continue;
00284         }
00285     
00286       this->m_PositionIndex[ n  ]--;
00287       if( this->m_PositionIndex[ n ] >=  this->m_BeginIndex[ n ] )
00288         {
00289         this->m_Position -= this->m_OffsetTable[ n ];
00290         this->m_Remaining = true;
00291         break;
00292         }
00293       else 
00294         {
00295         this->m_Position += this->m_OffsetTable[ n ] * ( this->m_Region.GetSize()[n]-1 );
00296         this->m_PositionIndex[ n ] = this->m_EndIndex[ n ] - 1; 
00297         }
00298       }
00299   }
00300 } // end namespace itk
00301 
00302 // Define instantiation macro for this template.
00303 #define ITK_TEMPLATE_ImageLinearConstIteratorWithIndex(_, EXPORT, x, y) namespace itk { \
00304   _(1(class EXPORT ImageLinearConstIteratorWithIndex< ITK_TEMPLATE_1 x >)) \
00305   namespace Templates { typedef ImageLinearConstIteratorWithIndex< ITK_TEMPLATE_1 x > \
00306                         ImageLinearConstIteratorWithIndex##y; } \
00307   }
00308 
00309 #if ITK_TEMPLATE_EXPLICIT
00310 # include "Templates/itkImageLinearConstIteratorWithIndex+-.h"
00311 #endif
00312 
00313 #if ITK_TEMPLATE_TXX
00314 # include "itkImageLinearConstIteratorWithIndex.txx"
00315 #endif
00316 
00317 #endif 
00318 

Generated at Mon Apr 14 12:52:45 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000