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

itkImageConstIterator.h

Go to the documentation of this file.
00001 /*========================================================================= 00002 00003 Program: Insight Segmentation & Registration Toolkit 00004 Module: $RCSfile: itkImageConstIterator.h,v $ 00005 Language: C++ 00006 Date: $Date: 2003/09/10 14:29:10 $ 00007 Version: $Revision: 1.17 $ 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 __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; // copy the smart pointer 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 &region ) 00138 { 00139 m_Image = ptr; 00140 m_Buffer = m_Image->GetBufferPointer(); 00141 m_Region = region; 00142 00143 // Compute the start offset 00144 m_Offset = m_Image->ComputeOffset( m_Region.GetIndex() ); 00145 m_BeginOffset = m_Offset; 00146 00147 // Compute the end offset. If any component of m_Region.GetSize() 00148 // is zero, the region is not valid and we set the EndOffset 00149 // to be same as BeginOffset so that iterator end condition is met 00150 // immediately. 00151 if (m_Region.GetNumberOfPixels() == 0) 00152 { 00153 // region is empty, probably has a size of 0 along one dimension 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; // copy the smart pointer 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 // two iterators are the same if they "point to" the same memory location 00197 return (m_Buffer + m_Offset) != (it.m_Buffer + it.m_Offset); 00198 }; 00199 00202 bool 00203 operator==(const Self &it) const 00204 { 00205 // two iterators are the same if they "point to" the same memory location 00206 return (m_Buffer + m_Offset) == (it.m_Buffer + it.m_Offset); 00207 }; 00208 00211 bool 00212 operator<=(const Self &it) const 00213 { 00214 // an iterator is "less than" another if it "points to" a lower 00215 // memory location 00216 return (m_Buffer + m_Offset) <= (it.m_Buffer + it.m_Offset); 00217 }; 00218 00221 bool 00222 operator<(const Self &it) const 00223 { 00224 // an iterator is "less than" another if it "points to" a lower 00225 // memory location 00226 return (m_Buffer + m_Offset) < (it.m_Buffer + it.m_Offset); 00227 }; 00228 00231 bool 00232 operator>=(const Self &it) const 00233 { 00234 // an iterator is "greater than" another if it "points to" a higher 00235 // memory location 00236 return (m_Buffer + m_Offset) >= (it.m_Buffer + it.m_Offset); 00237 }; 00238 00241 bool 00242 operator>(const Self &it) const 00243 { 00244 // an iterator is "greater than" another if it "points to" a higher 00245 // memory location 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: //made protected so other iterators can access 00322 SmartPointer<const ImageType> m_Image; 00323 RegionType m_Region; // region to iterate over 00324 00325 unsigned long m_Offset; 00326 unsigned long m_BeginOffset; // offset to first pixel in region 00327 unsigned long m_EndOffset; // offset to one pixel past last pixel in region 00328 00329 const InternalPixelType * m_Buffer; 00330 00331 AccessorType m_PixelAccessor; 00332 }; 00333 00334 } // end namespace itk 00335 00336 #ifndef ITK_MANUAL_INSTANTIATION 00337 #include "itkImageConstIterator.txx" 00338 #endif 00339 00340 #endif

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