Blender V5.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
8
10
11#include "../BPy_Convert.h"
13#include "../BPy_Interface1D.h"
14
29
30using namespace Freestyle;
31
33
34//-------------------MODULE INITIALIZATION--------------------------------
35
36int UnaryFunction1DDouble_Init(PyObject *module)
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__(*args)\n"
136 "\n"
137 " Accepted call signatures:\n"
138 "\n"
139 " - ``__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 " :param integration_type: An integration method.\n"
146 " :type integration_type: :class:`IntegrationType`\n");
148 PyObject *args,
149 PyObject *kwds)
150{
151 static const char *kwlist[] = {"integration", nullptr};
152 PyObject *obj = nullptr;
153
154 if (!PyArg_ParseTupleAndKeywords(args,
155 kwds,
156 "|" /* Optional arguments. */
157 "O!" /* `integration` */
158 ":__init__",
159 (char **)kwlist,
161 &obj))
162 {
163 return -1;
164 }
165
166 if (!obj) {
168 }
169 else {
171 }
172
173 self->uf1D_double->py_uf1D = (PyObject *)self;
174
175 return 0;
176}
177
179{
180 delete self->uf1D_double;
181 UnaryFunction1D_Type.tp_dealloc((PyObject *)self);
182}
183
185{
186 return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_double);
187}
188
190 PyObject *args,
191 PyObject *kwds)
192{
193 static const char *kwlist[] = {"inter", nullptr};
194 PyObject *obj = nullptr;
195
196 if (!PyArg_ParseTupleAndKeywords(args,
197 kwds,
198 "O!" /* `inter` */
199 ":__call__",
200 (char **)kwlist,
202 &obj))
203 {
204 return nullptr;
205 }
206
207 if (typeid(*(self->uf1D_double)) == typeid(UnaryFunction1D<double>)) {
208 PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
209 return nullptr;
210 }
211 if (self->uf1D_double->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) {
212 if (!PyErr_Occurred()) {
213 string class_name(Py_TYPE(self)->tp_name);
214 PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
215 }
216 return nullptr;
217 }
218 return PyFloat_FromDouble(self->uf1D_double->result);
219}
220
221/*----------------------UnaryFunction1DDouble get/setters ----------------------------*/
222
224 /* Wrap. */
225 integration_type_doc,
226 "The integration method.\n"
227 "\n"
228 ":type: :class:`IntegrationType`\n");
229static PyObject *integration_type_get(BPy_UnaryFunction1DDouble *self, void * /*closure*/)
230{
232}
233
235 PyObject *value,
236 void * /*closure*/)
237{
238 if (!BPy_IntegrationType_Check(value)) {
239 PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType");
240 return -1;
241 }
243 return 0;
244}
245
247 {"integration_type",
248 (getter)integration_type_get,
249 (setter)integration_type_set,
250 integration_type_doc,
251 nullptr},
252 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
253};
254
255/*-----------------------BPy_UnaryFunction1DDouble type definition ------------------------------*/
256
258 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
259 /*tp_name*/ "UnaryFunction1DDouble",
260 /*tp_basicsize*/ sizeof(BPy_UnaryFunction1DDouble),
261 /*tp_itemsize*/ 0,
262 /*tp_dealloc*/ (destructor)UnaryFunction1DDouble___dealloc__,
263 /*tp_vectorcall_offset*/ 0,
264 /*tp_getattr*/ nullptr,
265 /*tp_setattr*/ nullptr,
266 /*tp_as_async*/ nullptr,
267 /*tp_repr*/ (reprfunc)UnaryFunction1DDouble___repr__,
268 /*tp_as_number*/ nullptr,
269 /*tp_as_sequence*/ nullptr,
270 /*tp_as_mapping*/ nullptr,
271 /*tp_hash*/ nullptr,
272 /*tp_call*/ (ternaryfunc)UnaryFunction1DDouble___call__,
273 /*tp_str*/ nullptr,
274 /*tp_getattro*/ nullptr,
275 /*tp_setattro*/ nullptr,
276 /*tp_as_buffer*/ nullptr,
277 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
278 /*tp_doc*/ UnaryFunction1DDouble___doc__,
279 /*tp_traverse*/ nullptr,
280 /*tp_clear*/ nullptr,
281 /*tp_richcompare*/ nullptr,
282 /*tp_weaklistoffset*/ 0,
283 /*tp_iter*/ nullptr,
284 /*tp_iternext*/ nullptr,
285 /*tp_methods*/ nullptr,
286 /*tp_members*/ nullptr,
288 /*tp_base*/ &UnaryFunction1D_Type,
289 /*tp_dict*/ nullptr,
290 /*tp_descr_get*/ nullptr,
291 /*tp_descr_set*/ nullptr,
292 /*tp_dictoffset*/ 0,
293 /*tp_init*/ (initproc)UnaryFunction1DDouble___init__,
294 /*tp_alloc*/ nullptr,
295 /*tp_new*/ nullptr,
296};
297
IntegrationType IntegrationType_from_BPy_IntegrationType(PyObject *obj)
PyObject * BPy_IntegrationType_from_IntegrationType(IntegrationType i)
PyTypeObject Curvature2DAngleF1D_Type
PyTypeObject DensityF1D_Type
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 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[]
PyTypeObject UnaryFunction1D_Type
PyTypeObject ZDiscontinuityF1D_Type
IntegrationType getIntegrationType() const
Definition Functions1D.h:97
void setIntegrationType(IntegrationType integration)
Definition Functions1D.h:91
inherits from class Rep
Definition AppCanvas.cpp:20
Freestyle::UnaryFunction1D< double > * uf1D_double