HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LOP_Node.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: LOP Library (C++)
7  *
8  * COMMENTS: The base class for all Lighting Operators
9  *
10  */
11 
12 #ifndef __LOP_Node_h__
13 #define __LOP_Node_h__
14 
15 #include "LOP_API.h"
16 #include "LOP_Error.h"
17 #include "LOP_LayerCheckpoints.h"
18 #include <OP/OP_Network.h>
19 #include <HUSD/HUSD_DataHandle.h>
20 #include <HUSD/HUSD_PathSet.h>
21 #include <HUSD/HUSD_TimeCode.h>
22 #include <HUSD/HUSD_Xform.h>
23 #include <GU/GU_DetailHandle.h>
25 #include <UT/UT_Ramp.h>
26 
27 class LOP_Network;
30 class HUSD_FindPrims;
31 class HUSD_FindProps;
32 class HUSD_Info;
33 class PRM_Template;
34 class PRM_Name;
35 class UT_ArrayStringSet;
36 
37 extern "C" {
39 };
40 
41 #define LOP_DEBUG_FLAG 'D'
42 
47 };
48 
52 };
53 
58 };
59 
61 {
62 public:
64  : myFrame(1.0),
65  myTime(0.0),
66  myRampBasisIsArray(false),
69  myValueLength(1),
70  myValueIsTimeDep(false),
71  myValueIsOrdered(false),
72  myIsCustom(true), // USD assumes custom attribs
73  myExpandCollection(true),
74  myClearAttrib(false)
75  { }
76 
91  UT_StringHolder myConnection; // path to the source attrib
94  int myValueInt[4];
104 };
106 
108 {
109 public:
110  // Standard OP_Network stuff:
111  static const char *theChildTableName;
112  const char *getChildType() const override;
113  const char *getOpType() const override;
114 
115  OP_OpTypeId getChildTypeID() const override;
116  OP_OpTypeId getOpTypeID() const override;
117  OP_DataType getCookedDataType() const override;
118 
119  static void buildOperatorTable(OP_OperatorTable &table);
120  static OP_Operator *getManagementOperator();
121  static void initializeExpressions();
122 
123  // Get a LOP node from the provided path. If the path is a LOP node path,
124  // return that LOP node. If it is a LOP network path, return the path to
125  // that LOP network's viewer node.
126  static LOP_Node *getLopNodeFromLopOrNetworkPath(const char *path,
127  bool default_to_stage = true);
128 
129  // Local variables that can be used by nodes which allow user-specifiable
130  // names on inputs (such as merge into and add variant).
131  static CH_LocalVariable theInputNameLocalVariables[];
132 
133  void opChanged(OP_EventType reason, void *data=0) override;
134  void onCreated() override;
135 
136  fpreal getW() const override;
137  fpreal getH() const override;
138 
139  // Gets/sets the value of the debug flag on this node.
140  bool getDebug() const override;
141  bool setDebug(bool state) override;
142  void setFlag(char flag, int8 val) override;
143  bool getNestedDebug() const;
144 
145  // Overrides the current node pointer method to ensure that we always
146  // find a current node when the old current node is deleted, even in the
147  // absence of a display node.
148  OP_Node *getCurrentNodePtr() override;
149  // Overrides the display node pointer method because a LOP node with LOP
150  // children doesn't need to have a display node, and will return the
151  // display node of the parent LOP network if it doesn't have its own.
152  OP_Node *getDisplayNodePtr() override;
153  void childFlagChange(OP_Node *nodeptr) override;
154  virtual LOP_Node *getViewerLop();
155 
156  // Gets the output child node corresponding to the specified output index.
157  LOP_Node *getOutputLop(int outputidx) const;
158 
159  // Override the function that determines whether this node should be
160  // drawn in the network editor with a "bypass" look. LOPs have an optional
161  // "bypass" spare parameter that makes the node act like it is bypassed,
162  // so it should also be drawn like it's bypassed.
163  bool getUseBypassLook(
164  const OP_EditorContext &ctx) const override;
165 
166  // Cook this node and return a data handle for the resulting stage.
167  const HUSD_DataHandle &getCookedDataHandle(OP_Context &context,
168  int outidx = 0,
169  bool use_last_cook_context_options = false);
170  // Cook this node and return a data handle for the resulting stage. If
171  // the cook leaves this node in an error state, go to this node's first
172  // connected input, and try to return the cooked data handle for that
173  // node, and so on. This method is useful for the scene graph tree and
174  // similar panels, where it's much more useful to show something than
175  // nothing in the case of an error. Returns the data handle and a
176  // pointer to the node whose data is actually returned.
177  const HUSD_DataHandle &getCookedDataHandleBypassingErrors(
178  LOP_Node *&owner_node,
179  int &owner_outidx,
180  OP_Context &context,
181  int outidx = 0,
182  bool use_last_cook_context_options = false);
183  // Return true if this node was the most recent node to create a lock
184  // on the stage we may be sharing with many other nodes.
185  bool isMostRecentStageLock() const;
186 
187  // Get the badge clor we should use for this LOP node do indicate which
188  // active layer is modified by this node.
189  bool hasLayerColorIndex(int &clridx) const;
190 
191  // Override this for nodes that want to allow python code to edit their
192  // stage or active layer directly.
193  virtual HUSD_PythonConverter *getEditableObject(LOP_EditableObject obj);
194 
195  // Create a new HUSD_LoadMasks object using parameters on the creator
196  // LOP Network to set variant selection fallback values.
197  HUSD_LoadMasksPtr createNewLoadMasks();
198 
199  // Evaluate a simplified adhoc collection parm and use it to fill in an
200  // HUSD_FindPrims object.
201  static bool getSimplifiedCollection(OP_Node *node,
202  const UT_StringRef &primpattern,
203  HUSD_FindPrims &findprims);
204  // Evaluate a simplified adhoc collection parm and use it to fill in an
205  // HUSD_FindProps object.
206  static bool getSimplifiedCollection(OP_Node *node,
207  const UT_StringRef &primpattern,
208  const UT_StringRef &proppattern,
209  HUSD_FindProps &findprops);
210  // Evaluate a pattern string using an HUSD_FindPrims against a LOP node's
211  // editableDataHandle, and return an array of matching paths. Isolates
212  // the locking of the stage to this function.
213  static bool getPathsFromPattern(LOP_Node &lop,
214  const UT_StringRef &pattern,
215  UT_StringArray &paths,
216  bool allow_missing_explicit_prims = false);
217  // Tests if the provided primitive is editable. Adds the result to the
218  // provided map so the next call with the same path can return the cached
219  // result immediately. The first time each non-editable prim is found,
220  // a warning is added to this node.
221  bool isPrimitiveEditable(
222  UT_StringMap<bool> alloweditmap,
223  const HUSD_Info &info,
224  const UT_StringHolder &path,
225  bool ignoreeditableflag,
226  LOP_ErrorCodes non_editable_error_code =
228 
229  // Return the number of layers in our data handle.
230  int layerCount() const;
231 
232  // Track the set of primitives modified by the most recent cook of
233  // this node.
234  const HUSD_PathSet &lastModifiedPrims() const;
235  void setLastModifiedPrims(const UT_StringRef &path);
236  void setLastModifiedPrims(const UT_StringArray &paths);
237  void setLastModifiedPrims(const UT_ArrayStringSet &paths);
238  void setLastModifiedPrims(const HUSD_FindPrims &findprims);
239  void setLastModifiedPrims(const HUSD_PathSet &paths);
240  void clearLastModifiedPrims();
241 
242  // For a new stage being authored by this node, these methods allow the
243  // node to control the asset path or url/string pairs used to configure
244  // the stage's asset resolver context. Individual node types can provide
245  // custom implementations.
246  virtual bool getResolverContextAssetPath(UT_String &assetpath);
247  virtual bool getResolverContextStrings(
248  UT_StringMap<UT_StringHolder> &resolverstrings);
249 
250  // Code for tracking convex hulls around context option "blocks" in the
251  // network editor.
252  virtual bool showConvexHull() const
253  { return false; }
254  virtual int contextOptionsStackEffect(int input) const
255  { return 0; }
256  virtual void findEnclosedItems(OP_EnclosedItems &items) const;
257 
258  // Evaluate local variables common to multiple LOP node types.
259  bool evalVariableValue(fpreal &val, int var_id,
260  int thread) override;
261  bool evalVariableValue(UT_String &val, int var_id,
262  int thread) override;
264  const char *name) override;
266  UT_StringArray &names) override;
267 
269  { return myLastCookActivationState; }
270  HUSD_TimeCode getTimeCode(const OP_Context &context,
271  bool timedep) const;
272  HUSD_LoadMasksPtr getLoadMasks(int outidx = 0) const;
273 
274  // Public functions for adding warnings and errors, so that utility
275  // methods in LOP_PRMShared and elsewhere can add errors directly to
276  // LOP nodes.
277  void addSystemError(const char *msg = 0)
278  { getLockedErrorManager()->systemError(msg); }
279  void addError(int code, const char *msg = 0)
281  addError(LOP_OPTYPE_NAME, code, msg); }
282  void addWarning(int code, const char *msg = 0)
284  addWarning(LOP_OPTYPE_NAME, code, msg); }
285  void addMessage(int code, const char *msg = 0)
287  addMessage(LOP_OPTYPE_NAME, code, msg); }
288 
289  const char *inputLabel(unsigned idx) const override;
290  const char *outputLabel(unsigned idx) const override;
291 
293  const OP_NodeInfoTreeParms &parms) override;
294 
295  // Guide geometry for display in the viewport, but which does not appear
296  // in the USD stage anywhere.
297  virtual int getNumGuides() const;
298  virtual const char *getGuideColorName(int idx) const;
299  GU_DetailHandle cookGuide(int idx, OP_Context &context);
300 
301  // For transforming between LOP and OBJ spaces.
302  int getRelativeTransform(OP_Node &to,
303  UT_Matrix4 &xform,
304  OP_Context &context) override;
305  int getRelativeTransform(OP_Node &to,
306  UT_DMatrix4 &xform,
307  OP_Context &context) override;
308 
309 protected:
310  LOP_Node(OP_Network *parent, const char *name,
311  OP_Operator *entry);
312  ~LOP_Node() override;
313 
314  // Common cook method for all LOP nodes. Calls cookMyLop.
315  OP_ERROR cookMe(OP_Context &context) override;
316  // Specific cook method for each LOP node, must be overridden.
317  virtual OP_ERROR cookMyLop(OP_Context &context) = 0;
318  // Specific guide cook method for each LOP node.
319  virtual GU_DetailHandle cookMyGuide(int idx, OP_Context &context);
320  // Clears any cached data for this node. In the case of a LOP node, this
321  // means clearing our locked stage pointer from the GusdStageCache.
322  void clearCache() override;
323  // Makes our own data handle reference or copy the data handle of another
324  // node. Should be used to reference nodes that are not inputs to this
325  // node.
326  OP_ERROR cookReferenceNode(OP_Context &context,
327  LOP_Node *source_lop,
328  bool copy_data_handle = false,
329  bool add_extra_input = true,
330  const HUSD_LoadMasksPtr &load_masks =
332  // Makes our own data handle reference or copy the data handle of one
333  // of our input nodes.
334  OP_ERROR cookReferenceInput(OP_Context &context,
335  int which_input = 0,
336  bool require_input = false,
337  bool copy_data_handle = false,
338  const HUSD_LoadMasksPtr &load_masks =
340  // Wrapper to call copyReferenceInput with the copy_data_handle
341  // parameter set to true.
342  OP_ERROR cookModifyInput(OP_Context &context,
343  int which_input = 0,
344  bool require_input = false,
345  const HUSD_LoadMasksPtr &load_masks =
347  // Access the data handle of one of our inputs, that must have been
348  // locked already to ensure the data is cooked for the current context.
349  const HUSD_DataHandle &lockedInputData(OP_Context &context,
350  int which_input);
351  // Access our own data handle for modification. Should only be called
352  // from within cookMyLop.
353  HUSD_DataHandle &editableDataHandle();
354 
355  // For subnet nodes, this method will return the contained node that
356  // corresponds to specified output connector index. For all other nodes
357  // with will return nullptr.
358  LOP_Node *getNodeForSubnetOutput(int outidx) const;
359 
360  // For nodes with editable input names, this function evaluates all the
361  // input names, assigning any dependencies to the specified parameter.
362  OP_ERROR getInputStrings(const UT_StringRef &key_parm_name,
363  fpreal t,
364  UT_StringArray &input_names,
365  bool allow_empty_strings = false);
366 
367  // Functions for controlling checkpoints created during a cook operation.
368  void setClearCheckpointsOnInputChange(bool clear);
369  void createCheckpoint(const HUSD_AutoAnyLock &lock,
370  const UT_StringHolder &id);
371  void removeCheckpoint(const UT_StringRef &id);
372  void removeAllCheckpoints();
373 
374  // Functions for accessing existing checkpoitns during a cook operation.
375  void getAvailableCheckpoints(UT_StringArray &ids) const;
376  bool restoreCheckpoint(const HUSD_AutoLayerLock &layerlock,
377  const UT_StringRef &id);
378 
379  OP_ERROR bypassMe(OP_Context &context,
380  int &copied_input) override;
381  void deleteCookedData() override;
382  int saveCookedData(const char *, OP_Context &) override;
383  int saveCookedData(std::ostream &os, OP_Context &,
384  int binary = 0) override;
385  const char *getFileExtension(int bin) const override;
386 
387  // Specifically fills in the ramp attribute names from the spare tags on
388  // a parameter. Used by getAttributeParmSet, but can be called separately
389  // from that function for blocking attributes for a ramp parameter.
390  static void getRampAttributeNamesForParmSet(
391  const PRM_Template *tplate,
392  LOP_AttributeParmSet &pset);
393  // Populates a LOP_AttributeParmSet data structure from a parameter, using
394  // all the USD-specific information in the parameter's spare tags.
395  static void getAttributeParmSet(OP_Node *node,
396  const PRM_Template *tplate,
397  LOP_AttributeParmSet &pset,
398  fpreal t);
399  // Applies any API schema mentioned in the LOP_AttributeParmSet. This
400  // method can be called in a change block before calling
401  // setAttributeFromParmSet for a bunch of LOP_AttributeParmSets.
402  // Applying the schemas first in a change block can greatly reduce the
403  // amount of recomposition done as a result of adding an API schema to
404  // a large number of primitives.
405  bool applySchemaFromParmSet(
406  HUSD_AutoWriteLock &writelock,
407  LOP_AttributeParmSet &pset,
408  UT_StringSet *failedapis = nullptr);
409  // Sets a USD attribute or relationship on a USD primitive based on the
410  // current value of a node parameter. Use getAttributeParmSet to populate
411  // the LOP_AttributeParmSet data structure from the parm first.
412  bool setAttributeFromParmSet(
413  HUSD_AutoWriteLock &writelock,
414  LOP_AttributeParmSet &pset,
415  fpreal t,
416  UT_StringSet *failedapis = nullptr);
417 
418  // Helps with convex hull generation by looking at the context option
419  // stack information implemented by the virtual contextOptionsStackEffect.
420  void encloseInputs(OP_EnclosedItems &items,
421  int stackdepth) const;
422 
423  // Map of attribute names to evaluator objects.
426 
427  // Helper class to determine whether nodes with multiple inputs will be
428  // composing stages with differing time-codes-per-second (TCPS) metadata.
429  //
430  // As of USD 20.08, if you reference/sublayer (i.e., compose) a 60tcps stage
431  // into a 24tcps stage (for example), any time sample data within will be
432  // automatically time-scaled (1.0 -> 0.4, ..., 60.0 -> 24.0, etc).
433  //
434  // If the data for the stage is driven by Houdini expressions/keyframes and
435  // not by cached time samples, this time-scaling is not applied, which might
436  // be unexpected for the user. This class can help warn them.
437  //
438  // Expected usage in `cookMyLop()`:
439  // - sometime after `cookModifyInput(context);`, instantiate a checker:
440  // `DifferingTimeCodesPerSecChecker tcpsChecker(this);`
441  // - whenever you first get your secondary inputs via
442  // `const HUSD_DataHandle &datahandle = lockedInputData(context, i);`,
443  // add this data handle to the checker:
444  // `tcpsChecker.addInput(datahandle, context);`
445  // - whenever you first get your primary input via
446  // `const HUSD_DataHandle &datahandle = editableDataHandle();`
447  // also add this data handle to the checker, with `false`:
448  // `tcpsChecker.addInput(datahandle, context, false);`
449  // - after all the inputs (primary & secondary) have been added to the
450  // checker, check to see if there's an issue:
451  // `tcpsChecker.checkForDifferingTCPS();`
452  //
454  {
455  public:
456  explicit DifferingTimeCodesPerSecChecker(LOP_Node *lop) : myLop(lop) {}
457  void addInput(
458  const HUSD_DataHandle &handle,
459  OP_Context &context,
460  bool onlyTimeDep = true);
461  // Returns `true` if there are differing values; `false` otherwise
462  bool checkForDifferingTCPS(bool emitWarning = true);
463 
464  private:
465  LOP_Node *myLop;
466  std::set<fpreal64> myTCPSEntries;
467  };
468 
469 private:
470  // Resolves a node path pointing to a LOP node into an HUSD_LockedStagePtr.
471  // This is used by husdLopStageResolver in HUSD_Utils.C to help the
472  // GusdStageCache convert "op:/" USD file names into a stage generated
473  // by a LOP node.
474  static HUSD_LockedStagePtr resolveStage(const UT_StringRef &path);
475 
476  void setDebugDirtyRecursive(
477  void *change_data, bool top_level);
478  void resetDataHandle();
479 
480  HUSD_DataHandle myDataHandle;
481  LOP_LayerCheckpoints myCheckpoints;
482  HUSD_PathSet myLastModifiedPrims;
483  LOP_ActivationState myLastCookActivationState;
484 };
485 
486 #endif
virtual int saveCookedData(std::ostream &os, OP_Context &, int binary=0)=0
LOP_ActivationState lastCookActivationState() const
Definition: LOP_Node.h:268
Definition: UT_Set.h:58
int myEvaluatingInputNameIndex
Definition: LOP_Node.h:425
fpreal getH() const override
Node position/scale is used by the UI.
virtual bool getUseBypassLook(const OP_EditorContext &ctx) const
fpreal getW() const override
Node position/scale is used by the UI.
UT_SharedPtr< HUSD_LoadMasks > HUSD_LoadMasksPtr
UT_StringHolder myPrimPath
Definition: LOP_Node.h:79
virtual UT_AttributeEvaluator * createAttributeEvaluator(const char *name)
void addMessage(int code, const char *msg=0)
Definition: LOP_Node.h:285
HUSD_XformStyle myValueXformStyle
Definition: LOP_Node.h:97
virtual void getAttributeEvaluatorNames(UT_StringArray &names)
#define SYS_VISIBILITY_EXPORT
HUSD_XformStyle
Definition: HUSD_Xform.h:34
#define LOP_OPTYPE_NAME
Definition: OP_Node.h:304
virtual void setFlag(char tag, int8 val)
UT_StringHolder myRampBasisAttrName
Definition: LOP_Node.h:82
const GLuint GLenum const void * binary
Definition: glcorearb.h:1924
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
virtual const char * inputLabel(unsigned idx) const
UT_StringHolder myValueType
Definition: LOP_Node.h:92
UT_ErrorSeverity
Definition: UT_Error.h:25
LOP_InputNameVariableId
Definition: LOP_Node.h:49
Each instance is a tab.
Definition: PRM_Type.h:422
virtual OP_ERROR cookMe(OP_Context &context)=0
virtual void childFlagChange(OP_Node *)
UT_StringHolder myRampPosAttrName
Definition: LOP_Node.h:84
double fpreal64
Definition: SYS_Types.h:201
UT_StringHolder myControl
Definition: LOP_Node.h:85
PRM_Type myParmType
Definition: LOP_Node.h:87
virtual bool showConvexHull() const
Definition: LOP_Node.h:252
virtual OP_Node * getCurrentNodePtr()
UT_StringMap< UT_UniquePtr< UT_AttributeEvaluator > > myEvaluators
Definition: LOP_Node.h:424
void opChanged(OP_EventType reason, void *data=0) override
UT_Array< LOP_AttributeParmSet > LOP_AttributeParms
Definition: LOP_Node.h:105
SYS_VISIBILITY_EXPORT void newLopOperator(OP_OperatorTable *table)
OP_OpTypeId
Definition: OP_OpTypeId.h:18
void addWarning(int code, const char *msg=0)
Definition: LOP_Node.h:282
#define LOP_API
Definition: LOP_API.h:10
PRM_MultiType myMultiParmType
Definition: LOP_Node.h:88
GLuint const GLchar * name
Definition: glcorearb.h:786
LOP_ErrorCodes
Definition: LOP_Error.h:16
signed char int8
Definition: SYS_Types.h:35
GLushort pattern
Definition: glad.h:2583
virtual OP_DataType getCookedDataType() const =0
GLenum GLenum GLsizei void * table
Definition: glad.h:5129
virtual OP_OpTypeId getOpTypeID() const
Definition: OP_Node.h:532
UT_StringHolder myConnection
Definition: LOP_Node.h:91
GLdouble t
Definition: glad.h:2397
UT_Ramp myValueRamp
Definition: LOP_Node.h:96
UT_StringHolder myRampCountAttrName
Definition: LOP_Node.h:81
virtual int contextOptionsStackEffect(int input) const
Definition: LOP_Node.h:254
virtual const char * getChildType() const
static const char * theChildTableName
Definition: LOP_Node.h:111
UT_StringHolder myAttrName
Definition: LOP_Node.h:80
**Note that the tasks the is the thread number *for the or if it s being executed by a non pool thread(this *can happen in cases where the whole pool is occupied and the calling *thread contributes to running the work load).**Thread pool.Have fun
virtual const char * getFileExtension(int binary) const =0
void addSystemError(const char *msg=0)
Definition: LOP_Node.h:277
Parameters for OP_Node::fillInfoTree()/OP_Node::fillInfoTreeNodeSpecific()
virtual void fillInfoTreeNodeSpecific(UT_InfoTree &tree, const OP_NodeInfoTreeParms &parms)
LOP_ActivationState
Definition: LOP_Node.h:54
virtual const char * outputLabel(unsigned idx) const
LOP_EditableObject
Definition: LOP_Node.h:43
fpreal64 fpreal
Definition: SYS_Types.h:277
UT_SharedPtr< HUSD_LockedStage > HUSD_LockedStagePtr
Utility class for containing a color ramp.
Definition: UT_Ramp.h:92
virtual const char * getOpType() const
UT_StringHolder myApiSchema
Definition: LOP_Node.h:89
GLuint GLfloat * val
Definition: glcorearb.h:1608
UT_StringHolder myInterpolation
Definition: LOP_Node.h:86
UT_StringHolder myValueStr
Definition: LOP_Node.h:93
OP_EventType
Definition: OP_Value.h:22
OP_DataType
Definition: OP_DataTypes.h:28
virtual OP_OpTypeId getChildTypeID() const =0
virtual int getRelativeTransform(OP_Node &to, UT_Matrix4 &xform, OP_Context &context)
UT_StringHolder myXformParmPrefix
Definition: LOP_Node.h:90
virtual bool evalVariableValue(UT_String &val, int index, int thread)
void addError(int code, const char *msg=0)
Definition: LOP_Node.h:279
virtual bool getDebug() const
Definition: OP_Node.h:1359
GLuint * ids
Definition: glcorearb.h:652
virtual OP_ERROR bypassMe(OP_Context &context, int &copied_input)=0
UT_LockedRawPtr< UT_ErrorManager, OP_Lock > getLockedErrorManager()
fpreal64 myValueFloat[16]
Definition: LOP_Node.h:95
Definition: format.h:895
virtual OP_Node * getDisplayNodePtr()
PRM_MultiType
This type enum defines the different types of multi (dynamic) parameters.
Definition: PRM_Type.h:417
virtual void clearCache()
virtual void onCreated()
Overriden in VOPs.
Definition: OP_Node.h:3059
virtual bool setDebug(bool on_off)
Definition: OP_Node.h:1315
virtual void deleteCookedData()=0