HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OP_Utils.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: OP Library (C++)
7  *
8  * COMMENTS: Some utility functions for operators.
9  *
10  */
11 
12 #ifndef __OP_Utils_h__
13 #define __OP_Utils_h__
14 
15 #include "OP_API.h"
16 #include "OP_Node.h"
17 #include <UT/UT_Matrix2.h>
18 #include <UT/UT_Matrix3.h>
19 #include <UT/UT_Matrix4.h>
20 #include <UT/UT_Ramp.h>
21 #include <UT/UT_Vector2.h>
22 #include <UT/UT_Vector3.h>
23 #include <UT/UT_Vector4.h>
24 
25 class OP_NetworkBoxItem;
26 class UT_BitArray;
27 class UT_WorkBuffer;
28 class UT_StringArray;
29 
31  const UT_StringArray &badrefs);
33  bool checktoplevelnode,
34  UT_WorkBuffer &err);
36  bool checktoplevelnode,
37  UT_WorkBuffer &err);
38 
39 /// Looks for any nodes inside the specified operator that are defined by
40 /// VOP Networks outside the provided node. REtrns true if no such nodes
41 /// are found. Otherwise it puts an error message in the err buffer and
42 /// returns false.
44  UT_WorkBuffer &err);
46  UT_String &vopnetmask);
47 
48 /// @{ Functions for testing whether a node parameter is used as a shader
49 /// parameter, when the node represents a shader. Some node parameters may
50 /// belong to only certain contexts (eg, surface shader), while other ones
51 /// may be just true spare parameters that are not shader parameters at all.
53 OP_API bool OPisStandInShaderParm(const PRM_Template &parm);
55  const char *context_name);
56 OP_API bool OPisLegacyShaderParm(const PRM_Template &parm, OP_Node *owner);
57 OP_API bool OPhasShaderContextTag(const PRM_Template *list,
58  int start = 0, int end = -1);
59 /// @}
60 
61 OP_API OP_Node *OPfindOpInput(OP_Node *op, const char *find_op_type,
62  bool include_me = true);
63 OP_API OP_Node *OPfindOpInput(OP_Node *op, const char **find_op_types,
64  bool include_me = true);
65 
66 /// Returns coordinates specifying the smallest possible bounding box
67 /// around the items in 'items'. Takes each item's height and width into
68 /// consideration.
69 OP_API void OPgetItemBounds(fpreal &x1, fpreal &y1, fpreal &x2, fpreal &y2,
70  const OP_NetworkBoxItemList &items);
71 
72 /// Looks for any VOP Networks inside the specified node which define operator
73 /// types that are instantiated outside the node. If it returns false, the
74 /// badvopnets array will be filled with the VOP Networks that are used
75 /// outside the root node.
77  OP_NodeList *badvopnets);
78 
79 /// Creates a sticky note about the lack of vops inside synced HDAs, since the
80 /// children have been removed because the subnet is using cached code.
82 
83 /// Given a set of unique nodes, compute a topological ordering using only the
84 /// connectivity amongst the given nodes. If the roots are not known, then it
85 /// will be internally computed using OPmarkNodeRoots(only_picked=false).
86 /// Otherwise, the nodes will only be sorted by traversing from the given root
87 /// nodes.
89  UT_IntArray &order,
90  const OP_NodeList &nodes,
91  const UT_BitArray *roots = nullptr);
92 
93 /// Given a set of nodes return a bit array indicating the nodes which are
94 /// roots WITHIN THE SET. If assume_picked is true, then it's assumed that the
95 /// node is in the set if and only if it's in the set.
97  UT_BitArray &roots,
98  const OP_NodeList &nodes,
99  bool assume_picked);
100 
101 namespace OP_Utils
102 {
103  // Boiler plate to load individual types from op.
104  static inline void evalOpParm(
105  int64 &v, const OP_Node *node, const char *parmname, fpreal time,
106  DEP_MicroNode *depnode)
107  { v = node->evalInt(parmname, 0, time);
108  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParm(parmname).microNode(0));
109  }
110  static inline void evalOpParm(
111  bool &v, const OP_Node *node, const char *parmname, fpreal time,
112  DEP_MicroNode *depnode)
113  { v = node->evalInt(parmname, 0, time);
114  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParm(parmname).microNode(0));
115  }
116  static inline void evalOpParm(
117  fpreal64 &v, const OP_Node *node, const char *parmname, fpreal time,
118  DEP_MicroNode *depnode)
119  { v = node->evalFloat(parmname, 0, time);
120  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParm(parmname).microNode(0));
121  }
122  static inline void evalOpParm(
123  UT_Vector2D &v, const OP_Node *node, const char *parmname, fpreal time,
124  DEP_MicroNode *depnode)
125  { v.x() = node->evalFloat(parmname, 0, time);
126  v.y() = node->evalFloat(parmname, 1, time);
127  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParm(parmname).microNode(0));
128  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParm(parmname).microNode(1));
129  }
130  static inline void evalOpParm(
131  UT_Vector3D &v, const OP_Node *node, const char *parmname, fpreal time,
132  DEP_MicroNode *depnode)
133  { v.x() = node->evalFloat(parmname, 0, time);
134  v.y() = node->evalFloat(parmname, 1, time);
135  v.z() = node->evalFloat(parmname, 2, time);
136  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParm(parmname).microNode(0));
137  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParm(parmname).microNode(1));
138  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParm(parmname).microNode(2));
139  }
140  static inline void evalOpParm(
141  UT_Vector4D &v, const OP_Node *node, const char *parmname, fpreal time,
142  DEP_MicroNode *depnode)
143  { v.x() = node->evalFloat(parmname, 0, time);
144  v.y() = node->evalFloat(parmname, 1, time);
145  v.z() = node->evalFloat(parmname, 2, time);
146  v.w() = node->evalFloat(parmname, 3, time);
147  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParm(parmname).microNode(0));
148  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParm(parmname).microNode(1));
149  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParm(parmname).microNode(2));
150  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParm(parmname).microNode(3));
151  }
152 
153  static inline void evalOpParm(
154  UT_Matrix2D &v, const OP_Node *node, const char *parmname, fpreal time,
155  DEP_MicroNode *depnode)
156  { for (int r = 0; r < 2; r++)
157  {
158  for (int c = 0; c < 2; c++)
159  {
160  v(r, c) = node->evalFloat(parmname, r * 2 + c, time);
161  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParm(parmname).microNode(r * 2 + c));
162  }
163  }
164  }
165  static inline void evalOpParm(
166  UT_Matrix3D &v, const OP_Node *node, const char *parmname, fpreal time,
167  DEP_MicroNode *depnode)
168  { for (int r = 0; r < 3; r++)
169  {
170  for (int c = 0; c < 3; c++)
171  {
172  v(r, c) = node->evalFloat(parmname, r * 3 + c, time);
173  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParm(parmname).microNode(r * 3 + c));
174  }
175  }
176  }
177  static inline void evalOpParm(
178  UT_Matrix4D &v, const OP_Node *node, const char *parmname, fpreal time,
179  DEP_MicroNode *depnode)
180  { for (int r = 0; r < 4; r++)
181  {
182  for (int c = 0; c < 4; c++)
183  {
184  v(r, c) = node->evalFloat(parmname, r * 4 + c, time);
185  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParm(parmname).microNode(r * 4 + c));
186  }
187  }
188  }
189 
190  static void inline evalOpParm(
191  UT_Vector2I &v, const OP_Node *node, const char *parmname, fpreal time,
192  DEP_MicroNode *depnode)
193  { v.x() = node->evalInt(parmname, 0, time);
194  v.y() = node->evalInt(parmname, 1, time);
195  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParm(parmname).microNode(0));
196  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParm(parmname).microNode(1));
197  }
198  static void inline evalOpParm(
199  UT_Vector3I &v, const OP_Node *node, const char *parmname, fpreal time,
200  DEP_MicroNode *depnode)
201  { v.x() = node->evalInt(parmname, 0, time);
202  v.y() = node->evalInt(parmname, 1, time);
203  v.z() = node->evalInt(parmname, 2, time);
204  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParm(parmname).microNode(0));
205  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParm(parmname).microNode(1));
206  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParm(parmname).microNode(2));
207  }
208  static void inline evalOpParm(
209  UT_Vector4I &v, const OP_Node *node, const char *parmname, fpreal time,
210  DEP_MicroNode *depnode)
211  { v.x() = node->evalInt(parmname, 0, time);
212  v.y() = node->evalInt(parmname, 1, time);
213  v.z() = node->evalInt(parmname, 2, time);
214  v.w() = node->evalInt(parmname, 3, time);
215  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParm(parmname).microNode(0));
216  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParm(parmname).microNode(1));
217  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParm(parmname).microNode(2));
218  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParm(parmname).microNode(3));
219  }
220  static void inline evalOpParm(
221  UT_StringHolder &v, const OP_Node *node, const char *parmname, fpreal time,
222  DEP_MicroNode *depnode)
223  { UT_String result; node->evalString(result, parmname, 0, time); v = result;
224  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParm(parmname).microNode(0));
225  }
226  static void inline evalOpParm(
227  UT_SharedPtr<UT_Ramp> &v, const OP_Node *node, const char *parmname, fpreal time,
228  DEP_MicroNode *depnode)
229  {
230  v.reset(new UT_Ramp());
231 
232  if (node->hasParm(parmname))
233  node->updateRampFromMultiParm(time, node->getParm(parmname), *v, 0, depnode);
234  }
235  static void inline evalOpParm(
236  PRM_DataItemHandle &v, const OP_Node *node, const char *parmname, fpreal time,
237  DEP_MicroNode *depnode)
238  {
239  v = node->evalData(parmname, 0, time);
240  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParm(parmname).microNode(0));
241  }
242 
243 
244  static void inline evalOpParmInst(
245  int64 &v, const OP_Node *node, const char *parmname,
246  int *inst, fpreal time,
247  DEP_MicroNode *depnode)
248  {
249  v = node->evalIntInst(parmname, inst, 0, time);
250  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParmPtrInst(parmname, inst)->microNode(0));
251  }
252  static void inline evalOpParmInst(
253  bool &v, const OP_Node *node, const char *parmname,
254  int *inst, fpreal time,
255  DEP_MicroNode *depnode)
256  {
257  v = node->evalIntInst(parmname, inst, 0, time);
258  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParmPtrInst(parmname, inst)->microNode(0));
259  }
260  static void inline evalOpParmInst(
261  fpreal64 &v, const OP_Node *node, const char *parmname,
262  int *inst, fpreal time,
263  DEP_MicroNode *depnode)
264  {
265  v = node->evalFloatInst(parmname, inst, 0, time);
266  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParmPtrInst(parmname, inst)->microNode(0));
267  }
268  static void inline evalOpParmInst(
269  UT_Vector2D &v, const OP_Node *node, const char *parmname,
270  int *inst, fpreal time,
271  DEP_MicroNode *depnode)
272  {
273  v.x() = node->evalFloatInst(parmname, inst, 0, time);
274  v.y() = node->evalFloatInst(parmname, inst, 1, time);
275  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParmPtrInst(parmname, inst)->microNode(0));
276  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParmPtrInst(parmname, inst)->microNode(1));
277  }
278  static void inline evalOpParmInst(
279  UT_Vector3D &v, const OP_Node *node, const char *parmname,
280  int *inst, fpreal time,
281  DEP_MicroNode *depnode)
282  {
283  v.x() = node->evalFloatInst(parmname, inst, 0, time);
284  v.y() = node->evalFloatInst(parmname, inst, 1, time);
285  v.z() = node->evalFloatInst(parmname, inst, 2, time);
286  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParmPtrInst(parmname, inst)->microNode(0));
287  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParmPtrInst(parmname, inst)->microNode(1));
288  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParmPtrInst(parmname, inst)->microNode(2));
289  }
290  static void inline evalOpParmInst(
291  UT_Vector4D &v, const OP_Node *node, const char *parmname,
292  int *inst, fpreal time,
293  DEP_MicroNode *depnode)
294  {
295  v.x() = node->evalFloatInst(parmname, inst, 0, time);
296  v.y() = node->evalFloatInst(parmname, inst, 1, time);
297  v.z() = node->evalFloatInst(parmname, inst, 2, time);
298  v.w() = node->evalFloatInst(parmname, inst, 3, time);
299  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParmPtrInst(parmname, inst)->microNode(0));
300  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParmPtrInst(parmname, inst)->microNode(1));
301  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParmPtrInst(parmname, inst)->microNode(2));
302  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParmPtrInst(parmname, inst)->microNode(3));
303  }
304 
305  static void inline evalOpParmInst(
306  UT_Matrix2D &v, const OP_Node *node, const char *parmname,
307  int *inst, fpreal time,
308  DEP_MicroNode *depnode)
309  { for (int r = 0; r < 2; r++)
310  {
311  for (int c = 0; c < 2; c++)
312  {
313  v(r, c) = node->evalFloatInst(parmname, inst, r * 2 + c, time);
314  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParmPtrInst(parmname, inst)->microNode(r * 2 + c));
315  }
316  }
317  }
318  static void inline evalOpParmInst(
319  UT_Matrix3D &v, const OP_Node *node, const char *parmname,
320  int *inst, fpreal time,
321  DEP_MicroNode *depnode)
322  { for (int r = 0; r < 3; r++)
323  {
324  for (int c = 0; c < 3; c++)
325  {
326  v(r, c) = node->evalFloatInst(parmname, inst, r * 3 + c, time);
327  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParmPtrInst(parmname, inst)->microNode(r * 3 + c));
328  }
329  }
330  }
331  static void inline evalOpParmInst(
332  UT_Matrix4D &v, const OP_Node *node, const char *parmname,
333  int *inst, fpreal time,
334  DEP_MicroNode *depnode)
335  { for (int r = 0; r < 4; r++)
336  {
337  for (int c = 0; c < 4; c++)
338  {
339  v(r, c) = node->evalFloatInst(parmname, inst, r * 4 + c, time);
340  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParmPtrInst(parmname, inst)->microNode(r * 4 + c));
341  }
342  }
343  }
344 
345  static void inline evalOpParmInst(
346  UT_StringHolder &v, const OP_Node *node, const char *parmname,
347  int *inst, fpreal time,
348  DEP_MicroNode *depnode)
349  {
350  UT_String result; node->evalStringInst(parmname, inst, result, 0, time); v = result;
351  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParmPtrInst(parmname, inst)->microNode(0));
352  }
353  static void inline evalOpParmInst(
354  UT_SharedPtr<UT_Ramp> &v, const OP_Node *node, const char *parmname,
355  int *inst, fpreal time,
356  DEP_MicroNode *depnode)
357  {
358  v.reset(new UT_Ramp());
359 
360  const PRM_Parm *rampparm = node->getParmList()->getParmPtrInst(parmname, inst, /*nestlevel=*/1);
361  if (rampparm)
362  node->updateRampFromMultiParm(time, *rampparm, *v, 0, depnode);
363  }
364  static void inline evalOpParmInst(
365  PRM_DataItemHandle &v, const OP_Node *node, const char *parmname,
366  int *inst, fpreal time,
367  DEP_MicroNode *depnode)
368  {
369  v = node->evalDataInst(parmname, inst, 0, time);
370  if (depnode) depnode->addExplicitInput(SYSconst_cast(node)->getParmPtrInst(parmname, inst)->microNode(0));
371  }
372 }
373 
374 #endif
OP_API void OPmarkRootNodes(UT_BitArray &roots, const OP_NodeList &nodes, bool assume_picked)
T & z(void)
Definition: UT_Vector4.h:379
OP_API bool OPconvertOrWarnExternalReferences(OP_Node *node, bool checktoplevelnode, UT_WorkBuffer &err)
OP_API OP_Node * OPfindOpInput(OP_Node *op, const char *find_op_type, bool include_me=true)
GT_API const UT_StringHolder time
void addExplicitInput(DEP_MicroNode &inp, bool check_dup)
Methods for manipulating explicit edges.
const GLdouble * v
Definition: glcorearb.h:836
GLuint start
Definition: glcorearb.h:474
SYS_FORCE_INLINE T * SYSconst_cast(const T *foo)
Definition: SYS_Types.h:127
fpreal evalFloat(int pi, int vi, fpreal t) const
T & x(void)
Definition: UT_Vector2.h:285
SYS_FORCE_INLINE T & x(void)
Definition: UT_Vector3.h:498
OP_API bool OPconvertOrWarnExternalOverrides(OP_Node *node, bool checktoplevelnode, UT_WorkBuffer &err)
OP_API bool OPisStandInShaderParm(const PRM_Template &parm)
SYS_FORCE_INLINE T & z(void)
Definition: UT_Vector3.h:502
PRM_Parm & getParm(int i)
long long int64
Definition: SYS_Types.h:107
OP_API bool OPmatchesShaderContextTag(const PRM_Template &parm, const char *context_name)
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:28
void evalString(UT_String &val, int pi, int vi, fpreal t) const
OP_API void OPgetVopSubnetMask(OP_Node *node, UT_String &vopnetmask)
double fpreal64
Definition: SYS_Types.h:192
PRM_DataItemHandle evalDataInst(const UT_StringRef &name, const int *inst, int vi, fpreal t, int nestlevel=1) const
GLuint GLuint end
Definition: glcorearb.h:474
OP_API void OPtopologicalSort(UT_IntArray &order, const OP_NodeList &nodes, const UT_BitArray *roots=nullptr)
bool hasParm(const char *name) const
OP_API bool OPhasShaderContextTag(const PRM_Template *list, int start=0, int end=-1)
OP_API bool OPisPotentialShaderParm(const PRM_Template &parm)
fpreal evalFloatInst(const UT_StringRef &name, const int *inst, int vi, fpreal t, int nestlevel=1) const
T & y(void)
Definition: UT_Vector4.h:377
PRM_DataItemHandle evalData(int pi, int vi, fpreal t) const
OP_API bool OPcheckForVopnetDefinedNodes(OP_Node *node, UT_WorkBuffer &err)
OP_API void OPcreateStickyNoteAboutCachedCode(OP_Network *subnet)
SYS_FORCE_INLINE T & y(void)
Definition: UT_Vector3.h:500
double fpreal
Definition: SYS_Types.h:270
void evalStringInst(const UT_StringRef &name, const int *inst, UT_String &val, int vi, fpreal t, int nestlevel=1) const
OP_API bool OPisLegacyShaderParm(const PRM_Template &parm, OP_Node *owner)
Utility class for containing a color ramp.
Definition: UT_Ramp.h:84
#define OP_API
Definition: OP_API.h:10
OP_API void OPwarnBadRefs(UT_WorkBuffer &msg, const UT_StringArray &badrefs)
T & x(void)
Definition: UT_Vector4.h:375
void updateRampFromMultiParm(fpreal t, const PRM_Parm &m, UT_Ramp &ramp, bool *time_dep=NULL, DEP_MicroNode *depnode=NULL) const
T & y(void)
Definition: UT_Vector2.h:287
exint evalInt(int pi, int vi, fpreal t) const
GLboolean r
Definition: glcorearb.h:1221
exint evalIntInst(const UT_StringRef &name, const int *inst, int vi, fpreal t, int nestlevel=1) const
T & w(void)
Definition: UT_Vector4.h:381
PRM_Parm * getParmPtrInst(const UT_StringRef &parm_name, const int *instance, int nest_level)
Definition: PRM_ParmList.h:455
SYS_FORCE_INLINE PRM_ParmList * getParmList()
Definition: PRM_ParmOwner.h:67
OP_API void OPgetItemBounds(fpreal &x1, fpreal &y1, fpreal &x2, fpreal &y2, const OP_NetworkBoxItemList &items)
OP_API bool OPcheckForVopnetsUsedOutside(OP_Node *node, OP_NodeList *badvopnets)
UT_SharedPtr< const PRM_DataItem > PRM_DataItemHandle
Definition: PRM_Parm.h:88