ITK  4.6.0
Insight Segmentation and Registration Toolkit
itkConstSliceIterator.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkConstSliceIterator_h
19 #define __itkConstSliceIterator_h
20 
21 #include "itkMacro.h"
22 #include "itkIntTypes.h"
23 #include <valarray>
24 
25 namespace itk
26 {
50 template< typename TPixel, typename TContainer >
52 {
53 public:
54 
56  ConstSliceIterator(const TContainer *n, std::slice s):
57  m_ContainerPointer(n), m_Pos(0), m_Slice(s) {}
58 
61  {
62  ConstSliceIterator ans = *this;
63 
64  ans.m_Pos = 0;
65  return ans;
66  }
67 
71  {
72  ConstSliceIterator ans = *this;
73 
74  ans.m_Pos = static_cast< SizeValueType >( m_Slice.size() );
75  return ans;
76  }
77 
80  {
81  m_Pos++;
82  return *this;
83  }
84 
87  {
88  ConstSliceIterator ans = *this;
89 
90  m_Pos++;
91  return ans;
92  }
93 
96  const TPixel & operator[](SizeValueType n)
97  {
98  return this->Loc(m_Pos = n);
99  }
100 
103  const TPixel & operator*()
104  {
105  return Loc(m_Pos);
106  }
107 
110  bool operator==(const ConstSliceIterator & orig)
111  {
112  return orig.m_Pos == this->m_Pos
113  && orig.m_Slice.stride() == this->m_Slice.stride()
114  && orig.m_Slice.start() == this->m_Slice.start();
115  }
116 
118  bool operator!=(const ConstSliceIterator & orig)
119  {
120  return !operator==(orig);
121  }
122 
126  bool operator<(const ConstSliceIterator & orig)
127  {
128  return this->m_Pos < orig.m_Pos
129  && this->m_Slice.stride() == orig.m_Slice.stride()
130  && this->m_Slice.start() == orig.m_Slice.start();
131  }
132 
133 private:
135  const TPixel & Loc(SizeValueType n) const
136  {
137  return ( *m_ContainerPointer )[static_cast< SizeValueType >( m_Slice.start() + n * m_Slice.stride())];
138  }
139 
141  const TContainer *m_ContainerPointer;
142 
145 
147  std::slice m_Slice;
148 };
149 } // end namespace itk
150 
151 #endif
bool operator!=(const ConstSliceIterator &orig)
ConstSliceIterator operator++(int)
ConstSliceIterator(const TContainer *n, std::slice s)
unsigned long SizeValueType
Definition: itkIntTypes.h:143
bool operator<(const ConstSliceIterator &orig)
const TPixel & operator[](SizeValueType n)
const TPixel & Loc(SizeValueType n) const
ConstSliceIterator operator++()
ConstSliceIterator End()
bool operator==(const ConstSliceIterator &orig)
A flexible iterator for ITK containers(i.e. itk::Neighborhood) that support pixel access through oper...
const TContainer * m_ContainerPointer
ConstSliceIterator Begin()