00001 /*========================================================================= 00002 00003 Program: Insight Segmentation & Registration Toolkit 00004 Module: $RCSfile: itkImageConstIteratorWithIndex.h,v $ 00005 Language: C++ 00006 Date: $Date: 2002/09/23 12:35:43 $ 00007 Version: $Revision: 1.15 $ 00008 00009 Copyright (c) 2002 Insight 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 __itkImageConstIteratorWithIndex_h 00018 #define __itkImageConstIteratorWithIndex_h 00019 00020 #include "itkIndex.h" 00021 #include "itkImage.h" 00022 #include <memory> 00023 00024 namespace itk 00025 { 00026 00057 template<typename TImage> 00058 class ImageConstIteratorWithIndex { 00059 public: 00061 typedef ImageConstIteratorWithIndex Self; 00062 00067 itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension); 00068 00070 typedef typename TImage::IndexType IndexType; 00071 typedef typename IndexType::IndexValueType IndexValueType; 00072 00074 typedef typename TImage::SizeType SizeType; 00075 typedef typename SizeType::SizeValueType SizeValueType; 00076 00078 typedef typename TImage::RegionType RegionType; 00079 00081 typedef TImage ImageType; 00082 00086 typedef typename TImage::PixelContainer PixelContainer; 00087 typedef typename PixelContainer::Pointer PixelContainerPointer; 00088 00090 typedef typename TImage::InternalPixelType InternalPixelType; 00091 00093 typedef typename TImage::PixelType PixelType; 00094 00097 typedef typename TImage::AccessorType AccessorType; 00098 00100 typedef typename TImage::OffsetType OffsetType; 00101 typedef typename OffsetType::OffsetValueType OffsetValueType; 00102 00105 ImageConstIteratorWithIndex(); 00106 00109 ImageConstIteratorWithIndex(const Self& it); 00110 00113 ImageConstIteratorWithIndex( const TImage *ptr, 00114 const RegionType& region ); 00115 00118 Self &operator=(const Self& it); 00119 00121 static unsigned int GetImageDimension() 00122 {return ImageDimension;} 00123 00126 bool 00127 operator!=(const Self &it) const 00128 { 00129 // two iterators are the same if they "point to" the same memory location 00130 return (m_Position) != (it.m_Position); 00131 }; 00132 00135 bool 00136 operator==(const Self &it) const 00137 { 00138 // two iterators are the same if they "point to" the same memory location 00139 return (m_Position) == (it.m_Position); 00140 }; 00141 00144 bool 00145 operator<=(const Self &it) const 00146 { 00147 // an iterator is "less than" another if it "points to" a lower 00148 // memory location 00149 return (m_Position) <= (it.m_Position); 00150 }; 00151 00154 bool 00155 operator<(const Self &it) const 00156 { 00157 // an iterator is "less than" another if it "points to" a lower 00158 // memory location 00159 return (m_Position) < (it.m_Position); 00160 }; 00161 00164 bool 00165 operator>=(const Self &it) const 00166 { 00167 // an iterator is "greater than" another if it "points to" a higher 00168 // memory location 00169 return (m_Position) >= (it.m_Position); 00170 }; 00171 00174 bool 00175 operator>(const Self &it) const 00176 { 00177 // an iterator is "greater than" another if it "points to" a higher 00178 // memory location 00179 return (m_Position) > (it.m_Position); 00180 }; 00181 00184 const IndexType GetIndex() 00185 { return m_PositionIndex; } 00186 00189 const RegionType& GetRegion() const 00190 { return m_Region; }; 00191 00194 void SetIndex(const IndexType &ind) 00195 { m_Position = m_Begin + m_Image->ComputeOffset( ind ); 00196 m_PositionIndex = ind; } 00197 00199 PixelType Get(void) const 00200 { return m_PixelAccessor.Get(*m_Position); } 00201 00205 const PixelType & Value(void) const 00206 { return *m_Position; } 00207 00210 Self Begin(void) const; 00211 00213 void GoToBegin(void); 00214 00217 Self End(void) const; 00218 00220 void GoToEnd(void); 00221 00223 bool IsAtBegin(void) const 00224 { 00225 return !m_Remaining; 00226 } 00227 00229 bool IsAtEnd(void) const 00230 { 00231 return !m_Remaining; 00232 } 00233 00235 bool Remaining() 00236 { 00237 return m_Remaining; 00238 } 00239 00240 protected: //made protected so other iterators can access 00241 typename TImage::ConstPointer m_Image; 00242 00243 IndexType m_PositionIndex; // Index where we currently are 00244 IndexType m_BeginIndex; // Index to start iterating over 00245 IndexType m_EndIndex; // Index to finish iterating: 00246 // one pixel past the end of each 00247 // row, col, slice, etc.... 00248 00249 RegionType m_Region; // region to iterate over 00250 00251 unsigned long m_OffsetTable[ ImageDimension + 1 ]; 00252 00253 const InternalPixelType *m_Position; 00254 const InternalPixelType *m_Begin; 00255 const InternalPixelType *m_End; 00256 00257 bool m_Remaining; 00258 00259 AccessorType m_PixelAccessor; 00260 00261 }; 00262 00263 } // end namespace itk 00264 00265 #ifndef ITK_MANUAL_INSTANTIATION 00266 #include "itkImageConstIteratorWithIndex.txx" 00267 #endif 00268 00269 #endif