HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CVEX_Value.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: CVEX_Value.h ( CVEX Library, C++)
7  *
8  * COMMENTS: C++ interface to VEX. This class is used to specify
9  * input/output variable data.
10  */
11 
12 #ifndef __CVEX_Value__
13 #define __CVEX_Value__
14 
15 #include "CVEX_API.h"
16 #include <UT/UT_Array.h>
17 #include <UT/UT_StringHolder.h>
18 #include <UT/UT_Options.h>
20 #include <VEX/VEX_PodTypes.h>
21 #include <VEX/VEX_VexTypes.h> // for VEX_Type
22 
25 
26 /// The CVEX_Type enum defines the VEX types available to CVEX.
27 typedef enum {
28  CVEX_TYPE_INVALID = -1, // Invalid type
29  CVEX_TYPE_INTEGER, // Integer
30  CVEX_TYPE_FLOAT, // Float
31  CVEX_TYPE_VECTOR2, // 2-tuple of float
32  CVEX_TYPE_VECTOR3, // 3-tuple of float
33  CVEX_TYPE_VECTOR4, // 4-tuple of float
34  CVEX_TYPE_MATRIX2, // 4-tuple of float
35  CVEX_TYPE_MATRIX3, // 9-tuple of float
36  CVEX_TYPE_MATRIX4, // 16-tuple of float
37  CVEX_TYPE_STRING, // string values
38  CVEX_TYPE_DICT, // dictionary values
39  CVEX_TYPE_INTEGER_ARRAY, // Integer array
40  CVEX_TYPE_FLOAT_ARRAY, // Float array
41  CVEX_TYPE_VECTOR2_ARRAY, // 2-tuple of float array
42  CVEX_TYPE_VECTOR3_ARRAY, // 3-tuple of float array
43  CVEX_TYPE_VECTOR4_ARRAY, // 4-tuple of float array
44  CVEX_TYPE_MATRIX2_ARRAY, // 4-tuple of float array
45  CVEX_TYPE_MATRIX3_ARRAY, // 9-tuple of float array
46  CVEX_TYPE_MATRIX4_ARRAY, // 16-tuple of float array
47  CVEX_TYPE_STRING_ARRAY, // string array.
48  CVEX_TYPE_DICT_ARRAY, // dictionary array.
49 } CVEX_Type;
50 
51 /// @brief A class representing a VEX value.
52 ///
53 /// The CVEX_Value objects are created internally in the CVEX library. They
54 /// provide a mapping from the CVEX library to the underlying VEX
55 /// representation of objects.
56 template <VEX_Precision PREC>
58 {
59 public:
62  bool varying);
63  ~CVEX_ValueT();
64 
65  /// Query name of VEX value
66  const UT_StringHolder &getName() const { return myName; }
67  /// Query type of VEX value
68  CVEX_Type getType() const { return myType; }
69  void setType(CVEX_Type type);
70  /// Query whether the VEX value is an export (or read-only)
71  bool isExport() const { return myExport; }
72  /// Query whether the VEX value is uniform or varying
73  bool isVarying() const { return myVarying; }
74  /// Query the array size of the VEX value.
75  /// @note This is @b not the used for VEX arrays, but rather represents the
76  /// number of entries in the varying array.
77  int getArraySize() const { return myArraySize; }
78 
79  /// Get the raw data pointer.
80  /// For numeric types, the data refers to a raw array of data (depending on
81  /// the getType() of the value.
82  /// - CVEX_TYPE_INTEGER @c int
83  /// - CVEX_TYPE_FLOAT @c fpreal32
84  /// - CVEX_TYPE_VECTOR2 @c UT_Vector2F
85  /// - CVEX_TYPE_VECTOR3 @c UT_Vector3F
86  /// - CVEX_TYPE_VECTOR4 @c UT_Vector4F
87  /// - CVEX_TYPE_MATRIX2 @c UT_Matrix2F
88  /// - CVEX_TYPE_MATRIX3 @c UT_Matrix3F
89  /// - CVEX_TYPE_MATRIX4 @c UT_Matrix4F
90  /// For CVEX_TYPE_STRING, the data will point to a UT_StringArray.
91  void *getRawData() { return myData; }
92 
93  bool isPackedArray() const { return myIsPackedArray; }
94 
95  /// The array size is NOT the size in bytes, but rather the array size of
96  /// the input data. It should either be 1 or N, where N is the number of
97  /// values being computed by VEX.
98  ///
99  /// When passing data for output variables, please check to see whether
100  /// the output variable is uniform or varying. Varying values need to
101  /// have a full array of data (including string arrays).
102  ///
103  /// The CVEX_Value object will hold a pointer to the CVEX_StringArray,
104  /// so the data must be persistent.
105  bool setTypedData(VEXint<PREC> *data, int array_size);
106  bool setTypedData(VEXfloat<PREC> *data, int array_size);
107  bool setTypedData(VEXvec2<PREC> *data, int array_size);
108  bool setTypedData(VEXvec3<PREC> *data, int array_size);
109  bool setTypedData(VEXvec4<PREC> *data, int array_size);
110  bool setTypedData(VEXmat2<PREC> *data, int array_size);
111  bool setTypedData(VEXmat3<PREC> *data, int array_size);
112  bool setTypedData(VEXmat4<PREC> *data, int array_size);
113 
114  /// When setting values for string types, you need to pass in a
115  /// CVEX_StringArray instead of a void *. For input variables, the length
116  /// of the array will determine whether the parameter is varying or
117  /// uniform.
118  ///
119  /// The CVEX_Value object will hold a pointer to the CVEX_StringArray,
120  /// so the data must be persistent.
121  ///
122  /// When setting data for outputs, the packed arrays should be empty
123  /// and the array size specified.
124  bool setTypedData(CVEX_StringArray &stringdata);
125  bool setTypedData(CVEX_DictArray &dictdata);
126  bool setTypedData(UT_Array<UT_Array<VEXint<PREC>> > &intdata);
127  bool setTypedData(UT_PackedArrayOfArrays<VEXint<PREC>> &intdata,
128  int arraysize=0);
129  /// This is stored as xyzxyzxyz for vector data.
130  bool setTypedData(UT_Array<UT_Array<VEXfloat<PREC>> > &fltdata);
131  bool setTypedData(UT_PackedArrayOfArrays<VEXfloat<PREC>> &fltdata,
132  int arraysize=0);
133  bool setTypedData(UT_Array<CVEX_StringArray> &stringdata);
134  bool setTypedData(UT_Array<CVEX_DictArray> &dictdata);
135 
136  /// Type unsafe way of setting VEX data. Avoid using if possible.
137  bool setRawData(CVEX_Type type, void *data, int array_size);
138 
139 
140  // Deprecated equivalents. Please avoid, they're error-prone.
141  SYS_DEPRECATED(13.0)
142  void *getData()
143  { return getRawData(); }
144 
145  SYS_DEPRECATED(13.0)
146  bool setData(void *data, int array_size)
147  { return setRawData(myType, data, array_size); }
148 
149  SYS_DEPRECATED(13.0)
150  bool setData(CVEX_StringArray &stringdata)
151  { return setTypedData(stringdata); }
152 
153  static int getTupleSize(CVEX_Type t);
154  static CVEX_Type getArrayBaseType(CVEX_Type t);
155 
156  /// The IsConstant determines eligibility for constant folding.
157  /// It likely implies Uniform. But it is quite reasonable to have
158  /// a Uniform parameter that isn't constant, it is then a demand
159  /// that the VEX Assemble does not fold the input regardless of
160  /// the initial value during load()
161  void setIsConstant(bool isconstant)
162  { myIsConstant = isconstant; }
163  bool isConstant() const
164  { return myIsConstant; }
165 
166  /// Given the list of vex parameters, returns the list of cvex parmeters
167  /// that have valid cvex types.
168  static VEX_Type cvexToVexType(CVEX_Type type, bool &isarray);
169  static CVEX_Type vexToCVexType(VEX_Type vextype, bool isarray);
170 
171 private:
172  void clear();
173  void clearAndAllocArray(bool ispacked);
174 
175  void *myData;
176  void *myStringSet;
177  void *myDictSet;
178  void *myArrayType;
179  UT_StringHolder myName;
180  CVEX_Type myType; // Data type
181  VEX_Type myVexType; // VEX Type (mapped from CVEX_Type)
182  int myVexIndex; // Offset into VEX symbol table
183  int myArraySize; // Array size
184  bool myExport; // Whether the data is output by VEX
185  bool myVarying; // Whether the data is varying
186  bool myIsArray; // Am I an array?
187  bool myIsConstant; // Am I eligible for constant folding?
188  bool myIsPackedArray; // If the array is packed.
189 
190  template <VEX_Precision ALLPREC>
191  friend class CVEX_ContextT;
192  template <VEX_Precision ALLPREC>
193  friend class CVEX_ValueListT;
194 };
195 
197 
200 
201 #endif
VEX_Type
VEX variable types.
Definition: VEX_VexTypes.h:18
#define SYS_DEPRECATED(__V__)
GLuint const GLchar * name
Definition: glew.h:1814
CVEX_EXTERN_TEMPLATE(CVEX_ValueT< VEX_32 >)
CVEX_Type getType() const
Query type of VEX value.
Definition: CVEX_Value.h:68
void setIsConstant(bool isconstant)
Definition: CVEX_Value.h:161
bool isVarying() const
Query whether the VEX value is uniform or varying.
Definition: CVEX_Value.h:73
const UT_StringHolder & getName() const
Query name of VEX value.
Definition: CVEX_Value.h:66
typename VEX_PrecisionResolver< P >::vec3_type VEXvec3
Definition: VEX_PodTypes.h:70
int getArraySize() const
Definition: CVEX_Value.h:77
List of input or output values for a CVEX_Context.
UT_Array< UT_StringHolder > CVEX_StringArray
Definition: CVEX_Value.h:23
A class representing a VEX value.
Definition: CVEX_Value.h:57
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
typename VEX_PrecisionResolver< P >::float_type VEXfloat
Definition: VEX_PodTypes.h:67
void
Definition: png.h:1083
typename VEX_PrecisionResolver< P >::mat4_type VEXmat4
Definition: VEX_PodTypes.h:74
UT_Array< UT_OptionsHolder > CVEX_DictArray
Definition: CVEX_Value.h:24
CVEX_Type
The CVEX_Type enum defines the VEX types available to CVEX.
Definition: CVEX_Value.h:27
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
typename VEX_PrecisionResolver< P >::mat2_type VEXmat2
Definition: VEX_PodTypes.h:72
bool isExport() const
Query whether the VEX value is an export (or read-only)
Definition: CVEX_Value.h:71
typename VEX_PrecisionResolver< P >::vec2_type VEXvec2
Definition: VEX_PodTypes.h:69
void * getRawData()
Definition: CVEX_Value.h:91
#define CVEX_API
Definition: CVEX_API.h:12
typename VEX_PrecisionResolver< P >::vec4_type VEXvec4
Definition: VEX_PodTypes.h:71
bool isPackedArray() const
Definition: CVEX_Value.h:93
bool isConstant() const
Definition: CVEX_Value.h:163
typename VEX_PrecisionResolver< P >::int_type VEXint
Definition: VEX_PodTypes.h:68
Call VEX from C++.
Definition: CVEX_Context.h:175
typename VEX_PrecisionResolver< P >::mat3_type VEXmat3
Definition: VEX_PodTypes.h:73
GLdouble GLdouble t
Definition: glew.h:1398