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  mySSArray;
122  }
123  virtual void updateGeoDetail(const GU_ConstDetailHandle &dtl,
124  const char *name,
125  GT_Owner attrib_scope,
126  const int expected_size);
127 
128  /// @}
129 
130  /// @{
131  /// Access methods defined on GT_DataArray
132  virtual fpreal16 getF16(GT_Offset offset, int idx) const
133  { return getValue_t<fpreal32>(offset, idx); }
134  virtual fpreal32 getF32(GT_Offset offset, int idx) const
135  { return getValue_t<fpreal32>(offset, idx); }
136  virtual fpreal64 getF64(GT_Offset offset, int idx) const
137  { return getValue_t<fpreal64>(offset, idx); }
138  virtual uint8 getU8(GT_Offset offset, int idx) const
139  { return getValue_t<int32>(offset, idx); }
140  virtual int32 getI32(GT_Offset offset, int idx) const
141  { return getValue_t<int32>(offset, idx); }
142  virtual int64 getI64(GT_Offset offset, int idx) const
143  { return getValue_t<int64>(offset, idx); }
144  virtual GT_String getS(GT_Offset offset, int idx) const
145  {
146  if (mySTuple)
147  {
148  GA_Offset si = getDataOffset(offset);
149  return mySTuple->getString(myAttribute, si,idx);
150  }
151  return NULL;
152  }
153  virtual bool getSA(UT_StringArray &a, GT_Offset offset) const
154  {
155  if (mySSArray)
156  {
157  GA_Offset si = getDataOffset(offset);
158  mySSArray->getString(myAttribute, si, a);
159  return true;
160  }
161  return false;
162  }
163  virtual GT_Size getStringIndexCount() const;
164  virtual GT_Offset getStringIndex(GT_Offset offset, int idx=0) const;
165  virtual void getIndexedStrings(UT_StringArray &,
166  UT_IntArray &) const;
167 
169  { return getArrayValue_t<fpreal32>(a,offset); }
171  { return getArrayValue_t<int32>(a,offset); }
172  /// @}
173 
174  virtual const uint8 *get(GT_Offset i, uint8 *store, int sz) const
175  { return GT_DataArray::get(i, store, sz); }
176  virtual const int8 *get(GT_Offset i, int8 *store, int sz) const
177  { return GT_DataArray::get(i, store, sz); }
178  virtual const int16 *get(GT_Offset i, int16 *store, int sz) const
179  { return GT_DataArray::get(i, store, sz); }
180  virtual const int32 *get(GT_Offset i, int32 *store, int sz) const
181  { return getTuple_t(i, store, sz); }
182  virtual const int64 *get(GT_Offset i, int64 *store, int sz) const
183  { return getTuple_t(i, store, sz); }
184  virtual const fpreal16 *get(GT_Offset i, fpreal16 *store, int z) const
185  { return GT_DataArray::get(i, store, z); }
186  virtual const fpreal64 *get(GT_Offset i, fpreal64 *store, int z) const
187  { return getTuple_t(i, store, z); }
188  virtual const fpreal32 *get(GT_Offset idx, fpreal32 *store, int z) const
189  {
190  if (z == 3 && myV3.isValid())
191  {
192  UT_Vector3 v = myV3.get(getDataOffset(idx));
193  store[0] = v.x();
194  store[1] = v.y();
195  store[2] = v.z();
196  return store;
197  }
198  if (myF.isValid())
199  {
200  GA_Offset o = getDataOffset(idx);
201  for (int i = 0; i < z; ++i)
202  store[i] = myF.get(o, i);
203  return store;
204  }
205  return getTuple_t(idx, store, z);
206  }
207 
208  /// @{
209  /// Optimized filling methods
210  virtual void doImport(GT_Offset idx, uint8 *data, GT_Size size) const;
211  virtual void doImport(GT_Offset idx, int8 *data, GT_Size size) const;
212  virtual void doImport(GT_Offset idx, int16 *data, GT_Size size) const;
213  virtual void doImport(GT_Offset idx, int32 *data, GT_Size size) const;
214  virtual void doImport(GT_Offset idx, int64 *data, GT_Size size) const;
215  virtual void doImport(GT_Offset idx, fpreal16 *data, GT_Size size) const;
216  virtual void doImport(GT_Offset idx, fpreal32 *data, GT_Size size) const;
217  virtual void doImport(GT_Offset idx, fpreal64 *data, GT_Size size) const;
218  virtual void doImportArray(GT_Offset idx, UT_ValArray<fpreal32> &data) const;
219  virtual void doImportArray(GT_Offset idx, UT_ValArray<int32> &data) const;
221  int tuple_size, int stride) const;
223  int tuple_size, int stride) const;
225  int tuple_size, int stride) const;
227  int tuple_size, int stride) const;
229  int tuple_size, int stride) const;
231  int tuple_size, int stride) const;
233  int tuple_size, int stride) const;
235  int tuple_size, int stride) const;
237  UT_BoundingBoxF &bbox, int tsize, int stride);
239  UT_BoundingBoxD &bbox, int tsize, int stride);
240  virtual void doFillQuantizedArray(uint8 *data,
242  int tuple_size, int stride,
243  fpreal black, fpreal white) const;
244  virtual void doExtendedQuantizedFill(uint8 *data,
246  int tuple_size, int nrepeats, int stride,
247  fpreal black, fpreal white) const;
248  /// @}
249 protected:
250  /// GT_GEOAutoNormalArray has no attribute yet when calling constructor.
252  const GT_GEOOffsetList &offsets,
253  GA_AttributeOwner offset_owner);
254 
255  void initAttribute(const GA_Attribute *attrib);
256  void makeInvalid();
257 
258  template <typename T> inline T
259  getValue_t(GT_Offset offset, int idx) const
260  {
261  GA_Offset si = getDataOffset(offset);
262  T val;
263 
264  if (myTuple && myTuple->get(myAttribute, si, val, idx))
265  return val;
266  return 0;
267  }
268 
269  template <typename T> inline const T *
270  getTuple_t(GT_Offset offset, T *store, int size) const
271  {
272  GA_Offset si = getDataOffset(offset);
273  if (myTuple && myTuple->get(myAttribute, si, store, size))
274  return store;
275  return NULL;
276  }
277 
278  template <typename T> inline bool
280  {
281  GA_Offset si = getDataOffset(offset);
282 
283  if (myNumericArray &&
284  myNumericArray->get(myAttribute, si, val))
285  return true;
286  return false;
287  }
288 
289 
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  GT_Type mapTypeInfo(GA_TypeInfo type, int tsize) const;
314 
316  const GU_Detail *myGdp;
324  GA_AttributeOwner myOffsetOwner; // What type of offsets
333 };
334 
335 /// This class is specific to managing a detached, auto-generated
336 /// normal attribute, when no point, vertex, attrib_owner, or offset_owner
337 /// normals are present on the original detail.
339 {
340 public:
342  const GU_ConstDetailHandle &gdp,
343  GA_AttributeOwner attrib_owner,
344  const GT_GEOOffsetList &offsets,
345  GA_AttributeOwner offset_owner,
346  float cusp_angle);
347 
348  virtual ~GT_GEOAutoNormalArray();
349 
350  virtual int64 getMemoryUsage() const
351  { return sizeof(*this); }
352 
353 
354  virtual void updateGeoDetail(
355  const GU_ConstDetailHandle &dtl,
356  const char *name,
357  GT_Owner attrib_scope,
358  const int expected_size);
359 private:
360  void createAttribute();
361 
362  int64 myPDataId;
363  int64 myTopologyDataId;
364  int64 myPrimitiveListDataId;
365  const float myCuspAngle;
366  const GA_AttributeOwner myAttribOwner;
367 };
368 
369 #endif
GT_Storage
Definition: GT_Types.h:17
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:397
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:455
virtual const char * className() const
Generic Attribute Interface class to access an attribute as a array.
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
const GLdouble * v
Definition: glcorearb.h:836
GLuint start
Definition: glcorearb.h:474
const char * GT_String
Definition: GT_Types.h:111
GA_AttributeOwner myAttributeOwner
virtual bool getFA32(UT_ValArray< fpreal32 > &a, GT_Offset offset) const
virtual void doImport(GT_Offset idx, uint8 *data, GT_Size size) const
virtual GT_String getS(GT_Offset offset, int idx) const
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:847
virtual bool isValid() const
virtual GT_Type getTypeInfo() const
#define GT_API
Definition: GT_API.h:11
GT_Type
Definition: GT_Types.h:33
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
virtual uint8 getU8(GT_Offset offset, int idx) const
SYS_FORCE_INLINE T & x(void)
Definition: UT_Vector3.h:498
virtual fpreal64 getF64(GT_Offset offset, int idx) const
GA_Offset getDataOffset(GT_Offset offset) const
const GA_AIFSharedStringArray * mySSArray
png_uint_32 i
Definition: png.h:2877
virtual void doFillVec3BBox(fpreal32 *dest, GT_Offset start, GT_Size length, UT_BoundingBoxF &bbox, int, int stride)
Definition: GT_DataArray.h:513
GLsizeiptr size
Definition: glcorearb.h:663
const GU_Detail * myGdp
GLuint GLsizei const GLuint const GLintptr * offsets
Definition: glcorearb.h:2620
signed char int8
Definition: SYS_Types.h:31
GA_Size GA_Offset
Definition: GA_Types.h:617
SYS_FORCE_INLINE T & z(void)
Definition: UT_Vector3.h:502
long long int64
Definition: SYS_Types.h:107
GU_ConstDetailHandle myGdh
Abstract data class for an array of float, int or string data.
Definition: GT_DataArray.h:38
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
virtual GT_Size entries() const
A GT Data Array to extract values from a point/primitive attribute.
double fpreal64
Definition: SYS_Types.h:192
GLint GLenum GLboolean GLsizei stride
Definition: glcorearb.h:871
virtual GT_Size getTupleSize() const
GLintptr offset
Definition: glcorearb.h:664
A specialization of GA_AIFStringArray to access "shared strings".
virtual fpreal16 getF16(GT_Offset offset, int idx) const
virtual bool getSA(UT_StringArray &a, GT_Offset offset) const
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:429
virtual void doImportArray(GT_Offset idx, UT_ValArray< fpreal32 > &data) const
GLboolean * data
Definition: glcorearb.h:130
GLuint const GLchar * name
Definition: glcorearb.h:785
virtual GT_Offset getStringIndex(GT_Offset offset, int idx=0) const =0
int int32
Definition: SYS_Types.h:35
virtual void updateGeoDetail(const GU_ConstDetailHandle &dtl, const char *name, GT_Owner attrib_scope, const int expected_size)
virtual bool getIA32(UT_ValArray< int32 > &a, GT_Offset offset) const
GA_TypeInfo
Definition: GA_Types.h:80
GT_Owner
Definition: GT_Types.h:75
bool getArrayValue_t(UT_ValArray< T > &val, GT_Offset offset) const
GT_GEOOffsetList myOffsets
SYS_FORCE_INLINE T & y(void)
Definition: UT_Vector3.h:500
GA_AttributeOwner
Definition: GA_Types.h:33
double fpreal
Definition: SYS_Types.h:270
unsigned char uint8
Definition: SYS_Types.h:32
Data represents a normal vector. Token "normal".
Definition: GA_Types.h:93
GA_AttributeOwner myOffsetOwner
virtual GT_Storage getStorage() const
A specialization of GA_AIFStringTuple to access "shared strings".
GLuint GLfloat * val
Definition: glcorearb.h:1607
Data represents a direction vector. Token "vector".
Definition: GA_Types.h:91
const GA_AIFSharedStringTuple * mySSTuple
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
Data represents a position in space. Token "point".
Definition: GA_Types.h:85
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:126
virtual int64 getMemoryUsage() const
int64 GT_Offset
Definition: GT_Types.h:113
int64 GT_Size
Definition: GT_Types.h:112
short int16
Definition: SYS_Types.h:33
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:191
Generic Attribute Interface class to work with string indices directly, rather than string values...
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:794