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{
54
55template <typename T, typename TContainer>
57{
58public:
61
63 using ExternalType = T;
64
67 using InternalType = TContainer;
68
70 inline void
75
77 [[nodiscard]] inline ExternalType
78 Get(const InternalType & input) const
79 {
81 }
82
84 [[nodiscard]] unsigned int
86 {
87 return m_ElementNumber;
88 }
89
91 void
92 SetElementNumber(unsigned int nth)
93 {
94 m_ElementNumber = nth;
95 }
96
99 bool
100 operator==(const Self & accessor) const
101 {
102 return m_ElementNumber == accessor.m_ElementNumber;
103 }
104
106
107private:
108 // Identifier of the N-th element to be accessed
109 unsigned int m_ElementNumber{ 0 };
110};
111
112
113template <typename TOutputPixelType, typename TPixelType>
114class NthElementPixelAccessor<TOutputPixelType, VariableLengthVector<TPixelType>>
115 : private DefaultVectorPixelAccessor<TPixelType>
116{
117public:
120
121 using VectorLengthType = unsigned int;
122
125 using ExternalType = TOutputPixelType;
126
128 using InternalType = TPixelType;
129
131
132 inline void
133 Set(ActualPixelType & output, const ExternalType & input) const
134 {
135 output[m_ElementNumber] = input;
136 }
137
138 inline void
139 Set(InternalType & output, const ExternalType & input, const SizeValueType offset) const
140 {
141 // note: v is a reference to the internal buffer, this method of
142 // access relies on return value optimization to work
143 ActualPixelType v = Superclass::Get(output, offset);
144
145 return Set(v, input);
146 }
147
148 [[nodiscard]] inline ExternalType
149 Get(const ActualPixelType & input) const
150 {
151 const auto output = static_cast<ExternalType>(input[m_ElementNumber]);
152 return output;
153 }
154
155 [[nodiscard]] inline ExternalType
156 Get(const InternalType & input, const SizeValueType offset) const
157 {
158 return Get(Superclass::Get(input, offset));
159 }
160
161
163 [[nodiscard]] unsigned int
165 {
166 return m_ElementNumber;
167 }
168
170 void
171 SetElementNumber(unsigned int nth)
172 {
173 m_ElementNumber = nth;
174 }
175
177 void
182
184 [[nodiscard]] VectorLengthType
186 {
188 }
189
190 NthElementPixelAccessor(unsigned int length = 1) { Superclass::SetVectorLength(length); }
191
194 bool
195 operator==(const Self & accessor) const
196 {
197 return m_ElementNumber == accessor.m_ElementNumber;
198 }
199
201
202protected:
204
205private:
207};
208
209} // end namespace itk
210
211#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
void Set(InternalType &output, const ExternalType &input, const SizeValueType offset) const
ExternalType Get(const InternalType &input, const SizeValueType offset) const
Give access to the N-th of a Container type.
void Set(InternalType &output, const ExternalType &input) const
ExternalType Get(const InternalType &input) const
bool operator==(const Self &accessor) const
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition itkIntTypes.h:86