HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GT_AttributeBuilder.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: GT_AttributeBuilder.h ( GT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GT_AttributeBuilder__
12 #define __GT_AttributeBuilder__
13 
14 #include "GT_API.h"
15 #include "GT_AttributeList.h"
16 #include "GT_BuilderStatus.h"
17 #include "GT_DAConstantValue.h"
18 #include "GT_DANumeric.h"
19 #include "GT_DataArray.h"
20 
21 #include <UT/UT_Array.h>
22 #include <UT/UT_NonCopyable.h>
23 #include <UT/UT_Pair.h>
24 #include <UT/UT_SymbolTable.h>
25 #include <UT/UT_Variadic.h>
26 
27 #include <stdarg.h>
28 
31 
33 {
34 public:
37 
38  /// The parse method will take a NULL terminated argument list and parse
39  /// attributes using a very simple heuristic. Attributes are specified by
40  /// a name/value pair. The name includes binding class, storage and tuple
41  /// size information (possibly type information). The value is an array
42  /// which contains enough data to represent the data. A copy of the data
43  /// is made.
44  ///
45  /// The name consists of several parts:
46  /// <b>Binding Class</b>
47  /// The binding class is one of:
48  /// - @c detail, @c constant @n a single value shared over all primitives
49  /// - @c primitive, @c uniform @n a value for each primitive
50  /// - @c point, @c varying @n a value for each shared point
51  /// - @c vertex, @c facevarying @n a value for each vertex
52  /// <b> Storage Class </b>
53  /// - @c int32, @c int @n A 32 bit integer
54  /// - @c int64, @c long @n A 64 bit integer
55  /// - @c real16, @c fpreal16, @c float @n A 16 bit float
56  /// - @c real32, @c fpreal32, @c float @n A 32 bit float
57  /// - @c real64, @c fpreal64, @c double @n A 64 bit float
58  /// - @c point16, @c point @n A 16 bit position value (3-tuple)
59  /// - @c point32, @c point @n A 32 bit position value (3-tuple)
60  /// - @c point64, @n A 64 bit position value (3-tuple)
61  /// - @c vector16, @c vector @n A 16 bit direction vector value (3-tuple)
62  /// - @c vector32, @c vector @n A 32 bit direction vector value (3-tuple)
63  /// - @c vector64, @n A 64 bit direction vector value (3-tuple)
64  /// - @c normal16/32/64, @c normal @n A 16/32/64 bit normal vector value (3-tuple)
65  /// - @c color16/32/64, @c color @n A 16/32/64 bit color value (3-tuple)
66  /// - @c matrix32 @n A 32 bit transformation matrix (16-tuple)
67  /// - @c matrix64, @c matrix @n A 64 bit transform matrix (16-tuple)
68  /// - @c string @n An array of chars (i.e. const char *)
69  /// <b> Array Size </b>
70  /// Optionally, an array size can be specified by using <tt>[size]</tt>
71  /// notation. Please note that a "point32[3]" would require 9 fpreal32
72  /// values per array entry.
73  ///
74  /// For example: @code
75  /// parse(vertex, point, primitive, detail,
76  /// "varying point P", P,
77  /// "varying normal N", N,
78  /// "vertex float uv[2]", uv,
79  /// "uniform color Cd", Cd,
80  /// "constant matrix xform", xform);
81  /// @endcode
82 
83  /// It is possible to pass in the same GT_AttributeBuilder for different
84  /// binding classes. For example, for a GT_PrimSphere, you might
85  /// have something like:@code
86  /// parse(detail, detail, detail, detail, ...);
87  /// @endcode
88  /// which will build all attributes in the same builder (@c detail)
89 
90  /// If a variable is specified multiple times, the value will be used for
91  /// multi-segment motion blur. At the current time, all variables which
92  /// have multiple segments should have the same number of segments
93  /// specified. It is not necessary to specify segments for all variables,
94  /// only ones which change over time. For example @code
95  /// parse(vertex, point, primitive, detail,
96  /// "vertex point P", P0, // P at time 0
97  /// "vertex point P", P1, // P at time 1
98  /// "vertex normal N", N0, // N at time 0
99  /// "vertex normal N", N1, // N at time 1
100  /// "vertex float uv[2]", uv,
101  /// "constant matrix xform", xform);
102  /// @endcode
103  static bool parse(GT_BuilderStatus &err,
104  GT_AttributeBuilder &vertex,
105  GT_AttributeBuilder &point,
106  GT_AttributeBuilder &primitive,
107  GT_AttributeBuilder &detail,
108  const GT_VariadicAttributes &args);
109 
110  bool append(GT_BuilderStatus &status,
111  const char *name, const GT_DataArrayHandle &h);
112 
113  /// Add a named value to the attribute list
114  template <typename T_POD>
115  bool add(GT_BuilderStatus &status, const char *name,
116  const T_POD *data, int tuple_size,
117  GT_Type typeinfo = GT_TYPE_NONE)
118  {
119  GT_DataArray *array;
120  // Do a quick check to see if the array is constant
122  myArraySize, data, tuple_size))
123  {
124  array = new GT_DAConstantValue<T_POD>(
125  myArraySize, data, tuple_size);
126  }
127  else
128  {
129  GT_DANumeric<T_POD> *narray;
130  narray = new GT_DANumeric<T_POD>(myArraySize,
131  tuple_size, typeinfo);
132  narray->copyFrom(data);
133  array = narray;
134  }
135  return append(status, name, GT_DataArrayHandle(array));
136  }
137 
138  bool addString(GT_BuilderStatus &status, const char *name,
139  const char *const*data, int tuple_size);
140 
141  /// Make an attribute list for the attributes defined by parsing
142  GT_AttributeListHandle makeList();
143 
144  enum {
145  GT_BINDING_VERTEX, // Vertex/facevarying class
146  GT_BINDING_POINT, // Point/varying class
147  GT_BINDING_PRIMITIVE, // Primitive/uniform binding class
148  GT_BINDING_DETAIL // Detail binding
149  };
150  /// Guess at the binding, storage and type information. The values passed
151  /// in are not modified.
152  static bool guessTypeInformation(GT_BuilderStatus &err,
153  const char *token,
154  UT_WorkBuffer &name,
155  int &binding_class,
157  GT_Type &type,
158  GT_Size &tuple_size);
159 
160 private:
161  class MapEntry {
162  public:
163  MapEntry()
164  : myIndex(-1)
165  {
166  }
167  ~MapEntry() {}
169  int myIndex;
170  };
171 
172  UT_SymbolMap<MapEntry *> myArrays;
173  GT_Size myArraySize;
174  int mySegments;
175 };
176 
177 #endif
bool add(GT_BuilderStatus &status, const char *name, const T_POD *data, int tuple_size, GT_Type typeinfo=GT_TYPE_NONE)
Add a named value to the attribute list.
GT_Storage
Definition: GT_Types.h:17
UT_Pair< const char *, UT_VariadicPODType > GT_Attribute
#define GT_API
Definition: GT_API.h:11
GT_Type
Definition: GT_Types.h:33
GLsizeiptr size
Definition: glcorearb.h:663
Abstract data class for an array of float, int or string data.
Definition: GT_DataArray.h:38
UT_VariadicT< GT_Attribute > GT_VariadicAttributes
UT_IntrusivePtr< GT_DataArray > GT_DataArrayHandle
Definition: GT_DataArray.h:30
A data array for a constant value.
GLboolean * data
Definition: glcorearb.h:130
GLuint const GLchar * name
Definition: glcorearb.h:785
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
void copyFrom(const T *src)
Copy an entire data from a flat array.
Definition: GT_DANumeric.h:177
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
An array of numeric values (int32, int64, fpreal16, fpreal32, fpreal64)
Definition: GT_DANumeric.h:23
getOption("OpenEXR.storage") storage
Definition: HDK_Image.dox:276
Return the status of primitive creation from GT_PrimitiveBuilder.
int64 GT_Size
Definition: GT_Types.h:112