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