HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VEX_KVexRamp.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_KVexRamp.h (VEX Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __VEX_KVexRamp__
12 #define __VEX_KVexRamp__
13 
14 #include "VEX_API.h"
15 
16 #include <UT/UT_IntrusivePtr.h>
17 #include <UT/UT_Ramp.h>
18 #include <UT/UT_Span.h>
19 #include <UT/UT_StringHolder.h>
20 #include <SYS/SYS_Hash.h>
21 
22 class UT_JSONWriter;
23 
25  : public UT_IntrusiveRefCounter<VEX_KVexRamp>
26 {
27 public:
28  VEX_KVexRamp();
29 
31 
32  /// KEY_T should be float or double
33  /// VALUE_T should be float/double, UT_Vector2, UT_Vector3 or UT_Vector4
34  template <typename FLOAT_T, typename VALUE_T>
35  static inline vex_RampHash
38  const UT_Span<const UT_StringHolder> &basis,
39  uint components)
40  {
41  SYS_HashType hash = SYSsharpe_inthash(components);
42  for (const auto &k : keys)
43  SYShashCombine(hash, k);
44  for (const auto &v : values)
45  SYShashCombine(hash, v);
46  for (const auto &b : basis)
47  SYShashCombine(hash, b);
48  vex_RampHash uhash = (hash & 0xffffffff) ^ (hash >> 32);
49  return uhash ? uhash : 1;
50  }
51 
52 #define VEC_CTOR(FLOAT_T, VALUE_T) \
53  VEX_KVexRamp(const UT_Span<const FLOAT_T> &keys, \
54  const UT_Span<const VALUE_T<FLOAT_T>> &values, \
55  const UT_Span<const UT_StringHolder> &basis) \
56  { initVec<FLOAT_T, VALUE_T<FLOAT_T>>(keys, values, basis); } \
57  /* end macro */
58 
59 #define FLT_CTOR(FLOAT_T) \
60  VEX_KVexRamp(const UT_Span<const FLOAT_T> &keys, \
61  const UT_Span<const FLOAT_T> &values, \
62  const UT_Span<const UT_StringHolder> &basis) \
63  { initFloat<FLOAT_T>(keys, values, basis); } \
64  VEX_KVexRamp(int tsize, \
65  const UT_Span<const FLOAT_T> &keys, \
66  const UT_Span<const FLOAT_T> &vals, \
67  const UT_Span<const UT_StringHolder> &basis) \
68  { initArray<FLOAT_T>(tsize, keys, vals, basis); } \
69  VEC_CTOR(FLOAT_T, UT_Vector2T) \
70  VEC_CTOR(FLOAT_T, UT_Vector3T) \
71  VEC_CTOR(FLOAT_T, UT_Vector4T) \
72  /* end macro */
73 
76 #undef FLT_CTOR
77 #undef VEC_CTOR
78 
79  vex_RampHash hash() const { return myHash; }
80 
81  template <typename FLOAT_T>
82  void eval(FLOAT_T key, FLOAT_T *result, int size) const;
83 
84  fpreal32 evalF(float k) const { fpreal32 r; eval<fpreal32>(k, &r, 1); return r; }
85  UT_Vector2 evalU(float k) const { UT_Vector2 r; eval<fpreal32>(k, r.data(), 2); return r; }
86  UT_Vector3 evalV(float k) const { UT_Vector3 r; eval<fpreal32>(k, r.data(), 3); return r; }
87  UT_Vector4 evalP(float k) const { UT_Vector4 r; eval<fpreal32>(k, r.data(), 4); return r; }
88  int size() const { return mySize; }
89 
90  UT_StringHolder toString() const;
91  void dump() const;
92  void dump(UT_JSONWriter &w) const;
93 
95 
96 private:
97  template <typename FLOAT_T>
98  void initFloat(const UT_Span<const FLOAT_T> &keys,
100  const UT_Span<const UT_StringHolder> &basis);
101  template <typename FLOAT_T>
102  void initArray(int tsize,
103  const UT_Span<const FLOAT_T> &keys,
105  const UT_Span<const UT_StringHolder> &basis);
106  template <typename FLOAT_T, typename VALUE_T>
107  void initVec(const UT_Span<const FLOAT_T> &keys,
109  const UT_Span<const UT_StringHolder> &basis);
110 
111  template <typename FLOAT_T, int VSIZE>
112  void addKey(fpreal k,
113  const FLOAT_T *v,
114  const UT_StringHolder &basis);
115 
116  UT_Ramp myRamp;
117  vex_RampHash myHash;
118  int mySize; // number of components (1, 2, 3, 4)
119 };
120 
122  : public UT_NonCopyable
123 {
124 public:
125  virtual ~VEX_KVexRampEval();
126 
127  virtual void eval(const VEX_KVexRamp &ramp,
128  fpreal32 t,
129  fpreal32 *result,
130  int result_size) const
131  {
132  ramp.eval<fpreal32>(t, result, result_size);
133  }
134  virtual void eval(const VEX_KVexRamp &ramp,
135  fpreal64 t,
136  fpreal64 *result,
137  int result_size) const
138  {
139  ramp.eval<fpreal64>(t, result, result_size);
140  }
141 };
142 
144 
145 #endif
uint32 vex_RampHash
Definition: VEX_KVexRamp.h:30
fpreal32 evalF(float k) const
Definition: VEX_KVexRamp.h:84
const GLdouble * v
Definition: glcorearb.h:837
std::size_t SYS_HashType
Define the type for hash values.
Definition: SYS_Hash.h:19
virtual void eval(const VEX_KVexRamp &ramp, fpreal32 t, fpreal32 *result, int result_size) const
Definition: VEX_KVexRamp.h:127
UT_Vector2 evalU(float k) const
Definition: VEX_KVexRamp.h:85
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:39
**But if you need a result
Definition: thread.h:622
#define VEX_API
Definition: VEX_API.h:14
A reference counter base class for use with UT_IntrusivePtr.
UT_Vector3 evalV(float k) const
Definition: VEX_KVexRamp.h:86
float fpreal32
Definition: SYS_Types.h:200
constexpr SYS_FORCE_INLINE const T * data() const noexcept
Definition: UT_Vector3.h:294
UT_Vector4 evalP(float k) const
Definition: VEX_KVexRamp.h:87
vex_RampHash hash() const
Definition: VEX_KVexRamp.h:79
double fpreal64
Definition: SYS_Types.h:201
void eval(FLOAT_T key, FLOAT_T *result, int size) const
constexpr SYS_FORCE_INLINE const T * data() const noexcept
Definition: UT_Vector2.h:220
HUSD_API bool eval(VtValue &val, T &ret_val)
virtual void eval(const VEX_KVexRamp &ramp, fpreal64 t, fpreal64 *result, int result_size) const
Definition: VEX_KVexRamp.h:134
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GLdouble t
Definition: glad.h:2397
static UT_IntrusivePtr< VEX_KVexRamp > theEmptyRamp
Definition: VEX_KVexRamp.h:94
GLsizeiptr size
Definition: glcorearb.h:664
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1602
fpreal64 fpreal
Definition: SYS_Types.h:283
constexpr SYS_FORCE_INLINE const T * data() const noexcept
Definition: UT_Vector4.h:226
Utility class for containing a color ramp.
Definition: UT_Ramp.h:96
unsigned int uint32
Definition: SYS_Types.h:40
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
static vex_RampHash computeHash(const UT_Span< const FLOAT_T > &keys, const UT_Span< const VALUE_T > &values, const UT_Span< const UT_StringHolder > &basis, uint components)
Definition: VEX_KVexRamp.h:36
GLboolean r
Definition: glcorearb.h:1222
#define FLT_CTOR(FLOAT_T)
Definition: VEX_KVexRamp.h:59
int size() const
Definition: VEX_KVexRamp.h:88
unsigned int uint
Definition: SYS_Types.h:45