HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GEO_MetaExpr.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: GEO library (C++)
7  *
8  * COMMENTS: Meta expressions used to construct the meta primitive
9  * blending tree. There are operator nodes & primitive nodes.
10  *
11  */
12 
13 #ifndef __GEO_MetaExpr_h__
14 #define __GEO_MetaExpr_h__
15 
16 #include "GEO_API.h"
17 
18 #include <UT/UT_Array.h>
19 #include <UT/UT_WorkBuffer.h>
20 #include <UT/UT_VectorTypes.h>
21 #include <TS/TS_Expression.h>
22 #include <GA/GA_Types.h>
23 
24 class UT_MemoryCounter;
25 class GA_Range;
26 class GEO_Detail;
27 class GEO_Primitive;
28 class GA_PrimitiveGroup;
29 class GA_ROAttributeRef;
30 class GA_AttributeRefMap;
31 class GA_WeightedSum;
32 
34 {
35 public:
37  : myExpr()
38  {}
39 
41  const GA_PrimitiveGroup *primgroup = NULL)
42  : myExpr()
43  { preCompute(gdp, primgroup); }
44 
46  const GA_Range &prim_range)
47  : myExpr()
48  { preCompute(gdp, prim_range); }
49 
51 
52  /// Compute memory usage (includes all shared memory)
53  int64 getMemoryUsage(bool inclusive) const;
54 
55  /// Count memory usage using a UT_MemoryCounter in order to count
56  /// shared memory correctly.
57  /// If inclusive is true, the size of this object is counted,
58  /// else only memory owned by this object is counted.
59  /// If this is pointed to by the calling object, inclusive should be true.
60  /// If this is contained in the calling object, inclusive should be false.
61  /// (Its memory was already counted in the size of the calling object.)
62  void countMemory(UT_MemoryCounter &counter, bool inclusive) const;
63 
65  const GA_PrimitiveGroup *prims=nullptr);
67  const GA_Range &prim_range);
68 
69  /// Create a TS metaball expression given the gdp
70  /// NOTE: ref() has not been called on the TS_MetaExpression returned.
71  static TS_MetaExpressionPtr getExpression(const GEO_Detail *gdp);
72 
73  /// Create a TS metaball expression given the gdp and primitive range
74  /// NOTE: ref() has not been called on the TS_MetaExpression returned.
75  static TS_MetaExpressionPtr getExpression(const GEO_Detail *gdp,
76  const GA_Range &prim_range,
78 
79  const TS_MetaExpressionPtr &getTSExpression() const { return myExpr; }
80 
81  // These assume that you've already done the preCompute!
82  void computeAttributes(const UT_Vector3 &pos,
84  const GA_AttributeRefMap &map) const;
85  void sumPointAttributes(const UT_Vector3 &pos,
86  GA_Offset resultptoff,
87  const GA_AttributeRefMap &map,
88  GA_WeightedSum &sum) const;
89 
90 
91  // Compute a single attribute. Unlike the two methods above, this
92  // routine normalizes the result to the sum of metaball weights.
93  void computeNormalizedAttributes(const UT_Vector3 &pos,
95  const GA_AttributeRefMap &map) const;
96  void computeAttribute(const UT_Vector3 &pos, float *data,
97  const GA_ROAttributeRef &ref,
98  int size) const;
99 
100  UT_Array<const GEO_Primitive *> &getList() { return myPrimitives; }
101  const UT_Array<const GEO_Primitive *> &getList() const { return myPrimitives; }
102 
103  /// @{
104  /// Serialize into an integer array. Nodes in the graph are stored as:
105  /// @code
106  /// id operator count primlist
107  /// @endcode
108  /// Where the id can be used to reference a sub-expression in other
109  /// expressions. The first id is based on the number of primitives in the
110  /// gdp.
111  /// For example: "sum(1, max(0, 1), 2)", in a gdp with 10 primitives
112  /// will be stored as: @code
113  /// [ TS_SERIALIZE_MAGIC 10 TS_OP_MAX 2 0 1 11 TS_SUM 3 1 10 2 ]
114  /// @endcode
115  static void serialize(const TS_MetaExpression *expr,
116  UT_Int32Array &opcodes,
117  exint nprimitives)
118  { return serializeT<int32>(expr, opcodes, nprimitives); }
119  static void serialize(const TS_MetaExpression *expr,
120  UT_Int64Array &opcodes,
121  exint nprimitives)
122  { return serializeT<int64>(expr, opcodes, nprimitives); }
123  /// @}
124  /// @{
125  /// Create an expression for the given serialization
126  static bool unserialize(UT_WorkBuffer &expr, const UT_Int32Array &opcodes)
127  {
128  return unserializeT<int32>(expr, opcodes.getRawArray(),
129  opcodes.entries());
130  }
131  static bool unserialize(UT_WorkBuffer &expr, const UT_Int64Array &opcodes)
132  {
133  return unserializeT<int64>(expr, opcodes.getRawArray(),
134  opcodes.entries());
135  }
136  static bool unserialize(UT_WorkBuffer &expr, const int32 *array, exint size)
137  { return unserializeT<int32>(expr, array, size); }
138  static bool unserialize(UT_WorkBuffer &expr, const int64 *array, exint size)
139  { return unserializeT<int64>(expr, array, size); }
140  /// @}
141 
142 private:
143  template <typename INT_T>
144  static void serializeT(const TS_MetaExpression *expr,
145  UT_ValArray<INT_T> &opcodes,
146  exint nprimitives);
147  template <typename INT_T>
148  static bool unserializeT(UT_WorkBuffer &expr,
149  const INT_T *opcodes,
150  exint entries);
151 
152 #ifdef INTEL_COMPILER
154 #endif
155 
156 private:
157  TS_MetaExpressionPtr myExpr;
158  UT_Array<const GEO_Primitive *> myPrimitives;
159 };
160 
161 #endif
const T * getRawArray() const
Definition: UT_Array.h:817
int int32
Definition: SYS_Types.h:39
static bool unserialize(UT_WorkBuffer &expr, const int64 *array, exint size)
Definition: GEO_MetaExpr.h:138
GEO_MetaExpression(const GEO_Detail *gdp, const GA_Range &prim_range)
Definition: GEO_MetaExpr.h:45
static bool unserialize(UT_WorkBuffer &expr, const UT_Int32Array &opcodes)
Definition: GEO_MetaExpr.h:126
int64 exint
Definition: SYS_Types.h:125
const UT_Array< const GEO_Primitive * > & getList() const
Definition: GEO_MetaExpr.h:101
Context to keep track of weighted sums.
**But if you need a result
Definition: thread.h:613
void preCompute(int order, EvalBuffer &ebuf, int span, fpreal t, const Knots &knots) const
When computing with knots, there need to be Order*2+1 knots for a span.
static void serialize(const TS_MetaExpression *expr, UT_Int64Array &opcodes, exint nprimitives)
Definition: GEO_MetaExpr.h:119
UT_Array< const GEO_Primitive * > & getList()
Definition: GEO_MetaExpr.h:100
A range of elements in an index-map.
Definition: GA_Range.h:42
GA_Size GA_Offset
Definition: GA_Types.h:641
GLint ref
Definition: glcorearb.h:124
static void serialize(const TS_MetaExpression *expr, UT_Int32Array &opcodes, exint nprimitives)
Definition: GEO_MetaExpr.h:115
This class provides a way to manage a reference to an attribute permitting Read-Only access...
GEO_MetaExpression(const GEO_Detail *gdp, const GA_PrimitiveGroup *primgroup=NULL)
Definition: GEO_MetaExpr.h:40
#define GEO_API
Definition: GEO_API.h:14
long long int64
Definition: SYS_Types.h:116
A handle to simplify manipulation of multiple attributes.
const TS_MetaExpressionPtr & getTSExpression() const
Definition: GEO_MetaExpr.h:79
static bool unserialize(UT_WorkBuffer &expr, const UT_Int64Array &opcodes)
Definition: GEO_MetaExpr.h:131
static bool unserialize(UT_WorkBuffer &expr, const int32 *array, exint size)
Definition: GEO_MetaExpr.h:136
exint entries() const
Alias of size(). size() is preferred.
Definition: UT_Array.h:648
GLsizeiptr size
Definition: glcorearb.h:664
Definition: format.h:895