ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkDefaultVectorPixelAccessor.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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  * http://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 
54  typedef unsigned int VectorLengthType;
55 
61 
63  typedef TType InternalType;
64 
66  inline void Set(InternalType & output, const ExternalType & input,
67  const unsigned long offset) const
68  {
69  InternalType *truePixel = ( &output ) + offset * m_OffsetMultiplier;
70 
71  for ( VectorLengthType i = 0; i < m_VectorLength; i++ )
72  {
73  truePixel[i] = input[i];
74  }
75  }
76 
78  inline ExternalType 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 
87  {
88  m_VectorLength = l;
89  m_OffsetMultiplier = ( l - 1 );
90  }
92 
94  VectorLengthType GetVectorLength() const { return m_VectorLength; }
95 
96  DefaultVectorPixelAccessor() : m_VectorLength(0), m_OffsetMultiplier(0) {}
97 
100  {
101  m_VectorLength = l;
102  m_OffsetMultiplier = l - 1;
103  }
104 
106 
107 private:
110 };
111 } // end namespace itk
112 
113 #endif
ExternalType Get(const InternalType &input, const SizeValueType offset) const
unsigned long SizeValueType
Definition: itkIntTypes.h:143
Give access to partial aspects of a type.
VariableLengthVector< TType > ExternalType
void Set(InternalType &output, const ExternalType &input, const unsigned long offset) const
Represents an array whose length can be defined at run-time.