Blender  V2.93
BPy_IntegrationType.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "BPy_IntegrationType.h"
22 
23 #include "BPy_Convert.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 using namespace Freestyle;
34 
36 
37 //------------------------ MODULE FUNCTIONS ----------------------------------
38 
39 PyDoc_STRVAR(Integrator_integrate_doc,
40  ".. function:: integrate(func, it, it_end, integration_type)\n"
41  "\n"
42  " Returns a single value from a set of values evaluated at each 0D\n"
43  " element of this 1D element.\n"
44  "\n"
45  " :arg func: The UnaryFunction0D used to compute a value at each\n"
46  " Interface0D.\n"
47  " :type func: :class:`UnaryFunction0D`\n"
48  " :arg it: The Interface0DIterator used to iterate over the 0D\n"
49  " elements of this 1D element. The integration will occur over\n"
50  " the 0D elements starting from the one pointed by it.\n"
51  " :type it: :class:`Interface0DIterator`\n"
52  " :arg it_end: The Interface0DIterator pointing the end of the 0D\n"
53  " elements of the 1D element.\n"
54  " :type it_end: :class:`Interface0DIterator`\n"
55  " :arg integration_type: The integration method used to compute a\n"
56  " single value from a set of values.\n"
57  " :type integration_type: :class:`IntegrationType`\n"
58  " :return: The single value obtained for the 1D element. The return\n"
59  " value type is float if func is of the :class:`UnaryFunction0DDouble`\n"
60  " or :class:`UnaryFunction0DFloat` type, and int if func is of the\n"
61  " :class:`UnaryFunction0DUnsigned` type.\n"
62  " :rtype: int or float");
63 
64 static PyObject *Integrator_integrate(PyObject * /*self*/, PyObject *args, PyObject *kwds)
65 {
66  static const char *kwlist[] = {"func", "it", "it_end", "integration_type", nullptr};
67  PyObject *obj1, *obj4 = nullptr;
68  BPy_Interface0DIterator *obj2, *obj3;
69 
70  if (!PyArg_ParseTupleAndKeywords(args,
71  kwds,
72  "O!O!O!|O!",
73  (char **)kwlist,
75  &obj1,
77  &obj2,
79  &obj3,
81  &obj4)) {
82  return nullptr;
83  }
84 
85  Interface0DIterator it(*(obj2->if0D_it)), it_end(*(obj3->if0D_it));
87 
89  UnaryFunction0D<double> *fun = ((BPy_UnaryFunction0DDouble *)obj1)->uf0D_double;
90  double res = integrate(*fun, it, it_end, t);
91  return PyFloat_FromDouble(res);
92  }
94  UnaryFunction0D<float> *fun = ((BPy_UnaryFunction0DFloat *)obj1)->uf0D_float;
95  float res = integrate(*fun, it, it_end, t);
96  return PyFloat_FromDouble(res);
97  }
99  UnaryFunction0D<unsigned int> *fun = ((BPy_UnaryFunction0DUnsigned *)obj1)->uf0D_unsigned;
100  unsigned int res = integrate(*fun, it, it_end, t);
101  return PyLong_FromLong(res);
102  }
103 
104  string class_name(Py_TYPE(obj1)->tp_name);
105  PyErr_SetString(PyExc_TypeError, ("unsupported function type: " + class_name).c_str());
106  return nullptr;
107 }
108 
109 /*-----------------------Integrator module docstring---------------------------------------*/
110 
111 PyDoc_STRVAR(module_docstring, "The Blender Freestyle.Integrator submodule\n\n");
112 
113 /*-----------------------Integrator module functions definitions---------------------------*/
114 
115 static PyMethodDef module_functions[] = {
116  {"integrate",
117  (PyCFunction)Integrator_integrate,
118  METH_VARARGS | METH_KEYWORDS,
119  Integrator_integrate_doc},
120  {nullptr, nullptr, 0, nullptr},
121 };
122 
123 /*-----------------------Integrator module definition--------------------------------------*/
124 
125 static PyModuleDef module_definition = {
126  PyModuleDef_HEAD_INIT,
127  "Freestyle.Integrator",
129  -1,
131 };
132 
133 /*-----------------------BPy_IntegrationType type definition ------------------------------*/
134 
135 PyDoc_STRVAR(IntegrationType_doc,
136  "Class hierarchy: int > :class:`IntegrationType`\n"
137  "\n"
138  "Different integration methods that can be invoked to integrate into a\n"
139  "single value the set of values obtained from each 0D element of an 1D\n"
140  "element:\n"
141  "\n"
142  "* IntegrationType.MEAN: The value computed for the 1D element is the\n"
143  " mean of the values obtained for the 0D elements.\n"
144  "* IntegrationType.MIN: The value computed for the 1D element is the\n"
145  " minimum of the values obtained for the 0D elements.\n"
146  "* IntegrationType.MAX: The value computed for the 1D element is the\n"
147  " maximum of the values obtained for the 0D elements.\n"
148  "* IntegrationType.FIRST: The value computed for the 1D element is the\n"
149  " first of the values obtained for the 0D elements.\n"
150  "* IntegrationType.LAST: The value computed for the 1D element is the\n"
151  " last of the values obtained for the 0D elements.");
152 
153 PyTypeObject IntegrationType_Type = {
154  PyVarObject_HEAD_INIT(nullptr, 0) "IntegrationType", /* tp_name */
155  sizeof(PyLongObject), /* tp_basicsize */
156  0, /* tp_itemsize */
157  nullptr, /* tp_dealloc */
158  0, /* tp_vectorcall_offset */
159  nullptr, /* tp_getattr */
160  nullptr, /* tp_setattr */
161  nullptr, /* tp_reserved */
162  nullptr, /* tp_repr */
163  nullptr, /* tp_as_number */
164  nullptr, /* tp_as_sequence */
165  nullptr, /* tp_as_mapping */
166  nullptr, /* tp_hash */
167  nullptr, /* tp_call */
168  nullptr, /* tp_str */
169  nullptr, /* tp_getattro */
170  nullptr, /* tp_setattro */
171  nullptr, /* tp_as_buffer */
172  Py_TPFLAGS_DEFAULT, /* tp_flags */
173  IntegrationType_doc, /* tp_doc */
174  nullptr, /* tp_traverse */
175  nullptr, /* tp_clear */
176  nullptr, /* tp_richcompare */
177  0, /* tp_weaklistoffset */
178  nullptr, /* tp_iter */
179  nullptr, /* tp_iternext */
180  nullptr, /* tp_methods */
181  nullptr, /* tp_members */
182  nullptr, /* tp_getset */
183  &PyLong_Type, /* tp_base */
184  nullptr, /* tp_dict */
185  nullptr, /* tp_descr_get */
186  nullptr, /* tp_descr_set */
187  0, /* tp_dictoffset */
188  nullptr, /* tp_init */
189  nullptr, /* tp_alloc */
190  nullptr, /* tp_new */
191 };
192 
193 /*-----------------------BPy_IntegrationType instance definitions -------------------------*/
194 
195 static PyLongObject _IntegrationType_MEAN = {
196  PyVarObject_HEAD_INIT(&IntegrationType_Type, 1){MEAN}};
197 static PyLongObject _IntegrationType_MIN = {PyVarObject_HEAD_INIT(&IntegrationType_Type, 1){MIN}};
198 static PyLongObject _IntegrationType_MAX = {PyVarObject_HEAD_INIT(&IntegrationType_Type, 1){MAX}};
199 static PyLongObject _IntegrationType_FIRST = {
200  PyVarObject_HEAD_INIT(&IntegrationType_Type, 1){FIRST}};
201 static PyLongObject _IntegrationType_LAST = {
202  PyVarObject_HEAD_INIT(&IntegrationType_Type, 1){LAST}};
203 
204 #define BPy_IntegrationType_MEAN ((PyObject *)&_IntegrationType_MEAN)
205 #define BPy_IntegrationType_MIN ((PyObject *)&_IntegrationType_MIN)
206 #define BPy_IntegrationType_MAX ((PyObject *)&_IntegrationType_MAX)
207 #define BPy_IntegrationType_FIRST ((PyObject *)&_IntegrationType_FIRST)
208 #define BPy_IntegrationType_LAST ((PyObject *)&_IntegrationType_LAST)
209 
210 //-------------------MODULE INITIALIZATION--------------------------------
212 {
213  PyObject *m, *d, *f;
214 
215  if (module == nullptr) {
216  return -1;
217  }
218 
219  if (PyType_Ready(&IntegrationType_Type) < 0) {
220  return -1;
221  }
222  Py_INCREF(&IntegrationType_Type);
223  PyModule_AddObject(module, "IntegrationType", (PyObject *)&IntegrationType_Type);
224 
225  PyDict_SetItemString(IntegrationType_Type.tp_dict, "MEAN", BPy_IntegrationType_MEAN);
226  PyDict_SetItemString(IntegrationType_Type.tp_dict, "MIN", BPy_IntegrationType_MIN);
227  PyDict_SetItemString(IntegrationType_Type.tp_dict, "MAX", BPy_IntegrationType_MAX);
228  PyDict_SetItemString(IntegrationType_Type.tp_dict, "FIRST", BPy_IntegrationType_FIRST);
229  PyDict_SetItemString(IntegrationType_Type.tp_dict, "LAST", BPy_IntegrationType_LAST);
230 
231  m = PyModule_Create(&module_definition);
232  if (m == nullptr) {
233  return -1;
234  }
235  Py_INCREF(m);
236  PyModule_AddObject(module, "Integrator", m);
237 
238  // from Integrator import *
239  d = PyModule_GetDict(m);
240  for (PyMethodDef *p = module_functions; p->ml_name; p++) {
241  f = PyDict_GetItemString(d, p->ml_name);
242  Py_INCREF(f);
243  PyModule_AddObject(module, p->ml_name, f);
244  }
245 
246  return 0;
247 }
248 
250 
251 #ifdef __cplusplus
252 }
253 #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
static struct PyModuleDef module
inherits from class Rep
Definition: AppCanvas.cpp:32
T integrate(UnaryFunction0D< T > &fun, Interface0DIterator it, Interface0DIterator it_end, IntegrationType integration_type=MEAN)
Definition: Interface1D.h:72
Freestyle::Interface0DIterator * if0D_it