HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PRM_RampUtils.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: PRM_RampUtils.h (Parameter Library)
7  */
8 
9 #ifndef __PRM_RampUtils_h__
10 #define __PRM_RampUtils_h__
11 
12 #include "PRM_API.h"
13 #include "PRM_Parm.h"
14 #include "PRM_Type.h"
15 #include <UT/UT_Spline.h>
16 #include <SYS/SYS_Types.h>
17 
18 class UT_OStringStream;
19 class UT_Ramp;
20 
21 PRM_API UT_SPLINE_BASIS PRMgetRampBasis(int ramp_interp);
23 
24 /// Utility functions for working with ramp parameters.
26 {
27 public:
28  /// Helper enumeration for stating the type of value that should be set
29  /// when updating multi-parms from ramps.
31  {
33  PRM_FLOAT_TYPE
34  };
35 
36  /// Helper class for passing data to callback functions
37  /// when updating multi-parms from ramps.
38  class ValueData
39  {
40  public:
41  inline ValueData(
42  void *callee, fpreal t, PRM_Parm &p, int vector_index, int val,
43  PRM_AddKeyType add_key);
44  inline ValueData(
45  void *callee, fpreal t, PRM_Parm &p, int vector_index, fpreal val,
46  PRM_AddKeyType add_key);
47 
48  inline void *callee() const;
49  inline fpreal time() const;
50  inline PRM_Parm &parm() const;
51  inline int vectorIndex() const;
52  inline PRM_ValueType valueType() const;
53  inline int intValue() const;
54  inline fpreal floatValue() const;
55  inline PRM_AddKeyType addKey() const;
56 
57  private:
58  void *myCallee;
59  fpreal myTime;
60  PRM_Parm &myParm;
61  int myVectorIndex;
62  PRM_ValueType myValueType;
63  PRM_AddKeyType myAddKey;
64  int myIntValue;
65  fpreal myFloatValue;
66  };
67 
68  /// Callback function which sets values when updating multi-parms from
69  /// ramps.
70  typedef void (*SetValueCB)(ValueData value_info);
71 
72  /// Update ramp value from a multi parm.
73  static void updateRampFromMultiParm(
74  fpreal t, const PRM_Parm &m, UT_Ramp *ramp,
75  bool *time_dep = NULL, DEP_MicroNode *depnode = NULL);
76 
77  /// Update multi parm from a ramp value.
78  static void updateMultiParmFromRamp(
79  fpreal t, const UT_Ramp &ramp, PRM_Parm &m, bool add_wrap,
80  PRM_AddKeyType add_key);
81 
82  /// Update multi parm from a ramp value.
83  /// This method version takes in a callback function that sets the values
84  /// in the multi parm.
85  static void updateMultiParmFromRamp(
86  fpreal t, const UT_Ramp &ramp, PRM_Parm &m, bool add_wrap,
87  PRM_AddKeyType add_key, SetValueCB set_value_cb, void *cb_callee);
88 
89  /// Write out the ramp parameter values as an encoding of ramp defaults.
90  static void setRampDefaultFromParm(UT_OStringStream &defaults_os,
91  const PRM_Parm &ramp_parm);
92 
93  /// Parse the ramp defaults and set them as values on the parameter
94  static void getRampParmFromDefault(PRM_Parm &ramp_parm,
95  const char *defaults_string);
96 
97  /// Get the basis, positions, value (as component sequence array), and
98  /// value tuple size that define the ramp parameter value.
99  static void getRampValuesFromParm(
100  UT_DoubleArray &values, int &tuple_size,
101  UT_DoubleArray &keys, UT_StringArray &basis,
102  const UT_Ramp &ramp, bool is_rgb);
103 
104  /// Construct the string that defines the ramp default value based
105  /// on provided basis, positions, and value arrays.
106  static void getRampDefaultString(UT_WorkBuffer &wbuf,
107  const UT_DoubleArray &values, int tuple_size,
108  const UT_DoubleArray *keys,
109  const UT_StringArray *basis);
110 };
111 
112 // ==========================================================================
113 // PRM_RampUtils::ValueData implementation.
114 // ==========================================================================
116  void *callee, fpreal t, PRM_Parm &p, int vector_index, int val,
117  PRM_AddKeyType add_key)
118  : myCallee(callee)
119  , myTime(t)
120  , myParm(p)
121  , myVectorIndex(vector_index)
122  , myValueType(PRM_RampUtils::PRM_INT_TYPE)
123  , myIntValue(val)
124  , myFloatValue(0.0)
125  , myAddKey(add_key)
126 {
127 }
128 
130  void *callee, fpreal t, PRM_Parm &p, int vector_index, fpreal val,
131  PRM_AddKeyType add_key)
132  : myCallee(callee)
133  , myTime(t)
134  , myParm(p)
135  , myVectorIndex(vector_index)
136  , myValueType(PRM_RampUtils::PRM_FLOAT_TYPE)
137  , myIntValue(0)
138  , myFloatValue(val)
139  , myAddKey(add_key)
140 {
141 }
142 
143 inline void *
144 PRM_RampUtils::ValueData::callee() const { return myCallee; }
145 
146 inline fpreal
147 PRM_RampUtils::ValueData::time() const { return myTime; }
148 
149 inline PRM_Parm &
150 PRM_RampUtils::ValueData::parm() const { return myParm; }
151 
152 inline int
153 PRM_RampUtils::ValueData::vectorIndex() const { return myVectorIndex; }
154 
156 PRM_RampUtils::ValueData::valueType() const { return myValueType; }
157 
158 inline int
159 PRM_RampUtils::ValueData::intValue() const { return myIntValue; }
160 
161 inline fpreal
162 PRM_RampUtils::ValueData::floatValue() const { return myFloatValue; }
163 
164 inline PRM_AddKeyType
165 PRM_RampUtils::ValueData::addKey() const { return myAddKey; }
166 
167 #endif
PRM_AddKeyType
Definition: PRM_Parm.h:58
ValueData(void *callee, fpreal t, PRM_Parm &p, int vector_index, int val, PRM_AddKeyType add_key)
PRM_API PRM_RampInterpType PRMgetRampInterp(UT_SPLINE_BASIS basis)
PRM_Parm & parm() const
PRM_API UT_SPLINE_BASIS PRMgetRampBasis(int ramp_interp)
PRM_ValueType valueType() const
void
Definition: png.h:1083
GT_API const UT_StringHolder time
An output stream object that owns its own string buffer storage.
UT_SPLINE_BASIS
Definition: UT_Spline.h:31
fpreal floatValue() const
void * callee() const
PRM_AddKeyType addKey() const
GLdouble t
Definition: glad.h:2397
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1602
fpreal64 fpreal
Definition: SYS_Types.h:277
Utility class for containing a color ramp.
Definition: UT_Ramp.h:88
GLuint GLfloat * val
Definition: glcorearb.h:1608
Utility functions for working with ramp parameters.
Definition: PRM_RampUtils.h:25
PRM_RampInterpType
Definition: PRM_Type.h:442
#define PRM_API
Definition: PRM_API.h:10