ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkSliceIterator.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 itkSliceIterator_h
19#define itkSliceIterator_h
20
21#include "itkMacro.h"
22#include "itkIntTypes.h"
23#include <valarray>
24
25namespace itk
26{
46template <typename TPixel, typename TContainer>
48{
49public:
51 SliceIterator(TContainer * n, std::slice s)
53 , m_Slice(s)
54 {}
55
59 {
60 SliceIterator ans = *this;
61
62 ans.m_Pos = 0;
63 return ans;
64 }
65
69 {
70 SliceIterator ans = *this;
71
72 ans.m_Pos = static_cast<OffsetValueType>(m_Slice.size());
73 return ans;
74 }
75
79 {
80 ++m_Pos;
81 return *this;
82 }
83
87 {
88 SliceIterator ans = *this;
89
90 ++m_Pos;
91 return ans;
92 }
93
96 TPixel &
98 {
99 return this->Loc(m_Pos = n);
100 }
101
104 TPixel &
106 {
107 return Loc(m_Pos);
108 }
109
112 bool
113 operator==(const SliceIterator & orig) const
114 {
115 return orig.m_Pos == this->m_Pos && orig.m_Slice.stride() == this->m_Slice.stride() &&
116 orig.m_Slice.start() == this->m_Slice.start();
117 }
118
120
124 bool
125 operator<(const SliceIterator & orig) const
126 {
127 return this->m_Pos < orig.m_Pos && this->m_Slice.stride() == orig.m_Slice.stride() &&
128 this->m_Slice.start() == orig.m_Slice.start();
129 }
130
131private:
133 TPixel &
135 {
136 const auto start = static_cast<OffsetValueType>(m_Slice.start());
137 const auto stride = static_cast<OffsetValueType>(m_Slice.stride());
139
140 return (*m_ContainerPointer)[start + n * stride];
141 }
142
144 TContainer * m_ContainerPointer;
145
148
150 std::slice m_Slice;
151};
152} // end namespace itk
153
154#endif
A flexible iterator for itk containers(i.e. itk::Neighborhood) that support pixel access through oper...
OffsetValueType m_Pos
SliceIterator End()
SliceIterator Begin()
SliceIterator operator++(int)
TPixel & operator[](OffsetValueType n)
TPixel & Loc(OffsetValueType n) const
SliceIterator(TContainer *n, std::slice s)
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(SliceIterator)
bool operator==(const SliceIterator &orig) const
bool operator<(const SliceIterator &orig) const
SliceIterator operator++()
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
long OffsetValueType
Definition itkIntTypes.h:97