ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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{
49template <typename TPixel, typename TContainer>
51{
52public:
53
55 ConstSliceIterator(const TContainer * n, std::slice s)
57 , m_Slice(s)
58 {}
59
63 {
64 ConstSliceIterator ans = *this;
65
66 ans.m_Pos = 0;
67 return ans;
68 }
69
74 {
75 ConstSliceIterator ans = *this;
76
77 ans.m_Pos = static_cast<SizeValueType>(m_Slice.size());
78 return ans;
79 }
80
84 {
85 ++m_Pos;
86 return *this;
87 }
88
92 {
93 ConstSliceIterator ans = *this;
94
95 ++m_Pos;
96 return ans;
97 }
98
101 const TPixel &
103 {
104 return this->Loc(m_Pos = n);
105 }
106
109 const TPixel &
111 {
112 return Loc(m_Pos);
113 }
114
117 bool
118 operator==(const ConstSliceIterator & orig) const
119 {
120 return orig.m_Pos == this->m_Pos && orig.m_Slice.stride() == this->m_Slice.stride() &&
121 orig.m_Slice.start() == this->m_Slice.start();
122 }
123
125
129 bool
130 operator<(const ConstSliceIterator & orig) const
131 {
132 return this->m_Pos < orig.m_Pos && this->m_Slice.stride() == orig.m_Slice.stride() &&
133 this->m_Slice.start() == orig.m_Slice.start();
134 }
135
136private:
138 const TPixel &
140 {
141 return (*m_ContainerPointer)[static_cast<SizeValueType>(m_Slice.start() + n * m_Slice.stride())];
142 }
143
145 const TContainer * m_ContainerPointer;
146
149
151 std::slice m_Slice;
152};
153} // end namespace itk
154
155#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)
bool operator<(const ConstSliceIterator &orig) const
ConstSliceIterator operator++()
const TContainer * m_ContainerPointer
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(ConstSliceIterator)
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