Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
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
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 }
00300
00301
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