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