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_Slice(s)
59 {}
60
64 {
65 ConstSliceIterator ans = *this;
66
67 ans.m_Pos = 0;
68 return ans;
69 }
70
75 {
76 ConstSliceIterator ans = *this;
77
78 ans.m_Pos = static_cast<SizeValueType>(m_Slice.size());
79 return ans;
80 }
81
85 {
86 ++m_Pos;
87 return *this;
88 }
89
93 {
94 ConstSliceIterator ans = *this;
95
96 ++m_Pos;
97 return ans;
98 }
99
102 const TPixel &
104 {
105 return this->Loc(m_Pos = n);
106 }
107
110 const TPixel &
112 {
113 return Loc(m_Pos);
114 }
115
118 bool
119 operator==(const ConstSliceIterator & orig) const
120 {
121 return orig.m_Pos == this->m_Pos && orig.m_Slice.stride() == this->m_Slice.stride() &&
122 orig.m_Slice.start() == this->m_Slice.start();
123 }
124
126
130 bool
131 operator<(const ConstSliceIterator & orig) const
132 {
133 return this->m_Pos < orig.m_Pos && this->m_Slice.stride() == orig.m_Slice.stride() &&
134 this->m_Slice.start() == orig.m_Slice.start();
135 }
136
137private:
139 const TPixel &
141 {
142 return (*m_ContainerPointer)[static_cast<SizeValueType>(m_Slice.start() + n * m_Slice.stride())];
143 }
144
146 const TContainer * m_ContainerPointer;
147
150
152 std::slice m_Slice;
153};
154} // end namespace itk
155
156#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