HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VEX_PodTypes.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: VEX_PodTypes.h (VEX Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __VEX_PodTypes__
12 #define __VEX_PodTypes__
13 
14 #include <VM/VM_Math.h>
15 #include <UT/UT_Vector2.h>
16 #include <UT/UT_Vector3.h>
17 #include <UT/UT_Vector4.h>
18 #include <UT/UT_Matrix2.h>
19 #include <UT/UT_Matrix3.h>
20 #include <UT/UT_Matrix4.h>
21 #include <UT/UT_Quaternion.h>
22 #include <UT/UT_Assert.h>
23 #include <algorithm>
24 
25 enum class VEX_Precision
26 {
27  VEX_32, // 32 bit precision
28  VEX_64, // 64 bit precision
29 };
32 
33 template <VEX_Precision PREC> class VEX_PrecisionResolver;
34 
35 template <>
37 {
38 public:
39  using int_type = int32;
48  static constexpr int bitsize = 32;
49 };
50 
51 template <>
53 {
54 public:
55  using int_type = int64;
64  static constexpr int bitsize = 64;
65 };
66 
67 template <VEX_Precision P> using VEXfloat = typename VEX_PrecisionResolver<P>::float_type;
68 template <VEX_Precision P> using VEXint = typename VEX_PrecisionResolver<P>::int_type;
69 template <VEX_Precision P> using VEXvec2 = typename VEX_PrecisionResolver<P>::vec2_type;
70 template <VEX_Precision P> using VEXvec3 = typename VEX_PrecisionResolver<P>::vec3_type;
71 template <VEX_Precision P> using VEXvec4 = typename VEX_PrecisionResolver<P>::vec4_type;
72 template <VEX_Precision P> using VEXmat2 = typename VEX_PrecisionResolver<P>::mat2_type;
73 template <VEX_Precision P> using VEXmat3 = typename VEX_PrecisionResolver<P>::mat3_type;
74 template <VEX_Precision P> using VEXmat4 = typename VEX_PrecisionResolver<P>::mat4_type;
75 template <VEX_Precision P> using VEXquaternion = typename VEX_PrecisionResolver<P>::quat_type;
76 
77 template <typename T>
78 static inline void
79 VEXpodFill(T *a, T *b, const T &v)
80  { std::fill(a, b, v); }
81 
82 /// Filling with a disabled predicate
83 template <typename T>
84 static inline void
85 VEXpodFill(T *a, const T *b, const T &val, const uint32 *disabled)
86 {
87  for (; a != b; ++a, ++disabled)
88  *a = *disabled ? *a : val;
89 }
90 
91 template <> inline void
93 {
94  VM_Math::set(a, v, b-a);
95 }
96 
97 template <> inline void
99  const fpreal32 &val, const uint32 *disabled)
100 {
101  VM_Math::set(a, val, b-a, disabled);
102 }
103 
104 template <typename T>
105 static inline T *
106 VEXpodCopy(const T *a, const T *b, T *dest)
107 {
108  UT_ASSERT(dest <= a || dest >= b);
109  return std::copy(a, b, dest);
110 }
111 
112 /// Copying with a disabled predicate
113 template <typename T>
114 static inline T *
115 VEXpodCopy(const T *a, const T *b, T *dest, const uint32 *disabled)
116 {
117  UT_ASSERT(dest <= a || dest >= b);
118  for (; a != b; ++a, ++dest, ++disabled)
119  *dest = *disabled ? *dest : *a;
120  return dest;
121 }
122 
123 template <>
124 inline fpreal32 *
126  const uint32 *disabled)
127 {
128  UT_ASSERT(dest <= a || dest >= b);
129  VM_Math::set(dest, a, b-a, disabled);
130  return dest + (b-a);
131 }
132 
133 template <>
134 inline int32 *
135 VEXpodCopy<int32>(const int32 *a, const int32 *b, int32 *dest,
136  const uint32 *disabled)
137 {
138  UT_ASSERT(dest <= a || dest >= b);
139  VM_Math::set(dest, a, b-a, disabled);
140  return dest + (b-a);
141 }
142 
143 namespace VEX {
144  inline namespace Literal {
145  // 32 bit constants: 32_vi or 3.1415_vf
147  VEXint<VEX_32> operator "" _vi(unsigned long long int v)
148  { return v; }
150  VEXfloat<VEX_32> operator "" _vf(long double v)
151  { return v; }
152 
153  // 64 bit constants: 32_vl or 3.1415_vd
155  VEXint<VEX_64> operator "" _vl(unsigned long long int v)
156  { return v; }
158  VEXfloat<VEX_64> operator "" _vd(long double v)
159  { return v; }
160  }
161 }
162 
163 #endif
int32 * VEXpodCopy< int32 >(const int32 *a, const int32 *b, int32 *dest, const uint32 *disabled)
Definition: VEX_PodTypes.h:135
UT_Matrix4T< fpreal64 > UT_Matrix4D
int int32
Definition: SYS_Types.h:39
void VEXpodFill(fpreal32 *a, const fpreal32 *b, const fpreal32 &val, const uint32 *disabled)
Definition: VEX_PodTypes.h:98
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
const GLdouble * v
Definition: glcorearb.h:837
UT_Vector2T< fpreal64 > UT_Vector2D
VEX_Precision
Definition: VEX_PodTypes.h:25
constexpr VEX_Precision VEX_64
Definition: VEX_PodTypes.h:31
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
float fpreal32
Definition: SYS_Types.h:200
typename VEX_PrecisionResolver< P >::vec3_type VEXvec3
Definition: VEX_PodTypes.h:70
FMT_NOINLINE FMT_CONSTEXPR auto fill(OutputIt it, size_t n, const fill_t< Char > &fill) -> OutputIt
Definition: format.h:1262
double fpreal64
Definition: SYS_Types.h:201
UT_QuaternionT< fpreal32 > UT_QuaternionF
fpreal32 * VEXpodCopy< fpreal32 >(const fpreal32 *a, const fpreal32 *b, fpreal32 *dest, const uint32 *disabled)
Definition: VEX_PodTypes.h:125
typename VEX_PrecisionResolver< P >::quat_type VEXquaternion
Definition: VEX_PodTypes.h:75
typename VEX_PrecisionResolver< P >::float_type VEXfloat
Definition: VEX_PodTypes.h:67
UT_QuaternionT< fpreal64 > UT_QuaternionD
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
UT_Matrix4T< fpreal32 > UT_Matrix4F
long long int64
Definition: SYS_Types.h:116
constexpr VEX_Precision VEX_32
Definition: VEX_PodTypes.h:30
typename VEX_PrecisionResolver< P >::mat4_type VEXmat4
Definition: VEX_PodTypes.h:74
UT_Matrix3T< fpreal32 > UT_Matrix3F
UT_Vector3T< fpreal64 > UT_Vector3D
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
UT_Matrix2T< fpreal64 > UT_Matrix2D
UT_Vector3T< fpreal32 > UT_Vector3F
typename VEX_PrecisionResolver< P >::mat2_type VEXmat2
Definition: VEX_PodTypes.h:72
UT_Vector2T< fpreal32 > UT_Vector2F
typename VEX_PrecisionResolver< P >::vec2_type VEXvec2
Definition: VEX_PodTypes.h:69
UT_Vector4T< fpreal32 > UT_Vector4F
VM_SIV set(fpreal32 *d, const fpreal32 *a, exint num, const uint32 *disabled)
VM_Math::set(d, a, disabled) := d[i] = disabled[i] ? d[i] : a[i].
Definition: VM_Math.h:403
GLuint GLfloat * val
Definition: glcorearb.h:1608
typename VEX_PrecisionResolver< P >::vec4_type VEXvec4
Definition: VEX_PodTypes.h:71
unsigned int uint32
Definition: SYS_Types.h:40
typename VEX_PrecisionResolver< P >::int_type VEXint
Definition: VEX_PodTypes.h:68
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
UT_Vector4T< fpreal64 > UT_Vector4D
UT_Matrix2T< fpreal32 > UT_Matrix2F
typename VEX_PrecisionResolver< P >::mat3_type VEXmat3
Definition: VEX_PodTypes.h:73
void VEXpodFill< fpreal32 >(fpreal32 *a, fpreal32 *b, const fpreal32 &v)
Definition: VEX_PodTypes.h:92
UT_Matrix3T< fpreal64 > UT_Matrix3D