ITK  6.0.0
Insight Toolkit
itkConstSliceIterator.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
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 * https://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
25namespace itk
26{
50template <typename TPixel, typename TContainer>
52{
53public:
54
56 ConstSliceIterator(const TContainer * n, std::slice s)
58 , m_Pos(0)
59 , m_Slice(s)
60 {}
61
65 {
66 ConstSliceIterator ans = *this;
67
68 ans.m_Pos = 0;
69 return ans;
70 }
71
76 {
77 ConstSliceIterator ans = *this;
78
79 ans.m_Pos = static_cast<SizeValueType>(m_Slice.size());
80 return ans;
81 }
82
86 {
87 ++m_Pos;
88 return *this;
89 }
90
94 {
95 ConstSliceIterator ans = *this;
96
97 ++m_Pos;
98 return ans;
99 }
100
103 const TPixel & operator[](SizeValueType n) { return this->Loc(m_Pos = n); }
104
107 const TPixel & operator*() { return Loc(m_Pos); }
108
111 bool
112 operator==(const ConstSliceIterator & orig) const
113 {
114 return orig.m_Pos == this->m_Pos && orig.m_Slice.stride() == this->m_Slice.stride() &&
115 orig.m_Slice.start() == this->m_Slice.start();
116 }
117
119
123 bool
124 operator<(const ConstSliceIterator & orig) const
125 {
126 return this->m_Pos < orig.m_Pos && this->m_Slice.stride() == orig.m_Slice.stride() &&
127 this->m_Slice.start() == orig.m_Slice.start();
128 }
129
130private:
132 const TPixel &
134 {
135 return (*m_ContainerPointer)[static_cast<SizeValueType>(m_Slice.start() + n * m_Slice.stride())];
136 }
137
139 const TContainer * m_ContainerPointer;
140
143
145 std::slice m_Slice;
146};
147} // end namespace itk
148
149#endif
A flexible iterator for ITK containers(i.e. itk::Neighborhood) that support pixel access through oper...
const TPixel & operator[](SizeValueType n)
const TPixel & Loc(SizeValueType n) const
bool operator==(const ConstSliceIterator &orig) const
ConstSliceIterator operator++(int)
ConstSliceIterator End()
bool operator<(const ConstSliceIterator &orig) const
ConstSliceIterator operator++()
const TContainer * m_ContainerPointer
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(ConstSliceIterator)
ConstSliceIterator Begin()
ConstSliceIterator(const TContainer *n, std::slice s)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition: itkIntTypes.h:86