HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SOP_NodeVerb.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: SOP_NodeVerb.h ( SOP Library, C++)
7  *
8  * COMMENTS:
9  * Verb-based API for SOP cooking mechanisms. SOPs can return
10  * one of these objects to describe how they cook, allowing the
11  * cook engine to perform additional optimizations.
12  */
13 
14 #ifndef __SOP_NodeVerb_h__
15 #define __SOP_NodeVerb_h__
16 
17 #include "SOP_API.h"
18 #include "SOP_Node.h"
19 #include <OP/OP_Director.h>
20 #include <PRM/PRM_Parm.h>
21 #include <UT/UT_Array.h>
22 #include <UT/UT_Assert.h>
23 #include <SYS/SYS_Types.h>
24 
25 class CVEX_Context;
26 class CVEX_Function;
27 class DEP_MicroNode;
29 {
30 public:
31  int64 getMemoryUsage(bool inclusive) const
32  {
33  int64 mem = inclusive ? sizeof(*this) : 0;
34  mem += UTarrayDeepMemoryUsage(stringdata, false);
35  return mem;
36  }
37 
38 public:
39  fpreal32 floatdata[16];
42 };
43 
45 {
48 };
49 
50 
52 {
53 public:
55  {
56  myVexContext = 0;
57  myVexFunction = 0;
58  }
59  virtual ~SOP_NodeCache();
60 
61  virtual int64 getMemoryUsage(bool inclusive) const;
62 
63  CVEX_Context *getVexContext(const char *vexpression);
64  CVEX_Context *buildVexContext(const char *vexpression);
65  void setVexFunction(const CVEX_Function &function);
66  void clearVexContext();
67 
68 protected:
74  friend class SOP_NodeParms;
75 };
76 
78 {
79 public:
81  virtual ~SOP_NodeParms() {}
82 
83  class LoadParms
84  {
85  public:
87  SOP_CookEngine cookengine,
88  const OP_Node *node,
89  const OP_Context &context,
90  SOP_NodeCache *cache,
91  UT_ErrorManager *error,
92  DEP_MicroNode *depnode)
93  : myParms(parms)
94  , myCookEngine(cookengine)
95  , myNode(node)
96  , myContext(context)
97  , myCache(cache)
98  , myError(error)
99  , myDepNode(depnode)
100  {
101  }
102  virtual ~LoadParms() {}
103 
104  const OP_Node *node() const { return myNode; }
105  template <typename T>
106  const T &parms() const
107  { return *UTverify_cast<const T*>(myParms); }
108  SOP_NodeCache *cache() const { return myCache; }
109  const OP_Context &context() const { return myContext; }
110  UT_ErrorManager *error() const { return myError; }
111  DEP_MicroNode *depnode() const { return myDepNode; }
112 
113  /// Methods to wire directly to the optional depnode.
114  void addExplicitInput(DEP_MicroNode &inp, bool check_dup)
115  { if (myDepNode) myDepNode->addExplicitInput(inp, check_dup); }
117  { addExplicitInput(inp, /*check_dup*/true); }
118 
119  /// Methods to add directly to any present error manager.
120  UT_ErrorSeverity addMessage (const char *type, int code, const char *msg=0,
121  const UT_SourceLocation *loc=0) const
122  { if (myError) return myError->addMessage(type, code, formatError(msg), loc);
123  return UT_ERROR_MESSAGE; }
124  UT_ErrorSeverity addWarning (const char *type, int code, const char *msg=0,
125  const UT_SourceLocation *loc=0) const
126  { if (myError) return myError->addWarning(type, code, formatError(msg), loc);
127  return UT_ERROR_WARNING; }
128  UT_ErrorSeverity addError (const char *type, int code, const char *msg=0,
129  const UT_SourceLocation *loc=0) const
130  { if (myError) return myError->addError(type, code, formatError(msg), loc);
131  return UT_ERROR_ABORT; }
132 
133  UT_ErrorSeverity sopAddMessage (int code, const char *msg=0,
134  const UT_SourceLocation *loc=0) const
135  { return addMessage("SOP", code, msg, loc); }
136  UT_ErrorSeverity sopAddWarning (int code, const char *msg=0,
137  const UT_SourceLocation *loc=0) const
138  { return addWarning("SOP", code, msg, loc); }
139  UT_ErrorSeverity sopAddError (int code, const char *msg=0,
140  const UT_SourceLocation *loc=0) const
141  { return addError("SOP", code, msg, loc); }
142 
143  protected:
144  /// Prefix errors so we can get sensible results.
145  UT_StringHolder formatError(const char *msg) const
146  {
147  // Do not prefix with the path in traditional cook
148  // as it is properly assigned.
149  if (myCookEngine == SOP_COOK_TRADITIONAL)
150  return msg;
151  UT_StringHolder result;
152  if (!msg || !*msg)
153  return result;
155  UT_String fullpath;
156  if (node())
157  node()->getFullPath(fullpath);
158  else
159  fullpath = "<internal>";
160  buf.sprintf("%s: %s", (const char *) fullpath, msg);
161  result = buf;
162  return result;
163  }
164 
167  const OP_Node *myNode;
172  };
173 
174  void loadFromOp(const LoadParms &loadparms);
175 
176  bool applyVexpression(const char *vexpression,
177  const UT_Array<GU_ConstDetailHandle> &vexinputs,
178  const LoadParms &loadparm);
179 
180  /// Detects specially named parameters, cooks required inputs using
181  /// the traditional cook engine.
182  bool applyVexpressionFromNode(
183  SOP_Node *node, OP_Context &context,
184  SOP_NodeCache *cache);
185 
186  virtual void copyFrom(const SOP_NodeParms *src) { }
187 
188 
189  enum ParmType
190  {
202  PARM_UNSUPPORTED
203  };
204 
205  /// Marshalling interface to rest of world
206  /// These all use index based notation.
207  virtual exint getNumParms() const { return 0; }
208  virtual const char *getParmName(exint idx) const { return 0; }
209  virtual ParmType getParmType(exint idx) const { return PARM_UNSUPPORTED; }
210 
211  virtual void getParmValue(exint idx, exint &value) const {}
212  virtual void getParmValue(exint idx, fpreal &value) const {}
213  virtual void getParmValue(exint idx, UT_Vector2D &value) const {}
214  virtual void getParmValue(exint idx, UT_Vector3D &value) const {}
215  virtual void getParmValue(exint idx, UT_Vector4D &value) const {}
216  virtual void getParmValue(exint idx, UT_Matrix2D &value) const {}
217  virtual void getParmValue(exint idx, UT_Matrix3D &value) const {}
218  virtual void getParmValue(exint idx, UT_Matrix4D &value) const {}
219  virtual void getParmValue(exint idx, UT_StringHolder &value) const {}
220  virtual void getParmValue(exint idx, UT_SharedPtr<UT_Ramp> &value) const {}
221  virtual void getParmValue(exint idx, PRM_DataItemHandle &value) const {}
222 
223  virtual void setParmValue(exint idx, const exint &value) {}
224  virtual void setParmValue(exint idx, const fpreal &value) {}
225  virtual void setParmValue(exint idx, const UT_Vector2D &value) {}
226  virtual void setParmValue(exint idx, const UT_Vector3D &value) {}
227  virtual void setParmValue(exint idx, const UT_Vector4D &value) {}
228  virtual void setParmValue(exint idx, const UT_Matrix2D &value) {}
229  virtual void setParmValue(exint idx, const UT_Matrix3D &value) {}
230  virtual void setParmValue(exint idx, const UT_Matrix4D &value) {}
231  virtual void setParmValue(exint idx, const UT_StringHolder &value) {}
232  virtual void setParmValue(exint idx, const UT_SharedPtr<UT_Ramp> &value) {}
233  virtual void setParmValue(exint idx, const PRM_DataItemHandle &value) {}
234 
235 protected:
236  virtual void loadFromOpSubclass(const LoadParms &loadparms) = 0;
237 
238  // Used for coercing one type to another
239  template <typename T, typename S>
240  void coerceValue(T &result, const S &src) const
241  {
242  }
243 
244 };
245 
246 template <>
247 void inline SOP_NodeParms::coerceValue(exint &result, const exint &src) const
248 { result = src; }
249 template <>
250 void inline SOP_NodeParms::coerceValue(bool &result, const exint &src) const
251 { result = src; }
252 template <>
253 void inline SOP_NodeParms::coerceValue(exint &result, const bool &src) const
254 { result = src; }
255 template <>
256 void inline SOP_NodeParms::coerceValue(bool &result, const bool &src) const
257 { result = src; }
258 template <>
259 void inline SOP_NodeParms::coerceValue(fpreal &result, const fpreal &src) const
260 { result = src; }
261 template <>
262 void inline SOP_NodeParms::coerceValue(UT_Vector2D &result, const UT_Vector2D &src) const
263 { result = src; }
264 template <>
265 void inline SOP_NodeParms::coerceValue(UT_Vector3D &result, const UT_Vector3D &src) const
266 { result = src; }
267 template <>
268 void inline SOP_NodeParms::coerceValue(UT_Vector4D &result, const UT_Vector4D &src) const
269 { result = src; }
270 template <>
271 void inline SOP_NodeParms::coerceValue(UT_Matrix2D &result, const UT_Matrix2D &src) const
272 { result = src; }
273 template <>
274 void inline SOP_NodeParms::coerceValue(UT_Matrix3D &result, const UT_Matrix3D &src) const
275 { result = src; }
276 template <>
277 void inline SOP_NodeParms::coerceValue(UT_Matrix4D &result, const UT_Matrix4D &src) const
278 { result = src; }
279 template <>
281 { result = src; }
282 template <>
284 { result = src; }
285 template <>
287 { result = src; }
288 
289 
290 ///
291 /// SOP_NodeVerb
292 ///
293 /// This should be a singleton class. Build it with the Register
294 /// template to allow it to be discoverable by name.
295 ///
297 {
298 public:
300  virtual ~SOP_NodeVerb() {}
301 
302  template <typename T>
303  class Register
304  {
305  public:
307  {
308  myVerb = new T();
310  }
312  {
314  delete myVerb;
315  }
316 
317  const T *get() const { return myVerb; }
318 
319  private:
320  T *myVerb;
321 
322  };
323 
324  virtual SOP_NodeCache *allocCache() const
325  { return new SOP_NodeCache; }
326 
327  virtual SOP_NodeParms *allocParms() const = 0;
328 
329  virtual UT_StringHolder name() const = 0;
330 
331  /// Finds a verb which matches the given name
332  static const SOP_NodeVerb *lookupVerb(const UT_StringRef &name);
333  static void listVerbs(UT_StringArray &verbnames);
334  static void registerVerb(SOP_NodeVerb *verb);
335  static void unregisterVerb(SOP_NodeVerb *verb);
336 
338  {
339  public:
340  void clear()
341  {
342  myExprInputs.clear();
343  myTimeDeps.clear();
344  }
346  const UT_IntArray &timedeps)
347  {
348  myExprInputs = inputs;
349  myTimeDeps = timedeps;
350  }
351  const UT_Array<GU_ConstDetailHandle> &exprinputs() const { return myExprInputs; }
352  const UT_IntArray &timedeps() const { return myTimeDeps; }
353 
354  protected:
357  };
358 
360 
361  /// During execution of a verb chain you may wish to disable
362  /// the traditional cooking of nodes. This provides a set of
363  /// nodes you do not want recursed into during the verb cook.
364  /// It will be NULL if there are none or this thread isn't in
365  /// a compiled execution path.
366  static const ForbiddenNodeMap *forbiddenNodes();
367  static const ForbiddenNodeMap *forbiddenNodes(int thread);
368 
369  /// This scope class will push the given list of nodes marking
370  /// them as inelligible for cooking in the traditional path.
371  /// Needless to say, the invoker needs to ensure the set's lifetime
372  /// persists.
374  {
375  public:
376  ScopeForbiddenNodes(const ForbiddenNodeMap *forbiddennodes);
378  protected:
380  };
381 
382  enum CookMode
383  {
384  // With in place the destination gdp will be the first input or
385  // a copy.
386  // The first input will be null.
388  // With duplicate, the destination gdp will be a copy of the
389  // first input. All inputs will be valid.
391  // With generator, the destination gdp is empty, possibly
392  // a stashAll(). All inputs will be valid.
394  // With instance, the destination gdp is invalid. All inputs
395  // will be valid.
397  // There will be a destination gdp, but its contents are unspecified
398  // It may contain the results of the last cook. All inputs are
399  // valid.
401  // If cookMode is pass through, the cook method will not be
402  // invoked at all. Instead, the first input will be passed through
403  // unchanged. If there is no first input, an empty gdp is
404  // created.
406  };
407 
409  {
410  public:
412  virtual ~NodeInputs() {}
413 
414  virtual exint nInputs() const = 0;
415  /// Returns if the input is wired.
416  virtual bool hasInput(exint idx) const = 0;
417 
418  /// Demands the input be cooked. After this, the inputGeo()
419  /// will return the contents.
420  /// Returns false if the cook failed for some reason.
421  virtual bool cookInput(exint idx) = 0;
422 
423  /// Returns an invalid handle if the input isn't wired or not yet cooked.
424  virtual GU_DetailHandle inputGeo(exint idx) = 0;
425 
426  /// Unlocks/forgets the given input. Returns an invalid handle if
427  /// not wired or not cooked.
428  virtual GU_DetailHandle unloadInput(exint idx, bool flushce) = 0;
429  };
430 
432  {
433  public:
434  InputParms(NodeInputs &inputs, const SOP_NodeParms *parms,
435  UT_ErrorManager *error, DEP_MicroNode *depnode)
436  : myInputs(inputs)
437  , myParms(parms)
438  , myError(error)
439  , myDepNode(depnode)
440  {
441  }
442 
443  virtual ~InputParms() {}
444 
445  NodeInputs &inputs() const { return myInputs; }
446 
447  template <typename T>
448  const T &parms() const
449  { return *UTverify_cast<const T*>(myParms); }
450 
451  UT_ErrorManager *error() const { return myError; }
452 
453  DEP_MicroNode *depnode() const { return myDepNode; }
454 
455  protected:
460  };
461 
462  class CookParms
463  {
464  public:
466  const UT_Array<GU_ConstDetailHandle> &inputs,
467  SOP_CookEngine cookengine,
468  SOP_Node *node,
469  const SOP_NodeParms *parms,
470  SOP_NodeCache *cache,
471  UT_ErrorManager *error,
472  DEP_MicroNode *depnode)
473  : myDestGdh(destgdh)
474  , myInputs(inputs)
475  , myCookEngine(cookengine)
476  , myNode(node)
477  , myParms(parms)
478  , myCache(cache)
479  , myError(error)
480  , myDepNode(depnode)
481  , myCookTime(0)
482  {}
483  virtual ~CookParms() {}
484 
485  /// The initial state of gdh depends on the cookMode()
486  GU_DetailHandle &gdh() const { return myDestGdh; }
487 
488  /// The currently cooking SOP. This is only non-null if in
489  /// the old cook path. When executing compiled nodes it will
490  /// be null as the verb is supposed to operate independently
491  /// of the original SOP.
492  SOP_Node *getNode() const { return (myCookEngine == SOP_COOK_TRADITIONAL) ? myNode : 0; }
493 
494  template <typename T>
495  T *getCookNode() const
496  { if (myCookEngine != SOP_COOK_TRADITIONAL)
497  return 0;
498  return UTverify_cast<T *>(myNode); }
500  { if (myCookEngine != SOP_COOK_TRADITIONAL)
501  return 0;
502  return myCookTime; }
503  void setCookTime(fpreal time) { myCookTime = time; }
504 
505  /// The node that generated this verb, if any...
506  SOP_Node *getSrcNode() const { return myNode; }
507  /// The getCwd() should be used to evaluate relative paths.
508  OP_Node *getCwd() const { if (myNode) return myNode; return OPgetDirector(); }
509 
510  /// Whether the underlying verb manages data ids. All new nodes
511  /// should manage data ids, this is purely for the
512  /// SOP_NodeParmsOptions wrapper.
513  bool getManagesDataIDs() const
514  {
515  if (!myNode) return true;
516  return myNode->getFlags().getManagesDataIDs();
517  }
518 
519  /// Accessors designed to simplify porting from old cook code.
520  /// Just becaues you have nInputs does not mean all are wired or
521  /// cooked. But, the number demanded by your OP_Operator shall
522  /// be present.
523  /// Inputs have been locked & preserve request set
524  exint nInputs() const { return myInputs.size(); }
525  bool hasInput(exint idx) const
526  {
527  if (idx < 0 || idx >= myInputs.size())
528  return false;
529  return myInputs(idx).isValid();
530  }
531  const GU_Detail *inputGeo(exint idx) const
532  {
533  if (!hasInput(idx)) return 0;
534  return myInputs(idx).gdp();
535  }
537  {
538  if (!hasInput(idx)) return GU_ConstDetailHandle();
539  return myInputs(idx);
540  }
541 
542  template <typename T>
543  const T &parms() const
544  { return *UTverify_cast<const T*>(myParms); }
545 
546  /// Cache may, or may not, persist between cooks. But it is
547  /// guaranteed this is the only thread using the cache.
548  SOP_NodeCache *cache() const { return myCache; }
549 
550  UT_ErrorManager *error() const { return myError; }
551  DEP_MicroNode *depnode() const { return myDepNode; }
552 
553  /// Methods to wire directly to the optional depnode.
554  void addExplicitInput(DEP_MicroNode &inp, bool check_dup)
555  { if (myDepNode) myDepNode->addExplicitInput(inp, check_dup); }
557  { addExplicitInput(inp, /*check_dup*/true); }
558 
559  /// Methods to add directly to any present error manager.
560  UT_ErrorSeverity addMessage (const char *type, int code, const char *msg=0,
561  const UT_SourceLocation *loc=0) const
562  { if (myError) return myError->addMessage(type, code, formatError(msg), loc);
563  return UT_ERROR_MESSAGE; }
564  UT_ErrorSeverity addWarning (const char *type, int code, const char *msg=0,
565  const UT_SourceLocation *loc=0) const
566  { if (myError) return myError->addWarning(type, code, formatError(msg), loc);
567  return UT_ERROR_WARNING; }
568  UT_ErrorSeverity addError (const char *type, int code, const char *msg=0,
569  const UT_SourceLocation *loc=0) const
570  { if (myError) return myError->addError(type, code, formatError(msg), loc);
571  return UT_ERROR_ABORT; }
572 
573  UT_ErrorSeverity sopAddMessage (int code, const char *msg=0,
574  const UT_SourceLocation *loc=0) const
575  { return addMessage("SOP", code, msg, loc); }
576  UT_ErrorSeverity sopAddWarning (int code, const char *msg=0,
577  const UT_SourceLocation *loc=0) const
578  { return addWarning("SOP", code, msg, loc); }
579  UT_ErrorSeverity sopAddError (int code, const char *msg=0,
580  const UT_SourceLocation *loc=0) const
581  { return addError("SOP", code, msg, loc); }
582 
584  { if (getNode())
585  getNode()->select(gtype); }
586 
587  void select(GU_SelectionHandle selection,
588  bool add_to_sel = false) const
589  { if (getNode())
590  getNode()->select(selection, add_to_sel); }
591 
592  // Select the group. opt use its type as sel type
593  void select(const GA_Group &group, bool use_gtype = true,
594  bool add_to_sel = false) const
595  { if (getNode())
596  getNode()->select(group, use_gtype, add_to_sel); }
597 
598  void select(const GEO_Primitive &prim, bool sel_prim = true,
599  bool add_to_sel = false) const
600  { if (getNode())
601  getNode()->select(prim, sel_prim, add_to_sel); }
602  void selectPrimitive(GA_Offset primoff, bool prim_sel = true,
603  bool add_to_sel = false) const
604  { if (getNode())
605  getNode()->selectPrimitive(primoff, prim_sel, add_to_sel); }
606  void selectPoint(GA_Offset ptoff, bool point_sel = true,
607  bool add_to_sel = false) const
608  { if (getNode())
609  getNode()->selectPoint(ptoff, point_sel, add_to_sel); }
610  void selectFrom(const GEO_Primitive &prim, bool sel_prim = true,
611  bool add_to_sel = false) const
612  { if (getNode())
613  getNode()->selectFrom(prim, sel_prim, add_to_sel); }
614  void selectPointsFrom(GA_Offset ptoff, bool point_sel = true,
615  bool add_to_sel = false) const
616  { if (getNode())
617  getNode()->selectPointsFrom(ptoff, point_sel, add_to_sel); }
618  void select(const GA_Range &range, bool use_rtype = true,
619  bool add_to_sel = false) const
620  { if (getNode())
621  getNode()->select(range, use_rtype, add_to_sel); }
622 
623  // Selects input based on the group supplied and the group type. If
624  // group is not null, then it's type is used, otherwise the group type
625  // is used.
626  void selectInputGroup(const GA_Group *group,
627  GA_GroupType grouptype) const
628  { if (getNode())
629  getNode()->selectInputGroup(group, grouptype); }
630 
631  // If no selection is present, then create a new empty primitive cook
632  // selection group. Otherwise, clear the selection.
633  void clearSelection() const
634  { if (getNode())
635  getNode()->clearSelection(); }
636 
637  /// If the cook selection group is not of the given type, create an empty
638  /// cook selection group of that type. Otherwise, clear the existing cook
639  /// selection group.
640  void clearSelection(GA_GroupType gtype) const
641  { if (getNode())
642  getNode()->clearSelection(gtype); }
643 
644  // Blow away the selection and reinitialize it to 0. Much more radical
645  // than clearSelection(), which leaves behind a clean, empty selection.
646  // This method returns 1 if it had anything to destroy, else 0.
647  bool destroySelection() const
648  { if (getNode())
649  return getNode()->destroySelection();
650  return false;
651  }
652 
653  // Return 1 if selection is enabled, 0 if false.
654  bool selectionEnabled() const
655  {
656  if (!getNode())
657  return false;
658  return getNode()->getHighlight();
659  }
660 
661  /// Shims for local variables
662  bool setupLocalVars() const
663  { if (getNode()) return getNode()->setupLocalVars(); return false; }
664  void resetLocalVarRefs() const
665  { if (getNode()) getNode()->resetLocalVarRefs(); }
666  void setCurGdh(int index, const GU_DetailHandle &gdh) const
667  { if (getNode()) getNode()->setCurGdh(index, gdh); }
668  void clearCurGdh(int index) const
669  { if (getNode()) getNode()->clearCurGdh(index); }
670  void setCurPoint(int index, GA_Offset off) const
671  { if (getNode()) getNode()->setCurPoint(index, off); }
672  void clearCurPoint(int index) const
673  { if (getNode()) getNode()->clearCurPoint(index); }
674  void setCurVertex(int index, GA_Offset off) const
675  { if (getNode()) getNode()->setCurVertex(index, off); }
676  void clearCurVertex(int index) const
677  { if (getNode()) getNode()->clearCurVertex(index); }
678  void setCurPrim(int index, GA_Offset off) const
679  { if (getNode()) getNode()->setCurPrim(index, off); }
680  void clearCurPrim(int index) const
681  { if (getNode()) getNode()->clearCurPrim(index); }
682  void setCurVertexNum(int index, exint num) const
683  { if (getNode()) getNode()->setCurVertexNum(index, num); }
684  void clearCurVertexNum(int index) const
685  { if (getNode()) getNode()->clearCurVertexNum(index); }
686  void setVariableOrder(int detail, int prim,
687  int pt, int vtx) const
688  { if (getNode()) getNode()->setVariableOrder(detail, prim, pt, vtx); }
689 
690  /// Tracks if any local variables were accessed by op functions.
692  { if (getNode()) getNode()->myUsesSOPLocalVar = false; }
694  { if (!getNode()) return false;
695  return getNode()->myUsesSOPLocalVar; }
696 
697 
698  protected:
699  /// Prefix errors so we can get sensible results.
700  UT_StringHolder formatError(const char *msg) const
701  {
702  // Do not prefix with the path in traditional cook
703  // as it is properly assigned.
704  if (myCookEngine == SOP_COOK_TRADITIONAL)
705  return msg;
706  UT_StringHolder result;
707  if (!msg || !*msg)
708  return result;
710  UT_String fullpath;
711  if (myNode)
712  myNode->getFullPath(fullpath);
713  else
714  fullpath = "<internal>";
715  buf.sprintf("%s: %s", (const char *) fullpath, msg);
716  result = buf;
717  return result;
718  }
719 
728  // Only valid in traditional cook paths:
730 
731  };
732 
733  /// If doPartialInputCook is false, we do assume cookInputs() will
734  /// apply to all inputs regardless of node parameters. If local
735  /// variables require the inputs, it is required for this to be false
736  /// for the inputs to be available when parameters are evaluated.
737  virtual bool doPartialInputCook() const { return false; }
738  virtual bool cookInputs(const InputParms &parms) const
739  {
740  for (exint i = 0; i < parms.inputs().nInputs(); i++)
741  if (parms.inputs().hasInput(i))
742  {
743  if (!parms.inputs().cookInput(i))
744  return false;
745  }
746  return true;
747  }
748 
749  /// These are for the old-cook path to allow nodes to store relevant
750  /// local variable information inside the SOP for callbacks. The
751  /// evalVariableValue() should be guarded to ensure it doesn't
752  /// run from a forbidden node.
753  /// These can be used if the local variables depend only on the inputs
754  /// and are not change for every parameter. If they change for
755  /// every parameter, traditional cook paths will need to setup &
756  /// evaluate explicitly in the cook method.
757  virtual void setupLocalVariables(SOP_Node *sop, const UT_Array<GU_ConstDetailHandle> &inputs) const {}
758  virtual void resetLocalVariables(SOP_Node *sop) const {}
759 
760  /// Traditional nodes may evaluate parameters while cooking, this is
761  /// required for dynamic local variables. If this is true, no pre-cooking
762  /// of the parameter struture will be done in the traditional cook
763  /// path avoiding double cooking parameters. Remember other cook paths
764  /// will not have access to the sop so should use the parameter structure!
765  virtual bool evaluatesParametersDuringCook() const { return false; }
766 
767  virtual CookMode cookMode(const SOP_NodeParms *parms) const { return COOK_DUPLICATE; }
768 
769  /// Attributes can end up cached on the GPU. Some SOPs are able
770  /// to handle this. Some are ambivalent (such as switch or null)
771  /// And some expect all GPU buffers to be flushed prior to
772  /// operating. If a node requires a CE flush, all inputs
773  /// will be clean.
774  virtual bool requiresCEFlush() const { return true; }
775  virtual bool usesCE() const { return false; }
776 
777  /// Compute the output geometry.
778  virtual void cook(const CookParms &cookparms) const = 0;
779 
780  /// This is used to update handles, it only has an effect
781  /// if oldsop is non-null, ie, we are in the old cook path.
782  /// Neither the group nor the gdp have to persist beyond this call.
783  /// Pass -1 for the grouptype if there is no grouptype parameter.
784  void notifyGroupParmListeners(SOP_Node *oldsop,
785  int groupparm_idx,
786  int grouptype_idx,
787  const GU_Detail *gdp,
788  const GA_Group *group) const;
789 
790 protected:
791 };
792 
793 #endif
const OP_Context & myContext
Definition: SOP_NodeVerb.h:168
virtual void getParmValue(exint idx, UT_Matrix3D &value) const
Definition: SOP_NodeVerb.h:217
const T & parms() const
Definition: SOP_NodeVerb.h:448
DEP_MicroNode * depnode() const
Definition: SOP_NodeVerb.h:453
const UT_Array< GU_ConstDetailHandle > & exprinputs() const
Definition: SOP_NodeVerb.h:351
void setCurGdh(int index, const GU_DetailHandle &gdh) const
Definition: SOP_NodeVerb.h:666
static void registerVerb(SOP_NodeVerb *verb)
GLenum GLint * range
Definition: glcorearb.h:1924
SOP_Node * getNode() const
Definition: SOP_NodeVerb.h:492
const ForbiddenNodeMap * myPrevNodes
Definition: SOP_NodeVerb.h:379
bool getManagesDataIDs() const
Definition: SOP_NodeVerb.h:513
LoadParms(SOP_NodeParms *parms, SOP_CookEngine cookengine, const OP_Node *node, const OP_Context &context, SOP_NodeCache *cache, UT_ErrorManager *error, DEP_MicroNode *depnode)
Definition: SOP_NodeVerb.h:86
DEP_MicroNode * depnode() const
Definition: SOP_NodeVerb.h:551
Unsorted map container.
Definition: UT_Map.h:83
UT_ErrorSeverity sopAddMessage(int code, const char *msg=0, const UT_SourceLocation *loc=0) const
Definition: SOP_NodeVerb.h:573
virtual void getParmValue(exint idx, UT_Vector2D &value) const
Definition: SOP_NodeVerb.h:213
virtual void setParmValue(exint idx, const exint &value)
Definition: SOP_NodeVerb.h:223
UT_ErrorSeverity sopAddWarning(int code, const char *msg=0, const UT_SourceLocation *loc=0) const
Definition: SOP_NodeVerb.h:576
SOP_NodeCache * myCache
Definition: SOP_NodeVerb.h:725
void clearCurGdh(int index) const
Definition: SOP_NodeVerb.h:668
virtual void setParmValue(exint idx, const UT_Vector4D &value)
Definition: SOP_NodeVerb.h:227
virtual int hasInput()
void selectPoint(GA_Offset ptoff, bool point_sel=true, bool add_to_sel=false) const
Definition: SOP_NodeVerb.h:606
UT_ErrorSeverity addMessage(const char *type, int code, const char *msg=0, const UT_SourceLocation *loc=0) const
Methods to add directly to any present error manager.
Definition: SOP_NodeVerb.h:560
UT_ErrorSeverity addWarning(const char *type, int code, const char *msg=0, const UT_SourceLocation *loc=0) const
Definition: SOP_NodeVerb.h:124
void clearCurVertexNum(int index) const
Definition: SOP_NodeVerb.h:684
UT_ErrorSeverity addMessage(const char *type, int code, const char *msg=0, const UT_SourceLocation *loc=0) const
Methods to add directly to any present error manager.
Definition: SOP_NodeVerb.h:120
void resetLocalVarRefs() const
Definition: SOP_NodeVerb.h:664
UT_ErrorSeverity
Definition: UT_Error.h:25
UT_Array< GU_ConstDetailHandle > myExprInputs
Definition: SOP_NodeVerb.h:355
OP_Node * getCwd() const
The getCwd() should be used to evaluate relative paths.
Definition: SOP_NodeVerb.h:508
UT_ErrorSeverity sopAddMessage(int code, const char *msg=0, const UT_SourceLocation *loc=0) const
Definition: SOP_NodeVerb.h:133
void select(const GA_Range &range, bool use_rtype=true, bool add_to_sel=false) const
Definition: SOP_NodeVerb.h:618
virtual ParmType getParmType(exint idx) const
Definition: SOP_NodeVerb.h:209
CVEX_Function * myVexFunction
Definition: SOP_NodeVerb.h:70
const UT_Array< GU_ConstDetailHandle > & myInputs
Definition: SOP_NodeVerb.h:722
virtual void setParmValue(exint idx, const UT_Matrix3D &value)
Definition: SOP_NodeVerb.h:229
bool setupLocalVars() const
Shims for local variables.
Definition: SOP_NodeVerb.h:662
virtual void getParmValue(exint idx, UT_Vector4D &value) const
Definition: SOP_NodeVerb.h:215
png_uint_32 i
Definition: png.h:2877
static void unregisterVerb(SOP_NodeVerb *verb)
GU_DetailHandle & myDestGdh
Definition: SOP_NodeVerb.h:721
virtual bool doPartialInputCook() const
Definition: SOP_NodeVerb.h:737
UT_ErrorManager * error() const
Definition: SOP_NodeVerb.h:451
virtual void resetLocalVariables(SOP_Node *sop) const
Definition: SOP_NodeVerb.h:758
UT_StringHolder myVEXpression
Definition: SOP_NodeVerb.h:71
UT_ErrorManager * error() const
Definition: SOP_NodeVerb.h:110
Call VEX from C++.
Definition: CVEX_Context.h:147
void clearCurPoint(int index) const
Definition: SOP_NodeVerb.h:672
UT_ErrorSeverity sopAddError(int code, const char *msg=0, const UT_SourceLocation *loc=0) const
Definition: SOP_NodeVerb.h:579
A range of elements in an index-map.
Definition: GA_Range.h:42
DEP_MicroNode * myDepNode
Definition: SOP_NodeVerb.h:727
const SOP_NodeParms * myParms
Definition: SOP_NodeVerb.h:457
virtual void setParmValue(exint idx, const UT_Vector2D &value)
Definition: SOP_NodeVerb.h:225
GA_Size GA_Offset
Definition: GA_Types.h:617
virtual void getParmValue(exint idx, PRM_DataItemHandle &value) const
Definition: SOP_NodeVerb.h:221
virtual void getParmValue(exint idx, UT_Matrix4D &value) const
Definition: SOP_NodeVerb.h:218
virtual void getParmValue(exint idx, fpreal &value) const
Definition: SOP_NodeVerb.h:212
UT_ErrorSeverity addError(const char *type, int code, const char *msg=0, const UT_SourceLocation *loc=0) const
Definition: SOP_NodeVerb.h:128
long long int64
Definition: SYS_Types.h:100
GU_ConstDetailHandle inputGeoHandle(exint idx) const
Definition: SOP_NodeVerb.h:536
const T & parms() const
Definition: SOP_NodeVerb.h:543
const SOP_NodeParms * myParms
Definition: SOP_NodeVerb.h:724
virtual void setupLocalVariables(SOP_Node *sop, const UT_Array< GU_ConstDetailHandle > &inputs) const
Definition: SOP_NodeVerb.h:757
T * getCookNode() const
Definition: SOP_NodeVerb.h:495
const OP_Node * myNode
Definition: SOP_NodeVerb.h:167
void selectPrimitive(GA_Offset primoff, bool prim_sel=true, bool add_to_sel=false) const
Definition: SOP_NodeVerb.h:602
virtual void setParmValue(exint idx, const UT_SharedPtr< UT_Ramp > &value)
Definition: SOP_NodeVerb.h:232
void setCurPrim(int index, GA_Offset off) const
Definition: SOP_NodeVerb.h:678
UT_ErrorManager * myError
Definition: SOP_NodeVerb.h:458
CVEX_Context * myVexContext
Definition: SOP_NodeVerb.h:69
bool destroySelection() const
Definition: SOP_NodeVerb.h:647
UT_Array< UT_StringHolder > stringdata
Definition: SOP_NodeVerb.h:41
void select(GU_SelectionHandle selection, bool add_to_sel=false) const
Definition: SOP_NodeVerb.h:587
virtual void setParmValue(exint idx, const fpreal &value)
Definition: SOP_NodeVerb.h:224
void addExplicitInput(DEP_MicroNode &inp)
Definition: SOP_NodeVerb.h:116
int64 exint
Definition: SYS_Types.h:109
void addExplicitInput(DEP_MicroNode &inp, bool check_dup)
Methods to wire directly to the optional depnode.
Definition: SOP_NodeVerb.h:554
virtual exint nInputs() const =0
void selectFrom(const GEO_Primitive &prim, bool sel_prim=true, bool add_to_sel=false) const
Definition: SOP_NodeVerb.h:610
const OP_Node * node() const
Definition: SOP_NodeVerb.h:104
UT_ErrorManager * myError
Definition: SOP_NodeVerb.h:170
void clearSelection() const
Definition: SOP_NodeVerb.h:633
virtual bool usesCE() const
Definition: SOP_NodeVerb.h:775
SOP_Node * getSrcNode() const
The node that generated this verb, if any...
Definition: SOP_NodeVerb.h:506
virtual void setParmValue(exint idx, const UT_Matrix2D &value)
Definition: SOP_NodeVerb.h:228
void setCurPoint(int index, GA_Offset off) const
Definition: SOP_NodeVerb.h:670
UT_Array< SOP_CVEXDataBacking > myWriteBacking
Definition: SOP_NodeVerb.h:73
void selectInputGroup(const GA_Group *group, GA_GroupType grouptype) const
Definition: SOP_NodeVerb.h:626
const UT_IntArray & timedeps() const
Definition: SOP_NodeVerb.h:352
virtual exint getNumParms() const
Definition: SOP_NodeVerb.h:207
void setCookTime(fpreal time)
Definition: SOP_NodeVerb.h:503
void setExprInputs(const UT_Array< GU_ConstDetailHandle > &inputs, const UT_IntArray &timedeps)
Definition: SOP_NodeVerb.h:345
virtual bool hasInput(exint idx) const =0
Returns if the input is wired.
virtual SOP_NodeCache * allocCache() const
Definition: SOP_NodeVerb.h:324
void selectPointsFrom(GA_Offset ptoff, bool point_sel=true, bool add_to_sel=false) const
Definition: SOP_NodeVerb.h:614
UT_ErrorSeverity sopAddError(int code, const char *msg=0, const UT_SourceLocation *loc=0) const
Definition: SOP_NodeVerb.h:139
void clearCurPrim(int index) const
Definition: SOP_NodeVerb.h:680
virtual void setParmValue(exint idx, const UT_Vector3D &value)
Definition: SOP_NodeVerb.h:226
SOP_CookEngine
Definition: SOP_NodeVerb.h:44
virtual void getParmValue(exint idx, exint &value) const
Definition: SOP_NodeVerb.h:211
GLuint const GLchar * name
Definition: glcorearb.h:785
virtual ~SOP_NodeParms()
Definition: SOP_NodeVerb.h:81
int int32
Definition: SYS_Types.h:28
SYS_FORCE_INLINE TO_T UTverify_cast(FROM_T from)
Definition: UT_Assert.h:175
virtual bool evaluatesParametersDuringCook() const
Definition: SOP_NodeVerb.h:765
virtual void getParmValue(exint idx, UT_Vector3D &value) const
Definition: SOP_NodeVerb.h:214
void setCurVertexNum(int index, exint num) const
Definition: SOP_NodeVerb.h:682
void select(GA_GroupType gtype=GA_GROUP_PRIMITIVE) const
Definition: SOP_NodeVerb.h:583
virtual bool cookInputs(const InputParms &parms) const
Definition: SOP_NodeVerb.h:738
UT_ErrorManager * error() const
Definition: SOP_NodeVerb.h:550
bool hasInput(exint idx) const
Definition: SOP_NodeVerb.h:525
int sprintf(const char *fmt,...) SYS_PRINTF_CHECK_ATTRIBUTE(2
virtual ~SOP_NodeVerb()
Definition: SOP_NodeVerb.h:300
DEP_MicroNode * depnode() const
Definition: SOP_NodeVerb.h:111
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:2539
void select(const GEO_Primitive &prim, bool sel_prim=true, bool add_to_sel=false) const
Definition: SOP_NodeVerb.h:598
UT_ErrorSeverity addWarning(const char *type, int code, const char *msg=0, const UT_SourceLocation *loc=0) const
Definition: SOP_NodeVerb.h:564
GLsizei const GLfloat * value
Definition: glcorearb.h:823
void setCurVertex(int index, GA_Offset off) const
Definition: SOP_NodeVerb.h:674
double fpreal
Definition: SYS_Types.h:263
void addExplicitInput(DEP_MicroNode &inp)
Definition: SOP_NodeVerb.h:556
UT_Array< SOP_CVEXDataBacking > myReadBacking
Definition: SOP_NodeVerb.h:72
void select(const GA_Group &group, bool use_gtype=true, bool add_to_sel=false) const
Definition: SOP_NodeVerb.h:593
A class holding a VEX function.
Definition: CVEX_Function.h:26
SOP_NodeCache * cache() const
Definition: SOP_NodeVerb.h:108
OP_API OP_Director * OPgetDirector()
bool selectionEnabled() const
Definition: SOP_NodeVerb.h:654
DEP_MicroNode * myDepNode
Definition: SOP_NodeVerb.h:459
UT_ErrorSeverity addError(const char *type, int code, const char *msg=0, const UT_SourceLocation *loc=0) const
Definition: SOP_NodeVerb.h:568
GA_GroupType
An ordinal enum for the different types of groups in GA.
Definition: GA_Types.h:138
GLuint index
Definition: glcorearb.h:785
virtual const char * getParmName(exint idx) const
Definition: SOP_NodeVerb.h:208
UT_Map< const OP_Node *, NodeExecuteInfo > ForbiddenNodeMap
Definition: SOP_NodeVerb.h:359
UT_StringHolder formatError(const char *msg) const
Prefix errors so we can get sensible results.
Definition: SOP_NodeVerb.h:700
int64 getMemoryUsage(bool inclusive) const
Definition: SOP_NodeVerb.h:31
A global error manager scope.
void resetLocalVariableAccessed() const
Tracks if any local variables were accessed by op functions.
Definition: SOP_NodeVerb.h:691
#define SOP_API
Definition: SOP_API.h:10
InputParms(NodeInputs &inputs, const SOP_NodeParms *parms, UT_ErrorManager *error, DEP_MicroNode *depnode)
Definition: SOP_NodeVerb.h:434
const GU_Detail * inputGeo(exint idx) const
Definition: SOP_NodeVerb.h:531
void setVariableOrder(int detail, int prim, int pt, int vtx) const
Definition: SOP_NodeVerb.h:686
void clearCurVertex(int index) const
Definition: SOP_NodeVerb.h:676
virtual bool cookInput(exint idx)=0
SOP_NodeCache * cache() const
Definition: SOP_NodeVerb.h:548
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
UT_StringHolder formatError(const char *msg) const
Prefix errors so we can get sensible results.
Definition: SOP_NodeVerb.h:145
fpreal getCookTime() const
Definition: SOP_NodeVerb.h:499
virtual void setParmValue(exint idx, const UT_StringHolder &value)
Definition: SOP_NodeVerb.h:231
virtual void setParmValue(exint idx, const UT_Matrix4D &value)
Definition: SOP_NodeVerb.h:230
void clearSelection(GA_GroupType gtype) const
Definition: SOP_NodeVerb.h:640
png_infop png_uint_32 int num
Definition: png.h:2158
const T & parms() const
Definition: SOP_NodeVerb.h:106
NodeInputs & inputs() const
Definition: SOP_NodeVerb.h:445
virtual void getParmValue(exint idx, UT_SharedPtr< UT_Ramp > &value) const
Definition: SOP_NodeVerb.h:220
SOP_NodeCache * myCache
Definition: SOP_NodeVerb.h:169
bool wasLocalVariableAccessed() const
Definition: SOP_NodeVerb.h:693
virtual bool requiresCEFlush() const
Definition: SOP_NodeVerb.h:774
virtual void getParmValue(exint idx, UT_Matrix2D &value) const
Definition: SOP_NodeVerb.h:216
UT_ErrorSeverity sopAddWarning(int code, const char *msg=0, const UT_SourceLocation *loc=0) const
Definition: SOP_NodeVerb.h:136
void coerceValue(T &result, const S &src) const
Definition: SOP_NodeVerb.h:240
CookParms(GU_DetailHandle &destgdh, const UT_Array< GU_ConstDetailHandle > &inputs, SOP_CookEngine cookengine, SOP_Node *node, const SOP_NodeParms *parms, SOP_NodeCache *cache, UT_ErrorManager *error, DEP_MicroNode *depnode)
Definition: SOP_NodeVerb.h:465
exint nInputs() const
Definition: SOP_NodeVerb.h:524
SOP_NodeParms * myParms
Definition: SOP_NodeVerb.h:166
float fpreal32
Definition: SYS_Types.h:184
const OP_Context & context() const
Definition: SOP_NodeVerb.h:109
virtual void setParmValue(exint idx, const PRM_DataItemHandle &value)
Definition: SOP_NodeVerb.h:233
virtual CookMode cookMode(const SOP_NodeParms *parms) const
Definition: SOP_NodeVerb.h:767
void addExplicitInput(DEP_MicroNode &inp, bool check_dup)
Methods to wire directly to the optional depnode.
Definition: SOP_NodeVerb.h:114
GU_DetailHandle & gdh() const
The initial state of gdh depends on the cookMode()
Definition: SOP_NodeVerb.h:486
UT_ErrorManager * myError
Definition: SOP_NodeVerb.h:726
virtual void copyFrom(const SOP_NodeParms *src)
Definition: SOP_NodeVerb.h:186
DEP_MicroNode * myDepNode
Definition: SOP_NodeVerb.h:171
GLenum src
Definition: glcorearb.h:1792
virtual void getParmValue(exint idx, UT_StringHolder &value) const
Definition: SOP_NodeVerb.h:219