VTK-m  2.0
VecFromPortalPermute.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_VecFromPortalPermute_h
11 #define vtk_m_VecFromPortalPermute_h
12 
13 #include <vtkm/Math.h>
14 #include <vtkm/TypeTraits.h>
15 #include <vtkm/Types.h>
16 #include <vtkm/VecTraits.h>
17 
18 namespace vtkm
19 {
20 
27 template <typename IndexVecType, typename PortalType>
29 {
30 public:
31  using ComponentType = typename std::remove_const<typename PortalType::ValueType>::type;
32 
36 
39  VecFromPortalPermute(const IndexVecType* indices, const PortalType& portal)
40  : Indices(indices)
41  , Portal(portal)
42  {
43  }
44 
47  vtkm::IdComponent GetNumberOfComponents() const { return this->Indices->GetNumberOfComponents(); }
48 
50  template <vtkm::IdComponent DestSize>
52  {
53  vtkm::IdComponent numComponents = vtkm::Min(DestSize, this->GetNumberOfComponents());
54  for (vtkm::IdComponent index = 0; index < numComponents; index++)
55  {
56  dest[index] = (*this)[index];
57  }
58  }
59 
63  {
64  return this->Portal.Get((*this->Indices)[index]);
65  }
66 
67 private:
68  const IndexVecType* const Indices;
69  PortalType Portal;
70 };
71 
72 template <typename IndexVecType, typename PortalType>
73 class VecFromPortalPermute<IndexVecType, const PortalType*>
74 {
75 public:
76  using ComponentType = typename std::remove_const<typename PortalType::ValueType>::type;
77 
81 
84  VecFromPortalPermute(const IndexVecType* indices, const PortalType* const portal)
85  : Indices(indices)
86  , Portal(portal)
87  {
88  }
89 
92  vtkm::IdComponent GetNumberOfComponents() const { return this->Indices->GetNumberOfComponents(); }
93 
95  template <vtkm::IdComponent DestSize>
97  {
98  vtkm::IdComponent numComponents = vtkm::Min(DestSize, this->GetNumberOfComponents());
99  for (vtkm::IdComponent index = 0; index < numComponents; index++)
100  {
101  dest[index] = (*this)[index];
102  }
103  }
104 
108  {
109  return this->Portal->Get((*this->Indices)[index]);
110  }
111 
112 private:
113  const IndexVecType* const Indices;
114  const PortalType* const Portal;
115 };
116 
117 template <typename IndexVecType, typename PortalType>
118 struct TypeTraits<vtkm::VecFromPortalPermute<IndexVecType, PortalType>>
119 {
120 private:
122  using ComponentType = typename PortalType::ValueType;
123 
124 public:
127 
130  static VecType ZeroInitialization() { return VecType(); }
131 };
132 
133 template <typename IndexVecType, typename PortalType>
134 struct VecTraits<vtkm::VecFromPortalPermute<IndexVecType, PortalType>>
135 {
137 
142 
146  {
147  return vector.GetNumberOfComponents();
148  }
149 
152  static ComponentType GetComponent(const VecType& vector, vtkm::IdComponent componentIndex)
153  {
154  return vector[componentIndex];
155  }
156 
158  template <vtkm::IdComponent destSize>
160  {
161  src.CopyInto(dest);
162  }
163 };
164 
165 template <typename IndexVecType, typename PortalType>
167  const IndexVecType* index,
168  const PortalType& portal)
169 {
171 }
172 
173 template <typename IndexVecType, typename PortalType>
175  const IndexVecType* index,
176  const PortalType* const portal)
177 {
179 }
180 
181 } // namespace vtkm
182 
183 #endif //vtk_m_VecFromPortalPermute_h
vtkm::VecFromPortalPermute::operator[]
VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT ComponentType operator[](vtkm::IdComponent index) const
Definition: VecFromPortalPermute.h:62
vtkm::VecTraits< vtkm::VecFromPortalPermute< IndexVecType, PortalType > >::GetNumberOfComponents
VTKM_SUPPRESS_EXEC_WARNINGS static VTKM_EXEC_CONT vtkm::IdComponent GetNumberOfComponents(const VecType &vector)
Definition: VecFromPortalPermute.h:145
vtkm::VecFromPortalPermute< IndexVecType, const PortalType * >::GetNumberOfComponents
VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT vtkm::IdComponent GetNumberOfComponents() const
Definition: VecFromPortalPermute.h:92
vtkm::VecFromPortalPermute::Indices
const IndexVecType *const Indices
Definition: VecFromPortalPermute.h:68
vtkm::VecFromPortalPermute::GetNumberOfComponents
VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT vtkm::IdComponent GetNumberOfComponents() const
Definition: VecFromPortalPermute.h:47
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
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::make_VecFromPortalPermute
VTKM_EXEC VecFromPortalPermute< IndexVecType, PortalType > make_VecFromPortalPermute(const IndexVecType *index, const PortalType &portal)
Definition: VecFromPortalPermute.h:166
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::TypeTraits< vtkm::VecFromPortalPermute< IndexVecType, PortalType > >::NumericTag
typename vtkm::TypeTraits< ComponentType >::NumericTag NumericTag
Definition: VecFromPortalPermute.h:125
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::VecFromPortalPermute< IndexVecType, const PortalType * >
Definition: VecFromPortalPermute.h:73
vtkm::TypeTraits< vtkm::VecFromPortalPermute< IndexVecType, PortalType > >::ComponentType
typename PortalType::ValueType ComponentType
Definition: VecFromPortalPermute.h:122
vtkm::VecFromPortalPermute::VecFromPortalPermute
VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT VecFromPortalPermute()
Definition: VecFromPortalPermute.h:35
vtkm::VecFromPortalPermute< IndexVecType, const PortalType * >::operator[]
VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT ComponentType operator[](vtkm::IdComponent index) const
Definition: VecFromPortalPermute.h:107
vtkm::VecFromPortalPermute::CopyInto
VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT void CopyInto(vtkm::Vec< ComponentType, DestSize > &dest) const
Definition: VecFromPortalPermute.h:51
vtkm::VecTraits::BaseComponentType
typename vtkm::VecTraits< ComponentType >::BaseComponentType BaseComponentType
Base component type in the vector.
Definition: VecTraits.h:80
vtkm::VecFromPortalPermute::ComponentType
typename std::remove_const< typename PortalType::ValueType >::type ComponentType
Definition: VecFromPortalPermute.h:31
vtkm::VecFromPortalPermute< IndexVecType, const PortalType * >::CopyInto
VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT void CopyInto(vtkm::Vec< ComponentType, DestSize > &dest) const
Definition: VecFromPortalPermute.h:96
vtkm::VecTraits< vtkm::VecFromPortalPermute< IndexVecType, PortalType > >::ComponentType
typename VecType::ComponentType ComponentType
Definition: VecFromPortalPermute.h:138
vtkm::TypeTraits< vtkm::VecFromPortalPermute< IndexVecType, PortalType > >::ZeroInitialization
VTKM_SUPPRESS_EXEC_WARNINGS static VTKM_EXEC_CONT VecType ZeroInitialization()
Definition: VecFromPortalPermute.h:130
TypeTraits.h
vtkm::VecTraitsTagSizeVariable
A tag for vectors where the number of components are not determined until run time.
Definition: VecTraits.h:41
vtkm::VecFromPortalPermute::VecFromPortalPermute
VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT VecFromPortalPermute(const IndexVecType *indices, const PortalType &portal)
Definition: VecFromPortalPermute.h:39
Math.h
vtkm::VecFromPortalPermute< IndexVecType, const PortalType * >::ComponentType
typename std::remove_const< typename PortalType::ValueType >::type ComponentType
Definition: VecFromPortalPermute.h:76
vtkm::VecFromPortalPermute< IndexVecType, const PortalType * >::Portal
const PortalType *const Portal
Definition: VecFromPortalPermute.h:114
vtkm::VecFromPortalPermute::Portal
PortalType Portal
Definition: VecFromPortalPermute.h:69
vtkm::VecTraits< vtkm::VecFromPortalPermute< IndexVecType, PortalType > >::BaseComponentType
typename vtkm::VecTraits< ComponentType >::BaseComponentType BaseComponentType
Definition: VecFromPortalPermute.h:139
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::VecFromPortalPermute< IndexVecType, const PortalType * >::Indices
const IndexVecType *const Indices
Definition: VecFromPortalPermute.h:113
vtkm::Vec
A short fixed-length array.
Definition: Types.h:767
vtkm::VecTraits< vtkm::VecFromPortalPermute< IndexVecType, PortalType > >::GetComponent
VTKM_SUPPRESS_EXEC_WARNINGS static VTKM_EXEC_CONT ComponentType GetComponent(const VecType &vector, vtkm::IdComponent componentIndex)
Definition: VecFromPortalPermute.h:152
vtkm::VecTraits< vtkm::VecFromPortalPermute< IndexVecType, PortalType > >::CopyInto
VTKM_SUPPRESS_EXEC_WARNINGS static VTKM_EXEC_CONT void CopyInto(const VecType &src, vtkm::Vec< ComponentType, destSize > &dest)
Definition: VecFromPortalPermute.h:159
vtkm::VecFromPortalPermute< IndexVecType, const PortalType * >::VecFromPortalPermute
VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT VecFromPortalPermute()
Definition: VecFromPortalPermute.h:80
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::VecFromPortalPermute< IndexVecType, const PortalType * >::VecFromPortalPermute
VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT VecFromPortalPermute(const IndexVecType *indices, const PortalType *const portal)
Definition: VecFromPortalPermute.h:84
VTKM_SUPPRESS_EXEC_WARNINGS
#define VTKM_SUPPRESS_EXEC_WARNINGS
Definition: ExportMacros.h:53
VecTraits.h
vtkm::VecFromPortalPermute
A short vector from an ArrayPortal and a vector of indices.
Definition: VecFromPortalPermute.h:28