Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkImageReverseConstIterator.h

Go to the documentation of this file.
00001 /*========================================================================= 00002 00003 Program: Insight Segmentation & Registration Toolkit 00004 Module: $RCSfile: itkImageReverseConstIterator.h,v $ 00005 Language: C++ 00006 Date: $Date: 2003/09/10 14:29:12 $ 00007 Version: $Revision: 1.4 $ 00008 00009 Copyright (c) Insight Software Consortium. All rights reserved. 00010 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 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 00059 template<typename TImage> 00060 class ITK_EXPORT ImageReverseConstIterator 00061 { 00062 public: 00064 typedef ImageReverseConstIterator Self; 00065 00070 itkStaticConstMacro(ImageIteratorDimension, unsigned int, 00071 TImage::ImageDimension); 00072 00074 typedef typename TImage::IndexType IndexType; 00075 typedef typename TImage::IndexValueType IndexValueType; 00076 00078 typedef typename TImage::SizeType SizeType; 00079 typedef typename TImage::SizeValueType SizeValueType; 00080 00082 typedef typename TImage::OffsetType OffsetType; 00083 typedef typename TImage::OffsetValueType OffsetValueType; 00084 00086 typedef typename TImage::RegionType RegionType; 00087 00089 typedef TImage ImageType; 00090 00094 typedef typename TImage::PixelContainer PixelContainer; 00095 typedef typename PixelContainer::Pointer PixelContainerPointer; 00096 00098 typedef typename TImage::InternalPixelType InternalPixelType; 00099 00101 typedef typename TImage::PixelType PixelType; 00102 00105 typedef typename TImage::AccessorType AccessorType; 00106 00109 ImageReverseConstIterator() 00110 :m_PixelAccessor() 00111 { 00112 m_Buffer = 0; 00113 m_Offset = 0; 00114 m_BeginOffset = 0; 00115 m_EndOffset = 0; 00116 } 00117 00119 virtual ~ImageReverseConstIterator() {}; 00120 00123 ImageReverseConstIterator(const Self& it) 00124 { 00125 m_Image = it.m_Image; // copy the smart pointer 00126 00127 m_Region = it.m_Region; 00128 00129 m_Buffer = it.m_Buffer; 00130 m_Offset = it.m_Offset; 00131 m_BeginOffset = it.m_BeginOffset; 00132 m_EndOffset = it.m_EndOffset; 00133 m_PixelAccessor = it.m_PixelAccessor; 00134 } 00135 00138 ImageReverseConstIterator(ImageType *ptr, 00139 const RegionType &region) 00140 { 00141 unsigned long offset; 00142 m_Image = ptr; 00143 m_Buffer = m_Image->GetBufferPointer(); 00144 m_Region = region; 00145 00146 // Compute the end offset, one pixel before the first pixel 00147 offset = m_Image->ComputeOffset( m_Region.GetIndex() ); 00148 m_EndOffset = offset-1; 00149 00150 // Compute the begin offset, the last pixel in the region 00151 IndexType ind(m_Region.GetIndex()); 00152 SizeType size(m_Region.GetSize()); 00153 for (unsigned int i=0; i < TImage::ImageDimension; ++i) 00154 { 00155 ind[i] += (size[i] - 1); 00156 } 00157 m_BeginOffset = m_Image->ComputeOffset( ind ); 00158 m_Offset = m_BeginOffset; 00159 00160 m_PixelAccessor = ptr->GetPixelAccessor(); 00161 } 00162 00170 ImageReverseConstIterator( const ImageConstIterator<TImage> &it) 00171 { 00172 m_Image = it.GetImage(); 00173 m_Region = it.GetRegion(); 00174 m_Buffer = m_Image->GetBufferPointer(); 00175 00176 IndexType ind = it.GetIndex(); 00177 00178 m_Offset = m_Image->ComputeOffset( ind ); 00179 00180 // Compute the end offset, one pixel before the first pixel 00181 m_EndOffset = m_Image->ComputeOffset( m_Region.GetIndex() ) - 1; 00182 00183 // Compute the begin offset, the last pixel in the region 00184 IndexType regInd(m_Region.GetIndex()); 00185 SizeType regSize(m_Region.GetSize()); 00186 for (unsigned int i=0; i < TImage::ImageDimension; ++i) 00187 { 00188 regInd[i] += (regSize[i] - 1); 00189 } 00190 m_BeginOffset = m_Image->ComputeOffset( regInd ); 00191 00192 m_PixelAccessor = m_Image->GetPixelAccessor(); 00193 } 00194 00197 Self &operator=(const Self& it) 00198 { 00199 m_Image = it.m_Image; // copy the smart pointer 00200 m_Region = it.m_Region; 00201 00202 m_Buffer = it.m_Buffer; 00203 m_Offset = it.m_Offset; 00204 m_BeginOffset = it.m_BeginOffset; 00205 m_EndOffset = it.m_EndOffset; 00206 m_PixelAccessor = it.m_PixelAccessor; 00207 return *this; 00208 } 00209 00212 Self &operator=(const ImageConstIterator<TImage>& it) 00213 { 00214 m_Image = it.GetImage(); 00215 m_Region = it.GetRegion(); 00216 m_Buffer = m_Image->GetBufferPointer(); 00217 00218 IndexType ind = it.GetIndex(); 00219 00220 m_Offset = m_Image->ComputeOffset( ind ); 00221 00222 // Compute the end offset, one pixel before the first pixel 00223 m_EndOffset = m_Image->ComputeOffset( m_Region.GetIndex() ) - 1; 00224 00225 // Compute the begin offset, the last pixel in the region 00226 IndexType regInd(m_Region.GetIndex()); 00227 SizeType regSize(m_Region.GetSize()); 00228 for (unsigned int i=0; i < TImage::ImageDimension; ++i) 00229 { 00230 regInd[i] += (regSize[i] - 1); 00231 } 00232 m_BeginOffset = m_Image->ComputeOffset( regInd ); 00233 00234 m_PixelAccessor = m_Image->GetPixelAccessor(); 00235 00236 return *this; 00237 } 00238 00240 static unsigned int GetImageIteratorDimension() 00241 {return TImage::ImageDimension;} 00242 00245 bool 00246 operator!=(const Self &it) const 00247 { 00248 // two iterators are the same if they "point to" the same memory location 00249 return (m_Buffer + m_Offset) != (it.m_Buffer + it.m_Offset); 00250 }; 00251 00254 bool 00255 operator==(const Self &it) const 00256 { 00257 // two iterators are the same if they "point to" the same memory location 00258 return (m_Buffer + m_Offset) == (it.m_Buffer + it.m_Offset); 00259 }; 00260 00261 #if 0 00262 00268 bool 00269 operator<=(const Self &it) const 00270 { 00271 // an iterator is "less than" another if it "points to" a lower 00272 // memory location 00273 return (m_Buffer + m_Offset) <= (it.m_Buffer + it.m_Offset); 00274 }; 00275 00278 bool 00279 operator<(const Self &it) const 00280 { 00281 // an iterator is "less than" another if it "points to" a lower 00282 // memory location 00283 return (m_Buffer + m_Offset) < (it.m_Buffer + it.m_Offset); 00284 }; 00285 00288 bool 00289 operator>=(const Self &it) const 00290 { 00291 // an iterator is "greater than" another if it "points to" a higher 00292 // memory location 00293 return (m_Buffer + m_Offset) >= (it.m_Buffer + it.m_Offset); 00294 }; 00295 00298 bool 00299 operator>(const Self &it) const 00300 { 00301 // an iterator is "greater than" another if it "points to" a higher 00302 // memory location 00303 return (m_Buffer + m_Offset) > (it.m_Buffer + it.m_Offset); 00304 }; 00305 #endif 00306 00307 00312 const IndexType GetIndex() 00313 { return m_Image->ComputeIndex( m_Offset ); } 00314 00317 virtual void SetIndex(const IndexType &ind) 00318 { m_Offset = m_Image->ComputeOffset( ind ); } 00319 00320 00323 const RegionType& GetRegion() const 00324 { return m_Region; }; 00325 00327 const PixelType & Get(void) const 00328 { return m_PixelAccessor.Get(*(m_Buffer+m_Offset)); } 00329 00331 void Set( const PixelType & value) const 00332 { m_PixelAccessor.Set(*(m_Buffer+m_Offset),value); } 00333 00337 const PixelType & Value(void) const 00338 { return *(m_Buffer+m_Offset); } 00339 00343 PixelType & Value(void) 00344 { return *(m_Buffer+m_Offset); } 00345 00349 Self Begin() const; 00350 00353 void GoToBegin() 00354 { 00355 m_Offset = m_BeginOffset; 00356 }; 00357 00361 Self End() const; 00362 00365 void GoToEnd() 00366 { 00367 m_Offset = m_EndOffset; 00368 }; 00369 00372 bool IsAtBegin() 00373 { 00374 return (m_Offset == m_BeginOffset); 00375 } 00376 00379 bool IsAtEnd() 00380 { 00381 return (m_Offset == m_EndOffset); 00382 } 00383 00384 protected: //made protected so other iterators can access 00385 typename ImageType::ConstPointer m_Image; 00386 RegionType m_Region; // region to iterate over 00387 00388 unsigned long m_Offset; 00389 unsigned long m_BeginOffset; // offset to last pixel in region 00390 unsigned long m_EndOffset; // offset to one pixel before first pixel 00391 00392 const InternalPixelType *m_Buffer; 00393 00394 AccessorType m_PixelAccessor; 00395 }; 00396 00397 } // end namespace itk 00398 00399 #ifndef ITK_MANUAL_INSTANTIATION 00400 #include "itkImageReverseConstIterator.txx" 00401 #endif 00402 00403 #endif

Generated at Sun Apr 1 02:35:19 2007 for ITK by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2000