HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GT_GEOElementArray.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_GEOElementArray.h ( GEO Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GT_GEOElementArray__
12 #define __GT_GEOElementArray__
13 
14 #include "GT_API.h"
15 #include <UT/UT_Assert.h>
16 #include "GT_DataArray.h"
17 #include "GT_GEOSupport.h"
18 #include <GA/GA_AIFTuple.h>
19 #include <GA/GA_AIFStringTuple.h>
20 #include <GU/GU_Detail.h>
21 #include <GA/GA_Handle.h>
22 
24 class GA_Attribute;
25 
26 /// @brief A GT Data Array to extract values from a point/primitive attribute.
28 {
29 public:
31  {
32  GT_GEOATTRIB_INVALID = -1,
33 
34  GT_GEOATTRIB_VERTEX = GA_ATTRIB_VERTEX,
35  GT_GEOATTRIB_POINT = GA_ATTRIB_POINT,
36  GT_GEOATTRIB_PRIMITIVE = GA_ATTRIB_PRIMITIVE,
37  GT_GEOATTRIB_GLOBAL = GA_ATTRIB_GLOBAL,
38  GT_GEOATTRIB_DETAIL = GA_ATTRIB_DETAIL,
39 
40  // Point attribute indexed by vertex
42  // Primitive attribute index by vertex
44  // Detail attribute indexed by vertex
46 
47  // Detail attribute indexed by primitive
49  };
50  /// The @c index_mode is used to lookup values. This does @b not
51  /// necessarily have to match the attribute owner, but it must be one of
52  /// the following.
53  /// - @c index_mode := point, @c attribute := point @n
54  /// - @c index_mode := vertex, @c attribute := point @n
55  /// - @c index_mode := vertex, @c attribute := primitive @n
56  /// - @c index_mode := vertex, @c attribute := vertex @n
57  /// - @c index_mode := primitive, @c attribute := primitive @n
58  /// - @c index_mode := detail, @c attribute := detail @n
60  const GA_Attribute *attrib,
62  GA_AttributeOwner offset_owner);
63  ~GT_GEOElementArray() override;
64 
65  const char *className() const override
66  { return "GT_GEOElementArray"; }
67 
68  /// @{
69  /// Query methods defined on GT_DataArray
70  GT_Storage getStorage() const override
71  { return myStorage; }
72  GT_Size entries() const override
73  {
74  return myOffsets.entries();
75 #if 0
76  switch (myOffsetOwner)
77  {
78  case GA_ATTRIB_VERTEX:
79  return myGdp->getNumVertexOffsets();
80  case GA_ATTRIB_POINT:
81  return myGdp->getNumPointOffsets();
83  return myGdp->getNumPrimitiveOffsets();
84  case GA_ATTRIB_DETAIL:
85  return 1;
86  default:
87  UT_ASSERT(0);
88  }
89 #endif
90  return 0;
91  }
92  GT_Size itemSize(GT_Offset offset) const override;
93  GT_Size getTotalArrayEntries() const override;
94  GT_Size getTupleSize() const override
95  {
96  return myTupleSize;
97  }
98  GT_Type getTypeInfo() const override
99  {
100  GA_TypeInfo info = myAttribute
101  ? myAttribute->getTypeInfo()
102  : GA_TYPE_VOID;
103  // avoid transforming attributes like "rest"
104  switch(info)
105  {
106  case GA_TYPE_POINT:
107  case GA_TYPE_HPOINT:
108  case GA_TYPE_NORMAL:
109  case GA_TYPE_VECTOR:
110  if(!myAttribute->needsTransform())
111  return GT_TYPE_NONE;
112  break;
113 
114  default:
115  break;
116  }
117  return mapTypeInfo(info, myTupleSize);
118  }
119  int64 getMemoryUsage() const override
120  { return sizeof(*this); }
121  bool isValid() const override { return myAttribute != NULL; }
122  bool hasArrayEntries() const override
123  {
124  return myFA.isValid() ||
125  myIA.isValid() ||
126  myIA64.isValid() ||
127  mySSArray ||
128  mySDictArray;
129  }
130  void updateGeoDetail(const GU_ConstDetailHandle &dtl,
131  const char *name,
132  GT_Owner attrib_scope,
133  const int expected_size) override;
134 
135  /// @}
136 
137  /// @{
138  /// Access methods defined on GT_DataArray
139  fpreal16 getF16(GT_Offset offset, int idx) const override
140  { return getValue_t<fpreal32>(offset, idx); }
141  fpreal32 getF32(GT_Offset offset, int idx) const override
142  { return getValue_t<fpreal32>(offset, idx); }
143  fpreal64 getF64(GT_Offset offset, int idx) const override
144  { return getValue_t<fpreal64>(offset, idx); }
145  uint8 getU8(GT_Offset offset, int idx) const override
146  { return getValue_t<int32>(offset, idx); }
147  int32 getI32(GT_Offset offset, int idx) const override
148  { return getValue_t<int32>(offset, idx); }
149  int64 getI64(GT_Offset offset, int idx) const override
150  { return getValue_t<int64>(offset, idx); }
151  GT_String getS(GT_Offset offset, int idx) const override
152  {
153  if (mySTuple)
154  {
155  GA_Offset si = getDataOffset(offset);
156  return mySTuple->getString(myAttribute, si,idx);
157  }
159  }
161  GT_Offset offset) const override
162  {
163  if (mySSArray)
164  {
165  GA_Offset si = getDataOffset(offset);
166  mySSArray->getString(myAttribute, si, a);
167  return true;
168  }
169  return false;
170  }
171  GT_Dict getDict(GT_Offset offset, int idx = 0) const override
172  {
173  if (mySDictTuple)
174  {
175  GA_Offset si = getDataOffset(offset);
176  return mySDictTuple->getDict(myAttribute, si, idx);
177  }
179  }
181  {
182  if (mySDictArray)
183  {
184  GA_Offset si = getDataOffset(offset);
185  mySDictArray->getDict(myAttribute, si, a);
186  return true;
187  }
188  return false;
189  }
190  GT_Size getStringIndexCount() const override;
192  int idx=0) const override;
194  UT_IntArray &) const override;
195 
197  GT_Offset start, GT_Size length) const override;
198 
199  GT_Size getDictIndexCount() const override;
200  GT_Offset getDictIndex(GT_Offset offset, int idx = 0) const override;
202  UT_IntArray &) const override;
203 
205  GT_Offset start, GT_Size length) const override;
206 
208  GT_Offset offset) const override
209  { return getArrayValue_t<fpreal16>(a,offset); }
211  GT_Offset offset) const override
212  { return getArrayValue_t<fpreal32>(a,offset); }
214  GT_Offset offset) const override
215  { return getArrayValue_t<fpreal64>(a,offset); }
217  GT_Offset offset) const override
218  { return getArrayValue_t<uint8>(a,offset); }
220  GT_Offset offset) const override
221  { return getArrayValue_t<int8>(a,offset); }
223  GT_Offset offset) const override
224  { return getArrayValue_t<int16>(a,offset); }
226  GT_Offset offset) const override
227  { return getArrayValue_t<int32>(a,offset); }
229  GT_Offset offset) const override
230  { return getArrayValue_t<int64>(a,offset); }
231  /// @}
232 
233  const uint8 *get(GT_Offset i, uint8 *store, int sz) const override
234  { return GT_DataArray::get(i, store, sz); }
235  const int8 *get(GT_Offset i, int8 *store, int sz) const override
236  { return GT_DataArray::get(i, store, sz); }
237  const int16 *get(GT_Offset i, int16 *store, int sz) const override
238  { return GT_DataArray::get(i, store, sz); }
239  const int32 *get(GT_Offset i, int32 *store, int sz) const override
240  { return getTuple_t(i, store, sz); }
241  const int64 *get(GT_Offset i, int64 *store, int sz) const override
242  { return getTuple_t(i, store, sz); }
243  const fpreal16 *get(GT_Offset i, fpreal16 *store, int z) const override
244  { return GT_DataArray::get(i, store, z); }
245  const fpreal64 *get(GT_Offset i, fpreal64 *store, int z) const override
246  { return getTuple_t(i, store, z); }
247  const fpreal32 *get(GT_Offset idx, fpreal32 *store, int z) const override
248  {
249  if (z == 3 && myV3.isValid())
250  {
251  UT_Vector3 v = myV3.get(getDataOffset(idx));
252  store[0] = v.x();
253  store[1] = v.y();
254  store[2] = v.z();
255  return store;
256  }
257  if (myF.isValid())
258  {
259  GA_Offset o = getDataOffset(idx);
260  for (int i = 0; i < z; ++i)
261  store[i] = myF.get(o, i);
262  return store;
263  }
264  return getTuple_t(idx, store, z);
265  }
266 
267  /// Enlarge a bounding box with values
268  bool computeMinMax(fpreal64 *min, fpreal64 *max) const override;
269 
270  /// @{
271  /// Optimized filling methods
272  void doImport(GT_Offset idx, uint8 *data, GT_Size size) const override;
273  void doImport(GT_Offset idx, int8 *data, GT_Size size) const override;
274  void doImport(GT_Offset idx, int16 *data, GT_Size size) const override;
275  void doImport(GT_Offset idx, int32 *data, GT_Size size) const override;
276  void doImport(GT_Offset idx, int64 *data, GT_Size size) const override;
277  void doImport(GT_Offset idx, fpreal16 *data, GT_Size size) const override;
278  void doImport(GT_Offset idx, fpreal32 *data, GT_Size size) const override;
279  void doImport(GT_Offset idx, fpreal64 *data, GT_Size size) const override;
280  void doImportArray(
281  GT_Offset idx, UT_ValArray<fpreal16> &data) const override;
282  void doImportArray(
283  GT_Offset idx, UT_ValArray<fpreal32> &data) const override;
284  void doImportArray(
285  GT_Offset idx, UT_ValArray<fpreal64> &data) const override;
286  void doImportArray(GT_Offset idx, UT_ValArray<uint8> &data) const override;
287  void doImportArray(GT_Offset idx, UT_ValArray<int8> &data) const override;
288  void doImportArray(GT_Offset idx, UT_ValArray<int16> &data) const override;
289  void doImportArray(GT_Offset idx, UT_ValArray<int32> &data) const override;
290  void doImportArray(GT_Offset idx, UT_ValArray<int64> &data) const override;
292  int tuple_size, int stride) const override;
294  int tuple_size, int stride) const override;
296  int tuple_size, int stride) const override;
298  int tuple_size, int stride) const override;
300  int tuple_size, int stride) const override;
302  int tuple_size, int stride) const override;
304  int tuple_size, int stride) const override;
306  int tuple_size, int stride) const override;
309  UT_BoundingBoxF &bbox, int tsize, int stride) override;
312  UT_BoundingBoxD &bbox, int tsize, int stride) override;
315  int tuple_size, int stride,
316  fpreal black, fpreal white) const override;
319  int tuple_size, int nrepeats, int stride,
320  fpreal black, fpreal white) const override;
322  GT_Offset start, GT_Size length) const override;
324  GT_Offset start, GT_Size length) const override;
326  GT_Offset start, GT_Size length) const override;
328  GT_Offset start, GT_Size length) const override;
330  GT_Offset start, GT_Size length) const override;
332  GT_Offset start, GT_Size length) const override;
334  GT_Offset start, GT_Size length) const override;
336  GT_Offset start, GT_Size length) const override;
337  /// @}
338 
339  /// @private - This method relies on knowledge of the internal
340  /// implementation. It's only public for threading efficiency.
341  GA_Offset getDataOffset(GT_Offset offset) const
342  {
343  if (myAttributeOwner == GA_ATTRIB_DETAIL)
344  return GA_Offset(0);
345 
346  GA_Offset gaoff = myOffsets(offset);
347  if (myOffsetOwner == GA_ATTRIB_VERTEX &&
348  myOffsetOwner != myAttributeOwner)
349  {
350  if (myAttributeOwner == GA_ATTRIB_POINT)
351  {
352  gaoff = myGdp->vertexPoint(gaoff);
353  }
354  else
355  {
356  UT_ASSERT(myAttributeOwner ==
358  gaoff = myGdp->vertexPrimitive(gaoff);
359  }
360  }
361  return gaoff;
362  }
363 
364 protected:
365  /// GT_GEOAutoNormalArray has no attribute yet when calling constructor.
367  const GT_GEOOffsetList &offsets,
368  GA_AttributeOwner offset_owner);
369 
370  void initAttribute(const GA_Attribute *attrib);
371  void makeInvalid();
372 
373  template <typename T> inline T
374  getValue_t(GT_Offset offset, int idx) const
375  {
376  GA_Offset si = getDataOffset(offset);
377  T val;
378 
379  if (myTuple && myTuple->get(myAttribute, si, val, idx))
380  return val;
381  return 0;
382  }
383 
384  template <typename T> inline const T *
385  getTuple_t(GT_Offset offset, T *store, int size) const
386  {
387  GA_Offset si = getDataOffset(offset);
388  if (myTuple && myTuple->get(myAttribute, si, store, size))
389  return store;
390  return NULL;
391  }
392 
393  template <typename T> inline bool
395  {
396  GA_Offset si = getDataOffset(offset);
397 
398  if (myNumericArray &&
399  myNumericArray->get(myAttribute, si, val))
400  return true;
401  return false;
402  }
403 
404 
405  GT_Type mapTypeInfo(GA_TypeInfo type, int tsize) const;
406 
408  const GU_Detail *myGdp;
418  GA_AttributeOwner myOffsetOwner; // What type of offsets
432 };
433 
434 /// This class is specific to managing a detached, auto-generated
435 /// normal attribute, when no point, vertex, attrib_owner, or offset_owner
436 /// normals are present on the original detail.
438 {
439 public:
441  const GU_ConstDetailHandle &gdp,
442  GA_AttributeOwner attrib_owner,
443  const GT_GEOOffsetList &offsets,
444  GA_AttributeOwner offset_owner,
445  float cusp_angle);
446 
447  int64 getMemoryUsage() const override
448  { return sizeof(*this); }
449 
450 
451  void updateGeoDetail(
452  const GU_ConstDetailHandle &dtl,
453  const char *name,
454  GT_Owner attrib_scope,
455  const int expected_size) override;
456 private:
457  void createAttribute();
458 
459  int64 myPDataId;
460  int64 myTopologyDataId;
461  int64 myPrimitiveListDataId;
462  const float myCuspAngle;
463  const GA_AttributeOwner myAttribOwner;
464 
465  GA_ATINumericUPtr myAttributeHolder;
466 };
467 
468 #endif
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
Definition: glcorearb.h:2621
GT_Storage
Definition: GT_Types.h:19
virtual void updateGeoDetail(const GU_ConstDetailHandle &dtl, const char *attrib_name, GT_Owner attrib_owner, const int expected_size)
Update cached data, in case the underlying attribute changed.
Definition: GT_DataArray.h:570
Definition of a geometry attribute.
Definition: GA_Attribute.h:198
Data has no numeric representation.
Definition: GA_Types.h:103
virtual void doFillQuantizedArray(uint8 *data, GT_Offset start, GT_Size length, int tuple_size, int stride, fpreal black, fpreal white) const
Definition: GT_DataArray.h:750
Generic Attribute Interface class to access an attribute as a array.
int int32
Definition: SYS_Types.h:39
GT_Dict getDict(GT_Offset offset, int idx=0) const override
A specialization of GA_AIFDictTuple to access "shared strings".
const GA_Attribute * myAttribute
T getValue_t(GT_Offset offset, int idx) const
fpreal32 getF32(GT_Offset offset, int idx) const override
const T * getTuple_t(GT_Offset offset, T *store, int size) const
bool getIA64(UT_ValArray< int64 > &a, GT_Offset offset) const override
virtual void fillStringArray(UT_StringArray &data, UT_ValArray< int > &sizes, GT_Offset start, GT_Size length) const
Definition: GT_DataArray.h:203
const GA_AIFTuple * myTuple
GT_Storage getStorage() const override
const GLdouble * v
Definition: glcorearb.h:837
int64 getMemoryUsage() const override
bool getDictA(UT_Array< UT_OptionsHolder > &a, GT_Offset offset) const override
GLuint start
Definition: glcorearb.h:475
GA_AttributeOwner myAttributeOwner
int64 getI64(GT_Offset offset, int idx) const override
virtual void doImport(GT_Offset idx, uint8 *data, GT_Size size) const
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:848
#define GT_API
Definition: GT_API.h:13
constexpr SYS_FORCE_INLINE T & z() noexcept
Definition: UT_Vector3.h:667
GT_Type
Definition: GT_Types.h:36
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:795
int64 getMemoryUsage() const override
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
bool isValid() const override
virtual GT_Size itemSize(GT_Offset) const
Return the number of elements in the array for the given item.
Definition: GT_DataArray.h:60
float fpreal32
Definition: SYS_Types.h:200
const GA_AIFSharedStringArray * mySSArray
virtual void doFillVec3BBox(fpreal32 *dest, GT_Offset start, GT_Size length, UT_BoundingBoxF &bbox, int, int stride)
Definition: GT_DataArray.h:808
virtual bool computeMinMax(fpreal64 *min, fpreal64 *max) const
Definition: GT_DataArray.h:661
const GU_Detail * myGdp
GLuint GLsizei const GLuint const GLintptr * offsets
Definition: glcorearb.h:2621
double fpreal64
Definition: SYS_Types.h:201
bool getFA32(UT_ValArray< fpreal32 > &a, GT_Offset offset) const override
unsigned char uint8
Definition: SYS_Types.h:36
GA_Size GA_Offset
Definition: GA_Types.h:641
GU_ConstDetailHandle myGdh
virtual GT_Offset getDictIndex(GT_Offset offset, int idx=0) const =0
bool hasArrayEntries() const override
GLintptr offset
Definition: glcorearb.h:665
Abstract data class for an array of float, int or string data.
Definition: GT_DataArray.h:40
virtual GT_Size getStringIndexCount() const =0
const GA_AIFNumericArray * myNumericArray
virtual const uint8 * get(GT_Offset i, uint8 *store, int sz) const
fpreal64 getF64(GT_Offset offset, int idx) const override
void updateGeoDetail(const GU_ConstDetailHandle &dtl, const char *name, GT_Owner attrib_scope, const int expected_size) override
bool getUA8(UT_ValArray< uint8 > &a, GT_Offset offset) const override
static const UT_StringHolder theEmptyString
bool getIA8(UT_ValArray< int8 > &a, GT_Offset offset) const override
A GT Data Array to extract values from a point/primitive attribute.
static const UT_OptionsHolder theEmptyOptions
Definition: UT_Options.h:1168
A specialization of GA_AIFStringArray to access "shared strings".
GLint GLenum GLboolean GLsizei stride
Definition: glcorearb.h:872
bool getIA32(UT_ValArray< int32 > &a, GT_Offset offset) const override
int64 GT_Offset
Definition: GT_Types.h:129
const GA_AIFStringTuple * mySTuple
long long int64
Definition: SYS_Types.h:116
virtual void doFillArray(uint8 *data, GT_Offset start, GT_Size length, int tuple_size, int stride) const
Definition: GT_DataArray.h:700
virtual void getIndexedDicts(UT_Array< UT_OptionsHolder > &dicts, UT_IntArray &indices) const =0
GLuint const GLchar * name
Definition: glcorearb.h:786
virtual GT_Offset getStringIndex(GT_Offset offset, int idx=0) const =0
signed char int8
Definition: SYS_Types.h:35
GT_Size entries() const override
GA_TypeInfo
Definition: GA_Types.h:100
const char * className() const override
GT_Owner
Definition: GT_Types.h:90
uint8 getU8(GT_Offset offset, int idx) const override
bool getArrayValue_t(UT_ValArray< T > &val, GT_Offset offset) const
int64 GT_Size
Definition: GT_Types.h:128
GT_GEOOffsetList myOffsets
GLsizeiptr size
Definition: glcorearb.h:664
GA_AttributeOwner
Definition: GA_Types.h:34
GT_Size getTupleSize() const override
virtual void doImportArray(GT_Offset idx, UT_ValArray< fpreal16 > &data) const
short int16
Definition: SYS_Types.h:37
GT_Type getTypeInfo() const override
fpreal64 fpreal
Definition: SYS_Types.h:277
Data represents a normal vector. Token "normal".
Definition: GA_Types.h:113
GA_AttributeOwner myOffsetOwner
A specialization of GA_AIFDictArray to access "shared strings".
bool getIA16(UT_ValArray< int16 > &a, GT_Offset offset) const override
A specialization of GA_AIFStringTuple to access "shared strings".
GLuint GLfloat * val
Definition: glcorearb.h:1608
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
Data represents a direction vector. Token "vector".
Definition: GA_Types.h:111
const GA_AIFSharedStringTuple * mySSTuple
Data represents a position in space. Token "point".
Definition: GA_Types.h:105
virtual void doExtendedQuantizedFill(uint8 *data, GT_Offset start, GT_Size length, int tuple_size, int nrepeats, int stride, fpreal black, fpreal white) const
virtual void getIndexedStrings(UT_StringArray &strings, UT_IntArray &indices) const =0
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
virtual void fillDictionaryArray(UT_Array< UT_OptionsHolder > &data, UT_ValArray< int > &sizes, GT_Offset start, GT_Size length) const
Definition: GT_DataArray.h:234
const GA_AIFSharedDictArray * mySDictArray
GT_String getS(GT_Offset offset, int idx) const override
bool getSA(UT_StringArray &a, GT_Offset offset) const override
fpreal16 getF16(GT_Offset offset, int idx) const override
constexpr SYS_FORCE_INLINE T & y() noexcept
Definition: UT_Vector3.h:665
type
Definition: core.h:1059
Generic Attribute Interface class to access an attribute as a tuple.
Definition: GA_AIFTuple.h:32
virtual void doFillArrayAttr(UT_Array< uint8 > &data, UT_Array< int > &sizes, GT_Offset start, GT_Size length) const
Definition: GT_DataArray.h:725
bool getFA16(UT_ValArray< fpreal16 > &a, GT_Offset offset) const override
virtual GT_Size getTotalArrayEntries() const
Definition: GT_DataArray.h:63
UT_UniquePtr< GA_ATINumeric > GA_ATINumericUPtr
Definition: format.h:895
virtual GT_Size getDictIndexCount() const =0
const GA_AIFSharedDictTuple * mySDictTuple
Generic Attribute Interface class to work with string indices directly, rather than string values...
int32 getI32(GT_Offset offset, int idx) const override
bool getFA64(UT_ValArray< fpreal64 > &a, GT_Offset offset) const override
constexpr SYS_FORCE_INLINE T & x() noexcept
Definition: UT_Vector3.h:663