HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_FloatTupleAdapter.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: GA_FloatTupleAdapter.h ( GA Library, C++)
7  *
8  * COMMENTS: A simple class that adapts GA_AttributeRefMap interfaces to
9  * produce float tuples. This class can be used in
10  * combination with functions like GEO_TPSurf::evaluateMesh()
11  * to produce float tuples even when the interface requires a
12  * GA_AttributeRefMap and produces results in vertices or
13  * points.
14  */
15 
16 #ifndef __GA_FloatTupleAdapter__
17 #define __GA_FloatTupleAdapter__
18 
19 #include <UT/UT_UniquePtr.h>
20 #include <UT/UT_StackBuffer.h>
21 #include "GA_AttributeRefMap.h"
22 #include "GA_Detail.h"
23 
25 {
26 public:
27  /// Create a float tuple adapter for a given attribute. The attribute
28  /// should be a float tuple. This operation will allocate temporary
29  /// storage for `size` results.
31  : myDest(attr->getDetail().cloneEmptyDetail(false))
32  , myDAttr(myDest->getAttributes().cloneAttribute(
33  attr->getOwner(),
34  attr->getName(),
35  *attr, true))
36  , myList(*myDest, &attr->getDetail())
37  , myResults(size)
38  , mySize(size)
39  {
40  myList.append(myDAttr, attr);
41  for (int i = 0; i < size; i++)
42  myResults[i] = myList.getTempVertex(myList.appendTempVertex());
43  }
44 
45  GA_AttributeRefMap &getList() { return myList; }
46  GA_Offset *getResults() { return myResults; }
47 
48  /// Extract results to a float array. The float array has stride
49  /// specified by `asize`.
50  void extractToFloats(float *data, int asize)
51  {
52  GA_ROHandleF handle(myDAttr);
53  for (int i = 0; i < mySize; i++)
54  {
55  if (myDAttr->getOwner() == GA_ATTRIB_POINT)
56  handle.getV(myDest->vertexPoint(myResults[i]), data, asize);
57  else
58  handle.getV(myResults[i], data, asize);
59  data += asize;
60  }
61  }
62 
63  /// Extract to a templated type, which must have value_type of float
64  template <typename T>
65  void extract(T *data)
66  {
67  extractToFloats(data, sizeof(T)/sizeof(float));
68  }
69 
70 private:
72  GA_Attribute *myDAttr;
73  GA_AttributeRefMap myList;
74  UT_StackBuffer<GA_Offset> myResults;
75  int mySize;
76 };
77 
78 #endif
Definition of a geometry attribute.
Definition: GA_Attribute.h:198
GLboolean * data
Definition: glcorearb.h:131
void extractToFloats(float *data, int asize)
GA_FloatTupleAdapter(const GA_Attribute *attr, int size)
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
GA_Size GA_Offset
Definition: GA_Types.h:646
PXL_API const char * getName(const ColorSpace *space)
Return the name of the color space.
GA_AttributeRefMap & getList()
A handle to simplify manipulation of multiple attributes.
GLsizeiptr size
Definition: glcorearb.h:664
void extract(T *data)
Extract to a templated type, which must have value_type of float.
SYS_FORCE_INLINE GA_AttributeOwner getOwner() const
Definition: GA_Attribute.h:210
Definition: format.h:895