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  virtual ~GT_GEOElementArray();
64 
65  virtual const char *className() const { return "GT_GEOElementArray"; }
66 
67  /// @{
68  /// Query methods defined on GT_DataArray
69  virtual GT_Storage getStorage() const
70  { return myStorage; }
71  virtual GT_Size entries() const
72  {
73  return myOffsets.entries();
74 #if 0
75  switch (myOffsetOwner)
76  {
77  case GA_ATTRIB_VERTEX:
78  return myGdp->getNumVertexOffsets();
79  case GA_ATTRIB_POINT:
80  return myGdp->getNumPointOffsets();
82  return myGdp->getNumPrimitiveOffsets();
83  case GA_ATTRIB_DETAIL:
84  return 1;
85  default:
86  UT_ASSERT(0);
87  }
88 #endif
89  return 0;
90  }
91  GT_Size getTotalArrayEntries() const override;
92  GT_Size getTupleSize() const override
93  {
94  return myTupleSize;
95  }
96  virtual GT_Type getTypeInfo() const
97  {
98  GA_TypeInfo info = myAttribute->getTypeInfo();
99  // avoid transforming attributes like "rest"
100  switch(info)
101  {
102  case GA_TYPE_POINT:
103  case GA_TYPE_HPOINT:
104  case GA_TYPE_NORMAL:
105  case GA_TYPE_VECTOR:
106  if(!myAttribute->needsTransform())
107  return GT_TYPE_NONE;
108  break;
109 
110  default:
111  break;
112  }
113  return mapTypeInfo(info, myTupleSize);
114  }
115  virtual int64 getMemoryUsage() const
116  { return sizeof(*this); }
117  virtual bool isValid() const { return myAttribute != NULL; }
118  virtual bool hasArrayEntries() const
119  {
120  return myFA.isValid() ||
121  myIA.isValid() ||
122  myIA64.isValid() ||
123  mySSArray;
124  }
125  virtual void updateGeoDetail(const GU_ConstDetailHandle &dtl,
126  const char *name,
127  GT_Owner attrib_scope,
128  const int expected_size);
129 
130  /// @}
131 
132  /// @{
133  /// Access methods defined on GT_DataArray
134  virtual fpreal16 getF16(GT_Offset offset, int idx) const
135  { return getValue_t<fpreal32>(offset, idx); }
136  virtual fpreal32 getF32(GT_Offset offset, int idx) const
137  { return getValue_t<fpreal32>(offset, idx); }
138  virtual fpreal64 getF64(GT_Offset offset, int idx) const
139  { return getValue_t<fpreal64>(offset, idx); }
140  virtual uint8 getU8(GT_Offset offset, int idx) const
141  { return getValue_t<int32>(offset, idx); }
142  virtual int32 getI32(GT_Offset offset, int idx) const
143  { return getValue_t<int32>(offset, idx); }
144  virtual int64 getI64(GT_Offset offset, int idx) const
145  { return getValue_t<int64>(offset, idx); }
146  virtual GT_String getS(GT_Offset offset, int idx) const
147  {
148  if (mySTuple)
149  {
150  GA_Offset si = getDataOffset(offset);
151  return mySTuple->getString(myAttribute, si,idx);
152  }
154  }
155  virtual bool getSA(UT_StringArray &a, GT_Offset offset) const
156  {
157  if (mySSArray)
158  {
159  GA_Offset si = getDataOffset(offset);
160  mySSArray->getString(myAttribute, si, a);
161  return true;
162  }
163  return false;
164  }
165  virtual GT_Size getStringIndexCount() const;
166  virtual GT_Offset getStringIndex(GT_Offset offset, int idx=0) const;
167  virtual void getIndexedStrings(UT_StringArray &,
168  UT_IntArray &) const;
169 
171  GT_Offset start, GT_Size length) const override;
172 
174  GT_Offset offset) const override
175  { return getArrayValue_t<fpreal16>(a,offset); }
177  GT_Offset offset) const override
178  { return getArrayValue_t<fpreal32>(a,offset); }
180  GT_Offset offset) const override
181  { return getArrayValue_t<fpreal64>(a,offset); }
183  GT_Offset offset) const override
184  { return getArrayValue_t<int16>(a,offset); }
186  GT_Offset offset) const override
187  { return getArrayValue_t<int32>(a,offset); }
189  GT_Offset offset) const override
190  { return getArrayValue_t<int64>(a,offset); }
191  /// @}
192 
193  virtual const uint8 *get(GT_Offset i, uint8 *store, int sz) const
194  { return GT_DataArray::get(i, store, sz); }
195  virtual const int8 *get(GT_Offset i, int8 *store, int sz) const
196  { return GT_DataArray::get(i, store, sz); }
197  virtual const int16 *get(GT_Offset i, int16 *store, int sz) const
198  { return GT_DataArray::get(i, store, sz); }
199  virtual const int32 *get(GT_Offset i, int32 *store, int sz) const
200  { return getTuple_t(i, store, sz); }
201  virtual const int64 *get(GT_Offset i, int64 *store, int sz) const
202  { return getTuple_t(i, store, sz); }
203  virtual const fpreal16 *get(GT_Offset i, fpreal16 *store, int z) const
204  { return GT_DataArray::get(i, store, z); }
205  virtual const fpreal64 *get(GT_Offset i, fpreal64 *store, int z) const
206  { return getTuple_t(i, store, z); }
207  virtual const fpreal32 *get(GT_Offset idx, fpreal32 *store, int z) const
208  {
209  if (z == 3 && myV3.isValid())
210  {
211  UT_Vector3 v = myV3.get(getDataOffset(idx));
212  store[0] = v.x();
213  store[1] = v.y();
214  store[2] = v.z();
215  return store;
216  }
217  if (myF.isValid())
218  {
219  GA_Offset o = getDataOffset(idx);
220  for (int i = 0; i < z; ++i)
221  store[i] = myF.get(o, i);
222  return store;
223  }
224  return getTuple_t(idx, store, z);
225  }
226 
227  /// Enlarge a bounding box with values
228  virtual bool computeMinMax(fpreal64 *min, fpreal64 *max) const;
229 
230  /// @{
231  /// Optimized filling methods
232  virtual void doImport(GT_Offset idx, uint8 *data, GT_Size size) const;
233  virtual void doImport(GT_Offset idx, int8 *data, GT_Size size) const;
234  virtual void doImport(GT_Offset idx, int16 *data, GT_Size size) const;
235  virtual void doImport(GT_Offset idx, int32 *data, GT_Size size) const;
236  virtual void doImport(GT_Offset idx, int64 *data, GT_Size size) const;
237  virtual void doImport(GT_Offset idx, fpreal16 *data, GT_Size size) const;
238  virtual void doImport(GT_Offset idx, fpreal32 *data, GT_Size size) const;
239  virtual void doImport(GT_Offset idx, fpreal64 *data, GT_Size size) const;
240  virtual void doImportArray(GT_Offset idx, UT_ValArray<fpreal16> &data) const;
241  virtual void doImportArray(GT_Offset idx, UT_ValArray<fpreal32> &data) const;
242  virtual void doImportArray(GT_Offset idx, UT_ValArray<fpreal64> &data) const;
243  virtual void doImportArray(GT_Offset idx, UT_ValArray<int16> &data) const;
244  virtual void doImportArray(GT_Offset idx, UT_ValArray<int32> &data) const;
245  virtual void doImportArray(GT_Offset idx, UT_ValArray<int64> &data) const;
247  int tuple_size, int stride) const;
249  int tuple_size, int stride) const;
251  int tuple_size, int stride) const;
253  int tuple_size, int stride) const;
255  int tuple_size, int stride) const;
257  int tuple_size, int stride) const;
259  int tuple_size, int stride) const;
261  int tuple_size, int stride) const;
263  UT_BoundingBoxF &bbox, int tsize, int stride);
265  UT_BoundingBoxD &bbox, int tsize, int stride);
266  virtual void doFillQuantizedArray(uint8 *data,
268  int tuple_size, int stride,
269  fpreal black, fpreal white) const;
270  virtual void doExtendedQuantizedFill(uint8 *data,
272  int tuple_size, int nrepeats, int stride,
273  fpreal black, fpreal white) const;
275  GT_Offset start, GT_Size length) const override;
277  GT_Offset start, GT_Size length) const override;
279  GT_Offset start, GT_Size length) const override;
281  GT_Offset start, GT_Size length) const override;
283  GT_Offset start, GT_Size length) const override;
285  GT_Offset start, GT_Size length) const override;
286  /// @}
287 
288  /// @private - This method relies on knowledge of the internal
289  /// implementation. It's only public for threading efficiency.
290  GA_Offset getDataOffset(GT_Offset offset) const
291  {
292  if (myAttributeOwner == GA_ATTRIB_DETAIL)
293  return GA_Offset(0);
294 
295  GA_Offset gaoff = myOffsets(offset);
296  if (myOffsetOwner == GA_ATTRIB_VERTEX &&
297  myOffsetOwner != myAttributeOwner)
298  {
299  if (myAttributeOwner == GA_ATTRIB_POINT)
300  {
301  gaoff = myGdp->vertexPoint(gaoff);
302  }
303  else
304  {
305  UT_ASSERT(myAttributeOwner ==
307  gaoff = myGdp->vertexPrimitive(gaoff);
308  }
309  }
310  return gaoff;
311  }
312 
313 protected:
314  /// GT_GEOAutoNormalArray has no attribute yet when calling constructor.
316  const GT_GEOOffsetList &offsets,
317  GA_AttributeOwner offset_owner);
318 
319  void initAttribute(const GA_Attribute *attrib);
320  void makeInvalid();
321 
322  template <typename T> inline T
323  getValue_t(GT_Offset offset, int idx) const
324  {
325  GA_Offset si = getDataOffset(offset);
326  T val;
327 
328  if (myTuple && myTuple->get(myAttribute, si, val, idx))
329  return val;
330  return 0;
331  }
332 
333  template <typename T> inline const T *
334  getTuple_t(GT_Offset offset, T *store, int size) const
335  {
336  GA_Offset si = getDataOffset(offset);
337  if (myTuple && myTuple->get(myAttribute, si, store, size))
338  return store;
339  return NULL;
340  }
341 
342  template <typename T> inline bool
344  {
345  GA_Offset si = getDataOffset(offset);
346 
347  if (myNumericArray &&
348  myNumericArray->get(myAttribute, si, val))
349  return true;
350  return false;
351  }
352 
353 
354  GT_Type mapTypeInfo(GA_TypeInfo type, int tsize) const;
355 
357  const GU_Detail *myGdp;
365  GA_AttributeOwner myOffsetOwner; // What type of offsets
376 };
377 
378 /// This class is specific to managing a detached, auto-generated
379 /// normal attribute, when no point, vertex, attrib_owner, or offset_owner
380 /// normals are present on the original detail.
382 {
383 public:
385  const GU_ConstDetailHandle &gdp,
386  GA_AttributeOwner attrib_owner,
387  const GT_GEOOffsetList &offsets,
388  GA_AttributeOwner offset_owner,
389  float cusp_angle);
390 
391  virtual ~GT_GEOAutoNormalArray();
392 
393  virtual int64 getMemoryUsage() const
394  { return sizeof(*this); }
395 
396 
397  virtual void updateGeoDetail(
398  const GU_ConstDetailHandle &dtl,
399  const char *name,
400  GT_Owner attrib_scope,
401  const int expected_size);
402 private:
403  void createAttribute();
404 
405  int64 myPDataId;
406  int64 myTopologyDataId;
407  int64 myPrimitiveListDataId;
408  const float myCuspAngle;
409  const GA_AttributeOwner myAttribOwner;
410 };
411 
412 #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:479
Definition of a geometry attribute.
Definition: GA_Attribute.h:190
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:651
virtual const char * className() const
GLsizeiptr size
Definition: glew.h:1681
Generic Attribute Interface class to access an attribute as a array.
GLuint const GLchar * name
Definition: glew.h:1814
const GA_Attribute * myAttribute
T getValue_t(GT_Offset offset, int idx) const
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:183
const GA_AIFTuple * myTuple
GLuint const GLfloat * val
Definition: glew.h:2794
GLuint GLsizei const GLuint const GLintptr * offsets
Definition: glew.h:4117
GA_AttributeOwner myAttributeOwner
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:9477
virtual void doImport(GT_Offset idx, uint8 *data, GT_Size size) const
virtual GT_String getS(GT_Offset offset, int idx) const
virtual bool isValid() const
virtual GT_Type getTypeInfo() const
#define GT_API
Definition: GT_API.h:11
GT_Type
Definition: GT_Types.h:34
virtual uint8 getU8(GT_Offset offset, int idx) const
const GLdouble * v
Definition: glew.h:1391
SYS_FORCE_INLINE T & x(void)
Definition: UT_Vector3.h:507
virtual fpreal64 getF64(GT_Offset offset, int idx) const
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:709
virtual bool computeMinMax(fpreal64 *min, fpreal64 *max) const
Definition: GT_DataArray.h:570
const GU_Detail * myGdp
GLdouble GLdouble z
Definition: glew.h:1559
signed char int8
Definition: SYS_Types.h:35
bool getFA32(UT_ValArray< fpreal32 > &a, GT_Offset offset) const override
GA_Size GA_Offset
Definition: GA_Types.h:637
SYS_FORCE_INLINE T & z(void)
Definition: UT_Vector3.h:511
long long int64
Definition: SYS_Types.h:111
GU_ConstDetailHandle myGdh
Abstract data class for an array of float, int or string data.
Definition: GT_DataArray.h:39
virtual GT_Size getStringIndexCount() const =0
const GA_AIFNumericArray * myNumericArray
virtual const uint8 * get(GT_Offset i, uint8 *store, int sz) const
virtual int64 getMemoryUsage() const
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
Definition: glew.h:5268
virtual bool hasArrayEntries() const
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
virtual GT_Size entries() const
static const UT_StringHolder theEmptyString
A GT Data Array to extract values from a point/primitive attribute.
double fpreal64
Definition: SYS_Types.h:196
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
virtual fpreal16 getF16(GT_Offset offset, int idx) const
virtual bool getSA(UT_StringArray &a, GT_Offset offset) const
virtual void doFillArrayAttr(UT_Array< int16 > &data, UT_Array< int > &sizes, GT_Offset start, GT_Size length) const
Definition: GT_DataArray.h:632
int64 GT_Offset
Definition: GT_Types.h:114
const GA_AIFStringTuple * mySTuple
virtual void doFillArray(uint8 *data, GT_Offset start, GT_Size length, int tuple_size, int stride) const
Definition: GT_DataArray.h:607
virtual GT_Offset getStringIndex(GT_Offset offset, int idx=0) const =0
int int32
Definition: SYS_Types.h:39
virtual void updateGeoDetail(const GU_ConstDetailHandle &dtl, const char *name, GT_Owner attrib_scope, const int expected_size)
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
GLuint start
Definition: glew.h:1253
GA_TypeInfo
Definition: GA_Types.h:97
GLsizei stride
Definition: glew.h:1523
GT_Owner
Definition: GT_Types.h:76
bool getArrayValue_t(UT_ValArray< T > &val, GT_Offset offset) const
int64 GT_Size
Definition: GT_Types.h:113
GT_GEOOffsetList myOffsets
SYS_FORCE_INLINE T & y(void)
Definition: UT_Vector3.h:509
GA_AttributeOwner
Definition: GA_Types.h:33
double fpreal
Definition: SYS_Types.h:276
GT_Size getTupleSize() const override
virtual void doImportArray(GT_Offset idx, UT_ValArray< fpreal16 > &data) const
unsigned char uint8
Definition: SYS_Types.h:36
Data represents a normal vector. Token "normal".
Definition: GA_Types.h:110
GA_AttributeOwner myOffsetOwner
virtual GT_Storage getStorage() const
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:108
const GA_AIFSharedStringTuple * mySSTuple
Data represents a position in space. Token "point".
Definition: GA_Types.h:102
virtual void doExtendedQuantizedFill(uint8 *data, GT_Offset start, GT_Size length, int tuple_size, int nrepeats, int stride, fpreal black, fpreal white) const
virtual int32 getI32(GT_Offset offset, int idx) const
virtual void getIndexedStrings(UT_StringArray &strings, UT_IntArray &indices) const =0
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:135
virtual int64 getMemoryUsage() const
vint4 min(const vint4 &a, const vint4 &b)
Definition: simd.h:4694
short int16
Definition: SYS_Types.h:37
Generic Attribute Interface class to access an attribute as a tuple.
Definition: GA_AIFTuple.h:32
virtual fpreal32 getF32(GT_Offset offset, int idx) const
virtual int64 getI64(GT_Offset offset, int idx) const
float fpreal32
Definition: SYS_Types.h:195
bool getFA16(UT_ValArray< fpreal16 > &a, GT_Offset offset) const override
virtual GT_Size getTotalArrayEntries() const
Definition: GT_DataArray.h:60
Generic Attribute Interface class to work with string indices directly, rather than string values...
bool getFA64(UT_ValArray< fpreal64 > &a, GT_Offset offset) const override
GLintptr offset
Definition: glew.h:1682