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