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 <UT/UT_Tuple.h>
16 #include <vector>
17 
19 class OP_OTLDefinition;
20 class OP_ScriptOperator;
21 
23 {
24 public:
25  ~COP2_Python() override;
26 
27  static OP_ScriptOperator *createScriptOperator(
28  const OP_OTLDefinition &definition);
29 
30  static OP_Node *myConstructor(
31  OP_Network *network, const char *name, OP_Operator *op_type);
32 
34  COP2_Context &, int &maxp, int &maxn, int &op) const override;
35 
37 
39  COP2_CookAreaInfo &output_area,
40  const COP2_CookAreaList &input_areas,
41  COP2_CookAreaList &needed_areas) override;
42 
43  bool isTimeModifier() const override;
44  float copTimeTransform(
45  int input, COP2_Context &context, float time) override;
46 
47  bool isSlowOperation() const override;
48 
49  // These methods are used by HOMF_CopNode:
50  bool isCookingThisNode() const
51  { return myCookContext != NULL; }
52 
53  TIL_DataFormat formatOfCookingPlane() const;
54 
55  bool getInputPlaneWhileCookingFromPython(
56  std::vector<float> &result, int input_index, const char *plane_name,
57  const char *component, bool interleaved, UT_WorkBuffer &error_message);
58 
59  // If til_format is null, the input plane will be retrieved in the same
60  // format as the currently cooking plane.
61  bool getInputPlaneWhileCookingFromPython(
62  std::string &result, int input_index, const char *plane_name,
63  const char *component, const TIL_DataFormat *til_format,
64  bool interleaved, UT_WorkBuffer &error_message);
65 
66  bool setOutputPlaneWhileCookingFromPython(
67  const void *values, TIL_DataFormat til_format, int64 num_values,
68  const char *component, bool interleaved, bool flip_vertically,
69  UT_WorkBuffer &error_message);
70 
71 protected:
72  void computeImageBounds(COP2_Context &context) override;
73  OP_ERROR cookMyTile(COP2_Context &context, TIL_TileList *tiles) override;
74 
75 private:
76  COP2_Python(OP_Network *parent, const char *name, OP_Operator *entry);
77 
78  void copySequenceInfoFromFirstInput();
79  void matchFrameRangeOfInputs();
80  float timeToCookInput(int input_index, float time);
81 
82  TIL_DataFormat runPythonToOverrideDepth(const TIL_Plane &output_plane);
83  void runPythonToGetPlanesToCook();
84  TIL_Plane *addPlaneToSequence(const char *name);
85  void runPythonToOverrideFrameRange();
86  void runPythonToOverrideResolution();
87 
88  void buildRequiredInputPlanes();
89  void runPythonToGetRequiredInputPlanes(const TIL_Plane &output_plane);
90 
91  void cookUsingPython(COP2_Context &context, TIL_Region &output_region);
92  void clearComponentsNotWrittenTo();
93 
94  bool runFunctionInsidePythonCookCode(
95  const char *function_name, const char *parms_tuple,
96  PY_Result::Type desired_result_type, PY_Result &result,
97  float *time = NULL);
98  bool hasFunctionInsidePythonCookCode(const char *function_name);
99  bool ensurePythonCookCodeHasRun();
100 
101  bool isValidInputPlaneForOutputPlane(
102  const char *output_plane_name,
103  int input_index,
104  const char *input_plane_name);
105 
106  template <typename T>
107  bool templatedGetInputPlaneWhileCookingFromPython(
108  T &result, int input_index, const char *plane_name,
109  const char *component, TIL_DataFormat til_format, bool interleaved,
110  UT_WorkBuffer &error_message);
111 
112  void addPythonError(const char *message,
114  void addPythonWarning(const char *message,
116  UT_String houNodeExpression();
117 
118  class PlaneToCook
119  {
120  public:
121  PlaneToCook()
122  : myFormat(TILE_FLOAT32)
123  {}
124 
125  std::vector<UT_Tuple<int, std::string> > myInputIndicesAndPlanes;
126  TIL_DataFormat myFormat;
127  };
128 
129  PY_EvaluationContext *myPythonContext;
130  std::map<std::string, PlaneToCook> myPlanesToCook;
131  COP2_Context *myCookContext;
132  TIL_Region *myCookOutputRegion;
133  bool myCookPlaneComponentsWritten[PLANE_MAX_VECTOR_SIZE];
134  UT_Lock myCookLock;
135 };
136 
137 #endif
GLuint GLsizei const GLchar * message
Definition: glcorearb.h:2542
virtual bool isSlowOperation() const
Definition: COP2_Node.h:352
#define TILE_FLOAT32
Definition: TIL_Defines.h:68
GT_API const UT_StringHolder time
GLenum GLenum GLenum input
Definition: glew.h:14162
UT_ErrorSeverity
Definition: UT_Error.h:25
GLuint const GLchar * name
Definition: glcorearb.h:785
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1601
GLuint64EXT * result
Definition: glew.h:14311
#define TIL_DataFormat
Definition: TIL_Defines.h:64
virtual OP_ERROR cookMyTile(COP2_Context &context, TIL_TileList *tiles)
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
virtual void getMaxNumThreadsInCook(COP2_Context &, int &plane, int &node, int &op) const
Definition: COP2_Node.h:525
#define PLANE_MAX_VECTOR_SIZE
Definition: TIL_Defines.h:156
long long int64
Definition: SYS_Types.h:116
virtual bool isTimeModifier() const
Definition: COP2_Node.h:348
bool isCookingThisNode() const
Definition: COP2_Python.h:50
virtual void computeImageBounds(COP2_Context &context)
#define COP2_API
Definition: COP2_API.h:10
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