Viskores  1.0
VecVariable.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 #ifndef viskores_VecVariable_h
19 #define viskores_VecVariable_h
20 
21 #include <viskores/Assert.h>
22 #include <viskores/Math.h>
23 #include <viskores/TypeTraits.h>
24 #include <viskores/Types.h>
25 #include <viskores/VecTraits.h>
26 
27 namespace viskores
28 {
29 
37 template <typename T, viskores::IdComponent MaxSize>
39 {
40 public:
41  using ComponentType = T;
42 
45  : NumComponents(0)
46  {
47  }
48 
49  template <typename SrcVecType>
50  VISKORES_EXEC_CONT VecVariable(const SrcVecType& src)
52  {
53  VISKORES_ASSERT(this->NumComponents <= MaxSize);
54  for (viskores::IdComponent index = 0; index < this->NumComponents; index++)
55  {
56  this->Data[index] = src[index];
57  }
58  }
59 
62 
63  template <viskores::IdComponent DestSize>
65  {
66  viskores::IdComponent numComponents = viskores::Min(DestSize, this->NumComponents);
67  for (viskores::IdComponent index = 0; index < numComponents; index++)
68  {
69  dest[index] = this->Data[index];
70  }
71  }
72 
74  inline const ComponentType& operator[](viskores::IdComponent index) const
75  {
76  VISKORES_ASSERT(index >= 0 && index < this->NumComponents);
77  return this->Data[index];
78  }
79 
82  {
83  VISKORES_ASSERT(index >= 0 && index < this->NumComponents);
84  return this->Data[index];
85  }
86 
88  void Append(ComponentType value)
89  {
90  VISKORES_ASSERT(this->NumComponents < MaxSize);
91  this->Data[this->NumComponents] = value;
92  this->NumComponents++;
93  }
94 
95 private:
98 };
99 
100 template <typename T, viskores::IdComponent MaxSize>
101 struct TypeTraits<viskores::VecVariable<T, MaxSize>>
102 {
105 
108  {
110  }
111 };
112 
113 template <typename T, viskores::IdComponent MaxSize>
114 struct VecTraits<viskores::VecVariable<T, MaxSize>>
115 {
117 
122 
125  {
126  return vector.GetNumberOfComponents();
127  }
128 
130  static const ComponentType& GetComponent(const VecType& vector,
131  viskores::IdComponent componentIndex)
132  {
133  return vector[componentIndex];
134  }
136  static ComponentType& GetComponent(VecType& vector, viskores::IdComponent componentIndex)
137  {
138  return vector[componentIndex];
139  }
140 
142  static void SetComponent(VecType& vector,
143  viskores::IdComponent componentIndex,
144  const ComponentType& value)
145  {
146  vector[componentIndex] = value;
147  }
148 
149  template <typename NewComponentType>
151 
152  template <typename NewComponentType>
156  MaxSize>;
157 
158  template <viskores::IdComponent destSize>
159  VISKORES_EXEC_CONT static void CopyInto(const VecType& src,
161  {
162  src.CopyInto(dest);
163  }
164 };
165 
166 } // namespace viskores
167 
168 #endif //viskores_VecVariable_h
viskores::TypeTraits< viskores::VecVariable< T, MaxSize > >::ZeroInitialization
static viskores::VecVariable< T, MaxSize > ZeroInitialization()
Definition: VecVariable.h:107
viskores::TypeTraits< viskores::VecVariable< T, MaxSize > >::NumericTag
typename viskores::TypeTraits< T >::NumericTag NumericTag
Definition: VecVariable.h:103
Types.h
viskores::VecVariable
A short variable-length array with maximum length.
Definition: VecVariable.h:38
viskores::VecTraitsTagSizeVariable
A tag for vectors where the number of components are not determined until run time.
Definition: VecTraits.h:51
viskores::VecTraitsTagMultipleComponents
A tag for vectors that are "true" vectors (i.e.
Definition: VecTraits.h:31
Assert.h
viskores::IdComponent
viskores::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:202
viskores::VecTraits< viskores::VecVariable< T, MaxSize > >::ComponentType
typename VecType::ComponentType ComponentType
Definition: VecVariable.h:118
VISKORES_EXEC_CONT
#define VISKORES_EXEC_CONT
Definition: ExportMacros.h:60
viskores::VecVariable::Append
void Append(ComponentType value)
Definition: VecVariable.h:88
viskores::VecTraits< viskores::VecVariable< T, MaxSize > >::GetNumberOfComponents
static viskores::IdComponent GetNumberOfComponents(const VecType &vector)
Definition: VecVariable.h:124
viskores::VecVariable::GetNumberOfComponents
viskores::IdComponent GetNumberOfComponents() const
Definition: VecVariable.h:61
viskores::VecTraits< viskores::VecVariable< T, MaxSize > >::CopyInto
static void CopyInto(const VecType &src, viskores::Vec< ComponentType, destSize > &dest)
Definition: VecVariable.h:159
TypeTraits.h
viskores::TypeTraits
The TypeTraits class provides helpful compile-time information about the basic types used in Viskores...
Definition: TypeTraits.h:69
viskores::VecVariable::operator[]
const ComponentType & operator[](viskores::IdComponent index) const
Definition: VecVariable.h:74
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
Math.h
viskores::TypeTraitsUnknownTag
Tag used to identify types that aren't Real, Integer, Scalar or Vector.
Definition: TypeTraits.h:28
viskores::VecVariable::NumComponents
viskores::IdComponent NumComponents
Definition: VecVariable.h:97
viskores::VecTraits
Traits that can be queried to treat any type as a Vec.
Definition: VecTraits.h:69
viskores::VecVariable::Data
viskores::Vec< T, MaxSize > Data
Definition: VecVariable.h:96
viskores::VecTraits< viskores::VecVariable< T, MaxSize > >::SetComponent
static void SetComponent(VecType &vector, viskores::IdComponent componentIndex, const ComponentType &value)
Definition: VecVariable.h:142
viskores::VecVariable::CopyInto
void CopyInto(viskores::Vec< ComponentType, DestSize > &dest) const
Definition: VecVariable.h:64
VISKORES_ASSERT
#define VISKORES_ASSERT(condition)
Definition: Assert.h:51
viskores::VecVariable::ComponentType
T ComponentType
Definition: VecVariable.h:41
viskores::VecVariable::VecVariable
VecVariable(const SrcVecType &src)
Definition: VecVariable.h:50
viskores::VecVariable::VecVariable
VecVariable()
Definition: VecVariable.h:44
viskores::VecTraits< viskores::VecVariable< T, MaxSize > >::GetComponent
static ComponentType & GetComponent(VecType &vector, viskores::IdComponent componentIndex)
Definition: VecVariable.h:136
viskores::VecTraits::BaseComponentType
T BaseComponentType
Base component type in the vector.
Definition: VecTraits.h:86
viskores::VecTraits< viskores::VecVariable< T, MaxSize > >::BaseComponentType
typename viskores::VecTraits< ComponentType >::BaseComponentType BaseComponentType
Definition: VecVariable.h:119
viskores::TypeTraitsVectorTag
Tag used to identify 1 dimensional types (vectors).
Definition: TypeTraits.h:59
viskores::Vec
A short fixed-length array.
Definition: Types.h:365
viskores::VecTraits< viskores::VecVariable< T, MaxSize > >::GetComponent
static const ComponentType & GetComponent(const VecType &vector, viskores::IdComponent componentIndex)
Definition: VecVariable.h:130
viskores::VecVariable::operator[]
ComponentType & operator[](viskores::IdComponent index)
Definition: VecVariable.h:81
VecTraits.h
viskores::Plane
Represent a plane with a base point (origin) and normal vector.
Definition: Geometry.h:33