00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
#ifndef __itkImageConstIterator_h
00018
#define __itkImageConstIterator_h
00019
00020
#include "itkImage.h"
00021
#include "itkIndex.h"
00022
#include "itkSize.h"
00023
#include "itkOffset.h"
00024
00025
namespace itk
00026 {
00027
00055
template<
typename TImage>
00056 class ITK_EXPORT ImageConstIterator
00057 {
00058
public:
00060 typedef ImageConstIterator
Self;
00061
00066
itkStaticConstMacro(ImageIteratorDimension,
unsigned int,
00067 TImage::ImageDimension);
00068
00070 typedef typename TImage::IndexType
IndexType;
00071 typedef typename TImage::IndexValueType
IndexValueType;
00072
00074 typedef typename TImage::SizeType
SizeType;
00075 typedef typename TImage::SizeValueType
SizeValueType;
00076
00078 typedef typename TImage::OffsetType
OffsetType;
00079 typedef typename TImage::OffsetValueType
OffsetValueType;
00080
00082 typedef typename TImage::RegionType
RegionType;
00083
00085 typedef TImage
ImageType;
00086
00090 typedef typename TImage::PixelContainer
PixelContainer;
00091 typedef typename PixelContainer::Pointer
PixelContainerPointer;
00092
00094 typedef typename TImage::InternalPixelType
InternalPixelType;
00095
00097 typedef typename TImage::PixelType
PixelType;
00098
00101 typedef typename TImage::AccessorType
AccessorType;
00102
00105 ImageConstIterator()
00106 : m_Region(),
00107 m_PixelAccessor()
00108 {
00109 m_Image = 0;
00110 m_Buffer = 0;
00111 m_Offset = 0;
00112 m_BeginOffset = 0;
00113 m_EndOffset = 0;
00114 }
00115
00117
virtual ~ImageConstIterator() {};
00118
00121 ImageConstIterator(
const Self& it)
00122 {
00123 m_Image = it.
m_Image;
00124
00125 m_Region = it.
m_Region;
00126
00127 m_Buffer = it.
m_Buffer;
00128 m_Offset = it.
m_Offset;
00129 m_BeginOffset = it.
m_BeginOffset;
00130 m_EndOffset = it.
m_EndOffset;
00131 m_PixelAccessor = it.
m_PixelAccessor;
00132 }
00133
00136 ImageConstIterator(
const ImageType *ptr,
00137 const RegionType ®ion )
00138 {
00139 m_Image = ptr;
00140 m_Buffer = m_Image->GetBufferPointer();
00141 m_Region = region;
00142
00143
00144 m_Offset = m_Image->ComputeOffset( m_Region.GetIndex() );
00145 m_BeginOffset = m_Offset;
00146
00147
00148
00149
00150
00151
if (m_Region.GetNumberOfPixels() == 0)
00152 {
00153
00154 m_EndOffset = m_BeginOffset;
00155 }
00156
else
00157 {
00158
IndexType ind(m_Region.GetIndex());
00159
SizeType size(m_Region.GetSize());
00160
for (
unsigned int i=0; i < ImageIteratorDimension; ++i)
00161 {
00162 ind[i] += (static_cast<IndexValueType>(size[i]) - 1);
00163 }
00164 m_EndOffset = m_Image->ComputeOffset( ind );
00165 m_EndOffset++;
00166 }
00167
00168 m_PixelAccessor = ptr->GetPixelAccessor();
00169 }
00170
00173 Self &operator=(
const Self& it)
00174 {
00175 m_Image = it.m_Image;
00176 m_Region = it.m_Region;
00177
00178 m_Buffer = it.m_Buffer;
00179 m_Offset = it.m_Offset;
00180 m_BeginOffset = it.m_BeginOffset;
00181 m_EndOffset = it.m_EndOffset;
00182 m_PixelAccessor = it.m_PixelAccessor;
00183
00184
return *
this;
00185 }
00186
00188
static unsigned int GetImageIteratorDimension()
00189 {
return ImageIteratorDimension;}
00190
00193
bool
00194
operator!=(
const Self &it)
const
00195
{
00196
00197
return (m_Buffer + m_Offset) != (it.
m_Buffer + it.
m_Offset);
00198 };
00199
00202
bool
00203
operator==(
const Self &it)
const
00204
{
00205
00206 return (m_Buffer + m_Offset) == (it.m_Buffer + it.m_Offset);
00207 };
00208
00211
bool
00212 operator<=(
const Self &it)
const
00213
{
00214
00215
00216 return (m_Buffer + m_Offset) <= (it.m_Buffer + it.m_Offset);
00217 };
00218
00221
bool
00222 operator<(
const Self &it)
const
00223
{
00224
00225
00226
return (m_Buffer + m_Offset) < (it.m_Buffer + it.m_Offset);
00227 };
00228
00231
bool
00232 operator>=(
const Self &it)
const
00233
{
00234
00235
00236
return (m_Buffer + m_Offset) >= (it.m_Buffer + it.m_Offset);
00237 };
00238
00241
bool
00242 operator>(
const Self &it)
const
00243
{
00244
00245
00246
return (m_Buffer + m_Offset) > (it.
m_Buffer + it.
m_Offset);
00247 };
00248
00253
const IndexType GetIndex()
const
00254
{
return m_Image->ComputeIndex( static_cast<OffsetValueType>(m_Offset) ); }
00255
00258
virtual void SetIndex(
const IndexType &ind)
00259 { m_Offset = m_Image->ComputeOffset( ind ); }
00260
00263
const RegionType& GetRegion()
const
00264
{
return m_Region; };
00265
00267
const ImageType * GetImage()
const
00268
{
return m_Image.GetPointer(); };
00269
00271 PixelType Get(
void)
const
00272
{
return m_PixelAccessor.Get(*(m_Buffer+m_Offset)); }
00273
00277
const PixelType & Value(
void)
const
00278
{
return *(m_Buffer+m_Offset); }
00279
00284
Self Begin(
void) const;
00285
00288
void GoToBegin()
00289 {
00290 m_Offset = m_BeginOffset;
00291 };
00292
00297 Self End(
void) const;
00298
00301
void GoToEnd()
00302 {
00303 m_Offset = m_EndOffset;
00304 };
00305
00308
bool IsAtBegin(
void)
const
00309 {
00310
return (m_Offset == m_BeginOffset);
00311 }
00312
00315
bool IsAtEnd(
void)
const
00316 {
00317
return (m_Offset == m_EndOffset);
00318 }
00319
00320
00321
protected:
00322
SmartPointer<const ImageType> m_Image;
00323 RegionType m_Region;
00324
00325
unsigned long m_Offset;
00326
unsigned long m_BeginOffset;
00327
unsigned long m_EndOffset;
00328
00329
const InternalPixelType * m_Buffer;
00330
00331 AccessorType m_PixelAccessor;
00332 };
00333
00334 }
00335
00336
#ifndef ITK_MANUAL_INSTANTIATION
00337 #include "itkImageConstIterator.txx"
00338
#endif
00339
00340
#endif