VTK
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 template<typename T>
31 {
34  static constexpr vtkm::IdComponent NUM_COMPONENTS = 1;
35 
36  static inline
37  void SetComponent(Type& t, vtkm::IdComponent, const ComponentType& v)
38  { t = v; }
39 
40  static inline
41  ComponentType GetComponent(const Type& t, vtkm::IdComponent)
42  {
43  return t;
44  }
45 };
46 
47 template<typename T, int N>
48 struct vtkPortalTraits< vtkm::Vec<T,N> >
49 {
51  using Type = vtkm::Vec<T,N>;
52  static constexpr vtkm::IdComponent NUM_COMPONENTS = N;
53 
54  static inline
55  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
62  ComponentType GetComponent(const Type& t, vtkm::IdComponent i)
63  {
64  VTKM_ASSUME((i >= 0 && i < N));
65  return t[i];
66  }
67 };
68 
69 template<typename T, int N>
70 struct vtkPortalTraits< const vtkm::Vec<T,N> >
71 {
73  using Type = vtkm::Vec<T,N>;
74  static constexpr vtkm::IdComponent NUM_COMPONENTS = N;
75 
76  static inline
77  void SetComponent(Type& t, vtkm::IdComponent i, const ComponentType& v)
78  {
79  VTKM_ASSUME((i >= 0 && i < N));
80  t[i] = v;
81  }
82 
83  static inline
84  ComponentType GetComponent(const Type& t, vtkm::IdComponent i)
85  {
86  VTKM_ASSUME((i >= 0 && i < N));
87  return t[i];
88  }
89 };
90 
91 template<typename T, int N, int M>
92 struct vtkPortalTraits<vtkm::Vec< vtkm::Vec<T,N>, M> >
93 {
95  using Type = vtkm::Vec< vtkm::Vec<T,N>, M>;
96  static constexpr vtkm::IdComponent NUM_COMPONENTS = N*M;
97 
98  static inline
99  void SetComponent(Type& t, vtkm::IdComponent i, const ComponentType& v)
100  {
101  VTKM_ASSUME((i >= 0 && i < NUM_COMPONENTS));
102  //We need to convert i back to a 2d index
103  const vtkm::IdComponent j = i%N;
104  t[i/N][j] = v;
105  }
106 
107  static inline
108  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 {
121  using Type = vtkm::Vec< vtkm::Vec<T,N>, M>;
122  static constexpr vtkm::IdComponent NUM_COMPONENTS = N*M;
123 
124  static inline
125  void SetComponent(Type& t, vtkm::IdComponent i, const ComponentType& v)
126  {
127  VTKM_ASSUME((i >= 0 && i < NUM_COMPONENTS));
128  //We need to convert i back to a 2d index
129  const vtkm::IdComponent j = i%N;
130  t[i/N][j] = v;
131  }
132 
133  static inline
134  ComponentType GetComponent(const Type& t, vtkm::IdComponent i)
135  {
136  VTKM_ASSUME((i >= 0 && i < NUM_COMPONENTS));
137  //We need to convert i back to a 2d index
138  const vtkm::IdComponent j = i%N;
139  return t[i/N][j];
140  }
141 };
142 
143 } //namespace vtkmlib
144 
145 #endif // vtkmlib_PortalsTraits_h
typename std::remove_const< T >::type ComponentType
Definition: PortalTraits.h:50
static void SetComponent(Type &t, vtkm::IdComponent i, const ComponentType &v)
Definition: PortalTraits.h:125
typename std::remove_const< T >::type ComponentType
Definition: PortalTraits.h:94
static ComponentType GetComponent(const Type &t, vtkm::IdComponent)
Definition: PortalTraits.h:41
static ComponentType GetComponent(const Type &t, vtkm::IdComponent i)
Definition: PortalTraits.h:62
static ComponentType GetComponent(const Type &t, vtkm::IdComponent i)
Definition: PortalTraits.h:84
static constexpr vtkm::IdComponent NUM_COMPONENTS
Definition: PortalTraits.h:34
static ComponentType GetComponent(const Type &t, vtkm::IdComponent i)
Definition: PortalTraits.h:108
static void SetComponent(Type &t, vtkm::IdComponent i, const ComponentType &v)
Definition: PortalTraits.h:55
static void SetComponent(Type &t, vtkm::IdComponent i, const ComponentType &v)
Definition: PortalTraits.h:77
static ComponentType GetComponent(const Type &t, vtkm::IdComponent i)
Definition: PortalTraits.h:134
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:99
static void SetComponent(Type &t, vtkm::IdComponent, const ComponentType &v)
Definition: PortalTraits.h:37
typename std::remove_const< T >::type ComponentType
Definition: PortalTraits.h:32