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

itkImageRegionConstIterator.h

Go to the documentation of this file.
00001 /*========================================================================= 00002 00003 Program: Insight Segmentation & Registration Toolkit 00004 Module: $RCSfile: itkImageRegionConstIterator.h,v $ 00005 Language: C++ 00006 Date: $Date: 2003/09/10 14:29:11 $ 00007 Version: $Revision: 1.11 $ 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 __itkImageRegionConstIterator_h 00018 #define __itkImageRegionConstIterator_h 00019 00020 #include "itkImageConstIterator.h" 00021 #include "itkImageIterator.h" 00022 00023 namespace itk 00024 { 00025 00073 template<typename TImage> 00074 class ITK_EXPORT ImageRegionConstIterator : public ImageConstIterator<TImage> 00075 { 00076 public: 00078 typedef ImageRegionConstIterator Self; 00079 typedef ImageConstIterator<TImage> Superclass; 00080 00085 itkStaticConstMacro(ImageIteratorDimension, unsigned int, 00086 Superclass::ImageIteratorDimension); 00087 00090 typedef typename Superclass::IndexType IndexType; 00091 00094 typedef typename Superclass::SizeType SizeType; 00095 00097 typedef typename Superclass::RegionType RegionType; 00098 00101 typedef typename Superclass::ImageType ImageType; 00102 00106 typedef typename Superclass::PixelContainer PixelContainer; 00107 typedef typename Superclass::PixelContainerPointer PixelContainerPointer; 00108 00110 typedef typename Superclass::InternalPixelType InternalPixelType; 00111 00113 typedef typename Superclass::PixelType PixelType; 00114 00117 typedef typename Superclass::AccessorType AccessorType; 00118 00120 itkTypeMacro(ImageRegionConstIterator, ImageIterator); 00121 00123 ImageRegionConstIterator() : ImageConstIterator<TImage>() 00124 { 00125 m_SpanBeginOffset = 0; 00126 m_SpanEndOffset = 0; 00127 } 00128 00131 ImageRegionConstIterator(const ImageType *ptr, 00132 const RegionType &region) 00133 : ImageConstIterator<TImage>(ptr, region) 00134 { 00135 m_SpanBeginOffset = m_BeginOffset; 00136 m_SpanEndOffset = m_BeginOffset + static_cast<long>(m_Region.GetSize()[0]); 00137 } 00138 00145 ImageRegionConstIterator( const ImageIterator<TImage> &it) 00146 { 00147 this->ImageIterator<TImage>::operator=(it); 00148 IndexType ind = this->GetIndex(); 00149 m_SpanEndOffset = m_Offset + static_cast<long>(m_Region.GetSize()[0]) 00150 - (ind[0] - m_Region.GetIndex()[0]); 00151 m_SpanBeginOffset = m_SpanEndOffset 00152 - static_cast<long>(m_Region.GetSize()[0]); 00153 } 00154 00161 ImageRegionConstIterator( const ImageConstIterator<TImage> &it) 00162 { 00163 this->ImageConstIterator<TImage>::operator=(it); 00164 IndexType ind = this->GetIndex(); 00165 m_SpanEndOffset = m_Offset + static_cast<long>(m_Region.GetSize()[0]) 00166 - (ind[0] - m_Region.GetIndex()[0]); 00167 m_SpanBeginOffset = m_SpanEndOffset 00168 - static_cast<long>(m_Region.GetSize()[0]); 00169 } 00170 00174 Self Begin(void) const; 00175 00179 Self End(void) const; 00180 00181 00185 void SetIndex(const IndexType &ind) 00186 { Superclass::SetIndex(ind); 00187 m_SpanEndOffset = m_Offset + static_cast<long>(m_Region.GetSize()[0]) 00188 - (ind[0] - m_Region.GetIndex()[0]); 00189 m_SpanBeginOffset = m_SpanEndOffset 00190 - static_cast<long>(m_Region.GetSize()[0]); 00191 } 00192 00200 Self & 00201 operator++() 00202 { 00203 if (++m_Offset >= m_SpanEndOffset) 00204 { 00205 // We have reached the end of the span (row), need to wrap around. 00206 00207 // First back up one pixel, because we are going to use a different 00208 // algorithm to compute the next pixel 00209 --m_Offset; 00210 00211 // Get the index of the last pixel on the span (row) 00212 typename ImageIterator<TImage>::IndexType 00213 ind = m_Image->ComputeIndex( static_cast<typename Superclass::OffsetValueType>(m_Offset) ); 00214 00215 const typename ImageIterator<TImage>::IndexType& 00216 startIndex = m_Region.GetIndex(); 00217 const typename ImageIterator<TImage>::SizeType& 00218 size = m_Region.GetSize(); 00219 00220 // Increment along a row, then wrap at the end of the region row. 00221 bool done; 00222 unsigned int dim; 00223 00224 // Check to see if we are past the last pixel in the region 00225 // Note that ++ind[0] moves to the next pixel along the row. 00226 done = (++ind[0] == startIndex[0] + static_cast<typename Superclass::IndexValueType>(size[0])); 00227 for (unsigned int i=1; done && i < ImageIteratorDimension; i++) 00228 { 00229 done = (ind[i] == startIndex[i] + static_cast<typename Superclass::IndexValueType>(size[i]) - 1); 00230 } 00231 00232 // if the iterator is outside the region (but not past region end) then 00233 // we need to wrap around the region 00234 dim = 0; 00235 if (!done) 00236 { 00237 while ( ( dim+1 < ImageIteratorDimension ) 00238 && (ind[dim] > startIndex[dim] + static_cast<typename Superclass::IndexValueType>(size[dim]) - 1) ) 00239 { 00240 ind[dim] = startIndex[dim]; 00241 ind[++dim]++; 00242 } 00243 } 00244 m_Offset = m_Image->ComputeOffset( ind ); 00245 m_SpanEndOffset = m_Offset + static_cast<long>(size[0]); 00246 m_SpanBeginOffset = m_Offset; 00247 } 00248 return *this; 00249 } 00250 00258 Self & operator--() 00259 { 00260 if (--m_Offset < m_SpanBeginOffset) 00261 { 00262 // We have pasted the beginning of the span (row), need to wrap around. 00263 00264 // First move forward one pixel, because we are going to use a different 00265 // algorithm to compute the next pixel 00266 m_Offset++; 00267 00268 // Get the index of the first pixel on the span (row) 00269 typename ImageIterator<TImage>::IndexType 00270 ind = m_Image->ComputeIndex( static_cast<typename Superclass::IndexValueType>(m_Offset) ); 00271 00272 const typename ImageIterator<TImage>::IndexType& 00273 startIndex = m_Region.GetIndex(); 00274 const typename ImageIterator<TImage>::SizeType& 00275 size = m_Region.GetSize(); 00276 00277 // Deccrement along a row, then wrap at the beginning of the region row. 00278 bool done; 00279 unsigned int dim; 00280 00281 // Check to see if we are past the first pixel in the region 00282 // Note that --ind[0] moves to the previous pixel along the row. 00283 done = (--ind[0] == startIndex[0] - 1); 00284 for (unsigned int i=1; done && i < ImageIteratorDimension; i++) 00285 { 00286 done = (ind[i] == startIndex[i]); 00287 } 00288 00289 // if the iterator is outside the region (but not past region begin) then 00290 // we need to wrap around the region 00291 dim = 0; 00292 if (!done) 00293 { 00294 while ( (dim < ImageIteratorDimension - 1) 00295 && (ind[dim] < startIndex[dim]) ) 00296 { 00297 ind[dim] = startIndex[dim] + static_cast<typename Superclass::IndexValueType>(size[dim]) - 1; 00298 ind[++dim]--; 00299 } 00300 } 00301 m_Offset = m_Image->ComputeOffset( ind ); 00302 m_SpanEndOffset = m_Offset + 1; 00303 m_SpanBeginOffset = m_SpanEndOffset - static_cast<long>(size[0]); 00304 } 00305 return *this; 00306 } 00307 00308 protected: 00309 unsigned long m_SpanBeginOffset; // one pixel before the beginning of the span (row) 00310 unsigned long m_SpanEndOffset; // one pixel past the end of the span (row) 00311 00312 }; 00313 00314 } // end namespace itk 00315 00316 #ifndef ITK_MANUAL_INSTANTIATION 00317 #include "itkImageRegionConstIterator.txx" 00318 #endif 00319 00320 #endif

Generated at Sat Mar 31 02:21:40 2007 for ITK by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2000