Blender V5.3
BPy_IntegrationType.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2004-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10
11#include "BPy_Convert.h"
16
17#include "BLI_sys_types.hh"
18
19using namespace Freestyle;
20
22
23//------------------------ MODULE FUNCTIONS ----------------------------------
24
26 /* Wrap. */
27 Integrator_integrate_doc,
28 ".. function:: integrate(func, it, it_end, integration_type)\n"
29 "\n"
30 " Returns a single value from a set of values evaluated at each 0D\n"
31 " element of this 1D element.\n"
32 "\n"
33 " :param func: The UnaryFunction0D used to compute a value at each\n"
34 " Interface0D.\n"
35 " :type func: :class:`UnaryFunction0D`\n"
36 " :param it: The Interface0DIterator used to iterate over the 0D\n"
37 " elements of this 1D element. The integration will occur over\n"
38 " the 0D elements starting from the one pointed by it.\n"
39 " :type it: :class:`Interface0DIterator`\n"
40 " :param it_end: The Interface0DIterator pointing the end of the 0D\n"
41 " elements of the 1D element.\n"
42 " :type it_end: :class:`Interface0DIterator`\n"
43 " :param integration_type: The integration method used to compute a\n"
44 " single value from a set of values.\n"
45 " :type integration_type: :class:`IntegrationType`\n"
46 " :return: The single value obtained for the 1D element. The return\n"
47 " value type is float if func is of the :class:`UnaryFunction0DDouble`\n"
48 " or :class:`UnaryFunction0DFloat` type, and int if func is of the\n"
49 " :class:`UnaryFunction0DUnsigned` type.\n"
50 " :rtype: int | float\n");
51static PyObject *Integrator_integrate(PyObject * /*self*/, PyObject *args, PyObject *kwds)
52{
53 static const char *kwlist[] = {"func", "it", "it_end", "integration_type", nullptr};
54 PyObject *obj1, *obj4 = nullptr;
55 BPy_Interface0DIterator *obj2, *obj3;
56
57 if (!PyArg_ParseTupleAndKeywords(args,
58 kwds,
59 "O!" /* `func` */
60 "O!" /* `it` */
61 "O!" /* `it_end` */
62 "|" /* Optional arguments. */
63 "O!" /* `integration_type` */
64 ":integrate",
65 (char **)kwlist,
67 &obj1,
69 &obj2,
71 &obj3,
73 &obj4))
74 {
75 return nullptr;
76 }
77
78 Interface0DIterator it(*(obj2->if0D_it)), it_end(*(obj3->if0D_it));
80
82 UnaryFunction0D<double> *fun = ((BPy_UnaryFunction0DDouble *)obj1)->uf0D_double;
83 double res = integrate(*fun, it, it_end, t);
84 return PyFloat_FromDouble(res);
85 }
87 UnaryFunction0D<float> *fun = ((BPy_UnaryFunction0DFloat *)obj1)->uf0D_float;
88 float res = integrate(*fun, it, it_end, t);
89 return PyFloat_FromDouble(res);
90 }
92 UnaryFunction0D<uint> *fun = ((BPy_UnaryFunction0DUnsigned *)obj1)->uf0D_unsigned;
93 uint res = integrate(*fun, it, it_end, t);
94 return PyLong_FromLong(res);
95 }
96
97 string class_name(Py_TYPE(obj1)->tp_name);
98 PyErr_SetString(PyExc_TypeError, ("unsupported function type: " + class_name).c_str());
99 return nullptr;
100}
101
102/*-----------------------Integrator module docstring---------------------------------------*/
103
105 /* Wrap. */
106 module_docstring,
107 "The Blender Freestyle.Integrator submodule\n"
108 "\n");
109
110/*-----------------------Integrator module functions definitions---------------------------*/
111
112#ifdef __GNUC__
113# ifdef __clang__
114# pragma clang diagnostic push
115# pragma clang diagnostic ignored "-Wcast-function-type"
116# else
117# pragma GCC diagnostic push
118# pragma GCC diagnostic ignored "-Wcast-function-type"
119# endif
120#endif
121
122static PyMethodDef module_functions[] = {
123 {"integrate",
124 (PyCFunction)Integrator_integrate,
125 METH_VARARGS | METH_KEYWORDS,
126 Integrator_integrate_doc},
127 {nullptr, nullptr, 0, nullptr},
128};
129
130#ifdef __GNUC__
131# ifdef __clang__
132# pragma clang diagnostic pop
133# else
134# pragma GCC diagnostic pop
135# endif
136#endif
137
138/*-----------------------Integrator module definition--------------------------------------*/
139
140static PyModuleDef module_definition = {
141 /*m_base*/ PyModuleDef_HEAD_INIT,
142 /*m_name*/ "Freestyle.Integrator",
143 /*m_doc*/ module_docstring,
144 /*m_size*/ -1,
145 /*m_methods*/ module_functions,
146 /*m_slots*/ nullptr,
147 /*m_traverse*/ nullptr,
148 /*m_clear*/ nullptr,
149 /*m_free*/ nullptr,
150};
151
152/*-----------------------BPy_IntegrationType type definition ------------------------------*/
153
155 /* Wrap. */
156 IntegrationType_doc,
157 "Class hierarchy: int > :class:`IntegrationType`\n"
158 "\n"
159 "Different integration methods that can be invoked to integrate into a\n"
160 "single value the set of values obtained from each 0D element of an 1D\n"
161 "element.\n"
162 "\n"
163 ".. attribute:: MEAN\n"
164 "\n"
165 " The value computed for the 1D element is the mean of the values\n"
166 " obtained for the 0D elements.\n"
167 "\n"
168 ".. attribute:: MIN\n"
169 "\n"
170 " The value computed for the 1D element is the minimum of the values\n"
171 " obtained for the 0D elements.\n"
172 "\n"
173 ".. attribute:: MAX\n"
174 "\n"
175 " The value computed for the 1D element is the maximum of the values\n"
176 " obtained for the 0D elements.\n"
177 "\n"
178 ".. attribute:: FIRST\n"
179 "\n"
180 " The value computed for the 1D element is the first of the values\n"
181 " obtained for the 0D elements.\n"
182 "\n"
183 ".. attribute:: LAST\n"
184 "\n"
185 " The value computed for the 1D element is the last of the values\n"
186 " obtained for the 0D elements.\n");
187PyTypeObject IntegrationType_Type = {
188 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
189 /*tp_name*/ "IntegrationType",
190 /*tp_basicsize*/ sizeof(PyLongObject),
191 /*tp_itemsize*/ 0,
192 /*tp_dealloc*/ nullptr,
193 /*tp_vectorcall_offset*/ 0,
194 /*tp_getattr*/ nullptr,
195 /*tp_setattr*/ nullptr,
196 /*tp_as_async*/ nullptr,
197 /*tp_repr*/ nullptr,
198 /*tp_as_number*/ nullptr,
199 /*tp_as_sequence*/ nullptr,
200 /*tp_as_mapping*/ nullptr,
201 /*tp_hash*/ nullptr,
202 /*tp_call*/ nullptr,
203 /*tp_str*/ nullptr,
204 /*tp_getattro*/ nullptr,
205 /*tp_setattro*/ nullptr,
206 /*tp_as_buffer*/ nullptr,
207 /*tp_flags*/ Py_TPFLAGS_DEFAULT,
208 /*tp_doc*/ IntegrationType_doc,
209 /*tp_traverse*/ nullptr,
210 /*tp_clear*/ nullptr,
211 /*tp_richcompare*/ nullptr,
212 /*tp_weaklistoffset*/ 0,
213 /*tp_iter*/ nullptr,
214 /*tp_iternext*/ nullptr,
215 /*tp_methods*/ nullptr,
216 /*tp_members*/ nullptr,
217 /*tp_getset*/ nullptr,
218 /*tp_base*/ &PyLong_Type,
219 /*tp_dict*/ nullptr,
220 /*tp_descr_get*/ nullptr,
221 /*tp_descr_set*/ nullptr,
222 /*tp_dictoffset*/ 0,
223 /*tp_init*/ nullptr,
224 /*tp_alloc*/ nullptr,
225 /*tp_new*/ nullptr,
226};
227
228/*-----------------------BPy_IntegrationType instance definitions -------------------------*/
229
230//-------------------MODULE INITIALIZATION--------------------------------
231int IntegrationType_Init(PyObject *module)
232{
233 PyObject *m, *d, *f;
234
235 if (module == nullptr) {
236 return -1;
237 }
238
239 if (PyType_Ready(&IntegrationType_Type) < 0) {
240 return -1;
241 }
242 PyModule_AddObjectRef(module, "IntegrationType", (PyObject *)&IntegrationType_Type);
243
244#define ADD_TYPE_CONST(id) \
245 PyLong_subtype_add_to_dict( \
246 IntegrationType_Type.tp_dict, &IntegrationType_Type, STRINGIFY(id), id)
247
253
254#undef ADD_TYPE_CONST
255
256 m = PyModule_Create(&module_definition);
257 if (m == nullptr) {
258 return -1;
259 }
260 PyModule_AddObjectRef(module, "Integrator", m);
261
262 // from Integrator import *
263 d = PyModule_GetDict(m);
264 for (PyMethodDef *p = module_functions; p->ml_name; p++) {
265 f = PyDict_GetItemString(d, p->ml_name);
266 PyModule_AddObjectRef(module, p->ml_name, f);
267 }
268
269 return 0;
270}
271
IntegrationType IntegrationType_from_BPy_IntegrationType(PyObject *obj)
PyDoc_STRVAR(FalseBP1D___doc__, "Class hierarchy: :class:`freestyle.types.BinaryPredicate1D` > :class:`FalseBP1D`\n" "\n" ".. method:: __call__(inter1, inter2)\n" "\n" " Always returns false.\n" "\n" " :param inter1: The first Interface1D object.\n" " :type inter1: :class:`freestyle.types.Interface1D`\n" " :param inter2: The second Interface1D object.\n" " :type inter2: :class:`freestyle.types.Interface1D`\n" " :return: False.\n" " :rtype: bool\n")
PyTypeObject IntegrationType_Type
int IntegrationType_Init(PyObject *module)
#define ADD_TYPE_CONST(id)
static PyModuleDef module_definition
static PyObject * Integrator_integrate(PyObject *, PyObject *args, PyObject *kwds)
static PyMethodDef module_functions[]
PyTypeObject Interface0DIterator_Type
#define BPy_UnaryFunction0DDouble_Check(v)
#define BPy_UnaryFunction0DFloat_Check(v)
#define BPy_UnaryFunction0DUnsigned_Check(v)
PyTypeObject UnaryFunction0D_Type
#define MIN(_a, _b)
inherits from class Rep
Definition AppCanvas.cpp:20
T integrate(UnaryFunction0D< T > &fun, Interface0DIterator it, Interface0DIterator it_end, IntegrationType integration_type=MEAN)
Definition Interface1D.h:73
Freestyle::Interface0DIterator * if0D_it