VTK  9.5.20250708
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 viskores setup
10
11#include <viskores/Types.h>
12#include <viskores/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 viskores::IdComponent NUM_COMPONENTS = 1;
31
32 static void SetComponent(Type& t, viskores::IdComponent, const ComponentType& v) { t = v; }
33
34 static ComponentType GetComponent(const Type& t, viskores::IdComponent) { return t; }
35};
36
37template <typename T, int N>
38struct vtkPortalTraits<viskores::Vec<T, N>>
39{
40 using TagType = vtkPortalOfVecOfValues;
41 using ComponentType = typename std::remove_const<T>::type;
42 using Type = viskores::Vec<T, N>;
43 static constexpr viskores::IdComponent NUM_COMPONENTS = N;
44
45 static void SetComponent(Type& t, viskores::IdComponent i, const ComponentType& v)
46 {
47 VISKORES_ASSUME((i >= 0 && i < N));
48 t[i] = v;
49 }
50
51 static ComponentType GetComponent(const Type& t, viskores::IdComponent i)
52 {
53 VISKORES_ASSUME((i >= 0 && i < N));
54 return t[i];
55 }
56};
57
58template <typename T, int N>
59struct vtkPortalTraits<const viskores::Vec<T, N>>
60{
61 using TagType = vtkPortalOfVecOfValues;
62 using ComponentType = typename std::remove_const<T>::type;
63 using Type = viskores::Vec<T, N>;
64 static constexpr viskores::IdComponent NUM_COMPONENTS = N;
65
66 static void SetComponent(Type& t, viskores::IdComponent i, const ComponentType& v)
67 {
68 VISKORES_ASSUME((i >= 0 && i < N));
69 t[i] = v;
70 }
71
72 static ComponentType GetComponent(const Type& t, viskores::IdComponent i)
73 {
74 VISKORES_ASSUME((i >= 0 && i < N));
75 return t[i];
76 }
77};
78
79template <typename T, int N, int M>
80struct vtkPortalTraits<viskores::Vec<viskores::Vec<T, N>, M>>
81{
82 using TagType = vtkPortalOfVecOfVecValues;
83 using ComponentType = typename std::remove_const<T>::type;
84 using Type = viskores::Vec<viskores::Vec<T, N>, M>;
85 static constexpr viskores::IdComponent NUM_COMPONENTS = N * M;
86
87 static constexpr viskores::IdComponent NUM_COMPONENTS_OUTER = M;
88 static constexpr viskores::IdComponent NUM_COMPONENTS_INNER = N;
89
90 static void SetComponent(Type& t, viskores::IdComponent i, const ComponentType& v)
91 {
92 VISKORES_ASSUME((i >= 0 && i < NUM_COMPONENTS));
93 // We need to convert i back to a 2d index
94 const viskores::IdComponent j = i % N;
95 t[i / N][j] = v;
96 }
97
98 static ComponentType GetComponent(const Type& t, viskores::IdComponent i)
99 {
100 VISKORES_ASSUME((i >= 0 && i < NUM_COMPONENTS));
101 // We need to convert i back to a 2d index
102 const viskores::IdComponent j = i % N;
103 return t[i / N][j];
104 }
105};
106
107template <typename T, int N, int M>
108struct vtkPortalTraits<const viskores::Vec<viskores::Vec<T, N>, M>>
109{
110 using TagType = vtkPortalOfVecOfVecValues;
111 using ComponentType = typename std::remove_const<T>::type;
112 using Type = viskores::Vec<viskores::Vec<T, N>, M>;
113 static constexpr viskores::IdComponent NUM_COMPONENTS = N * M;
114
115 static constexpr viskores::IdComponent NUM_COMPONENTS_OUTER = M;
116 static constexpr viskores::IdComponent NUM_COMPONENTS_INNER = N;
117
118 static void SetComponent(Type& t, viskores::IdComponent i, const ComponentType& v)
119 {
120 VISKORES_ASSUME((i >= 0 && i < NUM_COMPONENTS));
121 // We need to convert i back to a 2d index
122 const viskores::IdComponent j = i % N;
123 t[i / N][j] = v;
124 }
125
126 static ComponentType GetComponent(const Type& t, viskores::IdComponent i)
127 {
128 VISKORES_ASSUME((i >= 0 && i < NUM_COMPONENTS));
129 // We need to convert i back to a 2d index
130 const viskores::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
typename std::remove_const< T >::type ComponentType
static void SetComponent(Type &t, viskores::IdComponent i, const ComponentType &v)
static ComponentType GetComponent(const Type &t, viskores::IdComponent i)
static void SetComponent(Type &t, viskores::IdComponent i, const ComponentType &v)
static ComponentType GetComponent(const Type &t, viskores::IdComponent i)
static ComponentType GetComponent(const Type &t, viskores::IdComponent i)
static void SetComponent(Type &t, viskores::IdComponent i, const ComponentType &v)
typename std::remove_const< T >::type ComponentType
static ComponentType GetComponent(const Type &t, viskores::IdComponent i)
static void SetComponent(Type &t, viskores::IdComponent i, const ComponentType &v)
static ComponentType GetComponent(const Type &t, viskores::IdComponent)
static void SetComponent(Type &t, viskores::IdComponent, const ComponentType &v)
typename std::remove_const< T >::type ComponentType
static constexpr viskores::IdComponent NUM_COMPONENTS
vtkPortalOfScalarValues TagType