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
00022 namespace itk
00023 {
00024
00099 template<typename TImage>
00100 class ITK_EXPORT ImageRegionReverseConstIterator : public ImageReverseConstIterator<TImage>
00101 {
00102 public:
00104 typedef ImageRegionReverseConstIterator Self;
00105 typedef ImageReverseConstIterator<TImage> Superclass;
00106
00111 enum { ImageIteratorDimension = Superclass::ImageIteratorDimension };
00112
00115 typedef typename Superclass::IndexType IndexType;
00116 typedef typename Superclass::IndexValueType IndexValueType;
00117
00120 typedef typename Superclass::SizeType SizeType;
00121 typedef typename Superclass::SizeValueType SizeValueType;
00122
00125 typedef typename Superclass::OffsetType OffsetType;
00126 typedef typename Superclass::OffsetValueType OffsetValueType;
00127
00129 typedef typename Superclass::RegionType RegionType;
00130
00133 typedef typename Superclass::ImageType ImageType;
00134
00138 typedef typename Superclass::PixelContainer PixelContainer;
00139 typedef typename PixelContainer::Pointer PixelContainerPointer;
00140
00142 typedef typename Superclass::InternalPixelType InternalPixelType;
00143
00145 typedef typename Superclass::PixelType PixelType;
00146
00149 typedef typename Superclass::AccessorType AccessorType;
00150
00152 itkTypeMacro(ImageRegionReverseConstIterator, ImageReverseConstIterator);
00153
00155 ImageRegionReverseConstIterator() : Superclass()
00156 {
00157 m_SpanBeginOffset = 0;
00158 m_SpanEndOffset = 0;
00159 }
00160
00163 ImageRegionReverseConstIterator(ImageType *ptr,
00164 const RegionType ®ion)
00165 : Superclass(ptr, region)
00166 {
00167 m_SpanBeginOffset = this->m_BeginOffset;
00168 m_SpanEndOffset = this->m_BeginOffset - static_cast<long>(this->m_Region.GetSize()[0]);
00169 }
00170
00178 ImageRegionReverseConstIterator( const ImageConstIterator<TImage> &it):Superclass(it)
00179 {
00180 IndexType ind = this->GetIndex();
00181 m_SpanBeginOffset = this->m_Offset + static_cast<long>(this->m_Region.GetSize()[0])
00182 - (ind[0] - this->m_Region.GetIndex()[0]);
00183 m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(this->m_Region.GetSize()[0]);
00184 }
00185
00188 ImageRegionReverseConstIterator( const ImageReverseConstIterator<TImage> &it):Superclass(it)
00189 {
00190 IndexType ind = this->GetIndex();
00191 m_SpanBeginOffset = this->m_Offset + static_cast<long>(this->m_Region.GetSize()[0])
00192 - (ind[0] - this->m_Region.GetIndex()[0]);
00193 m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(this->m_Region.GetSize()[0]);
00194 }
00195
00198 ImageRegionReverseConstIterator( const ImageRegionIterator<TImage> &it):Superclass(it)
00199 {
00200 IndexType ind = this->GetIndex();
00201 m_SpanBeginOffset = this->m_Offset + static_cast<long>(this->m_Region.GetSize()[0])
00202 - (ind[0] - this->m_Region.GetIndex()[0]);
00203 m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(this->m_Region.GetSize()[0]);
00204 }
00205
00208 void GoToBegin()
00209 {
00210 Superclass::GoToBegin();
00211
00212
00213 m_SpanBeginOffset = this->m_BeginOffset;
00214 m_SpanEndOffset = this->m_BeginOffset
00215 - static_cast<long>(this->m_Region.GetSize()[0]);
00216 };
00217
00220 void GoToEnd()
00221 {
00222 Superclass::GoToEnd();
00223
00224
00225 m_SpanEndOffset = this->m_EndOffset;
00226 m_SpanBeginOffset = m_SpanEndOffset
00227 + static_cast<long>(this->m_Region.GetSize()[0]);
00228 };
00229
00233 Self Begin(void) const;
00234
00239 Self End(void) const;
00240
00241
00245 void SetIndex(const IndexType &ind)
00246 { Superclass::SetIndex(ind);
00247 m_SpanBeginOffset = this->m_Offset + static_cast<long>(this->m_Region.GetSize()[0])
00248 - (ind[0] - this->m_Region.GetIndex()[0]);
00249 m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(this->m_Region.GetSize()[0]);
00250 }
00251
00260 Self &
00261 operator++()
00262 {
00263 if (--this->m_Offset <= m_SpanEndOffset)
00264 {
00265
00266
00267
00268
00269 this->m_Offset++;
00270
00271
00272 typename ImageConstIterator<TImage>::IndexType
00273 ind = this->m_Image->ComputeIndex( static_cast<OffsetValueType>(this->m_Offset) );
00274
00275 const typename ImageConstIterator<TImage>::IndexType&
00276 startIndex = this->m_Region.GetIndex();
00277 const typename ImageConstIterator<TImage>::SizeType&
00278 size = this->m_Region.GetSize();
00279
00280
00281 bool done;
00282 unsigned int dim;
00283
00284
00285
00286 done = (--ind[0] == startIndex[0] - 1);
00287 for (unsigned int i=1; done && i < ImageIteratorDimension; i++)
00288 {
00289 done = (ind[i] == startIndex[i]);
00290 }
00291
00292
00293
00294 dim = 0;
00295 if (!done)
00296 {
00297 while ( (dim < ImageIteratorDimension - 1)
00298 && (ind[dim] < startIndex[dim]) )
00299 {
00300 ind[dim] = startIndex[dim] + static_cast<long>(size[dim]) - 1;
00301 ind[++dim]--;
00302 }
00303 }
00304 this->m_Offset = this->m_Image->ComputeOffset( ind );
00305 m_SpanBeginOffset = this->m_Offset;
00306 m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(size[0]);
00307 }
00308 return *this;
00309 }
00310
00319 Self & operator--()
00320 {
00321 if (++this->m_Offset >= m_SpanBeginOffset)
00322 {
00323
00324
00325
00326
00327 --this->m_Offset;
00328
00329
00330 typename ImageConstIterator<TImage>::IndexType
00331 ind = this->m_Image->ComputeIndex( static_cast<OffsetValueType>(this->m_Offset) );
00332
00333 const typename ImageIterator<TImage>::IndexType&
00334 startIndex = this->m_Region.GetIndex();
00335 const typename ImageIterator<TImage>::SizeType&
00336 size = this->m_Region.GetSize();
00337
00338
00339 bool done;
00340 unsigned int dim;
00341
00342
00343
00344 done = (++ind[0] == startIndex[0] + static_cast<long>(size[0]));
00345 for (unsigned int i=1; done && i < ImageIteratorDimension; i++)
00346 {
00347 done = (ind[i] == startIndex[i] + static_cast<long>(size[i]) - 1);
00348 }
00349
00350
00351
00352 dim = 0;
00353 if (!done)
00354 {
00355 while ( (dim < ImageIteratorDimension - 1)
00356 && (ind[dim] > startIndex[dim] + static_cast<long>(size[dim]) - 1) )
00357 {
00358 ind[dim] = startIndex[dim];
00359 ind[++dim]++;
00360 }
00361 }
00362 this->m_Offset = this->m_Image->ComputeOffset( ind );
00363 m_SpanBeginOffset = this->m_Offset;
00364 m_SpanEndOffset = this->m_Offset - static_cast<long>(size[0]);
00365 }
00366 return *this;
00367 }
00368
00369 protected:
00370 unsigned long m_SpanBeginOffset;
00371 unsigned long m_SpanEndOffset;
00372
00373 };
00374
00375 }
00376
00377 #ifndef ITK_MANUAL_INSTANTIATION
00378 #include "itkImageRegionReverseConstIterator.txx"
00379 #endif
00380
00381 #endif