Blender V4.5
BPy_UnaryFunction1DFloat.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
15using namespace Freestyle;
16
18
19//-------------------MODULE INITIALIZATION--------------------------------
20
22{
23 if (module == nullptr) {
24 return -1;
25 }
26
27 if (PyType_Ready(&UnaryFunction1DFloat_Type) < 0) {
28 return -1;
29 }
30 PyModule_AddObjectRef(module, "UnaryFunction1DFloat", (PyObject *)&UnaryFunction1DFloat_Type);
31
32 return 0;
33}
34
35//------------------------INSTANCE METHODS ----------------------------------
36
38 /* Wrap. */
39 UnaryFunction1DFloat___doc__,
40 "Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DFloat`\n"
41 "\n"
42 "Base class for unary functions (functors) that work on\n"
43 ":class:`Interface1D` and return a float value.\n"
44 "\n"
45 ".. method:: __init__()\n"
46 " __init__(integration_type)\n"
47 "\n"
48 " Builds a unary 1D function using the default constructor\n"
49 " or the integration method given as an argument.\n"
50 "\n"
51 " :arg integration_type: An integration method.\n"
52 " :type integration_type: :class:`IntegrationType`\n");
53
55 PyObject *args,
56 PyObject *kwds)
57{
58 static const char *kwlist[] = {"integration", nullptr};
59 PyObject *obj = nullptr;
60
61 if (!PyArg_ParseTupleAndKeywords(
62 args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj))
63 {
64 return -1;
65 }
66
67 if (!obj) {
68 self->uf1D_float = new UnaryFunction1D<float>();
69 }
70 else {
72 }
73
74 self->uf1D_float->py_uf1D = (PyObject *)self;
75
76 return 0;
77}
78
80{
81 delete self->uf1D_float;
82 UnaryFunction1D_Type.tp_dealloc((PyObject *)self);
83}
84
86{
87 return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_float);
88}
89
91 PyObject *args,
92 PyObject *kwds)
93{
94 static const char *kwlist[] = {"inter", nullptr};
95 PyObject *obj = nullptr;
96
97 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) {
98 return nullptr;
99 }
100
101 if (typeid(*(self->uf1D_float)) == typeid(UnaryFunction1D<float>)) {
102 PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
103 return nullptr;
104 }
105 if (self->uf1D_float->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) {
106 if (!PyErr_Occurred()) {
107 string class_name(Py_TYPE(self)->tp_name);
108 PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
109 }
110 return nullptr;
111 }
112 return PyFloat_FromDouble(self->uf1D_float->result);
113}
114
115/*----------------------UnaryFunction1DFloat get/setters ----------------------------*/
116
118 /* Wrap. */
119 integration_type_doc,
120 "The integration method.\n"
121 "\n"
122 ":type: :class:`IntegrationType`");
123
124static PyObject *integration_type_get(BPy_UnaryFunction1DFloat *self, void * /*closure*/)
125{
126 return BPy_IntegrationType_from_IntegrationType(self->uf1D_float->getIntegrationType());
127}
128
130 PyObject *value,
131 void * /*closure*/)
132{
133 if (!BPy_IntegrationType_Check(value)) {
134 PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType");
135 return -1;
136 }
137 self->uf1D_float->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value));
138 return 0;
139}
140
142 {"integration_type",
143 (getter)integration_type_get,
144 (setter)integration_type_set,
145 integration_type_doc,
146 nullptr},
147 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
148};
149
150/*-----------------------BPy_UnaryFunction1DFloat type definition ------------------------------*/
151
153 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
154 /*tp_name*/ "UnaryFunction1DFloat",
155 /*tp_basicsize*/ sizeof(BPy_UnaryFunction1DFloat),
156 /*tp_itemsize*/ 0,
157 /*tp_dealloc*/ (destructor)UnaryFunction1DFloat___dealloc__,
158 /*tp_vectorcall_offset*/ 0,
159 /*tp_getattr*/ nullptr,
160 /*tp_setattr*/ nullptr,
161 /*tp_as_async*/ nullptr,
162 /*tp_repr*/ (reprfunc)UnaryFunction1DFloat___repr__,
163 /*tp_as_number*/ nullptr,
164 /*tp_as_sequence*/ nullptr,
165 /*tp_as_mapping*/ nullptr,
166 /*tp_hash*/ nullptr,
167 /*tp_call*/ (ternaryfunc)UnaryFunction1DFloat___call__,
168 /*tp_str*/ nullptr,
169 /*tp_getattro*/ nullptr,
170 /*tp_setattro*/ nullptr,
171 /*tp_as_buffer*/ nullptr,
172 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
173 /*tp_doc*/ UnaryFunction1DFloat___doc__,
174 /*tp_traverse*/ nullptr,
175 /*tp_clear*/ nullptr,
176 /*tp_richcompare*/ nullptr,
177 /*tp_weaklistoffset*/ 0,
178 /*tp_iter*/ nullptr,
179 /*tp_iternext*/ nullptr,
180 /*tp_methods*/ nullptr,
181 /*tp_members*/ nullptr,
183 /*tp_base*/ &UnaryFunction1D_Type,
184 /*tp_dict*/ nullptr,
185 /*tp_descr_get*/ nullptr,
186 /*tp_descr_set*/ nullptr,
187 /*tp_dictoffset*/ 0,
188 /*tp_init*/ (initproc)UnaryFunction1DFloat___init__,
189 /*tp_alloc*/ nullptr,
190 /*tp_new*/ nullptr,
191};
192
IntegrationType IntegrationType_from_BPy_IntegrationType(PyObject *obj)
PyObject * BPy_IntegrationType_from_IntegrationType(IntegrationType i)
PyTypeObject IntegrationType_Type
#define BPy_IntegrationType_Check(v)
PyTypeObject Interface1D_Type
static PyObject * integration_type_get(BPy_UnaryFunction1DDouble *self, void *)
static int integration_type_set(BPy_UnaryFunction1DDouble *self, PyObject *value, void *)
PyTypeObject UnaryFunction1DFloat_Type
static int UnaryFunction1DFloat___init__(BPy_UnaryFunction1DFloat *self, PyObject *args, PyObject *kwds)
int UnaryFunction1DFloat_Init(PyObject *module)
static PyObject * UnaryFunction1DFloat___call__(BPy_UnaryFunction1DFloat *self, PyObject *args, PyObject *kwds)
static PyGetSetDef BPy_UnaryFunction1DFloat_getseters[]
PyDoc_STRVAR(UnaryFunction1DFloat___doc__, "Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DFloat`\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")
static void UnaryFunction1DFloat___dealloc__(BPy_UnaryFunction1DFloat *self)
static PyObject * UnaryFunction1DFloat___repr__(BPy_UnaryFunction1DFloat *self)
static PyObject * integration_type_get(BPy_UnaryFunction1DFloat *self, void *)
static int integration_type_set(BPy_UnaryFunction1DFloat *self, PyObject *value, void *)
PyTypeObject UnaryFunction1D_Type
PyObject * self
inherits from class Rep
Definition AppCanvas.cpp:20
static struct PyModuleDef module
Definition python.cpp:796