ITK  5.2.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  * http://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  bool
120  operator!=(const ConstSliceIterator & orig) const
121  {
122  return !operator==(orig);
123  }
124 
128  bool
129  operator<(const ConstSliceIterator & orig) const
130  {
131  return this->m_Pos < orig.m_Pos && this->m_Slice.stride() == orig.m_Slice.stride() &&
132  this->m_Slice.start() == orig.m_Slice.start();
133  }
134 
135 private:
137  const TPixel &
139  {
140  return (*m_ContainerPointer)[static_cast<SizeValueType>(m_Slice.start() + n * m_Slice.stride())];
141  }
142 
144  const TContainer * m_ContainerPointer;
145 
148 
150  std::slice m_Slice;
151 };
152 } // end namespace itk
153 
154 #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:144
itk::ConstSliceIterator::m_Pos
SizeValueType m_Pos
Definition: itkConstSliceIterator.h:147
itkMacro.h
itk::ConstSliceIterator::Loc
const TPixel & Loc(SizeValueType n) const
Definition: itkConstSliceIterator.h:138
itkIntTypes.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ConstSliceIterator::operator==
bool operator==(const ConstSliceIterator &orig) const
Definition: itkConstSliceIterator.h:112
itk::ConstSliceIterator::operator!=
bool operator!=(const ConstSliceIterator &orig) const
Definition: itkConstSliceIterator.h:120
itk::ConstSliceIterator::m_Slice
std::slice m_Slice
Definition: itkConstSliceIterator.h:150
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
itk::ConstSliceIterator::operator++
ConstSliceIterator operator++(int)
Definition: itkConstSliceIterator.h:93
itk::ConstSliceIterator::operator<
bool operator<(const ConstSliceIterator &orig) const
Definition: itkConstSliceIterator.h:129
itk::ConstSliceIterator::Begin
ConstSliceIterator Begin()
Definition: itkConstSliceIterator.h:64