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  virtual GT_Size getTupleSize() const
92  {
93  return myTupleSize;
94  }
95  virtual GT_Type getTypeInfo() const
96  {
97  GA_TypeInfo info = myAttribute->getTypeInfo();
98  // avoid transforming attributes like "rest"
99  switch(info)
100  {
101  case GA_TYPE_POINT:
102  case GA_TYPE_HPOINT:
103  case GA_TYPE_NORMAL:
104  case GA_TYPE_VECTOR:
105  if(!myAttribute->needsTransform())
106  return GT_TYPE_NONE;
107  break;
108 
109  default:
110  break;
111  }
112  return mapTypeInfo(info, myTupleSize);
113  }
114  virtual int64 getMemoryUsage() const
115  { return sizeof(*this); }
116  virtual bool isValid() const { return myAttribute != NULL; }
117  virtual bool hasArrayEntries() const
118  {
119  return myFA.isValid() ||
120  myIA.isValid() ||
121  myIA64.isValid() ||
122  mySSArray;
123  }
124  virtual void updateGeoDetail(const GU_ConstDetailHandle &dtl,
125  const char *name,
126  GT_Owner attrib_scope,
127  const int expected_size);
128 
129  /// @}
130 
131  /// @{
132  /// Access methods defined on GT_DataArray
133  virtual fpreal16 getF16(GT_Offset offset, int idx) const
134  { return getValue_t<fpreal32>(offset, idx); }
135  virtual fpreal32 getF32(GT_Offset offset, int idx) const
136  { return getValue_t<fpreal32>(offset, idx); }
137  virtual fpreal64 getF64(GT_Offset offset, int idx) const
138  { return getValue_t<fpreal64>(offset, idx); }
139  virtual uint8 getU8(GT_Offset offset, int idx) const
140  { return getValue_t<int32>(offset, idx); }
141  virtual int32 getI32(GT_Offset offset, int idx) const
142  { return getValue_t<int32>(offset, idx); }
143  virtual int64 getI64(GT_Offset offset, int idx) const
144  { return getValue_t<int64>(offset, idx); }
145  virtual GT_String getS(GT_Offset offset, int idx) const
146  {
147  if (mySTuple)
148  {
149  GA_Offset si = getDataOffset(offset);
150  return mySTuple->getString(myAttribute, si,idx);
151  }
153  }
154  virtual bool getSA(UT_StringArray &a, GT_Offset offset) const
155  {
156  if (mySSArray)
157  {
158  GA_Offset si = getDataOffset(offset);
159  mySSArray->getString(myAttribute, si, a);
160  return true;
161  }
162  return false;
163  }
164  virtual GT_Size getStringIndexCount() const;
165  virtual GT_Offset getStringIndex(GT_Offset offset, int idx=0) const;
166  virtual void getIndexedStrings(UT_StringArray &,
167  UT_IntArray &) const;
168 
170  { return getArrayValue_t<fpreal16>(a,offset); }
172  { return getArrayValue_t<fpreal32>(a,offset); }
174  { return getArrayValue_t<fpreal64>(a,offset); }
176  { return getArrayValue_t<int16>(a,offset); }
178  { return getArrayValue_t<int32>(a,offset); }
180  { return getArrayValue_t<int64>(a,offset); }
181  /// @}
182 
183  virtual const uint8 *get(GT_Offset i, uint8 *store, int sz) const
184  { return GT_DataArray::get(i, store, sz); }
185  virtual const int8 *get(GT_Offset i, int8 *store, int sz) const
186  { return GT_DataArray::get(i, store, sz); }
187  virtual const int16 *get(GT_Offset i, int16 *store, int sz) const
188  { return GT_DataArray::get(i, store, sz); }
189  virtual const int32 *get(GT_Offset i, int32 *store, int sz) const
190  { return getTuple_t(i, store, sz); }
191  virtual const int64 *get(GT_Offset i, int64 *store, int sz) const
192  { return getTuple_t(i, store, sz); }
193  virtual const fpreal16 *get(GT_Offset i, fpreal16 *store, int z) const
194  { return GT_DataArray::get(i, store, z); }
195  virtual const fpreal64 *get(GT_Offset i, fpreal64 *store, int z) const
196  { return getTuple_t(i, store, z); }
197  virtual const fpreal32 *get(GT_Offset idx, fpreal32 *store, int z) const
198  {
199  if (z == 3 && myV3.isValid())
200  {
201  UT_Vector3 v = myV3.get(getDataOffset(idx));
202  store[0] = v.x();
203  store[1] = v.y();
204  store[2] = v.z();
205  return store;
206  }
207  if (myF.isValid())
208  {
209  GA_Offset o = getDataOffset(idx);
210  for (int i = 0; i < z; ++i)
211  store[i] = myF.get(o, i);
212  return store;
213  }
214  return getTuple_t(idx, store, z);
215  }
216 
217  /// Enlarge a bounding box with values
218  virtual bool computeMinMax(fpreal64 *min, fpreal64 *max) const;
219 
220  /// @{
221  /// Optimized filling methods
222  virtual void doImport(GT_Offset idx, uint8 *data, GT_Size size) const;
223  virtual void doImport(GT_Offset idx, int8 *data, GT_Size size) const;
224  virtual void doImport(GT_Offset idx, int16 *data, GT_Size size) const;
225  virtual void doImport(GT_Offset idx, int32 *data, GT_Size size) const;
226  virtual void doImport(GT_Offset idx, int64 *data, GT_Size size) const;
227  virtual void doImport(GT_Offset idx, fpreal16 *data, GT_Size size) const;
228  virtual void doImport(GT_Offset idx, fpreal32 *data, GT_Size size) const;
229  virtual void doImport(GT_Offset idx, fpreal64 *data, GT_Size size) const;
230  virtual void doImportArray(GT_Offset idx, UT_ValArray<fpreal16> &data) const;
231  virtual void doImportArray(GT_Offset idx, UT_ValArray<fpreal32> &data) const;
232  virtual void doImportArray(GT_Offset idx, UT_ValArray<fpreal64> &data) const;
233  virtual void doImportArray(GT_Offset idx, UT_ValArray<int16> &data) const;
234  virtual void doImportArray(GT_Offset idx, UT_ValArray<int32> &data) const;
235  virtual void doImportArray(GT_Offset idx, UT_ValArray<int64> &data) const;
237  int tuple_size, int stride) const;
239  int tuple_size, int stride) const;
241  int tuple_size, int stride) const;
243  int tuple_size, int stride) const;
245  int tuple_size, int stride) const;
247  int tuple_size, int stride) const;
249  int tuple_size, int stride) const;
251  int tuple_size, int stride) const;
253  UT_BoundingBoxF &bbox, int tsize, int stride);
255  UT_BoundingBoxD &bbox, int tsize, int stride);
256  virtual void doFillQuantizedArray(uint8 *data,
258  int tuple_size, int stride,
259  fpreal black, fpreal white) const;
260  virtual void doExtendedQuantizedFill(uint8 *data,
262  int tuple_size, int nrepeats, int stride,
263  fpreal black, fpreal white) const;
264  /// @}
265 
266  /// @private - This method relies on knowledge of the internal
267  /// implementation. It's only public for threading efficiency.
268  GA_Offset getDataOffset(GT_Offset offset) const
269  {
270  if (myAttributeOwner == GA_ATTRIB_DETAIL)
271  return GA_Offset(0);
272 
273  GA_Offset gaoff = myOffsets(offset);
274  if (myOffsetOwner == GA_ATTRIB_VERTEX &&
275  myOffsetOwner != myAttributeOwner)
276  {
277  if (myAttributeOwner == GA_ATTRIB_POINT)
278  {
279  gaoff = myGdp->vertexPoint(gaoff);
280  }
281  else
282  {
283  UT_ASSERT(myAttributeOwner ==
285  gaoff = myGdp->vertexPrimitive(gaoff);
286  }
287  }
288  return gaoff;
289  }
290 
291 protected:
292  /// GT_GEOAutoNormalArray has no attribute yet when calling constructor.
294  const GT_GEOOffsetList &offsets,
295  GA_AttributeOwner offset_owner);
296 
297  void initAttribute(const GA_Attribute *attrib);
298  void makeInvalid();
299 
300  template <typename T> inline T
301  getValue_t(GT_Offset offset, int idx) const
302  {
303  GA_Offset si = getDataOffset(offset);
304  T val;
305 
306  if (myTuple && myTuple->get(myAttribute, si, val, idx))
307  return val;
308  return 0;
309  }
310 
311  template <typename T> inline const T *
312  getTuple_t(GT_Offset offset, T *store, int size) const
313  {
314  GA_Offset si = getDataOffset(offset);
315  if (myTuple && myTuple->get(myAttribute, si, store, size))
316  return store;
317  return NULL;
318  }
319 
320  template <typename T> inline bool
322  {
323  GA_Offset si = getDataOffset(offset);
324 
325  if (myNumericArray &&
326  myNumericArray->get(myAttribute, si, val))
327  return true;
328  return false;
329  }
330 
331 
332  GT_Type mapTypeInfo(GA_TypeInfo type, int tsize) const;
333 
335  const GU_Detail *myGdp;
343  GA_AttributeOwner myOffsetOwner; // What type of offsets
354 };
355 
356 /// This class is specific to managing a detached, auto-generated
357 /// normal attribute, when no point, vertex, attrib_owner, or offset_owner
358 /// normals are present on the original detail.
360 {
361 public:
363  const GU_ConstDetailHandle &gdp,
364  GA_AttributeOwner attrib_owner,
365  const GT_GEOOffsetList &offsets,
366  GA_AttributeOwner offset_owner,
367  float cusp_angle);
368 
369  virtual ~GT_GEOAutoNormalArray();
370 
371  virtual int64 getMemoryUsage() const
372  { return sizeof(*this); }
373 
374 
375  virtual void updateGeoDetail(
376  const GU_ConstDetailHandle &dtl,
377  const char *name,
378  GT_Owner attrib_scope,
379  const int expected_size);
380 private:
381  void createAttribute();
382 
383  int64 myPDataId;
384  int64 myTopologyDataId;
385  int64 myPrimitiveListDataId;
386  const float myCuspAngle;
387  const GA_AttributeOwner myAttribOwner;
388 };
389 
390 #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:439
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:593
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
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
virtual bool getFA32(UT_ValArray< fpreal32 > &a, GT_Offset offset) const
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:651
virtual bool computeMinMax(fpreal64 *min, fpreal64 *max) const
Definition: GT_DataArray.h:530
const GU_Detail * myGdp
virtual bool getIA16(UT_ValArray< int16 > &a, GT_Offset offset) const
GLdouble GLdouble z
Definition: glew.h:1559
signed char int8
Definition: SYS_Types.h:35
virtual bool getIA64(UT_ValArray< int64 > &a, GT_Offset offset) const
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
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
virtual GT_Size getTupleSize() const
A specialization of GA_AIFStringArray to access "shared strings".
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
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:567
virtual GT_Offset getStringIndex(GT_Offset offset, int idx=0) const =0
virtual bool getFA16(UT_ValArray< fpreal16 > &a, GT_Offset offset) const
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
virtual bool getIA32(UT_ValArray< int32 > &a, GT_Offset offset) const
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
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
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
virtual bool getFA64(UT_ValArray< fpreal64 > &a, GT_Offset offset) const
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
Generic Attribute Interface class to work with string indices directly, rather than string values...
GLintptr offset
Definition: glew.h:1682