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 getTotalArrayEntries() const override;
93  GT_Size getTupleSize() const override
94  {
95  return myTupleSize;
96  }
97  GT_Type getTypeInfo() const override
98  {
99  GA_TypeInfo info = myAttribute->getTypeInfo();
100  // avoid transforming attributes like "rest"
101  switch(info)
102  {
103  case GA_TYPE_POINT:
104  case GA_TYPE_HPOINT:
105  case GA_TYPE_NORMAL:
106  case GA_TYPE_VECTOR:
107  if(!myAttribute->needsTransform())
108  return GT_TYPE_NONE;
109  break;
110 
111  default:
112  break;
113  }
114  return mapTypeInfo(info, myTupleSize);
115  }
116  int64 getMemoryUsage() const override
117  { return sizeof(*this); }
118  bool isValid() const override { return myAttribute != NULL; }
119  bool hasArrayEntries() const override
120  {
121  return myFA.isValid() ||
122  myIA.isValid() ||
123  myIA64.isValid() ||
124  mySSArray;
125  }
126  void updateGeoDetail(const GU_ConstDetailHandle &dtl,
127  const char *name,
128  GT_Owner attrib_scope,
129  const int expected_size) override;
130 
131  /// @}
132 
133  /// @{
134  /// Access methods defined on GT_DataArray
135  fpreal16 getF16(GT_Offset offset, int idx) const override
136  { return getValue_t<fpreal32>(offset, idx); }
137  fpreal32 getF32(GT_Offset offset, int idx) const override
138  { return getValue_t<fpreal32>(offset, idx); }
139  fpreal64 getF64(GT_Offset offset, int idx) const override
140  { return getValue_t<fpreal64>(offset, idx); }
141  uint8 getU8(GT_Offset offset, int idx) const override
142  { return getValue_t<int32>(offset, idx); }
143  int32 getI32(GT_Offset offset, int idx) const override
144  { return getValue_t<int32>(offset, idx); }
145  int64 getI64(GT_Offset offset, int idx) const override
146  { return getValue_t<int64>(offset, idx); }
147  GT_String getS(GT_Offset offset, int idx) const override
148  {
149  if (mySTuple)
150  {
151  GA_Offset si = getDataOffset(offset);
152  return mySTuple->getString(myAttribute, si,idx);
153  }
155  }
157  GT_Offset offset) const override
158  {
159  if (mySSArray)
160  {
161  GA_Offset si = getDataOffset(offset);
162  mySSArray->getString(myAttribute, si, a);
163  return true;
164  }
165  return false;
166  }
167  GT_Size getStringIndexCount() const override;
169  int idx=0) const override;
171  UT_IntArray &) const override;
172 
174  GT_Offset start, GT_Size length) const override;
175 
177  GT_Offset offset) const override
178  { return getArrayValue_t<fpreal16>(a,offset); }
180  GT_Offset offset) const override
181  { return getArrayValue_t<fpreal32>(a,offset); }
183  GT_Offset offset) const override
184  { return getArrayValue_t<fpreal64>(a,offset); }
186  GT_Offset offset) const override
187  { return getArrayValue_t<uint8>(a,offset); }
189  GT_Offset offset) const override
190  { return getArrayValue_t<int8>(a,offset); }
192  GT_Offset offset) const override
193  { return getArrayValue_t<int16>(a,offset); }
195  GT_Offset offset) const override
196  { return getArrayValue_t<int32>(a,offset); }
198  GT_Offset offset) const override
199  { return getArrayValue_t<int64>(a,offset); }
200  /// @}
201 
202  const uint8 *get(GT_Offset i, uint8 *store, int sz) const override
203  { return GT_DataArray::get(i, store, sz); }
204  const int8 *get(GT_Offset i, int8 *store, int sz) const override
205  { return GT_DataArray::get(i, store, sz); }
206  const int16 *get(GT_Offset i, int16 *store, int sz) const override
207  { return GT_DataArray::get(i, store, sz); }
208  const int32 *get(GT_Offset i, int32 *store, int sz) const override
209  { return getTuple_t(i, store, sz); }
210  const int64 *get(GT_Offset i, int64 *store, int sz) const override
211  { return getTuple_t(i, store, sz); }
212  const fpreal16 *get(GT_Offset i, fpreal16 *store, int z) const override
213  { return GT_DataArray::get(i, store, z); }
214  const fpreal64 *get(GT_Offset i, fpreal64 *store, int z) const override
215  { return getTuple_t(i, store, z); }
216  const fpreal32 *get(GT_Offset idx, fpreal32 *store, int z) const override
217  {
218  if (z == 3 && myV3.isValid())
219  {
220  UT_Vector3 v = myV3.get(getDataOffset(idx));
221  store[0] = v.x();
222  store[1] = v.y();
223  store[2] = v.z();
224  return store;
225  }
226  if (myF.isValid())
227  {
228  GA_Offset o = getDataOffset(idx);
229  for (int i = 0; i < z; ++i)
230  store[i] = myF.get(o, i);
231  return store;
232  }
233  return getTuple_t(idx, store, z);
234  }
235 
236  /// Enlarge a bounding box with values
237  bool computeMinMax(fpreal64 *min, fpreal64 *max) const override;
238 
239  /// @{
240  /// Optimized filling methods
241  void doImport(GT_Offset idx, uint8 *data, GT_Size size) const override;
242  void doImport(GT_Offset idx, int8 *data, GT_Size size) const override;
243  void doImport(GT_Offset idx, int16 *data, GT_Size size) const override;
244  void doImport(GT_Offset idx, int32 *data, GT_Size size) const override;
245  void doImport(GT_Offset idx, int64 *data, GT_Size size) const override;
246  void doImport(GT_Offset idx, fpreal16 *data, GT_Size size) const override;
247  void doImport(GT_Offset idx, fpreal32 *data, GT_Size size) const override;
248  void doImport(GT_Offset idx, fpreal64 *data, GT_Size size) const override;
249  void doImportArray(
250  GT_Offset idx, UT_ValArray<fpreal16> &data) const override;
251  void doImportArray(
252  GT_Offset idx, UT_ValArray<fpreal32> &data) const override;
253  void doImportArray(
254  GT_Offset idx, UT_ValArray<fpreal64> &data) const override;
255  void doImportArray(GT_Offset idx, UT_ValArray<uint8> &data) const override;
256  void doImportArray(GT_Offset idx, UT_ValArray<int8> &data) const override;
257  void doImportArray(GT_Offset idx, UT_ValArray<int16> &data) const override;
258  void doImportArray(GT_Offset idx, UT_ValArray<int32> &data) const override;
259  void doImportArray(GT_Offset idx, UT_ValArray<int64> &data) const override;
261  int tuple_size, int stride) const override;
263  int tuple_size, int stride) const override;
265  int tuple_size, int stride) const override;
267  int tuple_size, int stride) const override;
269  int tuple_size, int stride) const override;
271  int tuple_size, int stride) const override;
273  int tuple_size, int stride) const override;
275  int tuple_size, int stride) const override;
278  UT_BoundingBoxF &bbox, int tsize, int stride) override;
281  UT_BoundingBoxD &bbox, int tsize, int stride) override;
284  int tuple_size, int stride,
285  fpreal black, fpreal white) const override;
288  int tuple_size, int nrepeats, int stride,
289  fpreal black, fpreal white) const override;
291  GT_Offset start, GT_Size length) const override;
293  GT_Offset start, GT_Size length) const override;
295  GT_Offset start, GT_Size length) const override;
297  GT_Offset start, GT_Size length) const override;
299  GT_Offset start, GT_Size length) const override;
301  GT_Offset start, GT_Size length) const override;
303  GT_Offset start, GT_Size length) const override;
305  GT_Offset start, GT_Size length) const override;
306  /// @}
307 
308  /// @private - This method relies on knowledge of the internal
309  /// implementation. It's only public for threading efficiency.
310  GA_Offset getDataOffset(GT_Offset offset) const
311  {
312  if (myAttributeOwner == GA_ATTRIB_DETAIL)
313  return GA_Offset(0);
314 
315  GA_Offset gaoff = myOffsets(offset);
316  if (myOffsetOwner == GA_ATTRIB_VERTEX &&
317  myOffsetOwner != myAttributeOwner)
318  {
319  if (myAttributeOwner == GA_ATTRIB_POINT)
320  {
321  gaoff = myGdp->vertexPoint(gaoff);
322  }
323  else
324  {
325  UT_ASSERT(myAttributeOwner ==
327  gaoff = myGdp->vertexPrimitive(gaoff);
328  }
329  }
330  return gaoff;
331  }
332 
333 protected:
334  /// GT_GEOAutoNormalArray has no attribute yet when calling constructor.
336  const GT_GEOOffsetList &offsets,
337  GA_AttributeOwner offset_owner);
338 
339  void initAttribute(const GA_Attribute *attrib);
340  void makeInvalid();
341 
342  template <typename T> inline T
343  getValue_t(GT_Offset offset, int idx) const
344  {
345  GA_Offset si = getDataOffset(offset);
346  T val;
347 
348  if (myTuple && myTuple->get(myAttribute, si, val, idx))
349  return val;
350  return 0;
351  }
352 
353  template <typename T> inline const T *
354  getTuple_t(GT_Offset offset, T *store, int size) const
355  {
356  GA_Offset si = getDataOffset(offset);
357  if (myTuple && myTuple->get(myAttribute, si, store, size))
358  return store;
359  return NULL;
360  }
361 
362  template <typename T> inline bool
364  {
365  GA_Offset si = getDataOffset(offset);
366 
367  if (myNumericArray &&
368  myNumericArray->get(myAttribute, si, val))
369  return true;
370  return false;
371  }
372 
373 
374  GT_Type mapTypeInfo(GA_TypeInfo type, int tsize) const;
375 
377  const GU_Detail *myGdp;
385  GA_AttributeOwner myOffsetOwner; // What type of offsets
396 };
397 
398 /// This class is specific to managing a detached, auto-generated
399 /// normal attribute, when no point, vertex, attrib_owner, or offset_owner
400 /// normals are present on the original detail.
402 {
403 public:
405  const GU_ConstDetailHandle &gdp,
406  GA_AttributeOwner attrib_owner,
407  const GT_GEOOffsetList &offsets,
408  GA_AttributeOwner offset_owner,
409  float cusp_angle);
410 
411  int64 getMemoryUsage() const override
412  { return sizeof(*this); }
413 
414 
415  void updateGeoDetail(
416  const GU_ConstDetailHandle &dtl,
417  const char *name,
418  GT_Owner attrib_scope,
419  const int expected_size) override;
420 private:
421  void createAttribute();
422 
423  int64 myPDataId;
424  int64 myTopologyDataId;
425  int64 myPrimitiveListDataId;
426  const float myCuspAngle;
427  const GA_AttributeOwner myAttribOwner;
428 
429  GA_ATINumericUPtr myAttributeHolder;
430 };
431 
432 #endif
vint4 max(const vint4 &a, const vint4 &b)
Definition: simd.h:4703
GT_Storage
Definition: GT_Types.h:18
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:527
Definition of a geometry attribute.
Definition: GA_Attribute.h:196
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:707
GLsizeiptr size
Definition: glew.h:1681
Generic Attribute Interface class to access an attribute as a array.
int int32
Definition: SYS_Types.h:39
GLuint const GLchar * name
Definition: glew.h:1814
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:196
const GA_AIFTuple * myTuple
GT_Storage getStorage() const override
int64 getMemoryUsage() const override
GLuint const GLfloat * val
Definition: glew.h:2794
GLuint GLsizei const GLuint const GLintptr * offsets
Definition: glew.h:4117
GA_AttributeOwner myAttributeOwner
int64 getI64(GT_Offset offset, int idx) const override
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:9477
virtual void doImport(GT_Offset idx, uint8 *data, GT_Size size) const
#define GT_API
Definition: GT_API.h:11
GT_Type
Definition: GT_Types.h:34
int64 getMemoryUsage() const override
const GLdouble * v
Definition: glew.h:1391
bool isValid() const override
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:765
virtual bool computeMinMax(fpreal64 *min, fpreal64 *max) const
Definition: GT_DataArray.h:618
const GU_Detail * myGdp
GLdouble GLdouble z
Definition: glew.h:1559
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:639
GU_ConstDetailHandle myGdh
bool hasArrayEntries() const override
SYS_FORCE_INLINE T & y()
Definition: UT_Vector3.h:513
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
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
Definition: glew.h:5268
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
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
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.
SYS_FORCE_INLINE T & z()
Definition: UT_Vector3.h:515
A specialization of GA_AIFStringArray to access "shared strings".
bool getIA32(UT_ValArray< int32 > &a, GT_Offset offset) const override
GLuint GLsizei GLsizei * length
Definition: glew.h:1825
int64 GT_Offset
Definition: GT_Types.h:114
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:657
virtual GT_Offset getStringIndex(GT_Offset offset, int idx=0) const =0
signed char int8
Definition: SYS_Types.h:35
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
GT_Size entries() const override
GLuint start
Definition: glew.h:1253
GA_TypeInfo
Definition: GA_Types.h:99
const char * className() const override
GLsizei stride
Definition: glew.h:1523
GT_Owner
Definition: GT_Types.h:76
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:113
GT_GEOOffsetList myOffsets
GA_AttributeOwner
Definition: GA_Types.h:33
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:112
GA_AttributeOwner myOffsetOwner
bool getIA16(UT_ValArray< int16 > &a, GT_Offset offset) const override
A specialization of GA_AIFStringTuple to access "shared strings".
Data represents a direction vector. Token "vector".
Definition: GA_Types.h:110
const GA_AIFSharedStringTuple * mySSTuple
SYS_FORCE_INLINE T & x()
Definition: UT_Vector3.h:511
Data represents a position in space. Token "point".
Definition: GA_Types.h:104
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:135
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
vint4 min(const vint4 &a, const vint4 &b)
Definition: simd.h:4694
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:682
bool getFA16(UT_ValArray< fpreal16 > &a, GT_Offset offset) const override
virtual GT_Size getTotalArrayEntries() const
Definition: GT_DataArray.h:61
UT_UniquePtr< GA_ATINumeric > GA_ATINumericUPtr
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
GLintptr offset
Definition: glew.h:1682