00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
#ifndef __itkImageRegionConstIterator_h
00018
#define __itkImageRegionConstIterator_h
00019
00020
#include "itkImageConstIterator.h"
00021
#include "itkImageIterator.h"
00022
00023
namespace itk
00024 {
00025
00073
template<
typename TImage>
00074 class ITK_EXPORT ImageRegionConstIterator :
public ImageConstIterator<TImage>
00075 {
00076
public:
00078 typedef ImageRegionConstIterator
Self;
00079 typedef ImageConstIterator<TImage> Superclass;
00080
00085
itkStaticConstMacro(ImageIteratorDimension,
unsigned int,
00086 Superclass::ImageIteratorDimension);
00087
00090 typedef typename Superclass::IndexType
IndexType;
00091
00094 typedef typename Superclass::SizeType
SizeType;
00095
00097 typedef typename Superclass::RegionType
RegionType;
00098
00101 typedef typename Superclass::ImageType
ImageType;
00102
00106 typedef typename Superclass::PixelContainer
PixelContainer;
00107 typedef typename Superclass::PixelContainerPointer
PixelContainerPointer;
00108
00110 typedef typename Superclass::InternalPixelType
InternalPixelType;
00111
00113 typedef typename Superclass::PixelType
PixelType;
00114
00117 typedef typename Superclass::AccessorType
AccessorType;
00118
00120
itkTypeMacro(ImageRegionConstIterator,
ImageIterator);
00121
00123 ImageRegionConstIterator() :
ImageConstIterator<TImage>()
00124 {
00125 m_SpanBeginOffset = 0;
00126 m_SpanEndOffset = 0;
00127 }
00128
00131 ImageRegionConstIterator(
const ImageType *ptr,
00132
const RegionType ®ion)
00133 :
ImageConstIterator<TImage>(ptr, region)
00134 {
00135 m_SpanBeginOffset = m_BeginOffset;
00136 m_SpanEndOffset = m_BeginOffset + static_cast<long>(m_Region.GetSize()[0]);
00137 }
00138
00145 ImageRegionConstIterator(
const ImageIterator<TImage> &it)
00146 {
00147 this->
ImageIterator<TImage>::operator=(it);
00148
IndexType ind = this->GetIndex();
00149 m_SpanEndOffset = m_Offset + static_cast<long>(m_Region.GetSize()[0])
00150 - (ind[0] - m_Region.GetIndex()[0]);
00151 m_SpanBeginOffset = m_SpanEndOffset
00152 - static_cast<long>(m_Region.GetSize()[0]);
00153 }
00154
00161 ImageRegionConstIterator(
const ImageConstIterator<TImage> &it)
00162 {
00163 this->
ImageConstIterator<TImage>::operator=(it);
00164
IndexType ind = this->GetIndex();
00165 m_SpanEndOffset = m_Offset + static_cast<long>(m_Region.GetSize()[0])
00166 - (ind[0] - m_Region.GetIndex()[0]);
00167 m_SpanBeginOffset = m_SpanEndOffset
00168 - static_cast<long>(m_Region.GetSize()[0]);
00169 }
00170
00174 Self Begin(
void) const;
00175
00179 Self End(
void) const;
00180
00181
00185
void SetIndex(const IndexType &ind)
00186 { Superclass::SetIndex(ind);
00187 m_SpanEndOffset = m_Offset + static_cast<long>(m_Region.GetSize()[0])
00188 - (ind[0] - m_Region.GetIndex()[0]);
00189 m_SpanBeginOffset = m_SpanEndOffset
00190 - static_cast<long>(m_Region.GetSize()[0]);
00191 }
00192
00200 Self &
00201 operator++()
00202 {
00203
if (++m_Offset >= m_SpanEndOffset)
00204 {
00205
00206
00207
00208
00209 --m_Offset;
00210
00211
00212
typename ImageIterator<TImage>::IndexType
00213 ind = m_Image->ComputeIndex( static_cast<typename Superclass::OffsetValueType>(m_Offset) );
00214
00215
const typename ImageIterator<TImage>::IndexType&
00216 startIndex = m_Region.GetIndex();
00217
const typename ImageIterator<TImage>::SizeType&
00218 size = m_Region.GetSize();
00219
00220
00221
bool done;
00222
unsigned int dim;
00223
00224
00225
00226 done = (++ind[0] == startIndex[0] + static_cast<typename Superclass::IndexValueType>(size[0]));
00227
for (
unsigned int i=1; done && i < ImageIteratorDimension; i++)
00228 {
00229 done = (ind[i] == startIndex[i] + static_cast<typename Superclass::IndexValueType>(size[i]) - 1);
00230 }
00231
00232
00233
00234 dim = 0;
00235
if (!done)
00236 {
00237
while ( ( dim+1 < ImageIteratorDimension )
00238 && (ind[dim] > startIndex[dim] + static_cast<typename Superclass::IndexValueType>(size[dim]) - 1) )
00239 {
00240 ind[dim] = startIndex[dim];
00241 ind[++dim]++;
00242 }
00243 }
00244 m_Offset = m_Image->ComputeOffset( ind );
00245 m_SpanEndOffset = m_Offset + static_cast<long>(size[0]);
00246 m_SpanBeginOffset = m_Offset;
00247 }
00248
return *
this;
00249 }
00250
00258
Self & operator--()
00259 {
00260
if (--m_Offset < m_SpanBeginOffset)
00261 {
00262
00263
00264
00265
00266 m_Offset++;
00267
00268
00269
typename ImageIterator<TImage>::IndexType
00270 ind = m_Image->ComputeIndex( static_cast<typename Superclass::IndexValueType>(m_Offset) );
00271
00272
const typename ImageIterator<TImage>::IndexType&
00273 startIndex = m_Region.GetIndex();
00274
const typename ImageIterator<TImage>::SizeType&
00275 size = m_Region.GetSize();
00276
00277
00278
bool done;
00279
unsigned int dim;
00280
00281
00282
00283 done = (--ind[0] == startIndex[0] - 1);
00284
for (
unsigned int i=1; done && i < ImageIteratorDimension; i++)
00285 {
00286 done = (ind[i] == startIndex[i]);
00287 }
00288
00289
00290
00291 dim = 0;
00292
if (!done)
00293 {
00294
while ( (dim < ImageIteratorDimension - 1)
00295 && (ind[dim] < startIndex[dim]) )
00296 {
00297 ind[dim] = startIndex[dim] + static_cast<typename Superclass::IndexValueType>(size[dim]) - 1;
00298 ind[++dim]--;
00299 }
00300 }
00301 m_Offset = m_Image->ComputeOffset( ind );
00302 m_SpanEndOffset = m_Offset + 1;
00303 m_SpanBeginOffset = m_SpanEndOffset - static_cast<long>(size[0]);
00304 }
00305
return *
this;
00306 }
00307
00308
protected:
00309
unsigned long m_SpanBeginOffset;
00310
unsigned long m_SpanEndOffset;
00311
00312 };
00313
00314 }
00315
00316
#ifndef ITK_MANUAL_INSTANTIATION
00317
#include "itkImageRegionConstIterator.txx"
00318
#endif
00319
00320
#endif