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

itkSliceIterator.h

Go to the documentation of this file.
00001 /*========================================================================= 00002 00003 Program: Insight Segmentation & Registration Toolkit 00004 Module: $RCSfile: itkSliceIterator.h,v $ 00005 Language: C++ 00006 Date: $Date: 2003/09/10 14:29:26 $ 00007 Version: $Revision: 1.12 $ 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 __itkSliceIterator_h 00018 #define __itkSliceIterator_h 00019 00020 #include "itkMacro.h" 00021 #include "itkExceptionObject.h" 00022 #include <valarray> 00023 namespace itk { 00024 00044 template<class TPixel, class TContainer> 00045 class ITK_EXPORT SliceIterator 00046 { 00047 public: 00049 SliceIterator(TContainer *n, std::slice s) 00050 : m_ContainerPointer(n), m_Pos(0), m_Slice(s) {} 00051 00053 SliceIterator Begin() 00054 { 00055 SliceIterator ans = *this; 00056 ans.m_Pos = 0; 00057 return ans; 00058 } 00059 00061 SliceIterator End() 00062 { 00063 SliceIterator ans = *this; 00064 ans.m_Pos = static_cast<unsigned long>(m_Slice.size()); 00065 return ans; 00066 } 00067 00069 SliceIterator operator++() 00070 { 00071 m_Pos++; 00072 return *this; 00073 } 00074 00076 SliceIterator operator++(int) 00077 { 00078 SliceIterator ans = *this; 00079 m_Pos++; 00080 return ans; 00081 } 00082 00085 TPixel& operator[](unsigned long n) 00086 { return this->Loc(m_Pos=n); } 00087 00090 TPixel& operator*() 00091 { return Loc(m_Pos); } 00092 00095 bool operator==(const SliceIterator &orig) 00096 { 00097 return orig.m_Pos==this->m_Pos 00098 && orig.m_Slice.stride()==this->m_Slice.stride() 00099 && orig.m_Slice.start() ==this->m_Slice.start(); 00100 } 00101 00103 bool operator!=(const SliceIterator &orig) 00104 { 00105 return ! operator==(orig); 00106 } 00107 00111 bool operator<(const SliceIterator &orig) 00112 { 00113 return this->m_Pos < orig.m_Pos 00114 && this->m_Slice.stride()==orig.m_Slice.stride() 00115 && this->m_Slice.start()==orig.m_Slice.start(); 00116 } 00117 00118 private: 00120 TPixel& Loc(unsigned long n) const 00121 { 00122 const unsigned long start = static_cast<unsigned long>( m_Slice.start() ); 00123 const unsigned long stride = static_cast<unsigned long>( m_Slice.stride() ); 00124 return (*m_ContainerPointer)[ start + n * stride ]; 00125 } 00126 00128 TContainer *m_ContainerPointer; 00129 00131 unsigned long m_Pos; 00132 00134 std::slice m_Slice; 00135 }; 00136 00137 } // end namespace itk 00138 00139 #endif

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