VTK  9.4.20241118
PortalTraits.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-FileCopyrightText: Copyright (c) Kitware, Inc.
3// SPDX-FileCopyrightText: Copyright 2012 Sandia Corporation.
4// SPDX-License-Identifier: LicenseRef-BSD-3-Clause-Sandia-USGov
5
6#ifndef vtkmlib_PortalTraits_h
7#define vtkmlib_PortalTraits_h
8
9#include "vtkmConfigCore.h" //required for general vtkm setup
10
11#include <vtkm/Types.h>
12#include <vtkm/internal/Assume.h>
13
14#include <type_traits>
15
16namespace tovtkm
17{
18VTK_ABI_NAMESPACE_BEGIN
19
20struct vtkPortalOfVecOfVecValues;
21struct vtkPortalOfVecOfValues;
22struct vtkPortalOfScalarValues;
23
24template <typename T>
26{
27 using TagType = vtkPortalOfScalarValues;
28 using ComponentType = typename std::remove_const<T>::type;
30 static constexpr vtkm::IdComponent NUM_COMPONENTS = 1;
31
32 static inline void SetComponent(Type& t, vtkm::IdComponent, const ComponentType& v) { t = v; }
33
34 static inline ComponentType GetComponent(const Type& t, vtkm::IdComponent) { return t; }
35};
36
37template <typename T, int N>
38struct vtkPortalTraits<vtkm::Vec<T, N>>
39{
40 using TagType = vtkPortalOfVecOfValues;
41 using ComponentType = typename std::remove_const<T>::type;
42 using Type = vtkm::Vec<T, N>;
43 static constexpr vtkm::IdComponent NUM_COMPONENTS = N;
44
45 static inline void SetComponent(Type& t, vtkm::IdComponent i, const ComponentType& v)
46 {
47 VTKM_ASSUME((i >= 0 && i < N));
48 t[i] = v;
49 }
50
51 static inline ComponentType GetComponent(const Type& t, vtkm::IdComponent i)
52 {
53 VTKM_ASSUME((i >= 0 && i < N));
54 return t[i];
55 }
56};
57
58template <typename T, int N>
59struct vtkPortalTraits<const vtkm::Vec<T, N>>
60{
61 using TagType = vtkPortalOfVecOfValues;
62 using ComponentType = typename std::remove_const<T>::type;
63 using Type = vtkm::Vec<T, N>;
64 static constexpr vtkm::IdComponent NUM_COMPONENTS = N;
65
66 static inline void SetComponent(Type& t, vtkm::IdComponent i, const ComponentType& v)
67 {
68 VTKM_ASSUME((i >= 0 && i < N));
69 t[i] = v;
70 }
71
72 static inline ComponentType GetComponent(const Type& t, vtkm::IdComponent i)
73 {
74 VTKM_ASSUME((i >= 0 && i < N));
75 return t[i];
76 }
77};
78
79template <typename T, int N, int M>
80struct vtkPortalTraits<vtkm::Vec<vtkm::Vec<T, N>, M>>
81{
82 using TagType = vtkPortalOfVecOfVecValues;
83 using ComponentType = typename std::remove_const<T>::type;
84 using Type = vtkm::Vec<vtkm::Vec<T, N>, M>;
85 static constexpr vtkm::IdComponent NUM_COMPONENTS = N * M;
86
87 static constexpr vtkm::IdComponent NUM_COMPONENTS_OUTER = M;
88 static constexpr vtkm::IdComponent NUM_COMPONENTS_INNER = N;
89
90 static inline void SetComponent(Type& t, vtkm::IdComponent i, const ComponentType& v)
91 {
92 VTKM_ASSUME((i >= 0 && i < NUM_COMPONENTS));
93 // We need to convert i back to a 2d index
94 const vtkm::IdComponent j = i % N;
95 t[i / N][j] = v;
96 }
97
98 static inline ComponentType GetComponent(const Type& t, vtkm::IdComponent i)
99 {
100 VTKM_ASSUME((i >= 0 && i < NUM_COMPONENTS));
101 // We need to convert i back to a 2d index
102 const vtkm::IdComponent j = i % N;
103 return t[i / N][j];
104 }
105};
106
107template <typename T, int N, int M>
108struct vtkPortalTraits<const vtkm::Vec<vtkm::Vec<T, N>, M>>
109{
110 using TagType = vtkPortalOfVecOfVecValues;
111 using ComponentType = typename std::remove_const<T>::type;
112 using Type = vtkm::Vec<vtkm::Vec<T, N>, M>;
113 static constexpr vtkm::IdComponent NUM_COMPONENTS = N * M;
114
115 static constexpr vtkm::IdComponent NUM_COMPONENTS_OUTER = M;
116 static constexpr vtkm::IdComponent NUM_COMPONENTS_INNER = N;
117
118 static inline void SetComponent(Type& t, vtkm::IdComponent i, const ComponentType& v)
119 {
120 VTKM_ASSUME((i >= 0 && i < NUM_COMPONENTS));
121 // We need to convert i back to a 2d index
122 const vtkm::IdComponent j = i % N;
123 t[i / N][j] = v;
124 }
125
126 static inline ComponentType GetComponent(const Type& t, vtkm::IdComponent i)
127 {
128 VTKM_ASSUME((i >= 0 && i < NUM_COMPONENTS));
129 // We need to convert i back to a 2d index
130 const vtkm::IdComponent j = i % N;
131 return t[i / N][j];
132 }
133};
134
135VTK_ABI_NAMESPACE_END
136} // namespace vtkmlib
137
138#endif // vtkmlib_PortalsTraits_h
static void SetComponent(Type &t, vtkm::IdComponent i, const ComponentType &v)
static ComponentType GetComponent(const Type &t, vtkm::IdComponent i)
typename std::remove_const< T >::type ComponentType
static void SetComponent(Type &t, vtkm::IdComponent i, const ComponentType &v)
static ComponentType GetComponent(const Type &t, vtkm::IdComponent i)
static ComponentType GetComponent(const Type &t, vtkm::IdComponent i)
static void SetComponent(Type &t, vtkm::IdComponent i, const ComponentType &v)
typename std::remove_const< T >::type ComponentType
static ComponentType GetComponent(const Type &t, vtkm::IdComponent i)
typename std::remove_const< T >::type ComponentType
static void SetComponent(Type &t, vtkm::IdComponent i, const ComponentType &v)
static void SetComponent(Type &t, vtkm::IdComponent, const ComponentType &v)
typename std::remove_const< T >::type ComponentType
static constexpr vtkm::IdComponent NUM_COMPONENTS
static ComponentType GetComponent(const Type &t, vtkm::IdComponent)
vtkPortalOfScalarValues TagType