ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkDefaultVectorPixelAccessor.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 itkDefaultVectorPixelAccessor_h
19#define itkDefaultVectorPixelAccessor_h
20
21#include "itkMacro.h"
23#include "itkIntTypes.h"
24#include <algorithm> // for std::min
25
26namespace itk
27{
50template <typename TType>
51class ITK_TEMPLATE_EXPORT DefaultVectorPixelAccessor
52{
53public:
54 using VectorLengthType = unsigned int;
55
61
63 using InternalType = TType;
64
75 inline void
76 Set(InternalType & output, const ExternalType & input, const SizeValueType offset) const
77 {
78 InternalType * truePixel = (&output) + offset * m_OffsetMultiplier;
79
80 // A well-formed caller passes a source of length 0 (sentinel / no-op)
81 // or exactly m_VectorLength. Anything else is a caller bug that was
82 // silently masked by the pre-1d87efa5 allocation behavior; catch it
83 // in debug builds.
84 itkAssertInDebugAndIgnoreInReleaseMacro(input.GetSize() == 0 || input.GetSize() == m_VectorLength);
85
86 const VectorLengthType copyLength = std::min<VectorLengthType>(m_VectorLength, input.GetSize());
87
88 for (VectorLengthType i = 0; i < copyLength; ++i)
89 {
90 truePixel[i] = input[i];
91 }
92 }
93
95 [[nodiscard]] inline ExternalType
96 Get(const InternalType & input, const SizeValueType offset) const
97 {
98 // Do not create a local for this method, to use return value
99 // optimization.
100 return ExternalType((&input) + (offset * m_OffsetMultiplier), m_VectorLength);
101 }
102
104 void
110
112 [[nodiscard]] VectorLengthType
114 {
115 return m_VectorLength;
116 }
117
119
125
127
128private:
131};
132} // end namespace itk
133
134#endif
VariableLengthVector< TType > ExternalType
ExternalType Get(const InternalType &input, const SizeValueType offset) const
void Set(InternalType &output, const ExternalType &input, const SizeValueType offset) const
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition itkIntTypes.h:86