Blender  V3.3
BPy_IntegrationType.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include "BPy_IntegrationType.h"
8 
9 #include "BPy_Convert.h"
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 using namespace Freestyle;
20 
22 
23 //------------------------ MODULE FUNCTIONS ----------------------------------
24 
25 PyDoc_STRVAR(Integrator_integrate_doc,
26  ".. function:: integrate(func, it, it_end, integration_type)\n"
27  "\n"
28  " Returns a single value from a set of values evaluated at each 0D\n"
29  " element of this 1D element.\n"
30  "\n"
31  " :arg func: The UnaryFunction0D used to compute a value at each\n"
32  " Interface0D.\n"
33  " :type func: :class:`UnaryFunction0D`\n"
34  " :arg it: The Interface0DIterator used to iterate over the 0D\n"
35  " elements of this 1D element. The integration will occur over\n"
36  " the 0D elements starting from the one pointed by it.\n"
37  " :type it: :class:`Interface0DIterator`\n"
38  " :arg it_end: The Interface0DIterator pointing the end of the 0D\n"
39  " elements of the 1D element.\n"
40  " :type it_end: :class:`Interface0DIterator`\n"
41  " :arg integration_type: The integration method used to compute a\n"
42  " single value from a set of values.\n"
43  " :type integration_type: :class:`IntegrationType`\n"
44  " :return: The single value obtained for the 1D element. The return\n"
45  " value type is float if func is of the :class:`UnaryFunction0DDouble`\n"
46  " or :class:`UnaryFunction0DFloat` type, and int if func is of the\n"
47  " :class:`UnaryFunction0DUnsigned` type.\n"
48  " :rtype: int or float");
49 
50 static PyObject *Integrator_integrate(PyObject * /*self*/, PyObject *args, PyObject *kwds)
51 {
52  static const char *kwlist[] = {"func", "it", "it_end", "integration_type", nullptr};
53  PyObject *obj1, *obj4 = nullptr;
54  BPy_Interface0DIterator *obj2, *obj3;
55 
56  if (!PyArg_ParseTupleAndKeywords(args,
57  kwds,
58  "O!O!O!|O!",
59  (char **)kwlist,
61  &obj1,
63  &obj2,
65  &obj3,
67  &obj4)) {
68  return nullptr;
69  }
70 
71  Interface0DIterator it(*(obj2->if0D_it)), it_end(*(obj3->if0D_it));
73 
75  UnaryFunction0D<double> *fun = ((BPy_UnaryFunction0DDouble *)obj1)->uf0D_double;
76  double res = integrate(*fun, it, it_end, t);
77  return PyFloat_FromDouble(res);
78  }
80  UnaryFunction0D<float> *fun = ((BPy_UnaryFunction0DFloat *)obj1)->uf0D_float;
81  float res = integrate(*fun, it, it_end, t);
82  return PyFloat_FromDouble(res);
83  }
85  UnaryFunction0D<unsigned int> *fun = ((BPy_UnaryFunction0DUnsigned *)obj1)->uf0D_unsigned;
86  unsigned int res = integrate(*fun, it, it_end, t);
87  return PyLong_FromLong(res);
88  }
89 
90  string class_name(Py_TYPE(obj1)->tp_name);
91  PyErr_SetString(PyExc_TypeError, ("unsupported function type: " + class_name).c_str());
92  return nullptr;
93 }
94 
95 /*-----------------------Integrator module docstring---------------------------------------*/
96 
97 PyDoc_STRVAR(module_docstring, "The Blender Freestyle.Integrator submodule\n\n");
98 
99 /*-----------------------Integrator module functions definitions---------------------------*/
100 
101 static PyMethodDef module_functions[] = {
102  {"integrate",
103  (PyCFunction)Integrator_integrate,
104  METH_VARARGS | METH_KEYWORDS,
105  Integrator_integrate_doc},
106  {nullptr, nullptr, 0, nullptr},
107 };
108 
109 /*-----------------------Integrator module definition--------------------------------------*/
110 
111 static PyModuleDef module_definition = {
112  PyModuleDef_HEAD_INIT,
113  "Freestyle.Integrator",
115  -1,
117 };
118 
119 /*-----------------------BPy_IntegrationType type definition ------------------------------*/
120 
121 PyDoc_STRVAR(IntegrationType_doc,
122  "Class hierarchy: int > :class:`IntegrationType`\n"
123  "\n"
124  "Different integration methods that can be invoked to integrate into a\n"
125  "single value the set of values obtained from each 0D element of an 1D\n"
126  "element:\n"
127  "\n"
128  "* IntegrationType.MEAN: The value computed for the 1D element is the\n"
129  " mean of the values obtained for the 0D elements.\n"
130  "* IntegrationType.MIN: The value computed for the 1D element is the\n"
131  " minimum of the values obtained for the 0D elements.\n"
132  "* IntegrationType.MAX: The value computed for the 1D element is the\n"
133  " maximum of the values obtained for the 0D elements.\n"
134  "* IntegrationType.FIRST: The value computed for the 1D element is the\n"
135  " first of the values obtained for the 0D elements.\n"
136  "* IntegrationType.LAST: The value computed for the 1D element is the\n"
137  " last of the values obtained for the 0D elements.");
138 
139 PyTypeObject IntegrationType_Type = {
140  PyVarObject_HEAD_INIT(nullptr, 0) "IntegrationType", /* tp_name */
141  sizeof(PyLongObject), /* tp_basicsize */
142  0, /* tp_itemsize */
143  nullptr, /* tp_dealloc */
144  0, /* tp_vectorcall_offset */
145  nullptr, /* tp_getattr */
146  nullptr, /* tp_setattr */
147  nullptr, /* tp_reserved */
148  nullptr, /* tp_repr */
149  nullptr, /* tp_as_number */
150  nullptr, /* tp_as_sequence */
151  nullptr, /* tp_as_mapping */
152  nullptr, /* tp_hash */
153  nullptr, /* tp_call */
154  nullptr, /* tp_str */
155  nullptr, /* tp_getattro */
156  nullptr, /* tp_setattro */
157  nullptr, /* tp_as_buffer */
158  Py_TPFLAGS_DEFAULT, /* tp_flags */
159  IntegrationType_doc, /* tp_doc */
160  nullptr, /* tp_traverse */
161  nullptr, /* tp_clear */
162  nullptr, /* tp_richcompare */
163  0, /* tp_weaklistoffset */
164  nullptr, /* tp_iter */
165  nullptr, /* tp_iternext */
166  nullptr, /* tp_methods */
167  nullptr, /* tp_members */
168  nullptr, /* tp_getset */
169  &PyLong_Type, /* tp_base */
170  nullptr, /* tp_dict */
171  nullptr, /* tp_descr_get */
172  nullptr, /* tp_descr_set */
173  0, /* tp_dictoffset */
174  nullptr, /* tp_init */
175  nullptr, /* tp_alloc */
176  nullptr, /* tp_new */
177 };
178 
179 /*-----------------------BPy_IntegrationType instance definitions -------------------------*/
180 
181 static PyLongObject _IntegrationType_MEAN = {
182  PyVarObject_HEAD_INIT(&IntegrationType_Type, 1){MEAN}};
183 static PyLongObject _IntegrationType_MIN = {PyVarObject_HEAD_INIT(&IntegrationType_Type, 1){MIN}};
184 static PyLongObject _IntegrationType_MAX = {PyVarObject_HEAD_INIT(&IntegrationType_Type, 1){MAX}};
185 static PyLongObject _IntegrationType_FIRST = {
186  PyVarObject_HEAD_INIT(&IntegrationType_Type, 1){FIRST}};
187 static PyLongObject _IntegrationType_LAST = {
188  PyVarObject_HEAD_INIT(&IntegrationType_Type, 1){LAST}};
189 
190 #define BPy_IntegrationType_MEAN ((PyObject *)&_IntegrationType_MEAN)
191 #define BPy_IntegrationType_MIN ((PyObject *)&_IntegrationType_MIN)
192 #define BPy_IntegrationType_MAX ((PyObject *)&_IntegrationType_MAX)
193 #define BPy_IntegrationType_FIRST ((PyObject *)&_IntegrationType_FIRST)
194 #define BPy_IntegrationType_LAST ((PyObject *)&_IntegrationType_LAST)
195 
196 //-------------------MODULE INITIALIZATION--------------------------------
198 {
199  PyObject *m, *d, *f;
200 
201  if (module == nullptr) {
202  return -1;
203  }
204 
205  if (PyType_Ready(&IntegrationType_Type) < 0) {
206  return -1;
207  }
208  Py_INCREF(&IntegrationType_Type);
209  PyModule_AddObject(module, "IntegrationType", (PyObject *)&IntegrationType_Type);
210 
211  PyDict_SetItemString(IntegrationType_Type.tp_dict, "MEAN", BPy_IntegrationType_MEAN);
212  PyDict_SetItemString(IntegrationType_Type.tp_dict, "MIN", BPy_IntegrationType_MIN);
213  PyDict_SetItemString(IntegrationType_Type.tp_dict, "MAX", BPy_IntegrationType_MAX);
214  PyDict_SetItemString(IntegrationType_Type.tp_dict, "FIRST", BPy_IntegrationType_FIRST);
215  PyDict_SetItemString(IntegrationType_Type.tp_dict, "LAST", BPy_IntegrationType_LAST);
216 
217  m = PyModule_Create(&module_definition);
218  if (m == nullptr) {
219  return -1;
220  }
221  Py_INCREF(m);
222  PyModule_AddObject(module, "Integrator", m);
223 
224  // from Integrator import *
225  d = PyModule_GetDict(m);
226  for (PyMethodDef *p = module_functions; p->ml_name; p++) {
227  f = PyDict_GetItemString(d, p->ml_name);
228  Py_INCREF(f);
229  PyModule_AddObject(module, p->ml_name, f);
230  }
231 
232  return 0;
233 }
234 
236 
237 #ifdef __cplusplus
238 }
239 #endif
static char module_docstring[]
IntegrationType IntegrationType_from_BPy_IntegrationType(PyObject *obj)
static PyLongObject _IntegrationType_MEAN
PyTypeObject IntegrationType_Type
int IntegrationType_Init(PyObject *module)
#define BPy_IntegrationType_MIN
static PyModuleDef module_definition
static PyLongObject _IntegrationType_MIN
static PyLongObject _IntegrationType_MAX
#define BPy_IntegrationType_FIRST
static PyLongObject _IntegrationType_FIRST
#define BPy_IntegrationType_MAX
PyDoc_STRVAR(Integrator_integrate_doc, ".. function:: integrate(func, it, it_end, integration_type)\n" "\n" " Returns a single value from a set of values evaluated at each 0D\n" " element of this 1D element.\n" "\n" " :arg func: The UnaryFunction0D used to compute a value at each\n" " Interface0D.\n" " :type func: :class:`UnaryFunction0D`\n" " :arg it: The Interface0DIterator used to iterate over the 0D\n" " elements of this 1D element. The integration will occur over\n" " the 0D elements starting from the one pointed by it.\n" " :type it: :class:`Interface0DIterator`\n" " :arg it_end: The Interface0DIterator pointing the end of the 0D\n" " elements of the 1D element.\n" " :type it_end: :class:`Interface0DIterator`\n" " :arg integration_type: The integration method used to compute a\n" " single value from a set of values.\n" " :type integration_type: :class:`IntegrationType`\n" " :return: The single value obtained for the 1D element. The return\n" " value type is float if func is of the :class:`UnaryFunction0DDouble`\n" " or :class:`UnaryFunction0DFloat` type, and int if func is of the\n" " :class:`UnaryFunction0DUnsigned` type.\n" " :rtype: int or float")
static PyObject * Integrator_integrate(PyObject *, PyObject *args, PyObject *kwds)
#define BPy_IntegrationType_LAST
static PyLongObject _IntegrationType_LAST
static PyMethodDef module_functions[]
#define BPy_IntegrationType_MEAN
PyTypeObject Interface0DIterator_Type
#define BPy_UnaryFunction0DDouble_Check(v)
#define BPy_UnaryFunction0DFloat_Check(v)
#define BPy_UnaryFunction0DUnsigned_Check(v)
PyTypeObject UnaryFunction0D_Type
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
inherits from class Rep
Definition: AppCanvas.cpp:18
T integrate(UnaryFunction0D< T > &fun, Interface0DIterator it, Interface0DIterator it_end, IntegrationType integration_type=MEAN)
Definition: Interface1D.h:73
static struct PyModuleDef module
Definition: python.cpp:972
Freestyle::Interface0DIterator * if0D_it