Blender V5.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
8
10
11#include "../BPy_Convert.h"
13#include "../BPy_Interface1D.h"
14
16
17#include "BLI_sys_types.hh"
18
19using namespace Freestyle;
20
22
23//-------------------MODULE INITIALIZATION--------------------------------
24
25int UnaryFunction1DUnsigned_Init(PyObject *module)
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__(*args)\n"
57 "\n"
58 " Accepted call signatures:\n"
59 "\n"
60 " - ``__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 " :param integration_type: An integration method.\n"
67 " :type integration_type: :class:`IntegrationType`\n");
69 PyObject *args,
70 PyObject *kwds)
71{
72 static const char *kwlist[] = {"integration", nullptr};
73 PyObject *obj = nullptr;
74
75 if (!PyArg_ParseTupleAndKeywords(args,
76 kwds,
77 "|" /* Optional arguments. */
78 "O!" /* `integration` */
79 ":__init__",
80 (char **)kwlist,
82 &obj))
83 {
84 return -1;
85 }
86
87 if (!obj) {
89 }
90 else {
92 }
93
94 self->uf1D_unsigned->py_uf1D = (PyObject *)self;
95
96 return 0;
97}
98
100{
101 delete self->uf1D_unsigned;
102 UnaryFunction1D_Type.tp_dealloc((PyObject *)self);
103}
104
106{
107 return PyUnicode_FromFormat(
108 "type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_unsigned);
109}
110
112 PyObject *args,
113 PyObject *kwds)
114{
115 static const char *kwlist[] = {"inter", nullptr};
116 PyObject *obj = nullptr;
117
118 if (!PyArg_ParseTupleAndKeywords(args,
119 kwds,
120 "O!" /* `inter` */
121 ":__call__",
122 (char **)kwlist,
124 &obj))
125 {
126 return nullptr;
127 }
128
129 if (typeid(*(self->uf1D_unsigned)) == typeid(UnaryFunction1D<uint>)) {
130 PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
131 return nullptr;
132 }
133 if (self->uf1D_unsigned->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) {
134 if (!PyErr_Occurred()) {
135 string class_name(Py_TYPE(self)->tp_name);
136 PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
137 }
138 return nullptr;
139 }
140 return PyLong_FromLong(self->uf1D_unsigned->result);
141}
142
143/*----------------------UnaryFunction1DUnsigned get/setters ----------------------------*/
144
146 /* Wrap. */
147 integration_type_doc,
148 "The integration method.\n"
149 "\n"
150 ":type: :class:`IntegrationType`\n");
155
157 PyObject *value,
158 void * /*closure*/)
159{
160 if (!BPy_IntegrationType_Check(value)) {
161 PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType");
162 return -1;
163 }
165 return 0;
166}
167
169 {"integration_type",
170 (getter)integration_type_get,
171 (setter)integration_type_set,
172 integration_type_doc,
173 nullptr},
174 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
175};
176
177/*-----------------------BPy_UnaryFunction1DUnsigned type definition ----------------------------*/
178
180 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
181 /*tp_name*/ "UnaryFunction1DUnsigned",
182 /*tp_basicsize*/ sizeof(BPy_UnaryFunction1DUnsigned),
183 /*tp_itemsize*/ 0,
184 /*tp_dealloc*/ (destructor)UnaryFunction1DUnsigned___dealloc__,
185 /*tp_vectorcall_offset*/ 0,
186 /*tp_getattr*/ nullptr,
187 /*tp_setattr*/ nullptr,
188 /*tp_as_async*/ nullptr,
189 /*tp_repr*/ (reprfunc)UnaryFunction1DUnsigned___repr__,
190 /*tp_as_number*/ nullptr,
191 /*tp_as_sequence*/ nullptr,
192 /*tp_as_mapping*/ nullptr,
193 /*tp_hash*/ nullptr,
194 /*tp_call*/ (ternaryfunc)UnaryFunction1DUnsigned___call__,
195 /*tp_str*/ nullptr,
196 /*tp_getattro*/ nullptr,
197 /*tp_setattro*/ nullptr,
198 /*tp_as_buffer*/ nullptr,
199 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
200 /*tp_doc*/ UnaryFunction1DUnsigned___doc__,
201 /*tp_traverse*/ nullptr,
202 /*tp_clear*/ nullptr,
203 /*tp_richcompare*/ nullptr,
204 /*tp_weaklistoffset*/ 0,
205 /*tp_iter*/ nullptr,
206 /*tp_iternext*/ nullptr,
207 /*tp_methods*/ nullptr,
208 /*tp_members*/ nullptr,
210 /*tp_base*/ &UnaryFunction1D_Type,
211 /*tp_dict*/ nullptr,
212 /*tp_descr_get*/ nullptr,
213 /*tp_descr_set*/ nullptr,
214 /*tp_dictoffset*/ 0,
215 /*tp_init*/ (initproc)UnaryFunction1DUnsigned___init__,
216 /*tp_alloc*/ nullptr,
217 /*tp_new*/ nullptr,
218};
219
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 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 *)
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
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< uint > * uf1D_unsigned