Blender V5.3
BPy_UnaryFunction1DVec3f.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
17using namespace Freestyle;
18
20
21//-------------------MODULE INITIALIZATION--------------------------------
22
23int UnaryFunction1DVec3f_Init(PyObject *module)
24{
25 if (module == nullptr) {
26 return -1;
27 }
28
29 if (PyType_Ready(&UnaryFunction1DVec3f_Type) < 0) {
30 return -1;
31 }
32 PyModule_AddObjectRef(module, "UnaryFunction1DVec3f", (PyObject *)&UnaryFunction1DVec3f_Type);
33
34 if (PyType_Ready(&Orientation3DF1D_Type) < 0) {
35 return -1;
36 }
37 PyModule_AddObjectRef(module, "Orientation3DF1D", (PyObject *)&Orientation3DF1D_Type);
38
39 return 0;
40}
41
42//------------------------INSTANCE METHODS ----------------------------------
43
45 /* Wrap. */
46 UnaryFunction1DVec3f___doc__,
47 "Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DVec3f`\n"
48 "\n"
49 "Base class for unary functions (functors) that work on\n"
50 ":class:`Interface1D` and return a 3D vector.\n"
51 "\n"
52 ".. method:: __init__(*args)\n"
53 "\n"
54 " Accepted call signatures:\n"
55 "\n"
56 " - ``__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 " :param 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(args,
72 kwds,
73 "|" /* Optional arguments. */
74 "O!" /* `integration` */
75 ":__init__",
76 (char **)kwlist,
78 &obj))
79 {
80 return -1;
81 }
82
83 if (!obj) {
85 }
86 else {
88 }
89
90 self->uf1D_vec3f->py_uf1D = (PyObject *)self;
91
92 return 0;
93}
94
96{
97 delete self->uf1D_vec3f;
98 UnaryFunction1D_Type.tp_dealloc((PyObject *)self);
99}
100
102{
103 return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_vec3f);
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,
114 kwds,
115 "O!" /* `inter` */
116 ":__call__",
117 (char **)kwlist,
119 &obj))
120 {
121 return nullptr;
122 }
123
124 if (typeid(*(self->uf1D_vec3f)) == typeid(UnaryFunction1D<Vec3f>)) {
125 PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
126 return nullptr;
127 }
128 if (self->uf1D_vec3f->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) {
129 if (!PyErr_Occurred()) {
130 string class_name(Py_TYPE(self)->tp_name);
131 PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
132 }
133 return nullptr;
134 }
135 return Vector_from_Vec3f(self->uf1D_vec3f->result);
136}
137
138/*----------------------UnaryFunction1DVec3f get/setters ----------------------------*/
139
141 /* Wrap. */
142 integration_type_doc,
143 "The integration method.\n"
144 "\n"
145 ":type: :class:`IntegrationType`\n");
146static PyObject *integration_type_get(BPy_UnaryFunction1DVec3f *self, void * /*closure*/)
147{
148 return BPy_IntegrationType_from_IntegrationType(self->uf1D_vec3f->getIntegrationType());
149}
150
152 PyObject *value,
153 void * /*closure*/)
154{
155 if (!BPy_IntegrationType_Check(value)) {
156 PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType");
157 return -1;
158 }
159 self->uf1D_vec3f->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value));
160 return 0;
161}
162
164 {"integration_type",
165 (getter)integration_type_get,
166 (setter)integration_type_set,
167 integration_type_doc,
168 nullptr},
169 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
170};
171
172/*-----------------------BPy_UnaryFunction1DVec3f type definition ------------------------------*/
173
175 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
176 /*tp_name*/ "UnaryFunction1DVec3f",
177 /*tp_basicsize*/ sizeof(BPy_UnaryFunction1DVec3f),
178 /*tp_itemsize*/ 0,
179 /*tp_dealloc*/ (destructor)UnaryFunction1DVec3f___dealloc__,
180 /*tp_vectorcall_offset*/ 0,
181 /*tp_getattr*/ nullptr,
182 /*tp_setattr*/ nullptr,
183 /*tp_as_async*/ nullptr,
184 /*tp_repr*/ (reprfunc)UnaryFunction1DVec3f___repr__,
185 /*tp_as_number*/ nullptr,
186 /*tp_as_sequence*/ nullptr,
187 /*tp_as_mapping*/ nullptr,
188 /*tp_hash*/ nullptr,
189 /*tp_call*/ (ternaryfunc)UnaryFunction1DVec3f___call__,
190 /*tp_str*/ nullptr,
191 /*tp_getattro*/ nullptr,
192 /*tp_setattro*/ nullptr,
193 /*tp_as_buffer*/ nullptr,
194 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
195 /*tp_doc*/ UnaryFunction1DVec3f___doc__,
196 /*tp_traverse*/ nullptr,
197 /*tp_clear*/ nullptr,
198 /*tp_richcompare*/ nullptr,
199 /*tp_weaklistoffset*/ 0,
200 /*tp_iter*/ nullptr,
201 /*tp_iternext*/ nullptr,
202 /*tp_methods*/ nullptr,
203 /*tp_members*/ nullptr,
205 /*tp_base*/ &UnaryFunction1D_Type,
206 /*tp_dict*/ nullptr,
207 /*tp_descr_get*/ nullptr,
208 /*tp_descr_set*/ nullptr,
209 /*tp_dictoffset*/ 0,
210 /*tp_init*/ (initproc)UnaryFunction1DVec3f___init__,
211 /*tp_alloc*/ nullptr,
212 /*tp_new*/ nullptr,
213};
214
IntegrationType IntegrationType_from_BPy_IntegrationType(PyObject *obj)
PyObject * Vector_from_Vec3f(Vec3f &vec)
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 Orientation3DF1D_Type
static PyObject * UnaryFunction1DVec3f___repr__(BPy_UnaryFunction1DVec3f *self)
static PyObject * integration_type_get(BPy_UnaryFunction1DVec3f *self, void *)
int UnaryFunction1DVec3f_Init(PyObject *module)
static PyObject * UnaryFunction1DVec3f___call__(BPy_UnaryFunction1DVec3f *self, PyObject *args, PyObject *kwds)
static int UnaryFunction1DVec3f___init__(BPy_UnaryFunction1DVec3f *self, PyObject *args, PyObject *kwds)
static PyGetSetDef BPy_UnaryFunction1DVec3f_getseters[]
PyTypeObject UnaryFunction1DVec3f_Type
static int integration_type_set(BPy_UnaryFunction1DVec3f *self, PyObject *value, void *)
static void UnaryFunction1DVec3f___dealloc__(BPy_UnaryFunction1DVec3f *self)
PyTypeObject UnaryFunction1D_Type
inherits from class Rep
Definition AppCanvas.cpp:20
Freestyle::UnaryFunction1D< Freestyle::Geometry::Vec3f > * uf1D_vec3f