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
00071
template<
typename TImage>
00072 class ITK_EXPORT ImageRegionReverseConstIterator :
public ImageReverseConstIterator<TImage>
00073 {
00074
public:
00076
typedef ImageRegionReverseConstIterator
Self;
00077 typedef ImageReverseConstIterator<TImage> Superclass;
00078
00083
enum { ImageIteratorDimension = Superclass::ImageIteratorDimension };
00084
00087
typedef typename Superclass::IndexType IndexType;
00088 typedef typename Superclass::IndexValueType
IndexValueType;
00089
00092
typedef typename Superclass::SizeType
SizeType;
00093 typedef typename Superclass::SizeValueType
SizeValueType;
00094
00097
typedef typename Superclass::OffsetType
OffsetType;
00098 typedef typename Superclass::OffsetValueType
OffsetValueType;
00099
00101
typedef typename Superclass::RegionType
RegionType;
00102
00105
typedef typename Superclass::ImageType
ImageType;
00106
00110
typedef typename Superclass::PixelContainer
PixelContainer;
00111 typedef typename PixelContainer::Pointer
PixelContainerPointer;
00112
00114
typedef typename Superclass::InternalPixelType
InternalPixelType;
00115
00117
typedef typename Superclass::PixelType
PixelType;
00118
00121
typedef typename Superclass::AccessorType
AccessorType;
00122
00124
itkTypeMacro(ImageRegionReverseConstIterator,
ImageReverseConstIterator);
00125
00127 ImageRegionReverseConstIterator() :
Superclass()
00128 {
00129 m_SpanBeginOffset = 0;
00130 m_SpanEndOffset = 0;
00131 }
00132
00135 ImageRegionReverseConstIterator(ImageType *ptr,
00136 const RegionType ®ion)
00137 :
Superclass(ptr, region)
00138 {
00139 m_SpanBeginOffset = m_BeginOffset;
00140 m_SpanEndOffset = m_BeginOffset - static_cast<long>(m_Region.GetSize()[0]);
00141 }
00142
00150 ImageRegionReverseConstIterator(
const ImageConstIterator<TImage> &it):
Superclass(it)
00151 {
00152 IndexType ind = this->GetIndex();
00153 m_SpanBeginOffset = m_Offset + static_cast<long>(m_Region.GetSize()[0])
00154 - (ind[0] - m_Region.GetIndex()[0]);
00155 m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(m_Region.GetSize()[0]);
00156 }
00157
00160 ImageRegionReverseConstIterator(
const ImageReverseConstIterator<TImage> &it):
Superclass(it)
00161 {
00162 IndexType ind = this->GetIndex();
00163 m_SpanBeginOffset = m_Offset + static_cast<long>(m_Region.GetSize()[0])
00164 - (ind[0] - m_Region.GetIndex()[0]);
00165 m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(m_Region.GetSize()[0]);
00166 }
00167
00170 ImageRegionReverseConstIterator(
const ImageRegionIterator<TImage> &it):
Superclass(it)
00171 {
00172 IndexType ind = this->GetIndex();
00173 m_SpanBeginOffset = m_Offset + static_cast<long>(m_Region.GetSize()[0])
00174 - (ind[0] - m_Region.GetIndex()[0]);
00175 m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(m_Region.GetSize()[0]);
00176 }
00177
00181 Self Begin(
void) const;
00182
00186 Self End(
void) const;
00187
00188
00192
void SetIndex(const IndexType &ind)
00193 { Superclass::SetIndex(ind);
00194 m_SpanBeginOffset = m_Offset + static_cast<long>(m_Region.GetSize()[0])
00195 - (ind[0] - m_Region.GetIndex()[0]);
00196 m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(m_Region.GetSize()[0]);
00197 }
00198
00207 Self &
00208 operator++()
00209 {
00210
if (--m_Offset <= m_SpanEndOffset)
00211 {
00212
00213
00214
00215
00216 m_Offset++;
00217
00218
00219
typename ImageConstIterator<TImage>::IndexType
00220 ind = m_Image->ComputeIndex( static_cast<OffsetValueType>(m_Offset) );
00221
00222
const typename ImageConstIterator<TImage>::IndexType&
00223 startIndex = m_Region.GetIndex();
00224
const typename ImageConstIterator<TImage>::SizeType&
00225 size = m_Region.GetSize();
00226
00227
00228
bool done;
00229
unsigned int dim;
00230
00231
00232
00233 done = (--ind[0] == startIndex[0] - 1);
00234
for (
unsigned int i=1; done && i < ImageIteratorDimension; i++)
00235 {
00236 done = (ind[i] == startIndex[i]);
00237 }
00238
00239
00240
00241 dim = 0;
00242
if (!done)
00243 {
00244
while ( (dim < ImageIteratorDimension - 1)
00245 && (ind[dim] < startIndex[dim]) )
00246 {
00247 ind[dim] = startIndex[dim] + static_cast<long>(size[dim]) - 1;
00248 ind[++dim]--;
00249 }
00250 }
00251 m_Offset = m_Image->ComputeOffset( ind );
00252 m_SpanBeginOffset = m_Offset;
00253 m_SpanEndOffset = m_SpanBeginOffset - static_cast<long>(size[0]);
00254 }
00255
return *
this;
00256 }
00257
00266
Self & operator--()
00267 {
00268
if (++m_Offset >= m_SpanBeginOffset)
00269 {
00270
00271
00272
00273
00274 --m_Offset;
00275
00276
00277
typename ImageConstIterator<TImage>::IndexType
00278 ind = m_Image->ComputeIndex( static_cast<OffsetValueType>(m_Offset) );
00279
00280
const typename ImageIterator<TImage>::IndexType&
00281 startIndex = m_Region.GetIndex();
00282
const typename ImageIterator<TImage>::SizeType&
00283 size = m_Region.GetSize();
00284
00285
00286
bool done;
00287
unsigned int dim;
00288
00289
00290
00291 done = (++ind[0] == startIndex[0] + static_cast<long>(size[0]));
00292
for (
unsigned int i=1; done && i < ImageIteratorDimension; i++)
00293 {
00294 done = (ind[i] == startIndex[i] + static_cast<long>(size[i]) - 1);
00295 }
00296
00297
00298
00299 dim = 0;
00300
if (!done)
00301 {
00302
while ( (dim < ImageIteratorDimension - 1)
00303 && (ind[dim] > startIndex[dim] + static_cast<long>(size[dim]) - 1) )
00304 {
00305 ind[dim] = startIndex[dim];
00306 ind[++dim]++;
00307 }
00308 }
00309 m_Offset = m_Image->ComputeOffset( ind );
00310 m_SpanBeginOffset = m_Offset;
00311 m_SpanEndOffset = m_Offset - static_cast<long>(size[0]);
00312 }
00313
return *
this;
00314 }
00315
00316
protected:
00317
unsigned long m_SpanBeginOffset;
00318
unsigned long m_SpanEndOffset;
00319
00320 };
00321
00322 }
00323
00324 #ifndef ITK_MANUAL_INSTANTIATION
00325
#include "itkImageRegionReverseConstIterator.txx"
00326
#endif
00327
00328
#endif