Blender V5.0
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");
54 PyObject *args,
55 PyObject *kwds)
56{
57 static const char *kwlist[] = {"integration", nullptr};
58 PyObject *obj = nullptr;
59
60 if (!PyArg_ParseTupleAndKeywords(
61 args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj))
62 {
63 return -1;
64 }
65
66 if (!obj) {
67 self->uf1D_float = new UnaryFunction1D<float>();
68 }
69 else {
71 }
72
73 self->uf1D_float->py_uf1D = (PyObject *)self;
74
75 return 0;
76}
77
79{
80 delete self->uf1D_float;
81 UnaryFunction1D_Type.tp_dealloc((PyObject *)self);
82}
83
85{
86 return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_float);
87}
88
90 PyObject *args,
91 PyObject *kwds)
92{
93 static const char *kwlist[] = {"inter", nullptr};
94 PyObject *obj = nullptr;
95
96 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) {
97 return nullptr;
98 }
99
100 if (typeid(*(self->uf1D_float)) == typeid(UnaryFunction1D<float>)) {
101 PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
102 return nullptr;
103 }
104 if (self->uf1D_float->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) {
105 if (!PyErr_Occurred()) {
106 string class_name(Py_TYPE(self)->tp_name);
107 PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
108 }
109 return nullptr;
110 }
111 return PyFloat_FromDouble(self->uf1D_float->result);
112}
113
114/*----------------------UnaryFunction1DFloat get/setters ----------------------------*/
115
117 /* Wrap. */
118 integration_type_doc,
119 "The integration method.\n"
120 "\n"
121 ":type: :class:`IntegrationType`\n");
122static PyObject *integration_type_get(BPy_UnaryFunction1DFloat *self, void * /*closure*/)
123{
124 return BPy_IntegrationType_from_IntegrationType(self->uf1D_float->getIntegrationType());
125}
126
128 PyObject *value,
129 void * /*closure*/)
130{
131 if (!BPy_IntegrationType_Check(value)) {
132 PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType");
133 return -1;
134 }
135 self->uf1D_float->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value));
136 return 0;
137}
138
140 {"integration_type",
141 (getter)integration_type_get,
142 (setter)integration_type_set,
143 integration_type_doc,
144 nullptr},
145 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
146};
147
148/*-----------------------BPy_UnaryFunction1DFloat type definition ------------------------------*/
149
151 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
152 /*tp_name*/ "UnaryFunction1DFloat",
153 /*tp_basicsize*/ sizeof(BPy_UnaryFunction1DFloat),
154 /*tp_itemsize*/ 0,
155 /*tp_dealloc*/ (destructor)UnaryFunction1DFloat___dealloc__,
156 /*tp_vectorcall_offset*/ 0,
157 /*tp_getattr*/ nullptr,
158 /*tp_setattr*/ nullptr,
159 /*tp_as_async*/ nullptr,
160 /*tp_repr*/ (reprfunc)UnaryFunction1DFloat___repr__,
161 /*tp_as_number*/ nullptr,
162 /*tp_as_sequence*/ nullptr,
163 /*tp_as_mapping*/ nullptr,
164 /*tp_hash*/ nullptr,
165 /*tp_call*/ (ternaryfunc)UnaryFunction1DFloat___call__,
166 /*tp_str*/ nullptr,
167 /*tp_getattro*/ nullptr,
168 /*tp_setattro*/ nullptr,
169 /*tp_as_buffer*/ nullptr,
170 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
171 /*tp_doc*/ UnaryFunction1DFloat___doc__,
172 /*tp_traverse*/ nullptr,
173 /*tp_clear*/ nullptr,
174 /*tp_richcompare*/ nullptr,
175 /*tp_weaklistoffset*/ 0,
176 /*tp_iter*/ nullptr,
177 /*tp_iternext*/ nullptr,
178 /*tp_methods*/ nullptr,
179 /*tp_members*/ nullptr,
181 /*tp_base*/ &UnaryFunction1D_Type,
182 /*tp_dict*/ nullptr,
183 /*tp_descr_get*/ nullptr,
184 /*tp_descr_set*/ nullptr,
185 /*tp_dictoffset*/ 0,
186 /*tp_init*/ (initproc)UnaryFunction1DFloat___init__,
187 /*tp_alloc*/ nullptr,
188 /*tp_new*/ nullptr,
189};
190
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