itkImageReverseConstIterator.h
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 __itkImageReverseConstIterator_h
00018 #define __itkImageReverseConstIterator_h
00019
00020 #include "itkIndex.h"
00021 #include "itkSize.h"
00022 #include "itkImage.h"
00023 #include "itkImageConstIterator.h"
00024 #include <memory>
00025
00026 namespace itk
00027 {
00028
00086 template<typename TImage>
00087 class ITK_EXPORT ImageReverseConstIterator
00088 {
00089 public:
00091 typedef ImageReverseConstIterator Self;
00092
00097 itkStaticConstMacro(ImageIteratorDimension, unsigned int,
00098 TImage::ImageDimension);
00099
00101 typedef typename TImage::IndexType IndexType;
00102 typedef typename TImage::IndexValueType IndexValueType;
00103
00105 typedef typename TImage::SizeType SizeType;
00106 typedef typename TImage::SizeValueType SizeValueType;
00107
00109 typedef typename TImage::OffsetType OffsetType;
00110 typedef typename TImage::OffsetValueType OffsetValueType;
00111
00113 typedef typename TImage::RegionType RegionType;
00114
00116 typedef TImage ImageType;
00117
00121 typedef typename TImage::PixelContainer PixelContainer;
00122 typedef typename PixelContainer::Pointer PixelContainerPointer;
00123
00125 typedef typename TImage::InternalPixelType InternalPixelType;
00126
00128 typedef typename TImage::PixelType PixelType;
00129
00132 typedef typename TImage::AccessorType AccessorType;
00133
00135 typedef typename TImage::AccessorFunctorType AccessorFunctorType;
00136
00139 ImageReverseConstIterator() :m_PixelAccessor(), m_PixelAccessorFunctor()
00140 {
00141 m_Buffer = 0;
00142 m_Offset = 0;
00143 m_BeginOffset = 0;
00144 m_EndOffset = 0;
00145 m_PixelAccessorFunctor.SetBegin( m_Buffer );
00146 }
00148
00150 virtual ~ImageReverseConstIterator() {};
00151
00154 ImageReverseConstIterator(const Self& it)
00155 {
00156 m_Image = it.m_Image;
00157
00158 m_Region = it.m_Region;
00159
00160 m_Buffer = it.m_Buffer;
00161 m_Offset = it.m_Offset;
00162 m_BeginOffset = it.m_BeginOffset;
00163 m_EndOffset = it.m_EndOffset;
00164 m_PixelAccessor = it.m_PixelAccessor;
00165 m_PixelAccessorFunctor = it.m_PixelAccessorFunctor;
00166 m_PixelAccessorFunctor.SetBegin( m_Buffer );
00167 }
00168
00171 ImageReverseConstIterator(ImageType *ptr, const RegionType ®ion)
00172 {
00173 unsigned long offset;
00174 m_Image = ptr;
00175 m_Buffer = m_Image->GetBufferPointer();
00176 m_Region = region;
00178
00179
00180 offset = m_Image->ComputeOffset( m_Region.GetIndex() );
00181 m_EndOffset = offset-1;
00182
00183
00184 IndexType ind(m_Region.GetIndex());
00185 SizeType size(m_Region.GetSize());
00186 for (unsigned int i=0; i < TImage::ImageDimension; ++i)
00187 {
00188 ind[i] += (size[i] - 1);
00189 }
00190 m_BeginOffset = m_Image->ComputeOffset( ind );
00191 m_Offset = m_BeginOffset;
00192
00193 m_PixelAccessor = ptr->GetPixelAccessor();
00194 m_PixelAccessorFunctor.SetPixelAccessor( m_PixelAccessor );
00195 m_PixelAccessorFunctor.SetBegin( m_Buffer );
00196 }
00197
00205 ImageReverseConstIterator( const ImageConstIterator<TImage> &it)
00206 {
00207 m_Image = it.GetImage();
00208 m_Region = it.GetRegion();
00209 m_Buffer = m_Image->GetBufferPointer();
00211
00212 IndexType ind = it.GetIndex();
00213
00214 m_Offset = m_Image->ComputeOffset( ind );
00215
00216
00217 m_EndOffset = m_Image->ComputeOffset( m_Region.GetIndex() ) - 1;
00218
00219
00220 IndexType regInd(m_Region.GetIndex());
00221 SizeType regSize(m_Region.GetSize());
00222 for (unsigned int i=0; i < TImage::ImageDimension; ++i)
00223 {
00224 regInd[i] += (regSize[i] - 1);
00225 }
00226 m_BeginOffset = m_Image->ComputeOffset( regInd );
00227
00228 m_PixelAccessor = m_Image->GetPixelAccessor();
00229 m_PixelAccessorFunctor.SetPixelAccessor( m_PixelAccessor );
00230 m_PixelAccessorFunctor.SetBegin( m_Buffer );
00231 }
00232
00235 Self &operator=(const Self& it)
00236 {
00237 m_Image = it.m_Image;
00238 m_Region = it.m_Region;
00239
00240 m_Buffer = it.m_Buffer;
00241 m_Offset = it.m_Offset;
00242 m_BeginOffset = it.m_BeginOffset;
00243 m_EndOffset = it.m_EndOffset;
00244 m_PixelAccessor = it.m_PixelAccessor;
00245 m_PixelAccessorFunctor.SetPixelAccessor( m_PixelAccessor );
00246 m_PixelAccessorFunctor.SetBegin( m_Buffer );
00247 return *this;
00248 }
00249
00252 Self &operator=(const ImageConstIterator<TImage>& it)
00253 {
00254 m_Image = it.GetImage();
00255 m_Region = it.GetRegion();
00256 m_Buffer = m_Image->GetBufferPointer();
00258
00259 IndexType ind = it.GetIndex();
00260
00261 m_Offset = m_Image->ComputeOffset( ind );
00262
00263
00264 m_EndOffset = m_Image->ComputeOffset( m_Region.GetIndex() ) - 1;
00265
00266
00267 IndexType regInd(m_Region.GetIndex());
00268 SizeType regSize(m_Region.GetSize());
00269 for (unsigned int i=0; i < TImage::ImageDimension; ++i)
00270 {
00271 regInd[i] += (regSize[i] - 1);
00272 }
00273 m_BeginOffset = m_Image->ComputeOffset( regInd );
00274
00275 m_PixelAccessor = m_Image->GetPixelAccessor();
00276 m_PixelAccessorFunctor.SetPixelAccessor( m_PixelAccessor );
00277 m_PixelAccessorFunctor.SetBegin( m_Buffer );
00278
00279 return *this;
00280 }
00281
00283 static unsigned int GetImageIteratorDimension()
00284 {return TImage::ImageDimension;}
00285
00288 bool
00289 operator!=(const Self &it) const
00290 {
00291
00292 return (m_Buffer + m_Offset) != (it.m_Buffer + it.m_Offset);
00293 }
00294
00297 bool
00298 operator==(const Self &it) const
00299 {
00300
00301 return (m_Buffer + m_Offset) == (it.m_Buffer + it.m_Offset);
00302 }
00303
00308 const IndexType GetIndex()
00309 { return m_Image->ComputeIndex( m_Offset ); }
00310
00313 virtual void SetIndex(const IndexType &ind)
00314 { m_Offset = m_Image->ComputeOffset( ind ); }
00315
00316
00319 const RegionType& GetRegion() const
00320 { return m_Region; }
00321
00323 const PixelType Get(void) const
00324 { return m_PixelAccessorFunctor.Get(*(m_Buffer+m_Offset)); }
00325
00327 void Set( const PixelType & value) const
00328 {
00329 this->m_PixelAccessorFunctor.Set(*(const_cast<InternalPixelType *>(
00330 this->m_Buffer+this->m_Offset)),value);
00331 }
00332
00336 const PixelType & Value(void) const
00337 { return *(m_Buffer+m_Offset); }
00338
00342 const PixelType & Value(void)
00343 { return *(m_Buffer+m_Offset); }
00344
00348 Self Begin() const;
00349
00352 void GoToBegin()
00353 {
00354 m_Offset = m_BeginOffset;
00355 }
00356
00360 Self End() const;
00361
00364 void GoToEnd()
00365 {
00366 m_Offset = m_EndOffset;
00367 }
00368
00371 bool IsAtBegin()
00372 {
00373 return (m_Offset == m_BeginOffset);
00374 }
00375
00378 bool IsAtEnd()
00379 {
00380 return (m_Offset == m_EndOffset);
00381 }
00382
00383 protected:
00384 typename ImageType::ConstWeakPointer m_Image;
00385 RegionType m_Region;
00386
00387 unsigned long m_Offset;
00388 unsigned long m_BeginOffset;
00389 unsigned long m_EndOffset;
00390
00391 const InternalPixelType *m_Buffer;
00392
00393 AccessorType m_PixelAccessor;
00394 AccessorFunctorType m_PixelAccessorFunctor;
00395 };
00396
00397 }
00398
00399
00400 #define ITK_TEMPLATE_ImageReverseConstIterator(_, EXPORT, x, y) namespace itk { \
00401 _(1(class EXPORT ImageReverseConstIterator< ITK_TEMPLATE_1 x >)) \
00402 namespace Templates { typedef ImageReverseConstIterator< ITK_TEMPLATE_1 x > ImageReverseConstIterator##y; } \
00403 }
00404
00405 #if ITK_TEMPLATE_EXPLICIT
00406 # include "Templates/itkImageReverseConstIterator+-.h"
00407 #endif
00408
00409 #if ITK_TEMPLATE_TXX
00410 # include "itkImageReverseConstIterator.txx"
00411 #endif
00412
00413 #endif
00414