ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkNthElementPixelAccessor.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 itkNthElementPixelAccessor_h
19#define itkNthElementPixelAccessor_h
20
21#include "itkMacro.h"
25
26namespace itk
27{
51
52template <typename T, typename TContainer>
54{
55public:
58
60 using ExternalType = T;
61
64 using InternalType = TContainer;
65
67 inline void
72
74 [[nodiscard]] inline ExternalType
75 Get(const InternalType & input) const
76 {
78 }
79
81 [[nodiscard]] unsigned int
83 {
84 return m_ElementNumber;
85 }
86
88 void
89 SetElementNumber(unsigned int nth)
90 {
91 m_ElementNumber = nth;
92 }
93
96 bool
97 operator==(const Self & accessor) const
98 {
99 return m_ElementNumber == accessor.m_ElementNumber;
100 }
101
103
106 operator=(const NthElementPixelAccessor & accessor) = default;
107
110
111private:
112 // Identifier of the N-th element to be accessed
113 unsigned int m_ElementNumber{ 0 };
114};
115
116
117template <typename TOutputPixelType, typename TPixelType>
118class NthElementPixelAccessor<TOutputPixelType, itk::VariableLengthVector<TPixelType>>
119 : private DefaultVectorPixelAccessor<TPixelType>
120{
121public:
124
125 using VectorLengthType = unsigned int;
126
129 using ExternalType = TOutputPixelType;
130
132 using InternalType = TPixelType;
133
135
136 inline void
137 Set(ActualPixelType & output, const ExternalType & input) const
138 {
139 output[m_ElementNumber] = input;
140 }
141
142 inline void
143 Set(InternalType & output, const ExternalType & input, const SizeValueType offset) const
144 {
145 // note: v is a reference to the internal buffer, this method of
146 // access relies on return value optimization to work
147 ActualPixelType v = Superclass::Get(output, offset);
148
149 return Set(v, input);
150 }
151
152 [[nodiscard]] inline ExternalType
153 Get(const ActualPixelType & input) const
154 {
155 const auto output = static_cast<ExternalType>(input[m_ElementNumber]);
156 return output;
157 }
158
159 [[nodiscard]] inline ExternalType
160 Get(const InternalType & input, const SizeValueType offset) const
161 {
162 return Get(Superclass::Get(input, offset));
163 }
164
165
167 [[nodiscard]] unsigned int
169 {
170 return m_ElementNumber;
171 }
172
174 void
175 SetElementNumber(unsigned int nth)
176 {
177 m_ElementNumber = nth;
178 }
179
181 void
186
188 [[nodiscard]] VectorLengthType
190 {
192 }
193
194 NthElementPixelAccessor(unsigned int length = 1) { Superclass::SetVectorLength(length); }
195
198 bool
199 operator==(const Self & accessor) const
200 {
201 return m_ElementNumber == accessor.m_ElementNumber;
202 }
203
205
209 {
211 this->SetVectorLength(accessor.GetVectorLength());
212 return *this;
213 }
214
215protected:
217
218private:
220};
221
222} // end namespace itk
223
224#endif
static ComponentType GetNthComponent(int c, const PixelType &pixel)
static void SetNthComponent(int c, PixelType &pixel, const ComponentType &v)
ExternalType Get(const InternalType &input, const SizeValueType offset) const
ExternalType Get(const InternalType &input, const SizeValueType offset) const
void Set(InternalType &output, const ExternalType &input, const SizeValueType offset) const
void Set(InternalType &output, const ExternalType &input) const
ExternalType Get(const InternalType &input) const
bool operator==(const Self &accessor) const
NthElementPixelAccessor & operator=(const NthElementPixelAccessor &accessor)=default
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition itkIntTypes.h:86