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 
25 namespace itk
26 {
50 template <typename TPixel, typename TContainer>
52 {
53 public:
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 
75  End()
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 
130 private:
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
itk::ConstSliceIterator
A flexible iterator for ITK containers(i.e. itk::Neighborhood) that support pixel access through oper...
Definition: itkConstSliceIterator.h:51
itk::ConstSliceIterator::operator*
const TPixel & operator*()
Definition: itkConstSliceIterator.h:107
itk::ConstSliceIterator::End
ConstSliceIterator End()
Definition: itkConstSliceIterator.h:75
itk::ConstSliceIterator::operator[]
const TPixel & operator[](SizeValueType n)
Definition: itkConstSliceIterator.h:103
itk::ConstSliceIterator::ConstSliceIterator
ConstSliceIterator(const TContainer *n, std::slice s)
Definition: itkConstSliceIterator.h:56
itk::ConstSliceIterator::operator++
ConstSliceIterator operator++()
Definition: itkConstSliceIterator.h:85
itk::ConstSliceIterator::m_ContainerPointer
const TContainer * m_ContainerPointer
Definition: itkConstSliceIterator.h:139
itk::ConstSliceIterator::m_Pos
SizeValueType m_Pos
Definition: itkConstSliceIterator.h:142
itkMacro.h
itk::ConstSliceIterator::Loc
const TPixel & Loc(SizeValueType n) const
Definition: itkConstSliceIterator.h:133
itkIntTypes.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::ConstSliceIterator::operator==
bool operator==(const ConstSliceIterator &orig) const
Definition: itkConstSliceIterator.h:112
itk::ConstSliceIterator::m_Slice
std::slice m_Slice
Definition: itkConstSliceIterator.h:145
itk::ConstSliceIterator::ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(ConstSliceIterator)
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:86
itk::ConstSliceIterator::operator++
ConstSliceIterator operator++(int)
Definition: itkConstSliceIterator.h:93
itk::ConstSliceIterator::operator<
bool operator<(const ConstSliceIterator &orig) const
Definition: itkConstSliceIterator.h:124
itk::ConstSliceIterator::Begin
ConstSliceIterator Begin()
Definition: itkConstSliceIterator.h:64