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