VTK  9.3.0
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 
16 namespace tovtkm
17 {
18 VTK_ABI_NAMESPACE_BEGIN
19 
20 struct vtkPortalOfVecOfVecValues;
21 struct vtkPortalOfVecOfValues;
22 struct vtkPortalOfScalarValues;
23 
24 template <typename T>
26 {
27  using TagType = vtkPortalOfScalarValues;
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 
37 template <typename T, int N>
38 struct vtkPortalTraits<vtkm::Vec<T, N>>
39 {
40  using TagType = vtkPortalOfVecOfValues;
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 
58 template <typename T, int N>
59 struct vtkPortalTraits<const vtkm::Vec<T, N>>
60 {
61  using TagType = vtkPortalOfVecOfValues;
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 
79 template <typename T, int N, int M>
80 struct vtkPortalTraits<vtkm::Vec<vtkm::Vec<T, N>, M>>
81 {
82  using TagType = vtkPortalOfVecOfVecValues;
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 
107 template <typename T, int N, int M>
108 struct vtkPortalTraits<const vtkm::Vec<vtkm::Vec<T, N>, M>>
109 {
110  using TagType = vtkPortalOfVecOfVecValues;
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 
135 VTK_ABI_NAMESPACE_END
136 } // namespace vtkmlib
137 
138 #endif // vtkmlib_PortalsTraits_h
@ type
Definition: vtkX3D.h:516
static void SetComponent(Type &t, vtkm::IdComponent i, const ComponentType &v)
Definition: PortalTraits.h:66
static ComponentType GetComponent(const Type &t, vtkm::IdComponent i)
Definition: PortalTraits.h:72
typename std::remove_const< T >::type ComponentType
Definition: PortalTraits.h:62
static void SetComponent(Type &t, vtkm::IdComponent i, const ComponentType &v)
Definition: PortalTraits.h:118
static ComponentType GetComponent(const Type &t, vtkm::IdComponent i)
Definition: PortalTraits.h:126
static ComponentType GetComponent(const Type &t, vtkm::IdComponent i)
Definition: PortalTraits.h:51
static void SetComponent(Type &t, vtkm::IdComponent i, const ComponentType &v)
Definition: PortalTraits.h:45
typename std::remove_const< T >::type ComponentType
Definition: PortalTraits.h:41
static ComponentType GetComponent(const Type &t, vtkm::IdComponent i)
Definition: PortalTraits.h:98
typename std::remove_const< T >::type ComponentType
Definition: PortalTraits.h:83
static void SetComponent(Type &t, vtkm::IdComponent i, const ComponentType &v)
Definition: PortalTraits.h:90
static void SetComponent(Type &t, vtkm::IdComponent, const ComponentType &v)
Definition: PortalTraits.h:32
typename std::remove_const< T >::type ComponentType
Definition: PortalTraits.h:28
static constexpr vtkm::IdComponent NUM_COMPONENTS
Definition: PortalTraits.h:30
static ComponentType GetComponent(const Type &t, vtkm::IdComponent)
Definition: PortalTraits.h:34
vtkPortalOfScalarValues TagType
Definition: PortalTraits.h:27