HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
COP2_Python.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  * COMMENTS:
7  */
8 
9 #ifndef __COP2_Python_h__
10 #define __COP2_Python_h__
11 
12 #include "COP2_API.h"
13 #include "COP2_Node.h"
14 #include "COP2_Error.h"
15 #include <PY/PY_Result.h>
16 #include <UT/UT_Tuple.h>
17 #include <vector>
18 
20 class OP_OTLDefinition;
21 class OP_ScriptOperator;
22 
24 {
25 public:
26  ~COP2_Python() override;
27 
28  static OP_ScriptOperator *createScriptOperator(
29  const OP_OTLDefinition &definition);
30 
31  static OP_Node *myConstructor(
32  OP_Network *network, const char *name, OP_Operator *op_type);
33 
35  COP2_Context &, int &maxp, int &maxn, int &op) const override;
36 
38 
40  COP2_CookAreaInfo &output_area,
41  const COP2_CookAreaList &input_areas,
42  COP2_CookAreaList &needed_areas) override;
43 
44  bool isTimeModifier() const override;
45  float copTimeTransform(
46  int input, COP2_Context &context, float time) override;
47 
48  bool isSlowOperation() const override;
49 
50  // These methods are used by HOMF_Cop2Node:
51  bool isCookingThisNode() const
52  { return myCookContext != NULL; }
53 
54  TIL_DataFormat formatOfCookingPlane() const;
55 
56  bool getInputPlaneWhileCookingFromPython(
57  std::vector<float> &result, int input_index, const char *plane_name,
58  const char *component, bool interleaved, UT_WorkBuffer &error_message);
59 
60  // If til_format is null, the input plane will be retrieved in the same
61  // format as the currently cooking plane.
62  bool getInputPlaneWhileCookingFromPython(
63  std::string &result, int input_index, const char *plane_name,
64  const char *component, const TIL_DataFormat *til_format,
65  bool interleaved, UT_WorkBuffer &error_message);
66 
67  bool setOutputPlaneWhileCookingFromPython(
68  const void *values, TIL_DataFormat til_format, int64 num_values,
69  const char *component, bool interleaved, bool flip_vertically,
70  UT_WorkBuffer &error_message);
71 
72 protected:
73  void computeImageBounds(COP2_Context &context) override;
74  OP_ERROR cookMyTile(COP2_Context &context, TIL_TileList *tiles) override;
75 
76 private:
77  COP2_Python(OP_Network *parent, const char *name, OP_Operator *entry);
78 
79  void copySequenceInfoFromFirstInput();
80  void matchFrameRangeOfInputs();
81  float timeToCookInput(int input_index, float time);
82 
83  TIL_DataFormat runPythonToOverrideDepth(const TIL_Plane &output_plane);
84  void runPythonToGetPlanesToCook();
85  TIL_Plane *addPlaneToSequence(const char *name);
86  void runPythonToOverrideFrameRange();
87  void runPythonToOverrideResolution();
88 
89  void buildRequiredInputPlanes();
90  void runPythonToGetRequiredInputPlanes(const TIL_Plane &output_plane);
91 
92  void cookUsingPython(COP2_Context &context, TIL_Region &output_region);
93  void clearComponentsNotWrittenTo();
94 
95  bool runFunctionInsidePythonCookCode(
96  const char *function_name, const char *parms_tuple,
97  PY_Result::Type desired_result_type, PY_Result &result,
98  float *time = NULL);
99  bool hasFunctionInsidePythonCookCode(const char *function_name);
100  bool ensurePythonCookCodeHasRun();
101 
102  bool isValidInputPlaneForOutputPlane(
103  const char *output_plane_name,
104  int input_index,
105  const char *input_plane_name);
106 
107  template <typename T>
108  bool templatedGetInputPlaneWhileCookingFromPython(
109  T &result, int input_index, const char *plane_name,
110  const char *component, TIL_DataFormat til_format, bool interleaved,
111  UT_WorkBuffer &error_message);
112 
113  void addPythonError(const char *message,
115  void addPythonWarning(const char *message,
117  UT_String houNodeExpression();
118 
119  class PlaneToCook
120  {
121  public:
122  PlaneToCook()
123  : myFormat(TILE_FLOAT32)
124  {}
125 
126  std::vector<UT_Tuple<int, std::string> > myInputIndicesAndPlanes;
127  TIL_DataFormat myFormat;
128  };
129 
130  PY_EvaluationContext *myPythonContext;
131  std::map<std::string, PlaneToCook> myPlanesToCook;
132  COP2_Context *myCookContext;
133  TIL_Region *myCookOutputRegion;
134  bool myCookPlaneComponentsWritten[PLANE_MAX_VECTOR_SIZE];
135  UT_Lock myCookLock;
136 };
137 
138 #endif
GLuint GLsizei const GLchar * message
Definition: glcorearb.h:2543
virtual bool isSlowOperation() const
Definition: COP2_Node.h:378
#define TILE_FLOAT32
Definition: TIL_Defines.h:69
GT_API const UT_StringHolder time
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
UT_ErrorSeverity
Definition: UT_Error.h:25
**But if you need a result
Definition: thread.h:613
< returns > If no error
Definition: snippets.dox:2
#define TIL_DataFormat
Definition: TIL_Defines.h:65
virtual OP_ERROR cookMyTile(COP2_Context &context, TIL_TileList *tiles)
virtual void getMaxNumThreadsInCook(COP2_Context &, int &plane, int &node, int &op) const
Definition: COP2_Node.h:551
#define PLANE_MAX_VECTOR_SIZE
Definition: TIL_Defines.h:167
long long int64
Definition: SYS_Types.h:116
GLuint const GLchar * name
Definition: glcorearb.h:786
virtual bool isTimeModifier() const
Definition: COP2_Node.h:374
bool isCookingThisNode() const
Definition: COP2_Python.h:51
virtual void computeImageBounds(COP2_Context &context)
#define COP2_API
Definition: COP2_API.h:10
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1602
virtual void getInputDependenciesForOutputArea(COP2_CookAreaInfo &output_area, const COP2_CookAreaList &input_areas, COP2_CookAreaList &needed_areas)
COP2_ErrorCodes
Definition: COP2_Error.h:16
virtual TIL_Sequence * cookSequenceInfo(OP_ERROR &error)=0