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(const GT_GEOElementArray &src_array,
65  GA_AttributeOwner offset_owner);
66  ~GT_GEOElementArray() override;
67 
68  const char *className() const override
69  { return "GT_GEOElementArray"; }
70 
71  /// @{
72  /// Query methods defined on GT_DataArray
73  GT_Storage getStorage() const override
74  { return myStorage; }
75  GT_Size entries() const override
76  {
77  return myOffsets.entries();
78 #if 0
79  switch (myOffsetOwner)
80  {
81  case GA_ATTRIB_VERTEX:
82  return myGdp->getNumVertexOffsets();
83  case GA_ATTRIB_POINT:
84  return myGdp->getNumPointOffsets();
86  return myGdp->getNumPrimitiveOffsets();
87  case GA_ATTRIB_DETAIL:
88  return 1;
89  default:
90  UT_ASSERT(0);
91  }
92 #endif
93  return 0;
94  }
95  GT_Size itemSize(GT_Offset offset) const override;
96  GT_Size getTotalArrayEntries() const override;
97  GT_Size getTupleSize() const override
98  {
99  return myTupleSize;
100  }
101  GT_Type getTypeInfo() const override
102  {
103  GA_TypeInfo info = myAttribute
104  ? myAttribute->getTypeInfo()
105  : GA_TYPE_VOID;
106  // avoid transforming attributes like "rest"
107  switch(info)
108  {
109  case GA_TYPE_POINT:
110  case GA_TYPE_HPOINT:
111  case GA_TYPE_NORMAL:
112  case GA_TYPE_VECTOR:
113  if(!myAttribute->needsTransform())
114  return GT_TYPE_NONE;
115  break;
116 
117  default:
118  break;
119  }
120  return mapTypeInfo(info, myTupleSize);
121  }
122  int64 getMemoryUsage() const override
123  { return sizeof(*this); }
124  bool isValid() const override { return myAttribute != NULL; }
125  bool hasArrayEntries() const override
126  {
127  return myFA.isValid() ||
128  myIA.isValid() ||
129  myIA64.isValid() ||
130  mySSArray ||
131  mySDictArray;
132  }
133  void updateGeoDetail(const GU_ConstDetailHandle &dtl,
134  const char *name,
135  GT_Owner attrib_scope,
136  const int expected_size) override;
137 
138  /// @}
139 
140  /// @{
141  /// Access methods defined on GT_DataArray
142  fpreal16 getF16(GT_Offset offset, int idx) const override
143  { return getValue_t<fpreal32>(offset, idx); }
144  fpreal32 getF32(GT_Offset offset, int idx) const override
145  { return getValue_t<fpreal32>(offset, idx); }
146  fpreal64 getF64(GT_Offset offset, int idx) const override
147  { return getValue_t<fpreal64>(offset, idx); }
148  uint8 getU8(GT_Offset offset, int idx) const override
149  { return getValue_t<int32>(offset, idx); }
150  int32 getI32(GT_Offset offset, int idx) const override
151  { return getValue_t<int32>(offset, idx); }
152  int64 getI64(GT_Offset offset, int idx) const override
153  { return getValue_t<int64>(offset, idx); }
154  GT_String getS(GT_Offset offset, int idx) const override
155  {
156  if (mySTuple)
157  {
158  GA_Offset si = getDataOffset(offset);
159  return mySTuple->getString(myAttribute, si,idx);
160  }
162  }
164  GT_Offset offset) const override
165  {
166  if (mySSArray)
167  {
168  GA_Offset si = getDataOffset(offset);
169  mySSArray->getString(myAttribute, si, a);
170  return true;
171  }
172  return false;
173  }
174  GT_Dict getDict(GT_Offset offset, int idx = 0) const override
175  {
176  if (mySDictTuple)
177  {
178  GA_Offset si = getDataOffset(offset);
179  return mySDictTuple->getDict(myAttribute, si, idx);
180  }
182  }
184  {
185  if (mySDictArray)
186  {
187  GA_Offset si = getDataOffset(offset);
188  mySDictArray->getDict(myAttribute, si, a);
189  return true;
190  }
191  return false;
192  }
193  GT_Size getStringIndexCount() const override;
195  int idx=0) const override;
197  UT_IntArray &) const override;
198 
200  GT_Offset start, GT_Size length) const override;
201 
202  GT_Size getDictIndexCount() const override;
203  GT_Offset getDictIndex(GT_Offset offset, int idx = 0) const override;
205  UT_IntArray &) const override;
206 
208  GT_Offset start, GT_Size length) const override;
209 
211  GT_Offset offset) const override
212  { return getArrayValue_t<fpreal16>(a,offset); }
214  GT_Offset offset) const override
215  { return getArrayValue_t<fpreal32>(a,offset); }
217  GT_Offset offset) const override
218  { return getArrayValue_t<fpreal64>(a,offset); }
220  GT_Offset offset) const override
221  { return getArrayValue_t<uint8>(a,offset); }
223  GT_Offset offset) const override
224  { return getArrayValue_t<int8>(a,offset); }
226  GT_Offset offset) const override
227  { return getArrayValue_t<int16>(a,offset); }
229  GT_Offset offset) const override
230  { return getArrayValue_t<int32>(a,offset); }
232  GT_Offset offset) const override
233  { return getArrayValue_t<int64>(a,offset); }
234  /// @}
235 
236  const uint8 *get(GT_Offset i, uint8 *store, int sz) const override
237  { return GT_DataArray::get(i, store, sz); }
238  const int8 *get(GT_Offset i, int8 *store, int sz) const override
239  { return GT_DataArray::get(i, store, sz); }
240  const int16 *get(GT_Offset i, int16 *store, int sz) const override
241  { return GT_DataArray::get(i, store, sz); }
242  const int32 *get(GT_Offset i, int32 *store, int sz) const override
243  { return getTuple_t(i, store, sz); }
244  const int64 *get(GT_Offset i, int64 *store, int sz) const override
245  { return getTuple_t(i, store, sz); }
246  const fpreal16 *get(GT_Offset i, fpreal16 *store, int z) const override
247  { return GT_DataArray::get(i, store, z); }
248  const fpreal64 *get(GT_Offset i, fpreal64 *store, int z) const override
249  { return getTuple_t(i, store, z); }
250  const fpreal32 *get(GT_Offset idx, fpreal32 *store, int z) const override
251  {
252  if (z == 3 && myV3.isValid())
253  {
254  UT_Vector3 v = myV3.get(getDataOffset(idx));
255  store[0] = v.x();
256  store[1] = v.y();
257  store[2] = v.z();
258  return store;
259  }
260  if (myF.isValid())
261  {
262  GA_Offset o = getDataOffset(idx);
263  for (int i = 0; i < z; ++i)
264  store[i] = myF.get(o, i);
265  return store;
266  }
267  return getTuple_t(idx, store, z);
268  }
269 
270  /// Enlarge a bounding box with values
271  bool computeMinMax(fpreal64 *min, fpreal64 *max) const override;
272 
273  /// @{
274  /// Optimized filling methods
275  void doImport(GT_Offset idx, uint8 *data, GT_Size size) const override;
276  void doImport(GT_Offset idx, int8 *data, GT_Size size) const override;
277  void doImport(GT_Offset idx, int16 *data, GT_Size size) const override;
278  void doImport(GT_Offset idx, int32 *data, GT_Size size) const override;
279  void doImport(GT_Offset idx, int64 *data, GT_Size size) const override;
280  void doImport(GT_Offset idx, fpreal16 *data, GT_Size size) const override;
281  void doImport(GT_Offset idx, fpreal32 *data, GT_Size size) const override;
282  void doImport(GT_Offset idx, fpreal64 *data, GT_Size size) const override;
283  void doImportArray(
284  GT_Offset idx, UT_ValArray<fpreal16> &data) const override;
285  void doImportArray(
286  GT_Offset idx, UT_ValArray<fpreal32> &data) const override;
287  void doImportArray(
288  GT_Offset idx, UT_ValArray<fpreal64> &data) const override;
289  void doImportArray(GT_Offset idx, UT_ValArray<uint8> &data) const override;
290  void doImportArray(GT_Offset idx, UT_ValArray<int8> &data) const override;
291  void doImportArray(GT_Offset idx, UT_ValArray<int16> &data) const override;
292  void doImportArray(GT_Offset idx, UT_ValArray<int32> &data) const override;
293  void doImportArray(GT_Offset idx, UT_ValArray<int64> &data) const override;
295  int tuple_size, int stride) const override;
297  int tuple_size, int stride) const override;
299  int tuple_size, int stride) const override;
301  int tuple_size, int stride) const override;
303  int tuple_size, int stride) const override;
305  int tuple_size, int stride) const override;
307  int tuple_size, int stride) const override;
309  int tuple_size, int stride) const override;
312  UT_BoundingBoxF &bbox, int tsize, int stride) override;
315  UT_BoundingBoxD &bbox, int tsize, int stride) override;
318  int tuple_size, int stride,
319  fpreal black, fpreal white) const override;
322  int tuple_size, int nrepeats, int stride,
323  fpreal black, fpreal white) const override;
325  GT_Offset start, GT_Size length) const override;
327  GT_Offset start, GT_Size length) const override;
329  GT_Offset start, GT_Size length) const override;
331  GT_Offset start, GT_Size length) const override;
333  GT_Offset start, GT_Size length) const override;
335  GT_Offset start, GT_Size length) const override;
337  GT_Offset start, GT_Size length) const override;
339  GT_Offset start, GT_Size length) const override;
340  /// @}
341 
342  /// @private - This method relies on knowledge of the internal
343  /// implementation. It's only public for threading efficiency.
344  GA_Offset getDataOffset(GT_Offset offset) const
345  {
346  if (myAttributeOwner == GA_ATTRIB_DETAIL)
347  return GA_Offset(0);
348 
349  GA_Offset gaoff = myOffsets(offset);
350  if (myOffsetOwner == GA_ATTRIB_VERTEX &&
351  myOffsetOwner != myAttributeOwner)
352  {
353  if (myAttributeOwner == GA_ATTRIB_POINT)
354  {
355  gaoff = myGdp->vertexPoint(gaoff);
356  }
357  else
358  {
359  UT_ASSERT(myAttributeOwner ==
361  gaoff = myGdp->vertexPrimitive(gaoff);
362  }
363  }
364  return gaoff;
365  }
366 
367 protected:
368  /// GT_GEOAutoNormalArray has no attribute yet when calling constructor.
370  const GT_GEOOffsetList &offsets,
371  GA_AttributeOwner offset_owner);
372 
373  void initAttribute(const GA_Attribute *attrib);
374  void makeInvalid();
375 
376  template <typename T> inline T
377  getValue_t(GT_Offset offset, int idx) const
378  {
379  GA_Offset si = getDataOffset(offset);
380  T val;
381 
382  if (myTuple && myTuple->get(myAttribute, si, val, idx))
383  return val;
384  return 0;
385  }
386 
387  template <typename T> inline const T *
388  getTuple_t(GT_Offset offset, T *store, int size) const
389  {
390  GA_Offset si = getDataOffset(offset);
391  if (myTuple && myTuple->get(myAttribute, si, store, size))
392  return store;
393  return NULL;
394  }
395 
396  template <typename T> inline bool
398  {
399  GA_Offset si = getDataOffset(offset);
400 
401  if (myNumericArray &&
402  myNumericArray->get(myAttribute, si, val))
403  return true;
404  return false;
405  }
406 
407 
408  GT_Type mapTypeInfo(GA_TypeInfo type, int tsize) const;
409 
411  const GU_Detail *myGdp;
421  GA_AttributeOwner myOffsetOwner; // What type of offsets
435 };
436 
437 /// This class is specific to managing a detached, auto-generated
438 /// normal attribute, when no point, vertex, attrib_owner, or offset_owner
439 /// normals are present on the original detail.
441 {
442 public:
444  const GU_ConstDetailHandle &gdp,
445  GA_AttributeOwner attrib_owner,
446  const GT_GEOOffsetList &offsets,
447  GA_AttributeOwner offset_owner,
448  float cusp_angle);
449 
450  int64 getMemoryUsage() const override
451  { return sizeof(*this); }
452 
453 
454  void updateGeoDetail(
455  const GU_ConstDetailHandle &dtl,
456  const char *name,
457  GT_Owner attrib_scope,
458  const int expected_size) override;
459 private:
460  void createAttribute();
461 
462  int64 myPDataId;
463  int64 myTopologyDataId;
464  int64 myPrimitiveListDataId;
465  const float myCuspAngle;
466  const GA_AttributeOwner myAttribOwner;
467 
468  GA_ATINumericUPtr myAttributeHolder;
469 };
470 
471 #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:104
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:646
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:101
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:35
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:114
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:112
const GA_AIFSharedStringTuple * mySSTuple
Data represents a position in space. Token "point".
Definition: GA_Types.h:106
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