00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkImageRegionReverseConstIterator_h
00018 #define __itkImageRegionReverseConstIterator_h
00019
00020 #include "itkImageReverseConstIterator.h"
00021 #include "itkImageRegionIterator.h"
00022
00023 namespace itk
00024 {
00025
00100 template<typename TImage>
00101 class ITK_EXPORT ImageRegionReverseConstIterator : public ImageReverseConstIterator<TImage>
00102 {
00103 public:
00104
00106 typedef ImageRegionReverseConstIterator Self;
00107 typedef ImageReverseConstIterator<TImage> Superclass;
00108
00113 enum { ImageIteratorDimension = Superclass::ImageIteratorDimension };
00114
00117 typedef typename Superclass::IndexType IndexType;
00118 typedef typename Superclass::IndexValueType IndexValueType;
00119
00122 typedef typename Superclass::SizeType SizeType;
00123 typedef typename Superclass::SizeValueType SizeValueType;
00124
00127 typedef typename Superclass::OffsetType OffsetType;
00128 typedef typename Superclass::OffsetValueType OffsetValueType;
00129
00131 typedef typename Superclass::RegionType RegionType;
00132
00135 typedef typename Superclass::ImageType ImageType;
00136
00140 typedef typename Superclass::PixelContainer PixelContainer;
00141 typedef typename PixelContainer::Pointer 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(ImageRegionReverseConstIterator, ImageReverseConstIterator);
00155
00157 ImageRegionReverseConstIterator() : Superclass()
00158 {
00159 m_SpanBeginOffset = 0;
00160 m_SpanEndOffset = 0;
00161 }
00162
00165 ImageRegionReverseConstIterator(ImageType *ptr,
00166 const RegionType ®ion)
00167 : Superclass(ptr, region)
00168 {
00169 m_SpanBeginOffset = this->m_BeginOffset;
00170 m_SpanEndOffset = this->m_BeginOffset - static_cast<long>(this->m_Region.GetSize()[0]);
00171 }
00173
00181 ImageRegionReverseConstIterator( const ImageConstIterator<TImage> &it):Superclass(it)
00182 {
00183 IndexType ind = this->GetIndex();
00184 m_SpanBeginOffset = this->m_Offset + static_cast<long>(this->m_Region.GetSize()[0])
00185 - (ind[0] - this->m_Region.GetIndex()[0]);
00186 m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(this->m_Region.GetSize()[0]);
00187 }
00189
00192 ImageRegionReverseConstIterator( const ImageReverseConstIterator<TImage> &it):Superclass(it)
00193 {
00194 IndexType ind = this->GetIndex();
00195 m_SpanBeginOffset = this->m_Offset + static_cast<long>(this->m_Region.GetSize()[0])
00196 - (ind[0] - this->m_Region.GetIndex()[0]);
00197 m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(this->m_Region.GetSize()[0]);
00198 }
00200
00203 ImageRegionReverseConstIterator( const ImageRegionIterator<TImage> &it):Superclass(it)
00204 {
00205 IndexType ind = this->GetIndex();
00206 m_SpanBeginOffset = this->m_Offset + static_cast<long>(this->m_Region.GetSize()[0])
00207 - (ind[0] - this->m_Region.GetIndex()[0]);
00208 m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(this->m_Region.GetSize()[0]);
00209 }
00211
00214 void GoToBegin()
00215 {
00216 Superclass::GoToBegin();
00217
00218
00219 m_SpanBeginOffset = this->m_BeginOffset;
00220 m_SpanEndOffset = this->m_BeginOffset
00221 - static_cast<long>(this->m_Region.GetSize()[0]);
00222 };
00223
00226 void GoToEnd()
00227 {
00228 Superclass::GoToEnd();
00229
00230
00231 m_SpanEndOffset = this->m_EndOffset;
00232 m_SpanBeginOffset = m_SpanEndOffset
00233 + static_cast<long>(this->m_Region.GetSize()[0]);
00234 };
00235
00239 Self Begin(void) const;
00240
00245 Self End(void) const;
00246
00247
00251 void SetIndex(const IndexType &ind)
00252 { Superclass::SetIndex(ind);
00253 m_SpanBeginOffset = this->m_Offset + static_cast<long>(this->m_Region.GetSize()[0])
00254 - (ind[0] - this->m_Region.GetIndex()[0]);
00255 m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(this->m_Region.GetSize()[0]);
00256 }
00258
00267 Self &
00268 operator++()
00269 {
00270 if (--this->m_Offset <= m_SpanEndOffset)
00271 {
00272
00273
00274
00275
00276 this->m_Offset++;
00277
00278
00279 typename ImageConstIterator<TImage>::IndexType
00280 ind = this->m_Image->ComputeIndex( static_cast<OffsetValueType>(this->m_Offset) );
00281
00282 const typename ImageConstIterator<TImage>::IndexType&
00283 startIndex = this->m_Region.GetIndex();
00284 const typename ImageConstIterator<TImage>::SizeType&
00285 size = this->m_Region.GetSize();
00286
00287
00288 bool done;
00289 unsigned int dim;
00290
00291
00292
00293 done = (--ind[0] == startIndex[0] - 1);
00294 for (unsigned int i=1; done && i < ImageIteratorDimension; i++)
00295 {
00296 done = (ind[i] == startIndex[i]);
00297 }
00298
00299
00300
00301 dim = 0;
00302 if (!done)
00303 {
00304 while ( (dim < ImageIteratorDimension - 1)
00305 && (ind[dim] < startIndex[dim]) )
00306 {
00307 ind[dim] = startIndex[dim] + static_cast<long>(size[dim]) - 1;
00308 ind[++dim]--;
00309 }
00310 }
00311 this->m_Offset = this->m_Image->ComputeOffset( ind );
00312 m_SpanBeginOffset = this->m_Offset;
00313 m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(size[0]);
00314 }
00315 return *this;
00316 }
00317
00326 Self & operator--()
00327 {
00328 if (++this->m_Offset >= m_SpanBeginOffset)
00329 {
00330
00331
00332
00333
00334 --this->m_Offset;
00335
00336
00337 typename ImageConstIterator<TImage>::IndexType
00338 ind = this->m_Image->ComputeIndex( static_cast<OffsetValueType>(this->m_Offset) );
00339
00340 const typename ImageIterator<TImage>::IndexType&
00341 startIndex = this->m_Region.GetIndex();
00342 const typename ImageIterator<TImage>::SizeType&
00343 size = this->m_Region.GetSize();
00344
00345
00346 bool done;
00347 unsigned int dim;
00348
00349
00350
00351 done = (++ind[0] == startIndex[0] + static_cast<long>(size[0]));
00352 for (unsigned int i=1; done && i < ImageIteratorDimension; i++)
00353 {
00354 done = (ind[i] == startIndex[i] + static_cast<long>(size[i]) - 1);
00355 }
00356
00357
00358
00359 dim = 0;
00360 if (!done)
00361 {
00362 while ( (dim < ImageIteratorDimension - 1)
00363 && (ind[dim] > startIndex[dim] + static_cast<long>(size[dim]) - 1) )
00364 {
00365 ind[dim] = startIndex[dim];
00366 ind[++dim]++;
00367 }
00368 }
00369 this->m_Offset = this->m_Image->ComputeOffset( ind );
00370 m_SpanBeginOffset = this->m_Offset;
00371 m_SpanEndOffset = this->m_Offset - static_cast<long>(size[0]);
00372 }
00373 return *this;
00374 }
00375
00376 protected:
00377 unsigned long m_SpanBeginOffset;
00378 unsigned long m_SpanEndOffset;
00379
00380 };
00381
00382 }
00383
00384
00385 #define ITK_TEMPLATE_ImageRegionReverseConstIterator(_, EXPORT, x, y) namespace itk { \
00386 _(1(class EXPORT ImageRegionReverseConstIterator< ITK_TEMPLATE_1 x >)) \
00387 namespace Templates { typedef ImageRegionReverseConstIterator< ITK_TEMPLATE_1 x > ImageRegionReverseConstIterator##y; } \
00388 }
00389
00390 #if ITK_TEMPLATE_EXPLICIT
00391 # include "Templates/itkImageRegionReverseConstIterator+-.h"
00392 #endif
00393
00394 #if ITK_TEMPLATE_TXX
00395 # include "itkImageRegionReverseConstIterator.txx"
00396 #endif
00397
00398 #endif
00399