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