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 __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, const RegionType ®ion)
00166 : Superclass(ptr, region)
00167 {
00168 m_SpanBeginOffset = this->m_BeginOffset;
00169 m_SpanEndOffset = this->m_BeginOffset - static_cast<long>(this->m_Region.GetSize()[0]);
00170 }
00172
00180 ImageRegionReverseConstIterator( const ImageConstIterator<TImage> &it):Superclass(it)
00181 {
00182 IndexType ind = this->GetIndex();
00183 m_SpanBeginOffset = this->m_Offset + static_cast<long>(this->m_Region.GetSize()[0])
00184 - (ind[0] - this->m_Region.GetIndex()[0]);
00185 m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(this->m_Region.GetSize()[0]);
00186 }
00188
00191 ImageRegionReverseConstIterator( const ImageReverseConstIterator<TImage> &it):Superclass(it)
00192 {
00193 IndexType ind = this->GetIndex();
00194 m_SpanBeginOffset = this->m_Offset + static_cast<long>(this->m_Region.GetSize()[0])
00195 - (ind[0] - this->m_Region.GetIndex()[0]);
00196 m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(this->m_Region.GetSize()[0]);
00197 }
00199
00202 ImageRegionReverseConstIterator( const ImageRegionIterator<TImage> &it):Superclass(it)
00203 {
00204 IndexType ind = this->GetIndex();
00205 m_SpanBeginOffset = this->m_Offset + static_cast<long>(this->m_Region.GetSize()[0])
00206 - (ind[0] - this->m_Region.GetIndex()[0]);
00207 m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(this->m_Region.GetSize()[0]);
00208 }
00210
00213 void GoToBegin()
00214 {
00215 Superclass::GoToBegin();
00216
00217
00218 m_SpanBeginOffset = this->m_BeginOffset;
00219 m_SpanEndOffset = this->m_BeginOffset - static_cast<long>(this->m_Region.GetSize()[0]);
00220 }
00221
00224 void GoToEnd()
00225 {
00226 Superclass::GoToEnd();
00227
00228
00229 m_SpanEndOffset = this->m_EndOffset;
00230 m_SpanBeginOffset = m_SpanEndOffset + static_cast<long>(this->m_Region.GetSize()[0]);
00231 }
00232
00236 Self Begin(void) const;
00237
00242 Self End(void) const;
00243
00244
00248 void SetIndex(const IndexType &ind)
00249 {
00250 Superclass::SetIndex(ind);
00251 m_SpanBeginOffset = this->m_Offset + static_cast<long>(this->m_Region.GetSize()[0])
00252 - (ind[0] - this->m_Region.GetIndex()[0]);
00253 m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(this->m_Region.GetSize()[0]);
00254 }
00256
00265 Self &
00266 operator++()
00267 {
00268 if (--this->m_Offset <= m_SpanEndOffset)
00269 {
00270
00271
00272
00273
00274 this->m_Offset++;
00275
00276
00277 typename ImageConstIterator<TImage>::IndexType
00278 ind = this->m_Image->ComputeIndex( static_cast<OffsetValueType>(this->m_Offset) );
00279
00280 const typename ImageConstIterator<TImage>::IndexType&
00281 startIndex = this->m_Region.GetIndex();
00282 const typename ImageConstIterator<TImage>::SizeType&
00283 size = this->m_Region.GetSize();
00284
00285
00286 bool done;
00287 unsigned int dim;
00288
00289
00290
00291 done = (--ind[0] == startIndex[0] - 1);
00292 for (unsigned int i=1; done && i < ImageIteratorDimension; i++)
00293 {
00294 done = (ind[i] == startIndex[i]);
00295 }
00296
00297
00298
00299 dim = 0;
00300 if (!done)
00301 {
00302 while ( (dim < ImageIteratorDimension - 1)
00303 && (ind[dim] < startIndex[dim]) )
00304 {
00305 ind[dim] = startIndex[dim] + static_cast<long>(size[dim]) - 1;
00306 ind[++dim]--;
00307 }
00308 }
00309 this->m_Offset = this->m_Image->ComputeOffset( ind );
00310 m_SpanBeginOffset = this->m_Offset;
00311 m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(size[0]);
00312 }
00313 return *this;
00314 }
00315
00324 Self & operator--()
00325 {
00326 if (++this->m_Offset >= m_SpanBeginOffset)
00327 {
00328
00329
00330
00331
00332 --this->m_Offset;
00333
00334
00335 typename ImageConstIterator<TImage>::IndexType
00336 ind = this->m_Image->ComputeIndex( static_cast<OffsetValueType>(this->m_Offset) );
00337
00338 const typename ImageIterator<TImage>::IndexType&
00339 startIndex = this->m_Region.GetIndex();
00340 const typename ImageIterator<TImage>::SizeType&
00341 size = this->m_Region.GetSize();
00342
00343
00344 bool done;
00345 unsigned int dim;
00346
00347
00348
00349 done = (++ind[0] == startIndex[0] + static_cast<long>(size[0]));
00350 for (unsigned int i=1; done && i < ImageIteratorDimension; i++)
00351 {
00352 done = (ind[i] == startIndex[i] + static_cast<long>(size[i]) - 1);
00353 }
00354
00355
00356
00357 dim = 0;
00358 if (!done)
00359 {
00360 while ( (dim < ImageIteratorDimension - 1)
00361 && (ind[dim] > startIndex[dim] + static_cast<long>(size[dim]) - 1) )
00362 {
00363 ind[dim] = startIndex[dim];
00364 ind[++dim]++;
00365 }
00366 }
00367 this->m_Offset = this->m_Image->ComputeOffset( ind );
00368 m_SpanBeginOffset = this->m_Offset;
00369 m_SpanEndOffset = this->m_Offset - static_cast<long>(size[0]);
00370 }
00371 return *this;
00372 }
00373
00374 protected:
00375 unsigned long m_SpanBeginOffset;
00376 unsigned long m_SpanEndOffset;
00377
00378 };
00379
00380 }
00381
00382
00383 #define ITK_TEMPLATE_ImageRegionReverseConstIterator(_, EXPORT, x, y) namespace itk { \
00384 _(1(class EXPORT ImageRegionReverseConstIterator< ITK_TEMPLATE_1 x >)) \
00385 namespace Templates { typedef ImageRegionReverseConstIterator< ITK_TEMPLATE_1 x > ImageRegionReverseConstIterator##y; } \
00386 }
00387
00388 #if ITK_TEMPLATE_EXPLICIT
00389 # include "Templates/itkImageRegionReverseConstIterator+-.h"
00390 #endif
00391
00392 #if ITK_TEMPLATE_TXX
00393 # include "itkImageRegionReverseConstIterator.txx"
00394 #endif
00395
00396 #endif
00397