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