| VTK 9.0.1

PortalTraits.h
Go to the documentation of this file.
1 //=============================================================================
2 //
3 // Copyright (c) Kitware, Inc.
4 // All rights reserved.
5 // See LICENSE.txt for details.
6 //
7 // This software is distributed WITHOUT ANY WARRANTY; without even
8 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9 // PURPOSE. See the above copyright notice for more information.
10 //
11 // Copyright 2012 Sandia Corporation.
12 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
13 // the U.S. Government retains certain rights in this software.
14 //
15 //=============================================================================
16
17 #ifndef vtkmlib_PortalTraits_h
18 #define vtkmlib_PortalTraits_h
19
20 #include "vtkmConfig.h" //required for general vtkm setup
21
22 #include <vtkm/Types.h>
23 #include <vtkm/internal/Assume.h>
24
25 #include <type_traits>
26
27 namespace tovtkm
28 {
29
30 struct vtkPortalOfVecOfVecValues;
31 struct vtkPortalOfVecOfValues;
32 struct vtkPortalOfScalarValues;
33
34 template <typename T>
35 struct vtkPortalTraits
36 {
37 using TagType = vtkPortalOfScalarValues;
38 using ComponentType = typename std::remove_const<T>::type;
39 using Type = ComponentType;
40 static constexpr vtkm::IdComponent NUM_COMPONENTS = 1;
41
42 static inline void SetComponent(Type& t, vtkm::IdComponent, const ComponentType& v) { t = v; }
43
44 static inline ComponentType GetComponent(const Type& t, vtkm::IdComponent) { return t; }
45 };
46
47 template <typename T, int N>
48 struct vtkPortalTraits<vtkm::Vec<T, N> >
49 {
50 using TagType = vtkPortalOfVecOfValues;
51 using ComponentType = typename std::remove_const<T>::type;
52 using Type = vtkm::Vec<T, N>;
53 static constexpr vtkm::IdComponent NUM_COMPONENTS = N;
54
55 static inline void SetComponent(Type& t, vtkm::IdComponent i, const ComponentType& v)
56 {
57 VTKM_ASSUME((i >= 0 && i < N));
58 t[i] = v;
59 }
60
61 static inline ComponentType GetComponent(const Type& t, vtkm::IdComponent i)
62 {
63 VTKM_ASSUME((i >= 0 && i < N));
64 return t[i];
65 }
66 };
67
68 template <typename T, int N>
69 struct vtkPortalTraits<const vtkm::Vec<T, N> >
70 {
71 using TagType = vtkPortalOfVecOfValues;
72 using ComponentType = typename std::remove_const<T>::type;
73 using Type = vtkm::Vec<T, N>;
74 static constexpr vtkm::IdComponent NUM_COMPONENTS = N;
75
76 static inline void SetComponent(Type& t, vtkm::IdComponent i, const ComponentType& v)
77 {
78 VTKM_ASSUME((i >= 0 && i < N));
79 t[i] = v;
80 }
81
82 static inline ComponentType GetComponent(const Type& t, vtkm::IdComponent i)
83 {
84 VTKM_ASSUME((i >= 0 && i < N));
85 return t[i];
86 }
87 };
88
89 template <typename T, int N, int M>
90 struct vtkPortalTraits<vtkm::Vec<vtkm::Vec<T, N>, M> >
91 {
92 using TagType = vtkPortalOfVecOfVecValues;
93 using ComponentType = typename std::remove_const<T>::type;
94 using Type = vtkm::Vec<vtkm::Vec<T, N>, M>;
95 static constexpr vtkm::IdComponent NUM_COMPONENTS = N * M;
96
97 static constexpr vtkm::IdComponent NUM_COMPONENTS_OUTER = M;
98 static constexpr vtkm::IdComponent NUM_COMPONENTS_INNER = N;
99
100 static inline void SetComponent(Type& t, vtkm::IdComponent i, const ComponentType& v)
101 {
102 VTKM_ASSUME((i >= 0 && i < NUM_COMPONENTS));
103 // We need to convert i back to a 2d index
104 const vtkm::IdComponent j = i % N;
105 t[i / N][j] = v;
106 }
107
108 static inline ComponentType GetComponent(const Type& t, vtkm::IdComponent i)
109 {
110 VTKM_ASSUME((i >= 0 && i < NUM_COMPONENTS));
111 // We need to convert i back to a 2d index
112 const vtkm::IdComponent j = i % N;
113 return t[i / N][j];
114 }
115 };
116
117 template <typename T, int N, int M>
118 struct vtkPortalTraits<const vtkm::Vec<vtkm::Vec<T, N>, M> >
119 {
120 using TagType = vtkPortalOfVecOfVecValues;
121 using ComponentType = typename std::remove_const<T>::type;
122 using Type = vtkm::Vec<vtkm::Vec<T, N>, M>;
123 static constexpr vtkm::IdComponent NUM_COMPONENTS = N * M;
124
125 static constexpr vtkm::IdComponent NUM_COMPONENTS_OUTER = M;
126 static constexpr vtkm::IdComponent NUM_COMPONENTS_INNER = N;
127
128 static inline void SetComponent(Type& t, vtkm::IdComponent i, const ComponentType& v)
129 {
130 VTKM_ASSUME((i >= 0 && i < NUM_COMPONENTS));
131 // We need to convert i back to a 2d index
132 const vtkm::IdComponent j = i % N;
133 t[i / N][j] = v;
134 }
135
136 static inline ComponentType GetComponent(const Type& t, vtkm::IdComponent i)
137 {
138 VTKM_ASSUME((i >= 0 && i < NUM_COMPONENTS));
139 // We need to convert i back to a 2d index
140 const vtkm::IdComponent j = i % N;
141 return t[i / N][j];
142 }
143 };
144
145 } // namespace vtkmlib
146
147 #endif // vtkmlib_PortalsTraits_h
tovtkm::vtkPortalTraits< vtkm::Vec< T, N > >::ComponentType
typename std::remove_const< T >::type ComponentType
Definition: PortalTraits.h:51
vtkm
Definition: vtkmDataSet.h:28
tovtkm::vtkPortalTraits< vtkm::Vec< T, N > >::GetComponent
static ComponentType GetComponent(const Type &t, vtkm::IdComponent i)
Definition: PortalTraits.h:61
tovtkm::vtkPortalTraits< const vtkm::Vec< vtkm::Vec< T, N >, M > >::SetComponent
static void SetComponent(Type &t, vtkm::IdComponent i, const ComponentType &v)
Definition: PortalTraits.h:128
vtkX3D::type
@ type
Definition: vtkX3D.h:522
tovtkm::vtkPortalTraits::SetComponent
static void SetComponent(Type &t, vtkm::IdComponent, const ComponentType &v)
Definition: PortalTraits.h:42
tovtkm::vtkPortalTraits< const vtkm::Vec< vtkm::Vec< T, N >, M > >::Type
vtkm::Vec< vtkm::Vec< T, N >, M > Type
Definition: PortalTraits.h:122
tovtkm::vtkPortalTraits< vtkm::Vec< T, N > >::Type
vtkm::Vec< T, N > Type
Definition: PortalTraits.h:52
tovtkm::vtkPortalTraits< const vtkm::Vec< T, N > >::Type
vtkm::Vec< T, N > Type
Definition: PortalTraits.h:73
tovtkm::vtkPortalTraits::NUM_COMPONENTS
static constexpr vtkm::IdComponent NUM_COMPONENTS
Definition: PortalTraits.h:40
tovtkm::vtkPortalTraits::ComponentType
typename std::remove_const< T >::type ComponentType
Definition: PortalTraits.h:38
tovtkm::vtkPortalTraits< const vtkm::Vec< T, N > >::TagType
vtkPortalOfVecOfValues TagType
Definition: PortalTraits.h:71
tovtkm::vtkPortalTraits< vtkm::Vec< T, N > >::SetComponent
static void SetComponent(Type &t, vtkm::IdComponent i, const ComponentType &v)
Definition: PortalTraits.h:55
tovtkm::vtkPortalTraits< vtkm::Vec< vtkm::Vec< T, N >, M > >::SetComponent
static void SetComponent(Type &t, vtkm::IdComponent i, const ComponentType &v)
Definition: PortalTraits.h:100
tovtkm::vtkPortalTraits< const vtkm::Vec< T, N > >::SetComponent
static void SetComponent(Type &t, vtkm::IdComponent i, const ComponentType &v)
Definition: PortalTraits.h:76
tovtkm::vtkPortalTraits< const vtkm::Vec< vtkm::Vec< T, N >, M > >::GetComponent
static ComponentType GetComponent(const Type &t, vtkm::IdComponent i)
Definition: PortalTraits.h:136
tovtkm::vtkPortalTraits< vtkm::Vec< vtkm::Vec< T, N >, M > >::TagType
vtkPortalOfVecOfVecValues TagType
Definition: PortalTraits.h:92
tovtkm::vtkPortalTraits::Type
ComponentType Type
Definition: PortalTraits.h:39
tovtkm::vtkPortalTraits< const vtkm::Vec< vtkm::Vec< T, N >, M > >::ComponentType
typename std::remove_const< T >::type ComponentType
Definition: PortalTraits.h:121
tovtkm::vtkPortalTraits< vtkm::Vec< vtkm::Vec< T, N >, M > >::ComponentType
typename std::remove_const< T >::type ComponentType
Definition: PortalTraits.h:93
tovtkm::vtkPortalTraits< const vtkm::Vec< T, N > >::GetComponent
static ComponentType GetComponent(const Type &t, vtkm::IdComponent i)
Definition: PortalTraits.h:82
tovtkm::vtkPortalTraits< vtkm::Vec< vtkm::Vec< T, N >, M > >::GetComponent
static ComponentType GetComponent(const Type &t, vtkm::IdComponent i)
Definition: PortalTraits.h:108
tovtkm::vtkPortalTraits
Definition: PortalTraits.h:35
tovtkm::vtkPortalTraits< vtkm::Vec< vtkm::Vec< T, N >, M > >::Type
vtkm::Vec< vtkm::Vec< T, N >, M > Type
Definition: PortalTraits.h:94
tovtkm::vtkPortalTraits< const vtkm::Vec< vtkm::Vec< T, N >, M > >::TagType
vtkPortalOfVecOfVecValues TagType
Definition: PortalTraits.h:120
tovtkm::vtkPortalTraits< vtkm::Vec< T, N > >::TagType
vtkPortalOfVecOfValues TagType
Definition: PortalTraits.h:50
tovtkm
Definition: vtkmClip.h:35
tovtkm::vtkPortalTraits::TagType
vtkPortalOfScalarValues TagType
Definition: PortalTraits.h:37
tovtkm::vtkPortalTraits::GetComponent
static ComponentType GetComponent(const Type &t, vtkm::IdComponent)
Definition: PortalTraits.h:44
tovtkm::vtkPortalTraits< const vtkm::Vec< T, N > >::ComponentType
typename std::remove_const< T >::type ComponentType
Definition: PortalTraits.h:72