ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkConstSliceIterator_h 00019 #define __itkConstSliceIterator_h 00020 00021 #include "itkMacro.h" 00022 #include "itkIntTypes.h" 00023 #include <valarray> 00024 00025 namespace itk 00026 { 00050 template< class TPixel, class TContainer > 00051 class ITK_EXPORT ConstSliceIterator 00052 { 00053 public: 00054 00056 ConstSliceIterator(const TContainer *n, std::slice s): 00057 m_ContainerPointer(n), m_Pos(0), m_Slice(s) {} 00058 00060 ConstSliceIterator Begin() 00061 { 00062 ConstSliceIterator ans = *this; 00063 00064 ans.m_Pos = 0; 00065 return ans; 00066 } 00067 00070 ConstSliceIterator End() 00071 { 00072 ConstSliceIterator ans = *this; 00073 00074 ans.m_Pos = static_cast< SizeValueType >( m_Slice.size() ); 00075 return ans; 00076 } 00077 00079 ConstSliceIterator operator++() 00080 { 00081 m_Pos++; 00082 return *this; 00083 } 00084 00086 ConstSliceIterator operator++(int) 00087 { 00088 ConstSliceIterator ans = *this; 00089 00090 m_Pos++; 00091 return ans; 00092 } 00093 00096 const TPixel & operator[](SizeValueType n) 00097 { 00098 return this->Loc(m_Pos = n); 00099 } 00100 00103 const TPixel & operator*() 00104 { 00105 return Loc(m_Pos); 00106 } 00107 00110 bool operator==(const ConstSliceIterator & orig) 00111 { 00112 return orig.m_Pos == this->m_Pos 00113 && orig.m_Slice.stride() == this->m_Slice.stride() 00114 && orig.m_Slice.start() == this->m_Slice.start(); 00115 } 00116 00118 bool operator!=(const ConstSliceIterator & orig) 00119 { 00120 return !operator==(orig); 00121 } 00122 00126 bool operator<(const ConstSliceIterator & orig) 00127 { 00128 return this->m_Pos < orig.m_Pos 00129 && this->m_Slice.stride() == orig.m_Slice.stride() 00130 && this->m_Slice.start() == orig.m_Slice.start(); 00131 } 00132 00133 private: 00135 const TPixel & Loc(SizeValueType n) const 00136 { 00137 return ( *m_ContainerPointer )[static_cast< SizeValueType >( m_Slice.start() + n * m_Slice.stride())]; 00138 } 00139 00141 const TContainer *m_ContainerPointer; 00142 00144 SizeValueType m_Pos; 00145 00147 std::slice m_Slice; 00148 }; 00149 } // end namespace itk 00150 00151 #endif 00152