HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_Types.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: GA_Types.h ( GA Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #pragma once
12 
13 #ifndef __GA_Types__
14 #define __GA_Types__
15 
16 #include "GA_API.h"
17 #include <UT/UT_Assert.h>
18 #include <UT/UT_ValArray.h>
19 #include <SYS/SYS_Math.h>
20 #include <SYS/SYS_Types.h>
21 
22 
23 // -------------------------------------------------------------
24 // GA Enums/Defines
25 // -------------------------------------------------------------
26 /// The GA_AttributeOwner enum is used to differentiate between the different
27 /// types of attribute arrays stored in a GA_Detail. The different classes
28 /// represent
29 /// -# unique point attribute data (one per vertex on a primitive)
30 /// -# shared point attribute data (attributes shared multiple vertices)
31 /// -# per-primitive attribute data (one per primitive)
32 /// -# attribute data stored on the detail itself (single value)
34 {
35  GA_ATTRIB_VERTEX, // Unique vertex data
36  GA_ATTRIB_POINT, // Shared vertex data
37  GA_ATTRIB_PRIMITIVE, // Primitive attribute data
38  GA_ATTRIB_GLOBAL, // Global data
39 
40  GA_ATTRIB_OWNER_N, // Number of GA_AttributeOwner enums
41 
42  GA_ATTRIB_DETAIL = GA_ATTRIB_GLOBAL,// Detail data, same as global
43  GA_ATTRIB_INVALID = -1 // Not a valid attribute owner
44 };
45 GA_API size_t format(char *buffer, size_t buffer_size, const GA_AttributeOwner &v);
46 
47 /// Attributes (and other data) may be stored with different precision and
48 /// storage types.
50 {
51  GA_STORE_INVALID=-1, // Invalid storage
52  GA_STORE_BOOL, // Bool storage (bit-array)
53  GA_STORE_UINT8, // 8-bit unsigned integer
54  GA_STORE_INT8, // 8-bit signed integer
55  GA_STORE_INT16, // 16-bit integer
56  GA_STORE_INT32, // 32-bit integer
57  GA_STORE_INT64, // 64-bit integer
58  GA_STORE_REAL16, // 16-bit real
59  GA_STORE_REAL32, // 32-bit real
60  GA_STORE_REAL64, // 64-bit real
61  GA_STORE_STRING, // ASCII string data
62  // GA_STORE_UTF8, // Future?
63  // GA_STORE_UTF16, // Future?
64  // GA_STORE_UTF32, // Future?
65 };
66 GA_API size_t format(char *buffer, size_t buffer_size, const GA_Storage &v);
67 
68 /// Often one does not care about the precision. In this case
69 /// the storage class gives a good idea which AIFs will be supported.
71 {
72  GA_STORECLASS_INVALID = -1, // Invalid storage
73  GA_STORECLASS_INT, // Any integer type
74  GA_STORECLASS_REAL, // Any real type
78 };
79 GA_API size_t format(char *buffer, size_t buffer_size, const GA_StorageClass &v);
80 
81 /// If one only cares about precision, this can be used.
82 /// Note that 8-bit reals do not exist so will instead refer
83 /// to 16-bit.
85 {
86  GA_PRECISION_INVALID = -1, // Storage with no precision, String
92 };
93 GA_API size_t format(char *buffer, size_t buffer_size, const GA_Precision &v);
94 
95 /// Type qualifiers on attributes. These qualifiers can help to interpret the
96 /// data associated with an attribute, but are not required.
98 {
99  /// Data has no numeric representation
101  /// Data represents a position in space. Token "point"
103  /// Data represents a position and homogeneous coordinate. The position is
104  /// stored in non-homogeneous space (i.e. the w coordinate is not
105  /// multiplied through). Token "hpoint"
107  /// Data represents a direction vector. Token "vector"
109  /// Data represents a normal vector. Token "normal"
111  /// Data represents a color. Token "color"
113  /// Data represents a transform matrix. Token "matrix"
115  /// Data represents a quaternion. Token "quaternion"
117  /// Data represents an index-pair. Token "indexpair"
119 
120  /// When a numeric attribute is created with integer storage, the attribute
121  /// will be tagged as a non-arithmetic integer. This means that
122  /// mathematical operations will not typically be performed (i.e. integer
123  /// values will not be averaged). This works well for most cases of
124  /// integers under Houdini.
126  /// Arithmetic integers will be modified under arithmetic operations.
127  /// Their values will be averaged etc.
128  /// @note This is not the default behaviour for numeric attributes
130 
131  /// Data represents a coordinate in texture space, a.k.a. uv/uvw,
132  /// but not a primitive uv/uvw.
134 };
135 GA_API size_t format(char *buffer, size_t buffer_size, const GA_TypeInfo &v);
136 
137 /// Scope qualifiers on attributes. Each valid scope has its own namespace,
138 /// along with other consequences.
140 {
141  /// Data has no numeric representation
143  /// Standard user attribute level
144  // GA_OPTION_EXPORT_ON_SAVE/MERGE defaults to true
146  // Internal attribute level
147  // GA_OPTION_EXPORT_ON_SAVE/MERGE defaults to false
149  // Group attribute level
150  // GA_OPTION_EXPORT_ON_SAVE/MERGE defaults to false,
151  // because GA_Group saves/merges it, not GA_Attribute.
153 };
154 GA_API size_t format(char *buffer, size_t buffer_size, const GA_AttributeScope &v);
155 
156 /// An ordinal enum for the different types of groups in GA
158 {
166 };
167 GA_API size_t format(char *buffer, size_t buffer_size, const GA_GroupType &v);
168 
169 /// Currently SOP_Node::parseAllGroups takes a mask of different types of
170 /// groups. This enum allows group types to be packed into a bit field.
172 {
180 };
181 
182 // Maximum order for NURBs/Bezier bases
183 #define GA_MAX_ORDER 11
184 
185 // Types of knot spacing for NURBs operations
187 {
190 };
191 
192 // Basis parametrization types
194 {
199 };
200 
201 /// Strategies that may be used for attribute data IDs, usually when merging
202 /// or copying attributes.
203 ///
204 /// @note Most functions with a parameter of this type typically treat it as
205 /// a hint, and may ignore it when the requested strategy is not appropriate.
207 {
208  /// The default strategy, where the caller does not have to explicitly
209  /// worry about attribute data IDs.
211 
212  /// Attributes should inherit the data IDs from their corresponding source
213  /// attribute. The caller will typically call GA_Attribute::bumpDataId()
214  /// on any attributes that they later modify.
216 };
217 
218 /// Attributes may paritition their data in pages of GA_PAGE_SIZE offsets.
219 #define GA_PAGE_BITS 10
220 #define GA_PAGE_SIZE (1 << GA_PAGE_BITS)
221 #define GA_PAGE_MASK (GA_PAGE_SIZE - 1)
222 #define GA_DEFRAGMENT_OCCUPANCY 1.00
223 
224 // -------------------------------------------------------------
225 // GA Types
226 // When indexing points, vertices or primitives, use
227 // GA_Index (ordered) or GA_Offset (data offset)
228 // -------------------------------------------------------------
229 
230 /// Defines the bit width for index and offset types in GA
231 typedef exint GA_Size;
232 
233 /// Define the strictness of GA_Offset/GA_Index
234 #if !defined(GA_STRICT_TYPES) && UT_ASSERT_LEVEL > 2
235  #define GA_STRICT_TYPES 0
236 #endif
237 
238 #if defined(GA_STRICT_TYPES)
239 
240 #if (UT_ASSERT_LEVEL >= UT_ASSERT_LEVEL_NORMAL)
241 #define GA_MAGIC_BAD_VALUE 0x7BADF00D7F00DBAD
242 #endif
243 
244 #if (UT_ASSERT_LEVEL < UT_ASSERT_LEVEL_NORMAL)
245 #include <SYS/SYS_TypeDecorate.h>
246 #endif
247 
248 #include <SYS/SYS_Compiler.h>
249 #include <SYS/SYS_Hash.h>
250 #include <SYS/SYS_TypeTraits.h>
251 #include <ostream>
252 
253 #if defined(MBSD)
254  #define GA_DEFINE_ORDINAL_METHODS_EXTRA \
255  size_t operator*(size_t v) const { return myVal * v; } \
256  friend size_t operator*(size_t v, const ThisType &a) { return v * a.myVal; }
257 #else
258  #define GA_DEFINE_ORDINAL_METHODS_EXTRA
259 #endif
260 
261 
262 #define GA_DEFINE_ORDINAL_METHODS \
263  GA_DEFINE_ORDINAL_METHODS_EXTRA \
264  bool operator==(const ThisType &that) const { return (myVal == that.myVal); } \
265  bool operator!=(const ThisType &that) const { return (myVal != that.myVal); } \
266  bool operator<(const ThisType &that) const { return (myVal < that.myVal); } \
267  bool operator<=(const ThisType &that) const { return (myVal <= that.myVal); } \
268  bool operator>(const ThisType &that) const { return (myVal > that.myVal); } \
269  bool operator>=(const ThisType &that) const { return (myVal >= that.myVal); } \
270  exint operator&(exint v) const { return myVal & v; } \
271  exint operator&(int v) const { return myVal & v; } \
272  exint operator&(uint v) const { return myVal & v; } \
273  exint operator>>(exint v) const { return myVal >> v; } \
274  exint operator>>(int v) const { return myVal >> v; } \
275  exint operator>>(uint v) const { return myVal >> v; } \
276  exint operator*(exint v) const { return myVal * v; } \
277  exint operator*(int v) const { return myVal * v; } \
278  exint operator*(uint v) const { return myVal * v; } \
279  exint operator*(uint64 v) const { return exint(myVal * v); } \
280  ThisType operator+(const ThisType &that) const { return ThisType(myVal + that.myVal); } \
281  ThisType operator+(exint v) const { return ThisType(myVal + v); } \
282  ThisType operator+(uint64 v) const { return ThisType(myVal + v); } \
283  ThisType operator+(int v) const { return ThisType(myVal + v); } \
284  ThisType operator+(uint v) const { return ThisType(myVal + v); } \
285  friend ThisType operator+(exint v, const ThisType &a) { return ThisType(a.myVal + v); } \
286  friend ThisType operator+(uint64 v, const ThisType &a) { return ThisType(a.myVal + v); } \
287  friend ThisType operator+(int v, const ThisType &a) { return ThisType(a.myVal + v); } \
288  friend ThisType operator+(uint v, const ThisType &a) { return ThisType(a.myVal + v); } \
289  friend exint operator*(exint v, const ThisType &a) { return ThisType(a.myVal * v); } \
290  friend exint operator*(uint64 v, const ThisType &a) { return ThisType(a.myVal * v); } \
291  friend exint operator*(int v, const ThisType &a) { return ThisType(a.myVal * v); } \
292  friend exint operator*(uint v, const ThisType &a) { return ThisType(a.myVal * v); } \
293  /* NOTE: ThisType-ThisType must return something that can be divided \
294  by (unsigned int)2 in order to support TBB blocked ranges.*/ \
295  exint operator/(uint v) const { return myVal/v; } \
296  exint operator/(int v) const { return myVal/v; } \
297  exint operator/(uint64 v) const { return myVal/v; } \
298  exint operator/(int64 v) const { return myVal/v; } \
299  ThisType operator-(const ThisType &that) const { return ThisType(myVal - that.myVal); } \
300  ThisType operator-(exint v) const { return ThisType(myVal - v); } \
301  ThisType operator-(uint64 v) const { return ThisType(myVal - v); } \
302  ThisType operator-(int v) const { return ThisType(myVal - v); } \
303  ThisType operator-(uint v) const { return ThisType(myVal - v); } \
304  ThisType operator+=(const ThisType &that) { myVal += that.myVal; return *this; } \
305  ThisType operator+=(exint v) { myVal += v; return *this; } \
306  ThisType operator+=(uint64 v){ myVal += v; return *this; } \
307  ThisType operator+=(int v) { myVal += v; return *this; } \
308  ThisType operator+=(uint v) { myVal += v; return *this; } \
309  ThisType operator-=(const ThisType &that) { myVal -= that.myVal; return *this; } \
310  ThisType operator-=(exint v) { myVal -= v; return *this; } \
311  ThisType operator-=(uint64 v){ myVal -= v; return *this; } \
312  ThisType operator-=(int v) { myVal -= v; return *this; } \
313  ThisType operator-=(uint v) { myVal -= v; return *this; } \
314  ThisType & operator++() { ++myVal; return *this; } \
315  ThisType operator++(int) { return ThisType(myVal++); } \
316  ThisType & operator--() { --myVal; return *this; } \
317  ThisType operator--(int) { return ThisType(myVal--); } \
318  ThisType operator-() { return ThisType(-myVal); } \
319  friend std::ostream &operator<< (std::ostream &stream, const ThisType &a) { return stream << a.myVal; } \
320  friend ThisType SYSmax(const ThisType &a, const ThisType &b) \
321  { return ThisType(SYSmax(a.myVal, b.myVal)); } \
322  friend ThisType SYSmin(const ThisType &a, const ThisType &b) \
323  { return ThisType(SYSmin(a.myVal, b.myVal)); } \
324  friend ThisType SYSclamp(const ThisType &a, const ThisType &b, const ThisType &c) \
325  { return ThisType(SYSclamp(a.myVal, b.myVal, c.myVal)); } \
326  friend ThisType UTbumpAlloc(const ThisType &a) \
327  { return ThisType(UTbumpAlloc(a.myVal)); } \
328 
329  /**/
330 
331 template <typename TAG, typename BASE_TYPE>
332 class GA_API_TMPL GA_OrdinalType
333 {
334 private:
335  typedef GA_OrdinalType<TAG, BASE_TYPE> ThisType;
336 
337 public:
338  GA_OrdinalType()
339 #if (UT_ASSERT_LEVEL >= UT_ASSERT_LEVEL_NORMAL)
340  : myVal(BASE_TYPE(GA_MAGIC_BAD_VALUE))
341 #endif
342  {}
343  explicit GA_OrdinalType(const BASE_TYPE &val) : myVal(val) { }
344 
345  operator BASE_TYPE() const { return myVal; }
346 
347  GA_DEFINE_ORDINAL_METHODS
348 
349 private:
350  BASE_TYPE myVal;
351 };
352 
353 class GA_Index;
354 
355 /// GA_Offset defines an offset into the attribute table of a GA_IndexMap.
356 /// Properties:
357 /// - Not allowed to be converted from a GA_Index
358 /// - Not implicitly convertible from a GA_Size
360 {
361  typedef GA_Offset ThisType;
362 
363 public:
364  GA_Offset()
365 #if (UT_ASSERT_LEVEL >= UT_ASSERT_LEVEL_NORMAL)
366  : myVal(GA_MAGIC_BAD_VALUE)
367 #endif
368  {}
369  explicit constexpr GA_Offset(GA_Size val) : myVal(val) { }
370 
371  operator int64() const { return myVal; }
372  operator uint64() const { return myVal; }
373 
374  // NOTE: These should generally be avoided, but are mostly here
375  // for templated code that over-instantiates for bogus type
376  // conversions.
377  operator int32() const { return myVal; }
378  operator uint32() const { return myVal; }
379  operator int16() const { return myVal; }
380  operator uint16() const { return myVal; }
381  operator int8() const { return myVal; }
382  operator uint8() const { return myVal; }
383 #if defined(MBSD)
384  // NOTE: These ones are because on Mac GCC, long and size_t are treated as
385  // types different from int64 and uint64 somehow (they are both
386  // 64-bit integers).
387  operator long() const { return myVal; }
388  operator unsigned long() const { return myVal; }
389 #endif
390 
391  GA_DEFINE_ORDINAL_METHODS
392 
393 private:
394  GA_Offset(const GA_Index &v); // DISALLOW
395 
396  /// Disallow boolean operations, because they're almost guaranteed
397  /// to be porting errors checking if a pointer is NULL or non-NULL
398  /// instead of checking whether the offset is zero.
399  SYS_SAFE_BOOL operator bool() const;
400 
401  /// Disallow comparison with integers, for example, the
402  /// "if (ptoff==0)" case, since it's most likely a porting error.
403  bool operator==(exint v) const;
404  bool operator==(uint64 v) const;
405  bool operator==(int v) const;
406  bool operator==(uint v) const;
407  bool operator!=(exint v) const;
408  bool operator!=(uint64 v) const;
409  bool operator!=(int v) const;
410  bool operator!=(uint v) const;
411 
412  GA_Size myVal;
413 };
415 
417 {
418  return SYShash(GA_Size(off));
419 }
420 
421 /// GA_Index defines an ordered index of a GA_IndexMap.
422 /// Properties:
423 /// - Not allowed to be converted from a GA_Offset
424 /// - Implicitly convertible from and to a GA_Size
425 class GA_API_TMPL GA_Index
426 {
427 private:
428  typedef GA_Index ThisType;
429 
430 public:
431  GA_Index()
432 #if (UT_ASSERT_LEVEL >= UT_ASSERT_LEVEL_NORMAL)
433  : myVal(GA_MAGIC_BAD_VALUE)
434 #endif
435  {}
436  GA_Index(const GA_Size &val) : myVal(val) { }
437 
438  operator int64() const { return myVal; }
439  operator uint64() const { return myVal; }
440 
441  // NOTE: These should generally be avoided, but are mostly here
442  // for templated code that over-instantiates for bogus type
443  // conversions.
444  operator int32() const { return myVal; }
445  operator uint32() const { return myVal; }
446  operator int16() const { return myVal; }
447  operator uint16() const { return myVal; }
448  operator int8() const { return myVal; }
449  operator uint8() const { return myVal; }
450 #if defined(MBSD)
451  // NOTE: This one is because on Mac GCC, long is treated as a type
452  // different from int64 somehow (they are both 64-bit integers).
453  operator long() const { return myVal; }
454  operator unsigned long() const { return myVal; }
455 #endif
456 
457  GA_DEFINE_ORDINAL_METHODS
458 
459  // NOTE: These methods are to avoid having to change the ton of code that
460  // uses ints, etc, as interchangeable with GA_Index
461  // Equality comparisons with integers were re-allowed, since most porting
462  // errors would involve GA_Offset, not GA_Index, and not being able to compare
463  // getNumPoints() with 0 is counterintuitive.
464  bool operator< (exint v) const { return (myVal < v); }
465  bool operator<=(exint v) const { return (myVal <= v); }
466  bool operator> (exint v) const { return (myVal > v); }
467  bool operator>=(exint v) const { return (myVal >= v); }
468  bool operator==(exint v) const { return (myVal == v); }
469  bool operator!=(exint v) const { return (myVal != v); }
470  bool operator< (uint64 v) const { return (myVal < v); }
471  bool operator<=(uint64 v) const { return (myVal <= v); }
472  bool operator> (uint64 v) const { return (myVal > v); }
473  bool operator>=(uint64 v) const { return (myVal >= v); }
474  bool operator==(uint64 v) const { return (myVal == v); }
475  bool operator!=(uint64 v) const { return (myVal != v); }
476  bool operator< (int v) const { return (myVal < v); }
477  bool operator<=(int v) const { return (myVal <= v); }
478  bool operator> (int v) const { return (myVal > v); }
479  bool operator>=(int v) const { return (myVal >= v); }
480  bool operator==(int v) const { return (myVal == v); }
481  bool operator!=(int v) const { return (myVal != v); }
482  bool operator< (uint v) const { return (myVal < v); }
483  bool operator<=(uint v) const { return (myVal <= v); }
484  bool operator> (uint v) const { return (myVal > v); }
485  bool operator>=(uint v) const { return (myVal >= v); }
486  bool operator==(uint v) const { return (myVal == v); }
487  bool operator!=(uint v) const { return (myVal != v); }
488 #if defined(MBSD)
489  // NOTE: This one is because on Mac GCC, long is treated as a type
490  // different from int64 somehow (they are both 64-bit integers).
491  bool operator< (unsigned long v) const { return (myVal < v); }
492  bool operator<=(unsigned long v) const { return (myVal <= v); }
493  bool operator> (unsigned long v) const { return (myVal > v); }
494  bool operator>=(unsigned long v) const { return (myVal >= v); }
495  bool operator==(unsigned long v) const { return (myVal == v); }
496  bool operator!=(unsigned long v) const { return (myVal != v); }
497 #endif
498 
499  friend bool operator<( exint v, const GA_Index &a) { return (v < a.myVal); }
500  friend bool operator<=(exint v, const GA_Index &a) { return (v <= a.myVal); }
501  friend bool operator>( exint v, const GA_Index &a) { return (v > a.myVal); }
502  friend bool operator>=(exint v, const GA_Index &a) { return (v >= a.myVal); }
503  friend bool operator==(exint v, const GA_Index &a) { return (v == a.myVal); }
504  friend bool operator!=(exint v, const GA_Index &a) { return (v != a.myVal); }
505  friend bool operator<( uint64 v, const GA_Index &a) { return (v < a.myVal); }
506  friend bool operator<=(uint64 v, const GA_Index &a) { return (v <= a.myVal); }
507  friend bool operator>( uint64 v, const GA_Index &a) { return (v > a.myVal); }
508  friend bool operator>=(uint64 v, const GA_Index &a) { return (v >= a.myVal); }
509  friend bool operator==(uint64 v, const GA_Index &a) { return (v == a.myVal); }
510  friend bool operator!=(uint64 v, const GA_Index &a) { return (v != a.myVal); }
511  friend bool operator<( int v, const GA_Index &a) { return (v < a.myVal); }
512  friend bool operator<=(int v, const GA_Index &a) { return (v <= a.myVal); }
513  friend bool operator>( int v, const GA_Index &a) { return (v > a.myVal); }
514  friend bool operator>=(int v, const GA_Index &a) { return (v >= a.myVal); }
515  friend bool operator==(int v, const GA_Index &a) { return (v == a.myVal); }
516  friend bool operator!=(int v, const GA_Index &a) { return (v != a.myVal); }
517  friend bool operator<( uint v, const GA_Index &a) { return (v < a.myVal); }
518  friend bool operator<=(uint v, const GA_Index &a) { return (v <= a.myVal); }
519  friend bool operator>( uint v, const GA_Index &a) { return (v > a.myVal); }
520  friend bool operator>=(uint v, const GA_Index &a) { return (v >= a.myVal); }
521  friend bool operator==(uint v, const GA_Index &a) { return (v == a.myVal); }
522  friend bool operator!=(uint v, const GA_Index &a) { return (v != a.myVal); }
523 #if defined(MBSD)
524  // NOTE: This one is because on Mac GCC, long is treated as a type
525  // different from int64 somehow (they are both 64-bit integers).
526  friend bool operator<( unsigned long v, const GA_Index &a) { return (v < a.myVal); }
527  friend bool operator<=(unsigned long v, const GA_Index &a) { return (v <= a.myVal); }
528  friend bool operator>( unsigned long v, const GA_Index &a) { return (v > a.myVal); }
529  friend bool operator>=(unsigned long v, const GA_Index &a) { return (v >= a.myVal); }
530  friend bool operator==(unsigned long v, const GA_Index &a) { return (v == a.myVal); }
531  friend bool operator!=(unsigned long v, const GA_Index &a) { return (v != a.myVal); }
532 #endif
533 
534  /// Boolean operations were re-allowed for if (getNumPoints()), because
535  /// most porting errors would involve checking GA_Offset, not GA_Index.
536  SYS_SAFE_BOOL operator bool() const { return myVal != 0; }
537 
538 private:
539  GA_Index(const GA_Offset &v); // DISALLOW
540 
541  GA_Size myVal;
542 };
544 
546 {
547  return SYShash(GA_Size(idx));
548 }
549 
550 #undef GA_DEFINE_ORDINAL_BINARY_OPS
551 #undef GA_DEFINE_ORDINAL_METHODS
552 
553 
554 class GA_PageNumTag {};
555 typedef GA_OrdinalType<GA_PageNumTag, GA_Size> GA_PageNum;
557 
558 
559 class GA_PageOffTag {};
560 typedef GA_OrdinalType<GA_PageOffTag, GA_Size> GA_PageOff;
562 
563 inline bool GAisValid(GA_Offset v)
564 {
565  UT_ASSERT(v != GA_Offset(GA_MAGIC_BAD_VALUE));
566  return v >= GA_Offset(0);
567 }
568 inline bool GAisValid(GA_Index v)
569 {
570  UT_ASSERT(v != GA_Index(GA_MAGIC_BAD_VALUE));
571  return v >= GA_Index(0);
572 }
573 
574 namespace UT {
575 template<typename T>
576 struct DefaultClearer;
577 
578 template<>
579 struct DefaultClearer<GA_Offset>
580 {
581  static void clear(GA_Offset &v)
583  static bool isClear(GA_Offset v)
584  { return v == GA_Offset(std::numeric_limits<exint>::min()); }
585  static void clearConstruct(GA_Offset *p) { clear(*p); }
586 
587  static const bool clearNeedsDestruction = false;
588 };
589 
590 template<>
591 struct DefaultClearer<GA_Index>
592 {
593  static void clear(GA_Index &v)
595  static bool isClear(GA_Index v)
596  { return v == GA_Index(std::numeric_limits<exint>::min()); }
597  static void clearConstruct(GA_Index *p) { clear(*p); }
598 
599  static const bool clearNeedsDestruction = false;
600 };
601 }
602 
603 namespace std {
604 template<>
605 struct hash<GA_Offset>
606 {
607  size_t operator()(GA_Offset v)
608  { return std::hash<exint>()((exint)v); }
609 };
610 template<>
611 struct hash<GA_Index>
612 {
613  size_t operator()(GA_Index v)
614  { return std::hash<exint>()((exint)v); }
615 };
616 }
617 
618 GA_API size_t format(char *buf, size_t bufsize, const GA_Index &v);
619 GA_API size_t format(char *buf, size_t bufsize, const GA_Offset &v);
620 
621 #else
622 
623 /// GA_Index is a contiguous index into an element in a GA_Detail structure.
624 /// Since the list of elements can contain gaps, the index should be translated
625 /// into a GA_Offset prior to lookup. The index remains constant if the element
626 /// list is defragmented, but will be invalid if an element, prior to a given
627 /// index, is inserted or deleted.
628 /// \sa GA_Detail::pointOffset, GA_Detail::pointIndex,
629 /// \sa GA_Detail::primitiveOffset, GA_Detail::primitiveIndex
630 /// \sa GA_Detail::vertexOffset, GA_Detail::vertexIndex
632 
633 /// GA_Offset is a, possibly, non-contiguous offset to an element in a
634 /// GA_Detail structure. GA_Offsets remain constant even if an element prior to
635 /// it is deleted, but will be invalidated if an element is inserted prior to
636 /// it, or if the element list is defragmented.
638 
639 
642 
643 #endif
644 
645 inline bool GAisValid(GA_Size v) {
646 #if defined(GA_STRICT_TYPES)
647  UT_ASSERT(v != GA_Size(GA_MAGIC_BAD_VALUE));
648 #endif
649  return v >= 0;
650 }
651 
652 inline GA_PageNum GAgetPageNum(GA_Offset v)
653 {
654  return GA_PageNum(v >> GA_PAGE_BITS);
655 }
656 inline GA_PageOff GAgetPageOff(GA_Offset v)
657 {
658  return GA_PageOff(v & GA_PAGE_MASK);
659 }
660 inline bool GAisFullPage(GA_Offset start, GA_Offset end)
661 {
662  return (GAgetPageOff(start) == 0 &&
663  GAgetPageOff(end) == 0 &&
664  (GAgetPageNum(start) == GAgetPageNum(end)-1));
665 }
666 
667 inline GA_Offset GAgetPageBoundary(const GA_Offset &start,
668  const GA_Offset &end)
669 {
670  return GA_Offset(SYSmin(GA_Size(end), GA_Size(start) - GA_Size(GAgetPageOff(start)) + GA_PAGE_SIZE));
671 }
672 
673 #define GA_INVALID_INDEX GA_Index(-1)
674 #define GA_INVALID_OFFSET GA_Offset(-1)
675 
676 /// Details are always at index and offset zero in their own detail index map.
677 #define GA_DETAIL_INDEX GA_Index(0)
678 #define GA_DETAIL_OFFSET GA_Offset(0)
679 
682 
683 typedef int64 GA_DataId;
684 #define GA_INVALID_DATAID GA_DataId(-1)
685 
686 
687 /// @{
688 /// At the current time, intrinsic handles are an integer.
689 /// This may change in the future.
690 typedef int GA_LocalIntrinsic;
691 typedef int GA_GlobalIntrinsic;
692 #define GA_INVALID_INTRINSIC_HANDLE -1
693 static inline bool GAisValidGlobalIntrinsic(GA_GlobalIntrinsic h)
694  { return h >= 0; }
695 static inline bool GAisValidLocalIntrinsic(GA_LocalIntrinsic h)
696  { return h >= 0; }
697 /// @}
698 
699 // -------------------------------------------------------------
700 // Functions to map storage enums to tokens.
701 // -------------------------------------------------------------
702 /// Lookup the size in bytes of a storage type (inaccurate for bool)
703 GA_API extern unsigned GAsizeof(GA_Storage store);
704 
705 /// Compare precision of GA_Storage types. The function will return:
706 /// -2 invalid comparison (i.e. comparing a string to a float)
707 /// -1 if a is less precise than b
708 /// 0 if a and be have the same precision
709 /// 1 if a is more precise than b
711 
712 /// Return the precision associated with the storage.
714 /// Lookup the precision name from the precision
715 GA_API extern const char *GAprecision(GA_Precision precision);
716 /// Lookup the precision type from the precision name
717 GA_API extern GA_Precision GAprecision(const char *precision);
718 /// Returns the nominal bits of provided precision, 0 for invalid.
720 
721 /// Lookup the owner name from the owner type
722 GA_API extern const char *GAowner(GA_AttributeOwner owner);
723 /// Lookup the owner type from the owner name
724 GA_API extern GA_AttributeOwner GAowner(const char *owner);
725 
726 /// Lookup the scope name from the scope type
727 GA_API extern const char *GAscope(GA_AttributeScope scope);
728 /// Lookup the scope type from the scope name
729 GA_API extern GA_AttributeScope GAscope(const char *scope);
730 
731 /// Lookup the storage name from the storage type
732 GA_API extern const char *GAstorage(GA_Storage store);
733 /// Lookup the storage type from the storage name
734 GA_API extern GA_Storage GAstorage(const char *store);
735 
736 /// Lookup the storage label (descriptive name) from the storage type
737 GA_API extern const char *GAstorageLabel(GA_Storage store);
738 /// Lookup the storage type from the storage label
739 GA_API extern GA_Storage GAstorageLabel(const char *store);
740 
741 
742 
743 /// Lookup the storage name from the storage type
744 GA_API extern const char *GAstorageClass(GA_StorageClass store);
745 /// Lookup the intrinsic storage type from the storage name
746 GA_API extern GA_StorageClass GAstorageClass(const char *store);
747 
748 /// Lookup the type-info name from the type-info type
749 GA_API extern const char *GAtypeinfo(GA_TypeInfo type);
750 /// Lookup the type-info type from the type-info name
751 GA_API extern GA_TypeInfo GAtypeinfo(const char *type);
752 
753 /// Lookup the type-info label (descriptive name) from the type-info type
754 GA_API extern const char *GAtypeinfoLabel(GA_TypeInfo type);
755 /// Lookup the type-info type from the type-info label (descriptive name)
756 GA_API extern GA_TypeInfo GAtypeinfoLabel(const char *type);
757 
758 /// Lookup the owner name from the owner type
759 GA_API extern const char *GAgroupType(GA_GroupType owner);
760 /// Lookup the owner type from the owner name
761 GA_API extern GA_GroupType GAgroupType(const char *owner);
762 
763 
764 /// Convenience method to determine whether an integer represents a valid
765 /// storage type.
766 static inline bool GAisStorageType(int s)
767  {
768  return s >= GA_STORE_BOOL && s <= GA_STORE_STRING;
769  }
770 
771 /// Convenience method to determine whether storage is real valued
772 static inline bool GAisFloatStorage(GA_Storage s)
773  {
774  return s == GA_STORE_REAL16 ||
775  s == GA_STORE_REAL32 ||
776  s == GA_STORE_REAL64;
777  }
778 
779 /// Convenience method to determine whether storage is integer valued
780 static inline bool GAisIntStorage(GA_Storage s)
781  {
782  return
783  s == GA_STORE_UINT8 ||
784  s == GA_STORE_INT8 ||
785  s == GA_STORE_INT16 ||
786  s == GA_STORE_INT32 ||
787  s == GA_STORE_INT64;
788  }
789 
790 /// Convenience method to determine whether storage is numeric (real/integer)
791 static inline bool GAisNumericStorage(GA_Storage s)
792  {
793  return GAisFloatStorage(s) || GAisIntStorage(s);
794  }
795 
796 /// Convenience method to determine if type info is a transforming type
797 static inline bool GAisTransformingType(GA_TypeInfo t)
798  {
799  return
800  t == GA_TYPE_VECTOR ||
801  t == GA_TYPE_NORMAL ||
802  t == GA_TYPE_POINT ||
803  t == GA_TYPE_HPOINT ||
804  t == GA_TYPE_TRANSFORM ||
805  t == GA_TYPE_QUATERNION;
806  }
807 
809 {
810  switch (s)
811  {
812  case GA_STORE_INVALID:
813  return GA_STORECLASS_INVALID;
814  case GA_STORE_BOOL:
815  case GA_STORE_UINT8:
816  case GA_STORE_INT8:
817  case GA_STORE_INT16:
818  case GA_STORE_INT32:
819  case GA_STORE_INT64:
820  return GA_STORECLASS_INT;
821  case GA_STORE_REAL16:
822  case GA_STORE_REAL32:
823  case GA_STORE_REAL64:
824  return GA_STORECLASS_REAL;
825  case GA_STORE_STRING:
826  return GA_STORECLASS_STRING;
827  }
828 
829  return GA_STORECLASS_OTHER;
830 }
831 
832 static inline GA_Storage GAgetDefaultStorage(GA_StorageClass s)
833 {
834  switch (s)
835  {
836  case GA_STORECLASS_INT:
837  return GA_STORE_INT32;
838  case GA_STORECLASS_REAL:
839  return GA_STORE_REAL32;
841  return GA_STORE_STRING;
842  default:
843  // There's no default storage for this storage class
844  return GA_STORE_INVALID;
845  }
846 }
847 
848 static inline GA_Storage GAgetDefaultStorage(GA_StorageClass s, GA_Precision prec)
849 {
850  switch (s)
851  {
852  case GA_STORECLASS_INT:
853  switch (prec)
854  {
856  break;
857  case GA_PRECISION_1:
858  return GA_STORE_BOOL;
859  case GA_PRECISION_8:
860  return GA_STORE_UINT8;
861  case GA_PRECISION_16:
862  return GA_STORE_INT16;
863  case GA_PRECISION_32:
864  return GA_STORE_INT32;
865  case GA_PRECISION_64:
866  return GA_STORE_INT64;
867  }
868  return GA_STORE_INT32;
869  case GA_STORECLASS_REAL:
870  switch (prec)
871  {
873  break;
874  case GA_PRECISION_1:
875  case GA_PRECISION_8:
876  case GA_PRECISION_16:
877  return GA_STORE_REAL16;
878  case GA_PRECISION_32:
879  return GA_STORE_REAL32;
880  case GA_PRECISION_64:
881  return GA_STORE_REAL64;
882  }
883  return GA_STORE_REAL32;
885  return GA_STORE_STRING;
886  default:
887  // There's no default storage for this storage class
888  return GA_STORE_INVALID;
889  }
890 }
891 #endif
GLdouble s
Definition: glew.h:1390
GA_API const char * GAtypeinfoLabel(GA_TypeInfo type)
Lookup the type-info label (descriptive name) from the type-info type.
GA_API const char * GAstorageClass(GA_StorageClass store)
Lookup the storage name from the storage type.
bool GAisFullPage(GA_Offset start, GA_Offset end)
Definition: GA_Types.h:660
Data has no numeric representation.
Definition: GA_Types.h:100
GLsizei bufsize
Definition: glew.h:2581
GA_Size GA_PageOff
Definition: GA_Types.h:641
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
Definition: thread.h:643
GA_StorageClass
Definition: GA_Types.h:70
GA_DataIdStrategy
Definition: GA_Types.h:206
int64 GA_DataId
Definition: GA_Types.h:683
GA_Precision
Definition: GA_Types.h:84
GLuint const GLfloat * val
Definition: glew.h:2794
bool GAisValid(GA_Size v)
Definition: GA_Types.h:645
GA_API const char * GAowner(GA_AttributeOwner owner)
Lookup the owner name from the owner type.
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:9477
GA_API const char * GAgroupType(GA_GroupType owner)
Lookup the owner name from the owner type.
UT_ValArray< GA_Index > GA_IndexArray
Definition: GA_Types.h:680
Data represents a color. Token "color".
Definition: GA_Types.h:112
GA_API const char * GAtypeinfo(GA_TypeInfo type)
Lookup the type-info name from the type-info type.
std::size_t SYS_HashType
Define the type for hash values.
Definition: SYS_Hash.h:19
#define GA_API
Definition: GA_API.h:12
const GLdouble * v
Definition: glew.h:1391
Standard user attribute level.
Definition: GA_Types.h:145
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:231
OIIO_FORCEINLINE vbool4 operator>=(const vint4 &a, const vint4 &b)
Definition: simd.h:4444
GA_PageOff GAgetPageOff(GA_Offset v)
Definition: GA_Types.h:656
GA_API size_t format(char *buffer, size_t buffer_size, const GA_AttributeOwner &v)
int GA_GlobalIntrinsic
Definition: GA_Types.h:691
GA_ParameterizationType
Definition: GA_Types.h:193
GA_API GA_Precision GAprecision(GA_Storage a)
Return the precision associated with the storage.
signed char int8
Definition: SYS_Types.h:35
GA_Size GA_Offset
Definition: GA_Types.h:637
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
long long int64
Definition: SYS_Types.h:111
GA_API const char * GAstorage(GA_Storage store)
Lookup the storage name from the storage type.
int GA_LocalIntrinsic
Definition: GA_Types.h:690
GA_AttributeScope
Definition: GA_Types.h:139
OIIO_FORCEINLINE vbool4 operator>(const vint4 &a, const vint4 &b)
Definition: simd.h:4428
OIIO_FORCEINLINE vbool4 operator<=(const vint4 &a, const vint4 &b)
Definition: simd.h:4448
unsigned long long uint64
Definition: SYS_Types.h:112
#define SYS_SAFE_BOOL
Definition: SYS_Compiler.h:62
int64 exint
Definition: SYS_Types.h:120
GLuint buffer
Definition: glew.h:1680
GLuint GLuint end
Definition: glew.h:1253
#define SYS_DECLARE_IS_POD(T)
Declare a type as POD.
GA_API int GAprecisionBits(GA_Precision precision)
Returns the nominal bits of provided precision, 0 for invalid.
bool operator<(const GU_TetrahedronFacet &a, const GU_TetrahedronFacet &b)
Data has no numeric representation.
Definition: GA_Types.h:142
GA_API const char * GAstorageLabel(GA_Storage store)
Lookup the storage label (descriptive name) from the storage type.
#define GA_PAGE_MASK
Definition: GA_Types.h:221
GLfloat GLfloat GLfloat GLfloat h
Definition: glew.h:8011
int int32
Definition: SYS_Types.h:39
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:631
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
#define GA_PAGE_SIZE
Definition: GA_Types.h:220
unsigned int uint
Definition: SYS_Types.h:44
GLuint start
Definition: glew.h:1253
GA_TypeInfo
Definition: GA_Types.h:97
GA_API int GAcomparePrecision(GA_Storage a, GA_Storage b)
GLdouble GLdouble GLdouble b
Definition: glew.h:9122
GLfloat GLfloat p
Definition: glew.h:16321
Data represents a quaternion. Token "quaternion".
Definition: GA_Types.h:116
unsigned short uint16
Definition: SYS_Types.h:38
GA_AttributeOwner
Definition: GA_Types.h:33
GA_API const char * GAscope(GA_AttributeScope scope)
Lookup the scope name from the scope type.
unsigned char uint8
Definition: SYS_Types.h:36
#define GA_API_TMPL
Definition: GA_API.h:13
Data represents a normal vector. Token "normal".
Definition: GA_Types.h:110
GA_Size GA_PageNum
Definition: GA_Types.h:640
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: glew.h:1254
GA_GroupType
An ordinal enum for the different types of groups in GA.
Definition: GA_Types.h:157
#define GA_PAGE_BITS
Attributes may paritition their data in pages of GA_PAGE_SIZE offsets.
Definition: GA_Types.h:219
Data represents a direction vector. Token "vector".
Definition: GA_Types.h:108
Data represents a position in space. Token "point".
Definition: GA_Types.h:102
#define UT_IFNOT_ASSERT(ZZ)
Definition: UT_Assert.h:154
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:135
GA_GroupMaskType
Definition: GA_Types.h:171
bool operator!=(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:165
#define const
Definition: zconf.h:214
vint4 min(const vint4 &a, const vint4 &b)
Definition: simd.h:4694
short int16
Definition: SYS_Types.h:37
Data represents an index-pair. Token "indexpair".
Definition: GA_Types.h:118
GA_API unsigned GAsizeof(GA_Storage store)
Lookup the size in bytes of a storage type (inaccurate for bool)
GLenum GLuint GLsizei const GLchar * buf
Definition: glew.h:2580
#define SYSmin(a, b)
Definition: SYS_Math.h:1448
size_t hash_value(const CH_ChannelRef &ref)
GA_KnotSpaceType
Definition: GA_Types.h:186
GLenum GLint GLint * precision
Definition: glew.h:3500
UT_ValArray< GA_Offset > GA_OffsetArray
Definition: GA_Types.h:681
Data represents a transform matrix. Token "matrix".
Definition: GA_Types.h:114
GA_Offset GAgetPageBoundary(const GA_Offset &start, const GA_Offset &end)
Definition: GA_Types.h:667
GA_Storage
Definition: GA_Types.h:49
GLdouble GLdouble t
Definition: glew.h:1398
GA_PageNum GAgetPageNum(GA_Offset v)
Definition: GA_Types.h:652
unsigned int uint32
Definition: SYS_Types.h:40