HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 int32 *get(GT_Offset i, int32 *store, int sz) const
177  { return getTuple_t(i, store, sz); }
178  virtual const int64 *get(GT_Offset i, int64 *store, int sz) const
179  { return getTuple_t(i, store, sz); }
180  virtual const fpreal16 *get(GT_Offset i, fpreal16 *store, int z) const
181  { return GT_DataArray::get(i, store, z); }
182  virtual const fpreal64 *get(GT_Offset i, fpreal64 *store, int z) const
183  { return getTuple_t(i, store, z); }
184  virtual const fpreal32 *get(GT_Offset idx, fpreal32 *store, int z) const
185  {
186  if (z == 3 && myV3.isValid())
187  {
188  UT_Vector3 v = myV3.get(getDataOffset(idx));
189  store[0] = v.x();
190  store[1] = v.y();
191  store[2] = v.z();
192  return store;
193  }
194  if (myF.isValid())
195  {
196  GA_Offset o = getDataOffset(idx);
197  for (int i = 0; i < z; ++i)
198  store[i] = myF.get(o, i);
199  return store;
200  }
201  return getTuple_t(idx, store, z);
202  }
203 
204  /// @{
205  /// Optimized filling methods
206  virtual void doImport(GT_Offset idx, uint8 *data, GT_Size size) const;
207  virtual void doImport(GT_Offset idx, int32 *data, GT_Size size) const;
208  virtual void doImport(GT_Offset idx, int64 *data, GT_Size size) const;
209  virtual void doImport(GT_Offset idx, fpreal16 *data, GT_Size size) const;
210  virtual void doImport(GT_Offset idx, fpreal32 *data, GT_Size size) const;
211  virtual void doImport(GT_Offset idx, fpreal64 *data, GT_Size size) const;
212  virtual void doImportArray(GT_Offset idx, UT_ValArray<fpreal32> &data) const;
213  virtual void doImportArray(GT_Offset idx, UT_ValArray<int32> &data) const;
215  int tuple_size, int stride) const;
217  int tuple_size, int stride) const;
219  int tuple_size, int stride) const;
221  int tuple_size, int stride) const;
223  int tuple_size, int stride) const;
225  int tuple_size, int stride) const;
227  UT_BoundingBoxF &bbox, int tsize, int stride);
229  UT_BoundingBoxD &bbox, int tsize, int stride);
230  virtual void doFillQuantizedArray(uint8 *data,
232  int tuple_size, int stride,
233  fpreal black, fpreal white) const;
234  virtual void doExtendedQuantizedFill(uint8 *data,
236  int tuple_size, int nrepeats, int stride,
237  fpreal black, fpreal white) const;
238  /// @}
239 protected:
240  /// GT_GEOAutoNormalArray has no attribute yet when calling constructor.
242  const GT_GEOOffsetList &offsets,
243  GA_AttributeOwner offset_owner);
244 
245  void initAttribute(const GA_Attribute *attrib);
246  void makeInvalid();
247 
248  template <typename T> inline T
249  getValue_t(GT_Offset offset, int idx) const
250  {
251  GA_Offset si = getDataOffset(offset);
252  T val;
253 
254  if (myTuple && myTuple->get(myAttribute, si, val, idx))
255  return val;
256  return 0;
257  }
258 
259  template <typename T> inline const T *
260  getTuple_t(GT_Offset offset, T *store, int size) const
261  {
262  GA_Offset si = getDataOffset(offset);
263  if (myTuple && myTuple->get(myAttribute, si, store, size))
264  return store;
265  return NULL;
266  }
267 
268  template <typename T> inline bool
270  {
271  GA_Offset si = getDataOffset(offset);
272 
273  if (myNumericArray &&
274  myNumericArray->get(myAttribute, si, val))
275  return true;
276  return false;
277  }
278 
279 
281  {
282  if (myAttributeOwner == GA_ATTRIB_DETAIL)
283  return GA_Offset(0);
284 
285  GA_Offset gaoff = myOffsets(offset);
286  if (myOffsetOwner == GA_ATTRIB_VERTEX &&
287  myOffsetOwner != myAttributeOwner)
288  {
289  if (myAttributeOwner == GA_ATTRIB_POINT)
290  {
291  gaoff = myGdp->vertexPoint(gaoff);
292  }
293  else
294  {
295  UT_ASSERT(myAttributeOwner ==
297  gaoff = myGdp->vertexPrimitive(gaoff);
298  }
299  }
300  return gaoff;
301  }
302 
303  GT_Type mapTypeInfo(GA_TypeInfo type, int tsize) const;
304 
306  const GU_Detail *myGdp;
314  GA_AttributeOwner myOffsetOwner; // What type of offsets
323 };
324 
325 /// This class is specific to managing a detached, auto-generated
326 /// normal attribute, when no point, vertex, attrib_owner, or offset_owner
327 /// normals are present on the original detail.
329 {
330 public:
332  const GU_ConstDetailHandle &gdp,
333  GA_AttributeOwner attrib_owner,
334  const GT_GEOOffsetList &offsets,
335  GA_AttributeOwner offset_owner,
336  float cusp_angle);
337 
338  virtual ~GT_GEOAutoNormalArray();
339 
340  virtual int64 getMemoryUsage() const
341  { return sizeof(*this); }
342 
343 
344  virtual void updateGeoDetail(
345  const GU_ConstDetailHandle &dtl,
346  const char *name,
347  GT_Owner attrib_scope,
348  const int expected_size);
349 private:
350  void createAttribute();
351 
352  int64 myPDataId;
353  int64 myTopologyDataId;
354  int64 myPrimitiveListDataId;
355  const float myCuspAngle;
356  const GA_AttributeOwner myAttribOwner;
357 };
358 
359 #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:367
Definition of a geometry attribute.
Definition: GA_Attribute.h:189
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:417
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:108
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:31
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:581
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:475
GLsizeiptr size
Definition: glcorearb.h:663
const GU_Detail * myGdp
GLuint GLsizei const GLuint const GLintptr * offsets
Definition: glcorearb.h:2620
GA_Size GA_Offset
Definition: GA_Types.h:617
SYS_FORCE_INLINE T & z(void)
Definition: UT_Vector3.h:585
long long int64
Definition: SYS_Types.h:100
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
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:102
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:185
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:397
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:28
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:72
bool getArrayValue_t(UT_ValArray< T > &val, GT_Offset offset) const
GT_GEOOffsetList myOffsets
SYS_FORCE_INLINE T & y(void)
Definition: UT_Vector3.h:583
GA_AttributeOwner
Definition: GA_Types.h:33
double fpreal
Definition: SYS_Types.h:263
unsigned char uint8
Definition: SYS_Types.h:25
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
virtual int64 getMemoryUsage() const
int64 GT_Offset
Definition: GT_Types.h:110
int64 GT_Size
Definition: GT_Types.h:109
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:184
Generic Attribute Interface class to work with string indices directly, rather than string values...
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:794