Blender V4.3
BPy_UnaryFunction1DDouble.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include "../BPy_Convert.h"
13#include "../BPy_Interface1D.h"
14
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34using namespace Freestyle;
35
37
38//-------------------MODULE INITIALIZATION--------------------------------
39
41{
42 if (module == nullptr) {
43 return -1;
44 }
45
46 if (PyType_Ready(&UnaryFunction1DDouble_Type) < 0) {
47 return -1;
48 }
49 PyModule_AddObjectRef(module, "UnaryFunction1DDouble", (PyObject *)&UnaryFunction1DDouble_Type);
50
51 if (PyType_Ready(&DensityF1D_Type) < 0) {
52 return -1;
53 }
54 PyModule_AddObjectRef(module, "DensityF1D", (PyObject *)&DensityF1D_Type);
55
56 if (PyType_Ready(&Curvature2DAngleF1D_Type) < 0) {
57 return -1;
58 }
59 PyModule_AddObjectRef(module, "Curvature2DAngleF1D", (PyObject *)&Curvature2DAngleF1D_Type);
60
61 if (PyType_Ready(&GetCompleteViewMapDensityF1D_Type) < 0) {
62 return -1;
63 }
64 PyModule_AddObjectRef(
65 module, "GetCompleteViewMapDensityF1D", (PyObject *)&GetCompleteViewMapDensityF1D_Type);
66
67 if (PyType_Ready(&GetDirectionalViewMapDensityF1D_Type) < 0) {
68 return -1;
69 }
70 PyModule_AddObjectRef(module,
71 "GetDirectionalViewMapDensityF1D",
73
74 if (PyType_Ready(&GetProjectedXF1D_Type) < 0) {
75 return -1;
76 }
77 PyModule_AddObjectRef(module, "GetProjectedXF1D", (PyObject *)&GetProjectedXF1D_Type);
78
79 if (PyType_Ready(&GetProjectedYF1D_Type) < 0) {
80 return -1;
81 }
82 PyModule_AddObjectRef(module, "GetProjectedYF1D", (PyObject *)&GetProjectedYF1D_Type);
83
84 if (PyType_Ready(&GetProjectedZF1D_Type) < 0) {
85 return -1;
86 }
87 PyModule_AddObjectRef(module, "GetProjectedZF1D", (PyObject *)&GetProjectedZF1D_Type);
88
89 if (PyType_Ready(&GetSteerableViewMapDensityF1D_Type) < 0) {
90 return -1;
91 }
92 PyModule_AddObjectRef(
93 module, "GetSteerableViewMapDensityF1D", (PyObject *)&GetSteerableViewMapDensityF1D_Type);
94
95 if (PyType_Ready(&GetViewMapGradientNormF1D_Type) < 0) {
96 return -1;
97 }
98 PyModule_AddObjectRef(
99 module, "GetViewMapGradientNormF1D", (PyObject *)&GetViewMapGradientNormF1D_Type);
100
101 if (PyType_Ready(&GetXF1D_Type) < 0) {
102 return -1;
103 }
104 PyModule_AddObjectRef(module, "GetXF1D", (PyObject *)&GetXF1D_Type);
105
106 if (PyType_Ready(&GetYF1D_Type) < 0) {
107 return -1;
108 }
109 PyModule_AddObjectRef(module, "GetYF1D", (PyObject *)&GetYF1D_Type);
110
111 if (PyType_Ready(&GetZF1D_Type) < 0) {
112 return -1;
113 }
114 PyModule_AddObjectRef(module, "GetZF1D", (PyObject *)&GetZF1D_Type);
115
116 if (PyType_Ready(&LocalAverageDepthF1D_Type) < 0) {
117 return -1;
118 }
119 PyModule_AddObjectRef(module, "LocalAverageDepthF1D", (PyObject *)&LocalAverageDepthF1D_Type);
120
121 if (PyType_Ready(&ZDiscontinuityF1D_Type) < 0) {
122 return -1;
123 }
124 PyModule_AddObjectRef(module, "ZDiscontinuityF1D", (PyObject *)&ZDiscontinuityF1D_Type);
125
126 return 0;
127}
128
129//------------------------INSTANCE METHODS ----------------------------------
130
132 /* Wrap. */
133 UnaryFunction1DDouble___doc__,
134 "Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DDouble`\n"
135 "\n"
136 "Base class for unary functions (functors) that work on\n"
137 ":class:`Interface1D` and return a float value.\n"
138 "\n"
139 ".. method:: __init__()\n"
140 " __init__(integration_type)\n"
141 "\n"
142 " Builds a unary 1D function using the default constructor\n"
143 " or the integration method given as an argument.\n"
144 "\n"
145 " :arg integration_type: An integration method.\n"
146 " :type integration_type: :class:`IntegrationType`\n");
147
149 PyObject *args,
150 PyObject *kwds)
151{
152 static const char *kwlist[] = {"integration", nullptr};
153 PyObject *obj = nullptr;
154
155 if (!PyArg_ParseTupleAndKeywords(
156 args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj))
157 {
158 return -1;
159 }
160
161 if (!obj) {
162 self->uf1D_double = new UnaryFunction1D<double>();
163 }
164 else {
166 }
167
168 self->uf1D_double->py_uf1D = (PyObject *)self;
169
170 return 0;
171}
172
174{
175 delete self->uf1D_double;
176 UnaryFunction1D_Type.tp_dealloc((PyObject *)self);
177}
178
180{
181 return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_double);
182}
183
185 PyObject *args,
186 PyObject *kwds)
187{
188 static const char *kwlist[] = {"inter", nullptr};
189 PyObject *obj = nullptr;
190
191 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) {
192 return nullptr;
193 }
194
195 if (typeid(*(self->uf1D_double)) == typeid(UnaryFunction1D<double>)) {
196 PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
197 return nullptr;
198 }
199 if (self->uf1D_double->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) {
200 if (!PyErr_Occurred()) {
201 string class_name(Py_TYPE(self)->tp_name);
202 PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
203 }
204 return nullptr;
205 }
206 return PyFloat_FromDouble(self->uf1D_double->result);
207}
208
209/*----------------------UnaryFunction1DDouble get/setters ----------------------------*/
210
212 /* Wrap. */
213 integration_type_doc,
214 "The integration method.\n"
215 "\n"
216 ":type: :class:`IntegrationType`");
217
218static PyObject *integration_type_get(BPy_UnaryFunction1DDouble *self, void * /*closure*/)
219{
220 return BPy_IntegrationType_from_IntegrationType(self->uf1D_double->getIntegrationType());
221}
222
224 PyObject *value,
225 void * /*closure*/)
226{
227 if (!BPy_IntegrationType_Check(value)) {
228 PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType");
229 return -1;
230 }
231 self->uf1D_double->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value));
232 return 0;
233}
234
236 {"integration_type",
237 (getter)integration_type_get,
238 (setter)integration_type_set,
239 integration_type_doc,
240 nullptr},
241 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
242};
243
244/*-----------------------BPy_UnaryFunction1DDouble type definition ------------------------------*/
245
247 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
248 /*tp_name*/ "UnaryFunction1DDouble",
249 /*tp_basicsize*/ sizeof(BPy_UnaryFunction1DDouble),
250 /*tp_itemsize*/ 0,
251 /*tp_dealloc*/ (destructor)UnaryFunction1DDouble___dealloc__,
252 /*tp_vectorcall_offset*/ 0,
253 /*tp_getattr*/ nullptr,
254 /*tp_setattr*/ nullptr,
255 /*tp_as_async*/ nullptr,
256 /*tp_repr*/ (reprfunc)UnaryFunction1DDouble___repr__,
257 /*tp_as_number*/ nullptr,
258 /*tp_as_sequence*/ nullptr,
259 /*tp_as_mapping*/ nullptr,
260 /*tp_hash*/ nullptr,
261 /*tp_call*/ (ternaryfunc)UnaryFunction1DDouble___call__,
262 /*tp_str*/ nullptr,
263 /*tp_getattro*/ nullptr,
264 /*tp_setattro*/ nullptr,
265 /*tp_as_buffer*/ nullptr,
266 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
267 /*tp_doc*/ UnaryFunction1DDouble___doc__,
268 /*tp_traverse*/ nullptr,
269 /*tp_clear*/ nullptr,
270 /*tp_richcompare*/ nullptr,
271 /*tp_weaklistoffset*/ 0,
272 /*tp_iter*/ nullptr,
273 /*tp_iternext*/ nullptr,
274 /*tp_methods*/ nullptr,
275 /*tp_members*/ nullptr,
277 /*tp_base*/ &UnaryFunction1D_Type,
278 /*tp_dict*/ nullptr,
279 /*tp_descr_get*/ nullptr,
280 /*tp_descr_set*/ nullptr,
281 /*tp_dictoffset*/ 0,
282 /*tp_init*/ (initproc)UnaryFunction1DDouble___init__,
283 /*tp_alloc*/ nullptr,
284 /*tp_new*/ nullptr,
285};
286
288
289#ifdef __cplusplus
290}
291#endif
IntegrationType IntegrationType_from_BPy_IntegrationType(PyObject *obj)
PyObject * BPy_IntegrationType_from_IntegrationType(IntegrationType i)
PyTypeObject Curvature2DAngleF1D_Type
PyTypeObject DensityF1D_Type
PyTypeObject GetCompleteViewMapDensityF1D_Type
PyTypeObject GetDirectionalViewMapDensityF1D_Type
PyTypeObject GetProjectedXF1D_Type
PyTypeObject GetProjectedYF1D_Type
PyTypeObject GetProjectedZF1D_Type
PyTypeObject GetSteerableViewMapDensityF1D_Type
PyTypeObject GetViewMapGradientNormF1D_Type
PyTypeObject GetXF1D_Type
PyTypeObject GetYF1D_Type
PyTypeObject GetZF1D_Type
PyTypeObject IntegrationType_Type
#define BPy_IntegrationType_Check(v)
PyTypeObject Interface1D_Type
PyTypeObject LocalAverageDepthF1D_Type
static int UnaryFunction1DDouble___init__(BPy_UnaryFunction1DDouble *self, PyObject *args, PyObject *kwds)
static void UnaryFunction1DDouble___dealloc__(BPy_UnaryFunction1DDouble *self)
int UnaryFunction1DDouble_Init(PyObject *module)
static PyObject * UnaryFunction1DDouble___call__(BPy_UnaryFunction1DDouble *self, PyObject *args, PyObject *kwds)
static PyObject * integration_type_get(BPy_UnaryFunction1DDouble *self, void *)
PyTypeObject UnaryFunction1DDouble_Type
static int integration_type_set(BPy_UnaryFunction1DDouble *self, PyObject *value, void *)
static PyObject * UnaryFunction1DDouble___repr__(BPy_UnaryFunction1DDouble *self)
static PyGetSetDef BPy_UnaryFunction1DDouble_getseters[]
PyDoc_STRVAR(UnaryFunction1DDouble___doc__, "Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DDouble`\n" "\n" "Base class for unary functions (functors) that work on\n" ":class:`Interface1D` and return a float value.\n" "\n" ".. method:: __init__()\n" " __init__(integration_type)\n" "\n" " Builds a unary 1D function using the default constructor\n" " or the integration method given as an argument.\n" "\n" " :arg integration_type: An integration method.\n" " :type integration_type: :class:`IntegrationType`\n")
PyTypeObject UnaryFunction1D_Type
PyTypeObject ZDiscontinuityF1D_Type
PyObject * self
inherits from class Rep
Definition AppCanvas.cpp:20
static struct PyModuleDef module
Definition python.cpp:991