Blender V4.5
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");
143
145 PyObject *args,
146 PyObject *kwds)
147{
148 static const char *kwlist[] = {"integration", nullptr};
149 PyObject *obj = nullptr;
150
151 if (!PyArg_ParseTupleAndKeywords(
152 args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj))
153 {
154 return -1;
155 }
156
157 if (!obj) {
158 self->uf1D_double = new UnaryFunction1D<double>();
159 }
160 else {
162 }
163
164 self->uf1D_double->py_uf1D = (PyObject *)self;
165
166 return 0;
167}
168
170{
171 delete self->uf1D_double;
172 UnaryFunction1D_Type.tp_dealloc((PyObject *)self);
173}
174
176{
177 return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_double);
178}
179
181 PyObject *args,
182 PyObject *kwds)
183{
184 static const char *kwlist[] = {"inter", nullptr};
185 PyObject *obj = nullptr;
186
187 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) {
188 return nullptr;
189 }
190
191 if (typeid(*(self->uf1D_double)) == typeid(UnaryFunction1D<double>)) {
192 PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
193 return nullptr;
194 }
195 if (self->uf1D_double->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) {
196 if (!PyErr_Occurred()) {
197 string class_name(Py_TYPE(self)->tp_name);
198 PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
199 }
200 return nullptr;
201 }
202 return PyFloat_FromDouble(self->uf1D_double->result);
203}
204
205/*----------------------UnaryFunction1DDouble get/setters ----------------------------*/
206
208 /* Wrap. */
209 integration_type_doc,
210 "The integration method.\n"
211 "\n"
212 ":type: :class:`IntegrationType`");
213
214static PyObject *integration_type_get(BPy_UnaryFunction1DDouble *self, void * /*closure*/)
215{
216 return BPy_IntegrationType_from_IntegrationType(self->uf1D_double->getIntegrationType());
217}
218
220 PyObject *value,
221 void * /*closure*/)
222{
223 if (!BPy_IntegrationType_Check(value)) {
224 PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType");
225 return -1;
226 }
227 self->uf1D_double->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value));
228 return 0;
229}
230
232 {"integration_type",
233 (getter)integration_type_get,
234 (setter)integration_type_set,
235 integration_type_doc,
236 nullptr},
237 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
238};
239
240/*-----------------------BPy_UnaryFunction1DDouble type definition ------------------------------*/
241
243 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
244 /*tp_name*/ "UnaryFunction1DDouble",
245 /*tp_basicsize*/ sizeof(BPy_UnaryFunction1DDouble),
246 /*tp_itemsize*/ 0,
247 /*tp_dealloc*/ (destructor)UnaryFunction1DDouble___dealloc__,
248 /*tp_vectorcall_offset*/ 0,
249 /*tp_getattr*/ nullptr,
250 /*tp_setattr*/ nullptr,
251 /*tp_as_async*/ nullptr,
252 /*tp_repr*/ (reprfunc)UnaryFunction1DDouble___repr__,
253 /*tp_as_number*/ nullptr,
254 /*tp_as_sequence*/ nullptr,
255 /*tp_as_mapping*/ nullptr,
256 /*tp_hash*/ nullptr,
257 /*tp_call*/ (ternaryfunc)UnaryFunction1DDouble___call__,
258 /*tp_str*/ nullptr,
259 /*tp_getattro*/ nullptr,
260 /*tp_setattro*/ nullptr,
261 /*tp_as_buffer*/ nullptr,
262 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
263 /*tp_doc*/ UnaryFunction1DDouble___doc__,
264 /*tp_traverse*/ nullptr,
265 /*tp_clear*/ nullptr,
266 /*tp_richcompare*/ nullptr,
267 /*tp_weaklistoffset*/ 0,
268 /*tp_iter*/ nullptr,
269 /*tp_iternext*/ nullptr,
270 /*tp_methods*/ nullptr,
271 /*tp_members*/ nullptr,
273 /*tp_base*/ &UnaryFunction1D_Type,
274 /*tp_dict*/ nullptr,
275 /*tp_descr_get*/ nullptr,
276 /*tp_descr_set*/ nullptr,
277 /*tp_dictoffset*/ 0,
278 /*tp_init*/ (initproc)UnaryFunction1DDouble___init__,
279 /*tp_alloc*/ nullptr,
280 /*tp_new*/ nullptr,
281};
282
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