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