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  // Override the function that determines whether this node should be
135  // drawn in the network editor with a "bypass" look. LOPs have an optional
136  // "bypass" spare parameter that makes the node act like it is bypassed,
137  // so it should also be drawn like it's bypassed.
138  bool getUseBypassLook(
139  const OP_EditorContext &ctx) const override;
140 
141  // Cook this node and return a data handle for the resulting stage.
142  const HUSD_DataHandle &getCookedDataHandle(OP_Context &context,
143  int outidx = 0,
144  bool use_last_cook_context_options = false);
145  // Cook this node and return a data handle for the resulting stage. If
146  // the cook leaves this node in an error state, go to this node's first
147  // connected input, and try to return the cooked data handle for that
148  // node, and so on. This method is useful for the scene graph tree and
149  // similar panels, where it's much more useful to show something than
150  // nothing in the case of an error. Returns the data handle and a
151  // pointer to the node whose data is actually returned.
152  const HUSD_DataHandle &getCookedDataHandleBypassingErrors(
153  LOP_Node *&owner_node,
154  int &owner_outidx,
156  int outidx = 0,
157  bool use_last_cook_context_options = false);
158  // Resolves a node path pointing to a LOP node into an HUSD_LockedStagePtr.
159  // This is used by husdLopStageResolver in HUSD_Utils.C to help the
160  // GusdStageCache convert "op:/" USD file names into a stage generated
161  // by a LOP node.
162  static HUSD_LockedStagePtr resolveStage(const UT_StringRef &path);
163 
164  // Get the badge clor we should use for this LOP node do indicate which
165  // active layer is modified by this node.
166  bool hasLayerColorIndex(int &clridx) const;
167 
168  // Override this for nodes that want to allow python code to edit their
169  // stage or active layer directly.
170  virtual HUSD_PythonConverter *getEditableObject(LOP_EditableObject obj);
171 
172  // Evaluate a simplified adhoc collection parm and use it to fill in an
173  // HUSD_FindParms object.
174  static bool getSimplifiedCollection(OP_Node *node,
175  const UT_StringRef &primpattern,
176  HUSD_FindPrims &findprims);
177  // Evaluate a simplified adhoc collection parm and use it to fill in an
178  // HUSD_FindProps object.
179  static bool getSimplifiedCollection(OP_Node *node,
180  const UT_StringRef &primpattern,
181  const UT_StringRef &proppattern,
182  HUSD_FindProps &findprops);
183  // Evaluate a pattern string using an HUSD_FindPrims against a LOP node's
184  // editableDataHandle, and return an array of matching paths. Isolates
185  // the locking of the stage to this function.
186  static bool getPathsFromPattern(LOP_Node &lop,
187  const UT_StringRef &pattern,
189 
190  // Return the number of layers in our data handle.
191  int layerCount() const;
192 
193  // Track the set of primitives modified by the most recent cook of
194  // this node.
195  const HUSD_PathSet &lastModifiedPrims() const;
196  void setLastModifiedPrims(const UT_StringRef &path);
197  void setLastModifiedPrims(const UT_StringArray &paths);
198  void setLastModifiedPrims(const UT_ArrayStringSet &paths);
199  void setLastModifiedPrims(const HUSD_FindPrims &findprims);
200  void setLastModifiedPrims(const HUSD_PathSet &paths);
201  void clearLastModifiedPrims();
202 
203  // For a new stage being authored by this node, this function allows the
204  // node to control the asset path used to configure the stage's asset
205  // resolver context. Individual node types can provide custom
206  // implementations.
207  virtual bool getResolverContextAssetPath(UT_String &assetpath);
208 
209  // Code for tracking convex hulls around context option "blocks" in the
210  // network editor.
211  virtual bool showConvexHull() const
212  { return false; }
213  virtual int contextOptionsStackEffect(int input) const
214  { return 0; }
215  virtual void findEnclosedItems(OP_EnclosedItems &items) const;
216 
217  // Evaluate local variables common to multiple LOP node types.
218  bool evalVariableValue(fpreal &val, int var_id,
219  int thread) override;
220  bool evalVariableValue(UT_String &val, int var_id,
221  int thread) override;
223  const char *name) override;
225  UT_StringArray &names) override;
226 
228  { return myLastCookActivationState; }
229  HUSD_TimeCode getTimeCode(const OP_Context &context,
230  bool timedep) const;
231  HUSD_LoadMasksPtr getLoadMasks(int outidx = 0) const;
232 
233  // Public functions for adding warnings and errors, so that utility
234  // methods in LOP_PRMShared and elsewhere can add errors directly to
235  // LOP nodes.
236  void addSystemError(const char *msg = 0)
237  { getLockedErrorManager()->systemError(msg); }
238  void addError(int code, const char *msg = 0)
240  addError(LOP_OPTYPE_NAME, code, msg); }
241  void addWarning(int code, const char *msg = 0)
243  addWarning(LOP_OPTYPE_NAME, code, msg); }
244  void addMessage(int code, const char *msg = 0)
246  addMessage(LOP_OPTYPE_NAME, code, msg); }
247 
248  const char *inputLabel(unsigned idx) const override;
249  const char *outputLabel(unsigned idx) const override;
250 
252  const OP_NodeInfoTreeParms &parms) override;
253 
254  // Guide geometry for display in the viewport, but which does not appear
255  // in the USD stage anywhere.
256  virtual int getNumGuides() const;
257  virtual const char *getGuideColorName(int idx) const;
258  GU_DetailHandle cookGuide(int idx, OP_Context &context);
259 
260 protected:
261  LOP_Node(OP_Network *parent, const char *name,
262  OP_Operator *entry);
263  ~LOP_Node() override;
264 
265  // Common cook method for all LOP nodes. Calls cookMyLop.
266  OP_ERROR cookMe(OP_Context &context) override;
267  // Specific cook method for each LOP node, must be overridden.
268  virtual OP_ERROR cookMyLop(OP_Context &context) = 0;
269  // Specific guide cook method for each LOP node.
270  virtual GU_DetailHandle cookMyGuide(int idx, OP_Context &context);
271  // Clears any cached data for this node. In the case of a LOP node, this
272  // means clearing our locked stage pointer from the GusdStageCache.
273  void clearCache() override;
274  // Makes our own data handle reference or copy the data handle of another
275  // node. Should be used to reference nodes that are not inputs to this
276  // node.
277  OP_ERROR cookReferenceNode(OP_Context &context,
278  LOP_Node *source_lop,
279  bool copy_data_handle = false,
280  bool add_extra_input = true,
281  const HUSD_LoadMasksPtr &load_masks =
283  // Makes our own data handle reference or copy the data handle of one
284  // of our input nodes.
285  OP_ERROR cookReferenceInput(OP_Context &context,
286  int which_input = 0,
287  bool require_input = false,
288  bool copy_data_handle = false,
289  const HUSD_LoadMasksPtr &load_masks =
291  // Wrapper to call copyReferenceInput with the copy_data_handle
292  // parameter set to true.
293  OP_ERROR cookModifyInput(OP_Context &context,
294  int which_input = 0,
295  bool require_input = false,
296  const HUSD_LoadMasksPtr &load_masks =
298  // Access the data handle of one of our inputs, that must have been
299  // locked already to ensure the data is cooked for the current context.
300  const HUSD_DataHandle &lockedInputData(OP_Context &context,
301  int which_input);
302  // Access our own data handle for modification. Should only be called
303  // from within cookMyLop.
304  HUSD_DataHandle &editableDataHandle();
305 
306  // For subnet nodes, this method will return the contained node that
307  // corresponds to specified output connector index. For all other nodes
308  // with will return nullptr.
309  LOP_Node *getNodeForSubnetOutput(int outidx) const;
310 
311  // For nodes with editable input names, this function evaluates all the
312  // input names, assigning any dependencies to the specified parameter.
313  OP_ERROR getInputStrings(const UT_StringRef &key_parm_name,
314  UT_StringArray &input_names,
315  bool allow_empty_strings = false);
316 
317  // Functions for controlling checkpoints created during a cook operation.
318  void setClearCheckpointsOnInputChange(bool clear);
319  void createCheckpoint(const HUSD_AutoAnyLock &lock,
320  const UT_StringHolder &id);
321  void removeCheckpoint(const UT_StringRef &id);
322  void removeAllCheckpoints();
323 
324  // Functions for accessing existing checkpoitns during a cook operation.
325  void getAvailableCheckpoints(UT_StringArray &ids) const;
326  bool restoreCheckpoint(const HUSD_AutoLayerLock &layerlock,
327  const UT_StringRef &id);
328 
329  OP_ERROR bypassMe(OP_Context &context,
330  int &copied_input) override;
331  void deleteCookedData() override;
332  int saveCookedData(const char *, OP_Context &) override;
333  int saveCookedData(std::ostream &os, OP_Context &,
334  int binary = 0) override;
335  const char *getFileExtension(int bin) const override;
336 
337  // Sets a USD attribute or relationship on a USD primitive based on the
338  // current value of a node parameter.
339  void getAttributeParmSet(
340  const PRM_Template *tplate,
341  LOP_AttributeParmSet &pset,
342  fpreal t);
343  bool setAttributeFromParmSet(
344  HUSD_AutoWriteLock &writelock,
345  LOP_AttributeParmSet &pset,
346  fpreal t);
347 
348  // Helps with convex hull generation by looking at the context option
349  // stack information implemented by the virtual contextOptionsStackEffect.
350  void encloseInputs(OP_EnclosedItems &items,
351  int stackdepth) const;
352 
353  // Map of attribute names to evaluator objects.
356 
357  // Helper class to determine whether nodes with multiple inputs will be
358  // composing stages with differing time-codes-per-second (TCPS) metadata.
359  //
360  // As of USD 20.08, if you reference/sublayer (i.e., compose) a 60tcps stage
361  // into a 24tcps stage (for example), any time sample data within will be
362  // automatically time-scaled (1.0 -> 0.4, ..., 60.0 -> 24.0, etc).
363  //
364  // If the data for the stage is driven by Houdini expressions/keyframes and
365  // not by cached time samples, this time-scaling is not applied, which might
366  // be unexpected for the user. This class can help warn them.
367  //
368  // Expected usage in `cookMyLop()`:
369  // - sometime after `cookModifyInput(context);`, instantiate a checker:
370  // `DifferingTimeCodesPerSecChecker tcpsChecker(this);`
371  // - whenever you first get your secondary inputs via
372  // `const HUSD_DataHandle &datahandle = lockedInputData(context, i);`,
373  // add this data handle to the checker:
374  // `tcpsChecker.addInput(datahandle, context);`
375  // - whenever you first get your primary input via
376  // `const HUSD_DataHandle &datahandle = editableDataHandle();`
377  // also add this data handle to the checker, with `false`:
378  // `tcpsChecker.addInput(datahandle, context, false);`
379  // - after all the inputs (primary & secondary) have been added to the
380  // checker, check to see if there's an issue:
381  // `tcpsChecker.checkForDifferingTCPS();`
382  //
384  {
385  public:
386  explicit DifferingTimeCodesPerSecChecker(LOP_Node *lop) : myLop(lop) {}
387  void addInput(
388  const HUSD_DataHandle &handle,
389  OP_Context &context,
390  bool onlyTimeDep = true);
391  // Returns `true` if there are differing values; `false` otherwise
392  bool checkForDifferingTCPS(bool emitWarning = true);
393 
394  private:
395  LOP_Node *myLop;
396  std::set<fpreal64> myTCPSEntries;
397  };
398 
399 private:
400  void setDebugDirtyRecursive(
401  void *change_data, bool top_level);
402  void resetDataHandle();
403 
404  HUSD_DataHandle myDataHandle;
405  LOP_LayerCheckpoints myCheckpoints;
406  HUSD_PathSet myLastModifiedPrims;
407  LOP_ActivationState myLastCookActivationState;
408 };
409 
410 #endif
virtual int saveCookedData(std::ostream &os, OP_Context &, int binary=0)=0
LOP_ActivationState lastCookActivationState() const
Definition: LOP_Node.h:227
GLenum GLenum GLenum input
Definition: glew.h:13879
Definition: UT_Set.h:58
int myEvaluatingInputNameIndex
Definition: LOP_Node.h:355
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:244
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:211
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:354
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:241
*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:213
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:236
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:238
virtual bool getDebug() const
Definition: OP_Node.h:1349
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:2982
virtual bool setDebug(bool on_off)
Definition: OP_Node.h:1305
virtual void deleteCookedData()=0
GLenum const void * paths
Definition: glew.h:13589