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: 2008-10-18 20:31:36 $
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 __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 //  Pass to the last pixel on the previous line
00261 //----------------------------------------------------------------------
00262 template<class TImage>
00263 inline
00264 void
00265 ImageLinearConstIteratorWithIndex<TImage>
00266 ::PreviousLine(void)
00267 {
00268 
00269   this->m_Position += this->m_OffsetTable[ m_Direction ] *
00270     ( this->m_EndIndex[ m_Direction ] - 1 - this->m_PositionIndex[ m_Direction ] );
00271 
00272   this->m_PositionIndex[m_Direction] = this->m_EndIndex[m_Direction]-1;
00273 
00274 
00275   for( unsigned int n=0; n<TImage::ImageDimension; n++ )
00276     {
00277 
00278     this->m_Remaining = false;
00279 
00280     if( n == m_Direction )
00281       {
00282       continue;
00283       }
00284 
00285     this->m_PositionIndex[ n  ]--;
00286     if( this->m_PositionIndex[ n ] >=  this->m_BeginIndex[ n ] )
00287       {
00288       this->m_Position -= this->m_OffsetTable[ n ];
00289       this->m_Remaining = true;
00290       break;
00291       }
00292     else
00293       {
00294       this->m_Position += this->m_OffsetTable[ n ] * ( this->m_Region.GetSize()[n]-1 );
00295       this->m_PositionIndex[ n ] = this->m_EndIndex[ n ] - 1;
00296       }
00297     }
00298 }
00299 } // end namespace itk
00300 
00301 // Define instantiation macro for this template.
00302 #define ITK_TEMPLATE_ImageLinearConstIteratorWithIndex(_, EXPORT, x, y) namespace itk { \
00303   _(1(class EXPORT ImageLinearConstIteratorWithIndex< ITK_TEMPLATE_1 x >)) \
00304   namespace Templates { typedef ImageLinearConstIteratorWithIndex< ITK_TEMPLATE_1 x > \
00305                         ImageLinearConstIteratorWithIndex##y; } \
00306   }
00307 
00308 #if ITK_TEMPLATE_EXPLICIT
00309 # include "Templates/itkImageLinearConstIteratorWithIndex+-.h"
00310 #endif
00311 
00312 #if ITK_TEMPLATE_TXX
00313 # include "itkImageLinearConstIteratorWithIndex.txx"
00314 #endif
00315 
00316 #endif
00317 

Generated at Thu May 28 10:17:52 2009 for ITK by doxygen 1.5.5 written by Dimitri van Heesch, © 1997-2000