Blender V5.3
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
21int UnaryFunction1DFloat_Init(PyObject *module)
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__(*args)\n"
46 "\n"
47 " Accepted call signatures:\n"
48 "\n"
49 " - ``__init__()``\n"
50 " - ``__init__(integration_type)``\n"
51 "\n"
52 " Builds a unary 1D function using the default constructor\n"
53 " or the integration method given as an argument.\n"
54 "\n"
55 " :param integration_type: An integration method.\n"
56 " :type integration_type: :class:`IntegrationType`\n");
58 PyObject *args,
59 PyObject *kwds)
60{
61 static const char *kwlist[] = {"integration", nullptr};
62 PyObject *obj = nullptr;
63
64 if (!PyArg_ParseTupleAndKeywords(args,
65 kwds,
66 "|" /* Optional arguments. */
67 "O!" /* `integration` */
68 ":__init__",
69 (char **)kwlist,
71 &obj))
72 {
73 return -1;
74 }
75
76 if (!obj) {
78 }
79 else {
81 }
82
83 self->uf1D_float->py_uf1D = (PyObject *)self;
84
85 return 0;
86}
87
89{
90 delete self->uf1D_float;
91 UnaryFunction1D_Type.tp_dealloc((PyObject *)self);
92}
93
95{
96 return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_float);
97}
98
100 PyObject *args,
101 PyObject *kwds)
102{
103 static const char *kwlist[] = {"inter", nullptr};
104 PyObject *obj = nullptr;
105
106 if (!PyArg_ParseTupleAndKeywords(args,
107 kwds,
108 "O!" /* `inter` */
109 ":__call__",
110 (char **)kwlist,
112 &obj))
113 {
114 return nullptr;
115 }
116
117 if (typeid(*(self->uf1D_float)) == typeid(UnaryFunction1D<float>)) {
118 PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
119 return nullptr;
120 }
121 if (self->uf1D_float->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) {
122 if (!PyErr_Occurred()) {
123 string class_name(Py_TYPE(self)->tp_name);
124 PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
125 }
126 return nullptr;
127 }
128 return PyFloat_FromDouble(self->uf1D_float->result);
129}
130
131/*----------------------UnaryFunction1DFloat get/setters ----------------------------*/
132
134 /* Wrap. */
135 integration_type_doc,
136 "The integration method.\n"
137 "\n"
138 ":type: :class:`IntegrationType`\n");
139static PyObject *integration_type_get(BPy_UnaryFunction1DFloat *self, void * /*closure*/)
140{
142}
143
145 PyObject *value,
146 void * /*closure*/)
147{
148 if (!BPy_IntegrationType_Check(value)) {
149 PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType");
150 return -1;
151 }
153 return 0;
154}
155
157 {"integration_type",
158 (getter)integration_type_get,
159 (setter)integration_type_set,
160 integration_type_doc,
161 nullptr},
162 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
163};
164
165/*-----------------------BPy_UnaryFunction1DFloat type definition ------------------------------*/
166
168 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
169 /*tp_name*/ "UnaryFunction1DFloat",
170 /*tp_basicsize*/ sizeof(BPy_UnaryFunction1DFloat),
171 /*tp_itemsize*/ 0,
172 /*tp_dealloc*/ (destructor)UnaryFunction1DFloat___dealloc__,
173 /*tp_vectorcall_offset*/ 0,
174 /*tp_getattr*/ nullptr,
175 /*tp_setattr*/ nullptr,
176 /*tp_as_async*/ nullptr,
177 /*tp_repr*/ (reprfunc)UnaryFunction1DFloat___repr__,
178 /*tp_as_number*/ nullptr,
179 /*tp_as_sequence*/ nullptr,
180 /*tp_as_mapping*/ nullptr,
181 /*tp_hash*/ nullptr,
182 /*tp_call*/ (ternaryfunc)UnaryFunction1DFloat___call__,
183 /*tp_str*/ nullptr,
184 /*tp_getattro*/ nullptr,
185 /*tp_setattro*/ nullptr,
186 /*tp_as_buffer*/ nullptr,
187 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
188 /*tp_doc*/ UnaryFunction1DFloat___doc__,
189 /*tp_traverse*/ nullptr,
190 /*tp_clear*/ nullptr,
191 /*tp_richcompare*/ nullptr,
192 /*tp_weaklistoffset*/ 0,
193 /*tp_iter*/ nullptr,
194 /*tp_iternext*/ nullptr,
195 /*tp_methods*/ nullptr,
196 /*tp_members*/ nullptr,
198 /*tp_base*/ &UnaryFunction1D_Type,
199 /*tp_dict*/ nullptr,
200 /*tp_descr_get*/ nullptr,
201 /*tp_descr_set*/ nullptr,
202 /*tp_dictoffset*/ 0,
203 /*tp_init*/ (initproc)UnaryFunction1DFloat___init__,
204 /*tp_alloc*/ nullptr,
205 /*tp_new*/ nullptr,
206};
207
IntegrationType IntegrationType_from_BPy_IntegrationType(PyObject *obj)
PyObject * BPy_IntegrationType_from_IntegrationType(IntegrationType i)
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 IntegrationType_Type
#define BPy_IntegrationType_Check(v)
PyTypeObject Interface1D_Type
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[]
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
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< float > * uf1D_float