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