VTK-m  2.0
VecVariable.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 #ifndef vtk_m_VecVariable_h
11 #define vtk_m_VecVariable_h
12 
13 #include <vtkm/Assert.h>
14 #include <vtkm/Math.h>
15 #include <vtkm/TypeTraits.h>
16 #include <vtkm/Types.h>
17 #include <vtkm/VecTraits.h>
18 
19 namespace vtkm
20 {
21 
29 template <typename T, vtkm::IdComponent MaxSize>
31 {
32 public:
33  using ComponentType = T;
34 
37  : NumComponents(0)
38  {
39  }
40 
41  template <typename SrcVecType>
42  VTKM_EXEC_CONT VecVariable(const SrcVecType& src)
44  {
45  VTKM_ASSERT(this->NumComponents <= MaxSize);
46  for (vtkm::IdComponent index = 0; index < this->NumComponents; index++)
47  {
48  this->Data[index] = src[index];
49  }
50  }
51 
53  inline vtkm::IdComponent GetNumberOfComponents() const { return this->NumComponents; }
54 
55  template <vtkm::IdComponent DestSize>
57  {
58  vtkm::IdComponent numComponents = vtkm::Min(DestSize, this->NumComponents);
59  for (vtkm::IdComponent index = 0; index < numComponents; index++)
60  {
61  dest[index] = this->Data[index];
62  }
63  }
64 
66  inline const ComponentType& operator[](vtkm::IdComponent index) const
67  {
68  VTKM_ASSERT(index >= 0 && index < this->NumComponents);
69  return this->Data[index];
70  }
71 
74  {
75  VTKM_ASSERT(index >= 0 && index < this->NumComponents);
76  return this->Data[index];
77  }
78 
80  void Append(ComponentType value)
81  {
82  VTKM_ASSERT(this->NumComponents < MaxSize);
83  this->Data[this->NumComponents] = value;
84  this->NumComponents++;
85  }
86 
87 private:
90 };
91 
92 template <typename T, vtkm::IdComponent MaxSize>
93 struct TypeTraits<vtkm::VecVariable<T, MaxSize>>
94 {
97 
100  {
102  }
103 };
104 
105 template <typename T, vtkm::IdComponent MaxSize>
106 struct VecTraits<vtkm::VecVariable<T, MaxSize>>
107 {
109 
114 
117  {
118  return vector.GetNumberOfComponents();
119  }
120 
122  static const ComponentType& GetComponent(const VecType& vector, vtkm::IdComponent componentIndex)
123  {
124  return vector[componentIndex];
125  }
127  static ComponentType& GetComponent(VecType& vector, vtkm::IdComponent componentIndex)
128  {
129  return vector[componentIndex];
130  }
131 
133  static void SetComponent(VecType& vector,
134  vtkm::IdComponent componentIndex,
135  const ComponentType& value)
136  {
137  vector[componentIndex] = value;
138  }
139 
140  template <typename NewComponentType>
142 
143  template <typename NewComponentType>
146  MaxSize>;
147 
148  template <vtkm::IdComponent destSize>
150  {
151  src.CopyInto(dest);
152  }
153 };
154 
155 } // namespace vtkm
156 
157 #endif //vtk_m_VecVariable_h
vtkm::VecTraits< vtkm::VecVariable< T, MaxSize > >::SetComponent
static VTKM_EXEC_CONT void SetComponent(VecType &vector, vtkm::IdComponent componentIndex, const ComponentType &value)
Definition: VecVariable.h:133
vtkm::VecTraits< vtkm::VecVariable< T, MaxSize > >::CopyInto
static VTKM_EXEC_CONT void CopyInto(const VecType &src, vtkm::Vec< ComponentType, destSize > &dest)
Definition: VecVariable.h:149
vtkm::VecTraitsTagMultipleComponents
A tag for vectors that are "true" vectors (i.e.
Definition: VecTraits.h:21
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::TypeTraits
The TypeTraits class provides helpful compile-time information about the basic types used in VTKm (an...
Definition: TypeTraits.h:61
Types.h
VTKM_ASSERT
#define VTKM_ASSERT(condition)
Definition: Assert.h:43
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
vtkm::TypeTraits< vtkm::VecVariable< T, MaxSize > >::ZeroInitialization
static VTKM_EXEC_CONT vtkm::VecVariable< T, MaxSize > ZeroInitialization()
Definition: VecVariable.h:99
vtkm::VecVariable::NumComponents
vtkm::IdComponent NumComponents
Definition: VecVariable.h:89
Assert.h
vtkm::VecTraits::BaseComponentType
typename vtkm::VecTraits< ComponentType >::BaseComponentType BaseComponentType
Base component type in the vector.
Definition: VecTraits.h:80
vtkm::VecVariable::CopyInto
VTKM_EXEC_CONT void CopyInto(vtkm::Vec< ComponentType, DestSize > &dest) const
Definition: VecVariable.h:56
TypeTraits.h
vtkm::VecTraits< vtkm::VecVariable< T, MaxSize > >::GetComponent
static const VTKM_EXEC_CONT ComponentType & GetComponent(const VecType &vector, vtkm::IdComponent componentIndex)
Definition: VecVariable.h:122
vtkm::VecVariable::GetNumberOfComponents
VTKM_EXEC_CONT vtkm::IdComponent GetNumberOfComponents() const
Definition: VecVariable.h:53
vtkm::VecTraitsTagSizeVariable
A tag for vectors where the number of components are not determined until run time.
Definition: VecTraits.h:41
vtkm::VecVariable::VecVariable
VTKM_EXEC_CONT VecVariable()
Definition: VecVariable.h:36
Math.h
vtkm::VecVariable::Append
VTKM_EXEC_CONT void Append(ComponentType value)
Definition: VecVariable.h:80
vtkm::VecVariable
A short variable-length array with maximum length.
Definition: VecVariable.h:30
vtkm::VecVariable::VecVariable
VTKM_EXEC_CONT VecVariable(const SrcVecType &src)
Definition: VecVariable.h:42
vtkm::VecTraits< vtkm::VecVariable< T, MaxSize > >::GetNumberOfComponents
static VTKM_EXEC_CONT vtkm::IdComponent GetNumberOfComponents(const VecType &vector)
Definition: VecVariable.h:116
vtkm::VecVariable::operator[]
const VTKM_EXEC_CONT ComponentType & operator[](vtkm::IdComponent index) const
Definition: VecVariable.h:66
vtkm::VecTraits< vtkm::VecVariable< T, MaxSize > >::GetComponent
static VTKM_EXEC_CONT ComponentType & GetComponent(VecType &vector, vtkm::IdComponent componentIndex)
Definition: VecVariable.h:127
vtkm::TypeTraitsUnknownTag
Tag used to identify types that aren't Real, Integer, Scalar or Vector.
Definition: TypeTraits.h:20
vtkm::TypeTraitsVectorTag
Tag used to identify 1 dimensional types (vectors).
Definition: TypeTraits.h:51
vtkm::Vec
A short fixed-length array.
Definition: Types.h:767
vtkm::VecTraits< vtkm::VecVariable< T, MaxSize > >::BaseComponentType
typename vtkm::VecTraits< ComponentType >::BaseComponentType BaseComponentType
Definition: VecVariable.h:111
vtkm::VecTraits
The VecTraits class gives several static members that define how to use a given type as a vector.
Definition: VecTraits.h:66
vtkm::TypeTraits< vtkm::VecVariable< T, MaxSize > >::NumericTag
typename vtkm::TypeTraits< T >::NumericTag NumericTag
Definition: VecVariable.h:95
vtkm::VecVariable::ComponentType
T ComponentType
Definition: VecVariable.h:33
VecTraits.h
vtkm::VecTraits< vtkm::VecVariable< T, MaxSize > >::ComponentType
typename VecType::ComponentType ComponentType
Definition: VecVariable.h:110
vtkm::VecVariable::operator[]
VTKM_EXEC_CONT ComponentType & operator[](vtkm::IdComponent index)
Definition: VecVariable.h:73
vtkm::VecVariable::Data
vtkm::Vec< T, MaxSize > Data
Definition: VecVariable.h:88