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