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