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