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  }
129  void updateGeoDetail(const GU_ConstDetailHandle &dtl,
130  const char *name,
131  GT_Owner attrib_scope,
132  const int expected_size) override;
133 
134  /// @}
135 
136  /// @{
137  /// Access methods defined on GT_DataArray
138  fpreal16 getF16(GT_Offset offset, int idx) const override
139  { return getValue_t<fpreal32>(offset, idx); }
140  fpreal32 getF32(GT_Offset offset, int idx) const override
141  { return getValue_t<fpreal32>(offset, idx); }
142  fpreal64 getF64(GT_Offset offset, int idx) const override
143  { return getValue_t<fpreal64>(offset, idx); }
144  uint8 getU8(GT_Offset offset, int idx) const override
145  { return getValue_t<int32>(offset, idx); }
146  int32 getI32(GT_Offset offset, int idx) const override
147  { return getValue_t<int32>(offset, idx); }
148  int64 getI64(GT_Offset offset, int idx) const override
149  { return getValue_t<int64>(offset, idx); }
150  GT_String getS(GT_Offset offset, int idx) const override
151  {
152  if (mySTuple)
153  {
154  GA_Offset si = getDataOffset(offset);
155  return mySTuple->getString(myAttribute, si,idx);
156  }
158  }
160  GT_Offset offset) const override
161  {
162  if (mySSArray)
163  {
164  GA_Offset si = getDataOffset(offset);
165  mySSArray->getString(myAttribute, si, a);
166  return true;
167  }
168  return false;
169  }
170  GT_Size getStringIndexCount() const override;
172  int idx=0) const override;
174  UT_IntArray &) const override;
175 
177  GT_Offset start, GT_Size length) const override;
178 
180  GT_Offset offset) const override
181  { return getArrayValue_t<fpreal16>(a,offset); }
183  GT_Offset offset) const override
184  { return getArrayValue_t<fpreal32>(a,offset); }
186  GT_Offset offset) const override
187  { return getArrayValue_t<fpreal64>(a,offset); }
189  GT_Offset offset) const override
190  { return getArrayValue_t<uint8>(a,offset); }
192  GT_Offset offset) const override
193  { return getArrayValue_t<int8>(a,offset); }
195  GT_Offset offset) const override
196  { return getArrayValue_t<int16>(a,offset); }
198  GT_Offset offset) const override
199  { return getArrayValue_t<int32>(a,offset); }
201  GT_Offset offset) const override
202  { return getArrayValue_t<int64>(a,offset); }
203  /// @}
204 
205  const uint8 *get(GT_Offset i, uint8 *store, int sz) const override
206  { return GT_DataArray::get(i, store, sz); }
207  const int8 *get(GT_Offset i, int8 *store, int sz) const override
208  { return GT_DataArray::get(i, store, sz); }
209  const int16 *get(GT_Offset i, int16 *store, int sz) const override
210  { return GT_DataArray::get(i, store, sz); }
211  const int32 *get(GT_Offset i, int32 *store, int sz) const override
212  { return getTuple_t(i, store, sz); }
213  const int64 *get(GT_Offset i, int64 *store, int sz) const override
214  { return getTuple_t(i, store, sz); }
215  const fpreal16 *get(GT_Offset i, fpreal16 *store, int z) const override
216  { return GT_DataArray::get(i, store, z); }
217  const fpreal64 *get(GT_Offset i, fpreal64 *store, int z) const override
218  { return getTuple_t(i, store, z); }
219  const fpreal32 *get(GT_Offset idx, fpreal32 *store, int z) const override
220  {
221  if (z == 3 && myV3.isValid())
222  {
223  UT_Vector3 v = myV3.get(getDataOffset(idx));
224  store[0] = v.x();
225  store[1] = v.y();
226  store[2] = v.z();
227  return store;
228  }
229  if (myF.isValid())
230  {
231  GA_Offset o = getDataOffset(idx);
232  for (int i = 0; i < z; ++i)
233  store[i] = myF.get(o, i);
234  return store;
235  }
236  return getTuple_t(idx, store, z);
237  }
238 
239  /// Enlarge a bounding box with values
240  bool computeMinMax(fpreal64 *min, fpreal64 *max) const override;
241 
242  /// @{
243  /// Optimized filling methods
244  void doImport(GT_Offset idx, uint8 *data, GT_Size size) const override;
245  void doImport(GT_Offset idx, int8 *data, GT_Size size) const override;
246  void doImport(GT_Offset idx, int16 *data, GT_Size size) const override;
247  void doImport(GT_Offset idx, int32 *data, GT_Size size) const override;
248  void doImport(GT_Offset idx, int64 *data, GT_Size size) const override;
249  void doImport(GT_Offset idx, fpreal16 *data, GT_Size size) const override;
250  void doImport(GT_Offset idx, fpreal32 *data, GT_Size size) const override;
251  void doImport(GT_Offset idx, fpreal64 *data, GT_Size size) const override;
252  void doImportArray(
253  GT_Offset idx, UT_ValArray<fpreal16> &data) const override;
254  void doImportArray(
255  GT_Offset idx, UT_ValArray<fpreal32> &data) const override;
256  void doImportArray(
257  GT_Offset idx, UT_ValArray<fpreal64> &data) const override;
258  void doImportArray(GT_Offset idx, UT_ValArray<uint8> &data) const override;
259  void doImportArray(GT_Offset idx, UT_ValArray<int8> &data) const override;
260  void doImportArray(GT_Offset idx, UT_ValArray<int16> &data) const override;
261  void doImportArray(GT_Offset idx, UT_ValArray<int32> &data) const override;
262  void doImportArray(GT_Offset idx, UT_ValArray<int64> &data) const override;
264  int tuple_size, int stride) const override;
266  int tuple_size, int stride) const override;
268  int tuple_size, int stride) const override;
270  int tuple_size, int stride) const override;
272  int tuple_size, int stride) const override;
274  int tuple_size, int stride) const override;
276  int tuple_size, int stride) const override;
278  int tuple_size, int stride) const override;
281  UT_BoundingBoxF &bbox, int tsize, int stride) override;
284  UT_BoundingBoxD &bbox, int tsize, int stride) override;
287  int tuple_size, int stride,
288  fpreal black, fpreal white) const override;
291  int tuple_size, int nrepeats, int stride,
292  fpreal black, fpreal white) const override;
294  GT_Offset start, GT_Size length) const override;
296  GT_Offset start, GT_Size length) const override;
298  GT_Offset start, GT_Size length) const override;
300  GT_Offset start, GT_Size length) const override;
302  GT_Offset start, GT_Size length) const override;
304  GT_Offset start, GT_Size length) const override;
306  GT_Offset start, GT_Size length) const override;
308  GT_Offset start, GT_Size length) const override;
309  /// @}
310 
311  /// @private - This method relies on knowledge of the internal
312  /// implementation. It's only public for threading efficiency.
313  GA_Offset getDataOffset(GT_Offset offset) const
314  {
315  if (myAttributeOwner == GA_ATTRIB_DETAIL)
316  return GA_Offset(0);
317 
318  GA_Offset gaoff = myOffsets(offset);
319  if (myOffsetOwner == GA_ATTRIB_VERTEX &&
320  myOffsetOwner != myAttributeOwner)
321  {
322  if (myAttributeOwner == GA_ATTRIB_POINT)
323  {
324  gaoff = myGdp->vertexPoint(gaoff);
325  }
326  else
327  {
328  UT_ASSERT(myAttributeOwner ==
330  gaoff = myGdp->vertexPrimitive(gaoff);
331  }
332  }
333  return gaoff;
334  }
335 
336 protected:
337  /// GT_GEOAutoNormalArray has no attribute yet when calling constructor.
339  const GT_GEOOffsetList &offsets,
340  GA_AttributeOwner offset_owner);
341 
342  void initAttribute(const GA_Attribute *attrib);
343  void makeInvalid();
344 
345  template <typename T> inline T
346  getValue_t(GT_Offset offset, int idx) const
347  {
348  GA_Offset si = getDataOffset(offset);
349  T val;
350 
351  if (myTuple && myTuple->get(myAttribute, si, val, idx))
352  return val;
353  return 0;
354  }
355 
356  template <typename T> inline const T *
357  getTuple_t(GT_Offset offset, T *store, int size) const
358  {
359  GA_Offset si = getDataOffset(offset);
360  if (myTuple && myTuple->get(myAttribute, si, store, size))
361  return store;
362  return NULL;
363  }
364 
365  template <typename T> inline bool
367  {
368  GA_Offset si = getDataOffset(offset);
369 
370  if (myNumericArray &&
371  myNumericArray->get(myAttribute, si, val))
372  return true;
373  return false;
374  }
375 
376 
377  GT_Type mapTypeInfo(GA_TypeInfo type, int tsize) const;
378 
380  const GU_Detail *myGdp;
388  GA_AttributeOwner myOffsetOwner; // What type of offsets
399 };
400 
401 /// This class is specific to managing a detached, auto-generated
402 /// normal attribute, when no point, vertex, attrib_owner, or offset_owner
403 /// normals are present on the original detail.
405 {
406 public:
408  const GU_ConstDetailHandle &gdp,
409  GA_AttributeOwner attrib_owner,
410  const GT_GEOOffsetList &offsets,
411  GA_AttributeOwner offset_owner,
412  float cusp_angle);
413 
414  int64 getMemoryUsage() const override
415  { return sizeof(*this); }
416 
417 
418  void updateGeoDetail(
419  const GU_ConstDetailHandle &dtl,
420  const char *name,
421  GT_Owner attrib_scope,
422  const int expected_size) override;
423 private:
424  void createAttribute();
425 
426  int64 myPDataId;
427  int64 myTopologyDataId;
428  int64 myPrimitiveListDataId;
429  const float myCuspAngle;
430  const GA_AttributeOwner myAttribOwner;
431 
432  GA_ATINumericUPtr myAttributeHolder;
433 };
434 
435 #endif
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:532
Definition of a geometry attribute.
Definition: GA_Attribute.h:197
Data has no numeric representation.
Definition: GA_Types.h:102
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:712
Generic Attribute Interface class to access an attribute as a array.
int int32
Definition: SYS_Types.h:39
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:198
const GA_AIFTuple * myTuple
GT_Storage getStorage() const override
int64 getMemoryUsage() const override
GLuint start
Definition: glcorearb.h:475
GA_AttributeOwner myAttributeOwner
int64 getI64(GT_Offset offset, int idx) const override
GLuint GLsizei const GLuint const GLintptr * offsets
Definition: glcorearb.h:2621
virtual void doImport(GT_Offset idx, uint8 *data, GT_Size size) const
#define GT_API
Definition: GT_API.h:11
constexpr SYS_FORCE_INLINE T & z() noexcept
Definition: UT_Vector3.h:657
GT_Type
Definition: GT_Types.h:34
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
GLuint const GLchar * name
Definition: glcorearb.h:786
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:770
virtual bool computeMinMax(fpreal64 *min, fpreal64 *max) const
Definition: GT_DataArray.h:623
const GU_Detail * myGdp
GLsizeiptr size
Definition: glcorearb.h:664
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:640
GU_ConstDetailHandle myGdh
bool hasArrayEntries() const override
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.
const GLdouble * v
Definition: glcorearb.h:837
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
A specialization of GA_AIFStringArray to access "shared strings".
bool getIA32(UT_ValArray< int32 > &a, GT_Offset offset) const override
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:848
int64 GT_Offset
Definition: GT_Types.h:124
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:662
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:99
const char * className() const override
GT_Owner
Definition: GT_Types.h:86
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:123
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:795
GLuint GLfloat * val
Definition: glcorearb.h:1608
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".
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:110
const GA_AIFSharedStringTuple * mySSTuple
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
Definition: glcorearb.h:2621
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:153
GLintptr offset
Definition: glcorearb.h:665
GT_String getS(GT_Offset offset, int idx) const override
bool getSA(UT_StringArray &a, GT_Offset offset) const override
GLint GLenum GLboolean GLsizei stride
Definition: glcorearb.h:872
fpreal16 getF16(GT_Offset offset, int idx) const override
type
Definition: core.h:1059
constexpr SYS_FORCE_INLINE T & y() noexcept
Definition: UT_Vector3.h:655
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:687
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
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:653