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_TimeCode.h>
20 #include <HUSD/HUSD_Xform.h>
22 
23 class LOP_Network;
26 class HUSD_FindPrims;
27 class HUSD_FindProps;
28 class PRM_Template;
29 class PRM_Name;
30 class UT_ArrayStringSet;
31 
32 extern "C" {
34 };
35 
36 #define LOP_DEBUG_FLAG 'D'
37 
41 };
42 
46 };
47 
52 };
53 
55 {
56 public:
59  myValueLength(1),
60  myValueIsTimeDep(false)
61  { }
62 
72  int myValueInt[4];
77 };
79 
80 class LOP_API LOP_Node : public OP_Network
81 {
82 public:
83  // Standard OP_Network stuff:
84  static const char *theChildTableName;
85  virtual const char *getChildType() const override;
86  virtual const char *getOpType() const override;
87 
88  virtual OP_OpTypeId getChildTypeID() const override;
89  virtual OP_OpTypeId getOpTypeID() const override;
90  virtual OP_DataType getCookedDataType() const override;
91 
92  static void buildOperatorTable(OP_OperatorTable &table);
93  static OP_Operator *getManagementOperator();
94  static void initializeExpressions();
95 
96  // Local variables that can be used by nodes which allow user-specifiable
97  // names on inputs (such as merge into and add variant).
98  static CH_LocalVariable theInputNameLocalVariables[];
99 
100  virtual void opChanged(OP_EventType reason, void *data=0) override;
101  virtual void onCreated() override;
102 
103  virtual fpreal getW() const override;
104  virtual fpreal getH() const override;
105 
106  // Gets/sets the value of the debug flag on this node.
107  virtual int getDebug() const override;
108  virtual int setDebug(int state) override;
109  virtual int setFlag(char flag, int onoff) override;
110  bool getNestedDebug() const;
111 
112  // Override the function that determines whether this node should be
113  // drawn in the network editor with a "bypass" look. LOPs have an optional
114  // "bypass" spare parameter that makes the node act like it is bypassed,
115  // so it should also be drawn like it's bypassed.
116  virtual bool getUseBypassLook(
117  const OP_EditorContext &ctx) const override;
118 
119  // Cook this node and return a data handle for the resulting stage.
120  const HUSD_DataHandle &getCookedDataHandle(OP_Context &context,
121  int outidx = 0);
122  // Cook this node and return a data handle for the resulting stage. If
123  // the cook leaves this node in an error state, go to this node's first
124  // connected input, and try to return the cooked data handle for that
125  // node, and so on. This method is useful for the scene graph tree and
126  // similar panels, where it's much more useful to show something than
127  // nothing in the case of an error. Returns the data handle and a
128  // pointer to the node whose data is actually returned.
129  const HUSD_DataHandle &getCookedDataHandleBypassingErrors(
130  LOP_Node *&owner_node,
131  int &owner_outidx,
133  int outidx = 0);
134  // Resolves a node path pointing to a LOP node into an HUSD_LockedStagePtr.
135  // This is used by husdLopStageResolver in HUSD_Utils.C to help the
136  // GusdStageCache convert "op:/" USD file names into a stage generated
137  // by a LOP node.
138  static HUSD_LockedStagePtr resolveStage(const UT_StringRef &path);
139 
140  // Get the badge clor we should use for this LOP node do indicate which
141  // active layer is modified by this node.
142  bool hasLayerColorIndex(int &clridx) const;
143 
144  // Override this for nodes that want to allow python code to edit their
145  // stage or active layer directly.
146  virtual HUSD_PythonConverter *getEditableObject(LOP_EditableObject obj);
147 
148  // Evaluate a simplified adhoc collection parm and use it to fill in an
149  // HUSD_FindParms object.
150  static bool getSimplifiedCollection(OP_Node *node,
151  const UT_StringRef &primpattern,
152  HUSD_FindPrims &findprims);
153  // Evaluate a simplified adhoc collection parm and use it to fill in an
154  // HUSD_FindProps object.
155  static bool getSimplifiedCollection(OP_Node *node,
156  const UT_StringRef &primpattern,
157  const UT_StringRef &proppattern,
158  HUSD_FindProps &findprops);
159  // Evaluate a pattern string using an HUSD_FindPrims against a LOP node's
160  // editableDataHandle, and return an array of matching paths. Isolates
161  // the locking of the stage to this function.
162  static bool getPathsFromPattern(LOP_Node &lop,
163  const UT_StringRef &pattern,
165 
166  // Return the number of layers in our data handle.
167  int layerCount() const;
168 
169  // Track the set of primitives modified by the most recent cook of
170  // this node.
171  const UT_StringArray &lastModifiedPrims() const;
172  void setLastModifiedPrims(const UT_StringRef &path);
173  void setLastModifiedPrims(const UT_StringArray &paths);
174  void setLastModifiedPrims(const UT_ArrayStringSet &paths);
175  void setLastModifiedPrims(const HUSD_FindPrims &findprims);
176  void clearLastModifiedPrims();
177 
178  // For a new stage being authored by this node, this function allows the
179  // node to control the asset path used to configure the stage's asset
180  // resolver context. Individual node types can provide custom
181  // implementations.
182  virtual bool getResolverContextAssetPath(UT_String &assetpath);
183 
184  // Code for tracking convex hulls around context option "blocks" in the
185  // network editor.
186  virtual bool showConvexHull() const
187  { return false; }
188  virtual int contextOptionsStackEffect(int input) const
189  { return 0; }
190  virtual void findEnclosedItems(OP_EnclosedItems &items) const;
191 
192  // Evaluate local variables common to multiple LOP node types.
193  virtual bool evalVariableValue(fpreal &val, int var_id,
194  int thread) override;
195  virtual bool evalVariableValue(UT_String &val, int var_id,
196  int thread) override;
198  const char *name) override;
199 
201  { return myLastCookActivationState; }
202  HUSD_TimeCode getTimeCode(const OP_Context &context,
203  bool timedep) const;
204 
205  // Public functions for adding warnings and errors, so that utility
206  // methods in LOP_PRMShared and elsewhere can add errors directly to
207  // LOP nodes.
208  void addSystemError(const char *msg = 0)
209  { getLockedErrorManager()->systemError(msg); }
210  void addError(int code, const char *msg = 0)
212  addError(LOP_OPTYPE_NAME, code, msg); }
213  void addWarning(int code, const char *msg = 0)
215  addWarning(LOP_OPTYPE_NAME, code, msg); }
216  void addMessage(int code, const char *msg = 0)
218  addMessage(LOP_OPTYPE_NAME, code, msg); }
219 
220  virtual const char *inputLabel(unsigned idx) const override;
221  virtual const char *outputLabel(unsigned idx) const override;
222 
223 protected:
224  LOP_Node(OP_Network *parent, const char *name,
225  OP_Operator *entry);
226  virtual ~LOP_Node();
227 
228  // Common cook method for all LOP nodes. Calls cookMyLop.
229  virtual OP_ERROR cookMe(OP_Context &context) override;
230  // Specific cook method for each LOP node, must be overridden.
231  virtual OP_ERROR cookMyLop(OP_Context &context) = 0;
232  // Clears any cached data for this node. In the case of a LOP node, this
233  // means clearing our locked stage pointer from the GusdStageCache.
234  virtual void clearCache() override;
235  // Makes our own data handle reference or copy the data handle of another
236  // node. Should be used to reference nodes that are not inputs to this
237  // node.
238  OP_ERROR cookReferenceNode(OP_Context &context,
239  LOP_Node *source_lop,
240  bool copy_data_handle = false,
241  bool add_extra_input = true,
242  const HUSD_LoadMasksPtr &load_masks =
244  // Makes our own data handle reference or copy the data handle of one
245  // of our input nodes.
246  OP_ERROR cookReferenceInput(OP_Context &context,
247  int which_input = 0,
248  bool require_input = false,
249  bool copy_data_handle = false,
250  const HUSD_LoadMasksPtr &load_masks =
252  // Wrapper to call copyReferenceInput with the copy_data_handle
253  // parameter set to true.
254  OP_ERROR cookModifyInput(OP_Context &context,
255  int which_input = 0,
256  bool require_input = false,
257  const HUSD_LoadMasksPtr &load_masks =
259  // Access the data handle of one of our inputs, that must have been
260  // locked already to ensure the data is cooked for the current context.
261  const HUSD_DataHandle &lockedInputData(OP_Context &context,
262  int which_input);
263  // Access our own data handle for modification. Should only be called
264  // from within cookMyLop.
265  HUSD_DataHandle &editableDataHandle();
266 
267  // For subnet nodes, this method will return the contained node that
268  // corresponds to specified output connector index. For all other nodes
269  // with will return nullptr.
270  LOP_Node *getNodeForSubnetOutput(int outidx) const;
271 
272  // For nodes with editable input names, this function evaluates all the
273  // input names, assigning any dependencies to the specified parameter.
274  OP_ERROR getInputStrings(const UT_StringRef &key_parm_name,
275  UT_StringArray &input_names);
276 
277  // Functions for controlling checkpoints created during a cook operation.
278  void setClearCheckpointsOnInputChange(bool clear);
279  void createCheckpoint(const HUSD_AutoAnyLock &lock,
280  const UT_StringHolder &id);
281  void removeCheckpoint(const UT_StringRef &id);
282  void removeAllCheckpoints();
283 
284  // Functions for accessing existing checkpoitns during a cook operation.
285  void getAvailableCheckpoints(UT_StringArray &ids) const;
286  bool restoreCheckpoint(const HUSD_AutoLayerLock &layerlock,
287  const UT_StringRef &id);
288 
289  virtual OP_ERROR bypassMe(OP_Context &context,
290  int &copied_input) override;
291  virtual void deleteCookedData() override;
292  virtual int saveCookedData(const char *, OP_Context &) override;
293  virtual int saveCookedData(std::ostream &os, OP_Context &,
294  int binary = 0) override;
295  virtual const char *getFileExtension(int bin) const override;
296 
297  // Sets a USD attribute or relationship on a USD primitive based on the
298  // current value of a node parameter.
299  void getAttributeParmSet(
300  const PRM_Template *tplate,
301  LOP_AttributeParmSet &pset,
302  fpreal t);
303  bool setAttributeFromParmSet(
304  HUSD_AutoWriteLock &writelock,
305  LOP_AttributeParmSet &pset,
306  fpreal t);
307 
308  // Helps with convex hull generation by looking at the context option
309  // stack information implemented by the virtual contextOptionsStackEffect.
310  void encloseInputs(OP_EnclosedItems &items,
311  int stackdepth) const;
312 
313  // Map of attribute names to evaluator objects.
316 
317 private:
318  void setDebugDirtyRecursive(
319  void *change_data, bool top_level);
320  void resetDataHandle();
321 
322  HUSD_DataHandle myDataHandle;
323  LOP_LayerCheckpoints myCheckpoints;
324  UT_StringArray myLastModifiedPrims;
325  LOP_ActivationState myLastCookActivationState;
326 };
327 
328 #endif
virtual int saveCookedData(std::ostream &os, OP_Context &, int binary=0)=0
LOP_ActivationState lastCookActivationState() const
Definition: LOP_Node.h:200
GLenum GLenum GLenum input
Definition: glew.h:13879
Definition: UT_Set.h:58
int myEvaluatingInputNameIndex
Definition: LOP_Node.h:315
virtual bool getUseBypassLook(const OP_EditorContext &ctx) const
GLuint const GLchar * name
Definition: glew.h:1814
UT_SharedPtr< HUSD_LoadMasks > HUSD_LoadMasksPtr
UT_StringHolder myPrimPath
Definition: LOP_Node.h:63
virtual UT_AttributeEvaluator * createAttributeEvaluator(const char *name)
void addMessage(int code, const char *msg=0)
Definition: LOP_Node.h:216
HUSD_XformStyle myValueXformStyle
Definition: LOP_Node.h:74
virtual fpreal getH() const
Node position/scale is used by the UI.
#define SYS_VISIBILITY_EXPORT
HUSD_XformStyle
Definition: HUSD_Xform.h:33
#define LOP_OPTYPE_NAME
Definition: OP_Node.h:303
GLuint const GLfloat * val
Definition: glew.h:2794
virtual OP_OpTypeId getOpTypeID() const =0
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:70
UT_ErrorSeverity
Definition: UT_Error.h:25
LOP_InputNameVariableId
Definition: LOP_Node.h:43
GLhandleARB obj
Definition: glew.h:6236
virtual OP_ERROR cookMe(OP_Context &context)=0
UT_StringHolder myControl
Definition: LOP_Node.h:65
virtual int setDebug(int on_off)
Definition: OP_Node.h:1279
virtual void opChanged(OP_EventType reason, void *data=0)
fpreal myValueFloat[16]
Definition: LOP_Node.h:73
virtual const char * getOpType() const =0
PRM_Type myParmType
Definition: LOP_Node.h:67
virtual bool showConvexHull() const
Definition: LOP_Node.h:186
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:314
UT_Array< LOP_AttributeParmSet > LOP_AttributeParms
Definition: LOP_Node.h:78
SYS_VISIBILITY_EXPORT void newLopOperator(OP_OperatorTable *table)
virtual fpreal getW() const
Node position/scale is used by the UI.
OP_OpTypeId
Definition: OP_OpTypeId.h:18
void addWarning(int code, const char *msg=0)
Definition: LOP_Node.h:213
*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
virtual OP_DataType getCookedDataType() const =0
GLsizei const GLchar *const * path
Definition: glew.h:6461
virtual int contextOptionsStackEffect(int input) const
Definition: LOP_Node.h:188
virtual const char * getChildType() const
static const char * theChildTableName
Definition: LOP_Node.h:84
UT_StringHolder myAttrName
Definition: LOP_Node.h:64
double fpreal
Definition: SYS_Types.h:276
virtual const char * getFileExtension(int binary) const =0
void addSystemError(const char *msg=0)
Definition: LOP_Node.h:208
LOP_ActivationState
Definition: LOP_Node.h:48
virtual const char * outputLabel(unsigned idx) const
LOP_EditableObject
Definition: LOP_Node.h:38
UT_SharedPtr< HUSD_LockedStage > HUSD_LockedStagePtr
virtual int setFlag(char tag, int on_off)
UT_StringHolder myApiSchema
Definition: LOP_Node.h:68
UT_StringHolder myInterpolation
Definition: LOP_Node.h:66
UT_StringHolder myValueStr
Definition: LOP_Node.h:71
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:69
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:210
virtual int getDebug() const
Definition: OP_Node.h:1322
GLubyte * pattern
Definition: glew.h:5711
virtual void onCreated(void)
Overriden in VOPs.
Definition: OP_Node.h:2948
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 void clearCache()
virtual void deleteCookedData()=0
GLenum const void * paths
Definition: glew.h:13589