VTK  9.1.0
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 "vtkmConfigCore.h" //required for general vtkm setup
21
22#include <vtkm/Types.h>
23#include <vtkm/internal/Assume.h>
24
25#include <type_traits>
26
27namespace tovtkm
28{
29
30struct vtkPortalOfVecOfVecValues;
31struct vtkPortalOfVecOfValues;
32struct vtkPortalOfScalarValues;
33
34template <typename T>
36{
37 using TagType = vtkPortalOfScalarValues;
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
47template <typename T, int N>
48struct vtkPortalTraits<vtkm::Vec<T, N>>
49{
50 using TagType = vtkPortalOfVecOfValues;
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
68template <typename T, int N>
69struct vtkPortalTraits<const vtkm::Vec<T, N>>
70{
71 using TagType = vtkPortalOfVecOfValues;
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
89template <typename T, int N, int M>
90struct vtkPortalTraits<vtkm::Vec<vtkm::Vec<T, N>, M>>
91{
92 using TagType = vtkPortalOfVecOfVecValues;
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
117template <typename T, int N, int M>
118struct vtkPortalTraits<const vtkm::Vec<vtkm::Vec<T, N>, M>>
119{
120 using TagType = vtkPortalOfVecOfVecValues;
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
@ type
Definition: vtkX3D.h:522
static void SetComponent(Type &t, vtkm::IdComponent i, const ComponentType &v)
Definition: PortalTraits.h:76
static ComponentType GetComponent(const Type &t, vtkm::IdComponent i)
Definition: PortalTraits.h:82
typename std::remove_const< T >::type ComponentType
Definition: PortalTraits.h:72
static void SetComponent(Type &t, vtkm::IdComponent i, const ComponentType &v)
Definition: PortalTraits.h:128
static ComponentType GetComponent(const Type &t, vtkm::IdComponent i)
Definition: PortalTraits.h:136
static ComponentType GetComponent(const Type &t, vtkm::IdComponent i)
Definition: PortalTraits.h:61
static void SetComponent(Type &t, vtkm::IdComponent i, const ComponentType &v)
Definition: PortalTraits.h:55
typename std::remove_const< T >::type ComponentType
Definition: PortalTraits.h:51
static ComponentType GetComponent(const Type &t, vtkm::IdComponent i)
Definition: PortalTraits.h:108
typename std::remove_const< T >::type ComponentType
Definition: PortalTraits.h:93
static void SetComponent(Type &t, vtkm::IdComponent i, const ComponentType &v)
Definition: PortalTraits.h:100
static void SetComponent(Type &t, vtkm::IdComponent, const ComponentType &v)
Definition: PortalTraits.h:42
typename std::remove_const< T >::type ComponentType
Definition: PortalTraits.h:38
static constexpr vtkm::IdComponent NUM_COMPONENTS
Definition: PortalTraits.h:40
static ComponentType GetComponent(const Type &t, vtkm::IdComponent)
Definition: PortalTraits.h:44
vtkPortalOfScalarValues TagType
Definition: PortalTraits.h:37