Viskores  1.0
VecFromPortalPermute.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_VecFromPortalPermute_h
19 #define viskores_VecFromPortalPermute_h
20 
21 #include <viskores/Math.h>
22 #include <viskores/TypeTraits.h>
23 #include <viskores/Types.h>
24 #include <viskores/VecTraits.h>
25 
26 namespace viskores
27 {
28 
35 template <typename IndexVecType, typename PortalType>
37 {
38 public:
39  using ComponentType = typename std::remove_const<typename PortalType::ValueType>::type;
40 
44 
47  VecFromPortalPermute(const IndexVecType* indices, const PortalType& portal)
48  : Indices(indices)
49  , Portal(portal)
50  {
51  }
52 
56  {
57  return this->Indices->GetNumberOfComponents();
58  }
59 
61  template <viskores::IdComponent DestSize>
63  {
64  viskores::IdComponent numComponents = viskores::Min(DestSize, this->GetNumberOfComponents());
65  for (viskores::IdComponent index = 0; index < numComponents; index++)
66  {
67  dest[index] = (*this)[index];
68  }
69  }
70 
74  {
75  return this->Portal.Get((*this->Indices)[index]);
76  }
77 
78 private:
79  const IndexVecType* const Indices;
80  PortalType Portal;
81 };
82 
83 template <typename IndexVecType, typename PortalType>
84 class VecFromPortalPermute<IndexVecType, const PortalType*>
85 {
86 public:
87  using ComponentType = typename std::remove_const<typename PortalType::ValueType>::type;
88 
92 
95  VecFromPortalPermute(const IndexVecType* indices, const PortalType* const portal)
96  : Indices(indices)
97  , Portal(portal)
98  {
99  }
100 
104  {
105  return this->Indices->GetNumberOfComponents();
106  }
107 
109  template <viskores::IdComponent DestSize>
111  {
112  viskores::IdComponent numComponents = viskores::Min(DestSize, this->GetNumberOfComponents());
113  for (viskores::IdComponent index = 0; index < numComponents; index++)
114  {
115  dest[index] = (*this)[index];
116  }
117  }
118 
122  {
123  return this->Portal->Get((*this->Indices)[index]);
124  }
125 
126 private:
127  const IndexVecType* const Indices;
128  const PortalType* const Portal;
129 };
130 
131 template <typename IndexVecType, typename PortalType>
132 struct TypeTraits<viskores::VecFromPortalPermute<IndexVecType, PortalType>>
133 {
134 private:
136  using ComponentType = typename PortalType::ValueType;
137 
138 public:
141 
144  static VecType ZeroInitialization() { return VecType(); }
145 };
146 
147 template <typename IndexVecType, typename PortalType>
148 struct VecTraits<viskores::VecFromPortalPermute<IndexVecType, PortalType>>
149 {
151 
156 
160  {
161  return vector.GetNumberOfComponents();
162  }
163 
166  static ComponentType GetComponent(const VecType& vector, viskores::IdComponent componentIndex)
167  {
168  return vector[componentIndex];
169  }
170 
172  template <viskores::IdComponent destSize>
173  VISKORES_EXEC_CONT static void CopyInto(const VecType& src,
175  {
176  src.CopyInto(dest);
177  }
178 };
179 
180 template <typename IndexVecType, typename PortalType>
182  const IndexVecType* index,
183  const PortalType& portal)
184 {
186 }
187 
188 template <typename IndexVecType, typename PortalType>
189 inline VISKORES_EXEC VecFromPortalPermute<IndexVecType, const PortalType*>
190 make_VecFromPortalPermute(const IndexVecType* index, const PortalType* const portal)
191 {
193 }
194 
195 } // namespace viskores
196 
197 #endif //viskores_VecFromPortalPermute_h
viskores::VecFromPortalPermute::operator[]
ComponentType operator[](viskores::IdComponent index) const
Definition: VecFromPortalPermute.h:73
viskores::VecFromPortalPermute< IndexVecType, const PortalType * >::Indices
const IndexVecType *const Indices
Definition: VecFromPortalPermute.h:127
viskores::VecFromPortalPermute::GetNumberOfComponents
viskores::IdComponent GetNumberOfComponents() const
Definition: VecFromPortalPermute.h:55
viskores::VecFromPortalPermute< IndexVecType, const PortalType * >
Definition: VecFromPortalPermute.h:84
viskores::VecTraits< viskores::VecFromPortalPermute< IndexVecType, PortalType > >::BaseComponentType
typename viskores::VecTraits< ComponentType >::BaseComponentType BaseComponentType
Definition: VecFromPortalPermute.h:153
viskores::VecTraits< viskores::VecFromPortalPermute< IndexVecType, PortalType > >::GetNumberOfComponents
static viskores::IdComponent GetNumberOfComponents(const VecType &vector)
Definition: VecFromPortalPermute.h:159
Types.h
viskores::VecFromPortalPermute< IndexVecType, const PortalType * >::Portal
const PortalType *const Portal
Definition: VecFromPortalPermute.h:128
viskores::VecFromPortalPermute< IndexVecType, const PortalType * >::VecFromPortalPermute
VecFromPortalPermute()
Definition: VecFromPortalPermute.h:91
viskores::VecTraitsTagSizeVariable
A tag for vectors where the number of components are not determined until run time.
Definition: VecTraits.h:51
VISKORES_SUPPRESS_EXEC_WARNINGS
#define VISKORES_SUPPRESS_EXEC_WARNINGS
Definition: ExportMacros.h:61
viskores::VecTraitsTagMultipleComponents
A tag for vectors that are "true" vectors (i.e.
Definition: VecTraits.h:31
viskores::VecFromPortalPermute::VecFromPortalPermute
VecFromPortalPermute()
Definition: VecFromPortalPermute.h:43
viskores::IdComponent
viskores::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:202
VISKORES_EXEC_CONT
#define VISKORES_EXEC_CONT
Definition: ExportMacros.h:60
viskores::VecFromPortalPermute::Indices
const IndexVecType *const Indices
Definition: VecFromPortalPermute.h:79
viskores::VecTraits< viskores::VecFromPortalPermute< IndexVecType, PortalType > >::CopyInto
static void CopyInto(const VecType &src, viskores::Vec< ComponentType, destSize > &dest)
Definition: VecFromPortalPermute.h:173
TypeTraits.h
viskores::TypeTraits
The TypeTraits class provides helpful compile-time information about the basic types used in Viskores...
Definition: TypeTraits.h:69
viskores::TypeTraits< viskores::VecFromPortalPermute< IndexVecType, PortalType > >::ComponentType
typename PortalType::ValueType ComponentType
Definition: VecFromPortalPermute.h:136
viskores::make_VecFromPortalPermute
VecFromPortalPermute< IndexVecType, PortalType > make_VecFromPortalPermute(const IndexVecType *index, const PortalType &portal)
Definition: VecFromPortalPermute.h:181
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::VecFromPortalPermute< IndexVecType, const PortalType * >::ComponentType
typename std::remove_const< typename PortalType::ValueType >::type ComponentType
Definition: VecFromPortalPermute.h:87
viskores::VecTraits< viskores::VecFromPortalPermute< IndexVecType, PortalType > >::ComponentType
typename VecType::ComponentType ComponentType
Definition: VecFromPortalPermute.h:152
viskores::VecFromPortalPermute< IndexVecType, const PortalType * >::GetNumberOfComponents
viskores::IdComponent GetNumberOfComponents() const
Definition: VecFromPortalPermute.h:103
viskores::VecTraits
Traits that can be queried to treat any type as a Vec.
Definition: VecTraits.h:69
viskores::VecFromPortalPermute
A short vector from an ArrayPortal and a vector of indices.
Definition: VecFromPortalPermute.h:36
viskores::VecFromPortalPermute::CopyInto
void CopyInto(viskores::Vec< ComponentType, DestSize > &dest) const
Definition: VecFromPortalPermute.h:62
viskores::VecTraits< viskores::VecFromPortalPermute< IndexVecType, PortalType > >::GetComponent
static ComponentType GetComponent(const VecType &vector, viskores::IdComponent componentIndex)
Definition: VecFromPortalPermute.h:166
viskores::VecFromPortalPermute< IndexVecType, const PortalType * >::operator[]
ComponentType operator[](viskores::IdComponent index) const
Definition: VecFromPortalPermute.h:121
viskores::TypeTraits< viskores::VecFromPortalPermute< IndexVecType, PortalType > >::ZeroInitialization
static VecType ZeroInitialization()
Definition: VecFromPortalPermute.h:144
viskores::VecFromPortalPermute::Portal
PortalType Portal
Definition: VecFromPortalPermute.h:80
viskores::VecFromPortalPermute::VecFromPortalPermute
VecFromPortalPermute(const IndexVecType *indices, const PortalType &portal)
Definition: VecFromPortalPermute.h:47
viskores::VecTraits::BaseComponentType
T BaseComponentType
Base component type in the vector.
Definition: VecTraits.h:86
viskores::VecFromPortalPermute< IndexVecType, const PortalType * >::CopyInto
void CopyInto(viskores::Vec< ComponentType, DestSize > &dest) const
Definition: VecFromPortalPermute.h:110
viskores::TypeTraits< viskores::VecFromPortalPermute< IndexVecType, PortalType > >::NumericTag
typename viskores::TypeTraits< ComponentType >::NumericTag NumericTag
Definition: VecFromPortalPermute.h:139
viskores::VecFromPortalPermute< IndexVecType, const PortalType * >::VecFromPortalPermute
VecFromPortalPermute(const IndexVecType *indices, const PortalType *const portal)
Definition: VecFromPortalPermute.h:95
viskores::VecFromPortalPermute::ComponentType
typename std::remove_const< typename PortalType::ValueType >::type ComponentType
Definition: VecFromPortalPermute.h:39
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_EXEC
#define VISKORES_EXEC
Definition: ExportMacros.h:59
VecTraits.h