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_Slice(s)
59  {}
60 
64  {
65  ConstSliceIterator ans = *this;
66 
67  ans.m_Pos = 0;
68  return ans;
69  }
70 
74  End()
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 
137 private:
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
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:111
itk::ConstSliceIterator::End
ConstSliceIterator End()
Definition: itkConstSliceIterator.h:74
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:84
itk::ConstSliceIterator::m_ContainerPointer
const TContainer * m_ContainerPointer
Definition: itkConstSliceIterator.h:146
itk::ConstSliceIterator::m_Pos
SizeValueType m_Pos
Definition: itkConstSliceIterator.h:149
itkMacro.h
itk::ConstSliceIterator::Loc
const TPixel & Loc(SizeValueType n) const
Definition: itkConstSliceIterator.h:140
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:119
itk::ConstSliceIterator::m_Slice
std::slice m_Slice
Definition: itkConstSliceIterator.h:152
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:92
itk::ConstSliceIterator::operator<
bool operator<(const ConstSliceIterator &orig) const
Definition: itkConstSliceIterator.h:131
itk::ConstSliceIterator::Begin
ConstSliceIterator Begin()
Definition: itkConstSliceIterator.h:63