ITK  6.0.0
Insight Toolkit
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 
25 namespace itk
26 {
49 template <typename TType>
50 class ITK_TEMPLATE_EXPORT DefaultVectorPixelAccessor
51 {
52 public:
53  using VectorLengthType = unsigned int;
54 
60 
62  using InternalType = TType;
63 
65  inline void
66  Set(InternalType & output, const ExternalType & input, const unsigned long offset) const
67  {
68  InternalType * truePixel = (&output) + offset * m_OffsetMultiplier;
69 
70  for (VectorLengthType i = 0; i < m_VectorLength; ++i)
71  {
72  truePixel[i] = input[i];
73  }
74  }
75 
77  inline ExternalType
78  Get(const InternalType & input, const SizeValueType offset) const
79  {
80  // Do not create a local for this method, to use return value
81  // optimization.
82  return ExternalType((&input) + (offset * m_OffsetMultiplier), m_VectorLength);
83  }
84 
86  void
88  {
89  m_VectorLength = l;
90  m_OffsetMultiplier = (l - 1);
91  }
95  VectorLengthType
97  {
98  return m_VectorLength;
99  }
100 
101  DefaultVectorPixelAccessor() = default;
102 
105  {
106  m_VectorLength = l;
107  m_OffsetMultiplier = l - 1;
108  }
109 
110  ~DefaultVectorPixelAccessor() = default;
111 
112 private:
113  VectorLengthType m_VectorLength{ 0 };
114  VectorLengthType m_OffsetMultiplier{ 0 };
115 };
116 } // end namespace itk
117 
118 #endif
itkVariableLengthVector.h
itk::DefaultVectorPixelAccessor< TPixelType >::InternalType
TPixelType InternalType
Definition: itkDefaultVectorPixelAccessor.h:62
itk::DefaultVectorPixelAccessor::Get
ExternalType Get(const InternalType &input, const SizeValueType offset) const
Definition: itkDefaultVectorPixelAccessor.h:78
itk::DefaultVectorPixelAccessor
Give access to partial aspects of a type.
Definition: itkDefaultVectorPixelAccessor.h:50
itkMacro.h
itk::DefaultVectorPixelAccessor::Set
void Set(InternalType &output, const ExternalType &input, const unsigned long offset) const
Definition: itkDefaultVectorPixelAccessor.h:66
itk::VariableLengthVector
Represents an array whose length can be defined at run-time.
Definition: itkConstantBoundaryCondition.h:28
itkIntTypes.h
itk::DefaultVectorPixelAccessor::SetVectorLength
void SetVectorLength(VectorLengthType l)
Definition: itkDefaultVectorPixelAccessor.h:87
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::DefaultVectorPixelAccessor< TPixelType >::VectorLengthType
unsigned int VectorLengthType
Definition: itkDefaultVectorPixelAccessor.h:53
itk::DefaultVectorPixelAccessor::GetVectorLength
VectorLengthType GetVectorLength() const
Definition: itkDefaultVectorPixelAccessor.h:96
itk::DefaultVectorPixelAccessor::DefaultVectorPixelAccessor
DefaultVectorPixelAccessor(VectorLengthType l)
Definition: itkDefaultVectorPixelAccessor.h:104
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:86