Blender  V3.3
BPy_UnaryFunction1DDouble.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
8 
9 #include "../BPy_Convert.h"
10 #include "../BPy_IntegrationType.h"
11 #include "../BPy_Interface1D.h"
12 
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 using namespace Freestyle;
33 
35 
36 //-------------------MODULE INITIALIZATION--------------------------------
37 
39 {
40  if (module == nullptr) {
41  return -1;
42  }
43 
44  if (PyType_Ready(&UnaryFunction1DDouble_Type) < 0) {
45  return -1;
46  }
47  Py_INCREF(&UnaryFunction1DDouble_Type);
48  PyModule_AddObject(module, "UnaryFunction1DDouble", (PyObject *)&UnaryFunction1DDouble_Type);
49 
50  if (PyType_Ready(&DensityF1D_Type) < 0) {
51  return -1;
52  }
53  Py_INCREF(&DensityF1D_Type);
54  PyModule_AddObject(module, "DensityF1D", (PyObject *)&DensityF1D_Type);
55 
56  if (PyType_Ready(&Curvature2DAngleF1D_Type) < 0) {
57  return -1;
58  }
59  Py_INCREF(&Curvature2DAngleF1D_Type);
60  PyModule_AddObject(module, "Curvature2DAngleF1D", (PyObject *)&Curvature2DAngleF1D_Type);
61 
62  if (PyType_Ready(&GetCompleteViewMapDensityF1D_Type) < 0) {
63  return -1;
64  }
66  PyModule_AddObject(
67  module, "GetCompleteViewMapDensityF1D", (PyObject *)&GetCompleteViewMapDensityF1D_Type);
68 
69  if (PyType_Ready(&GetDirectionalViewMapDensityF1D_Type) < 0) {
70  return -1;
71  }
73  PyModule_AddObject(module,
74  "GetDirectionalViewMapDensityF1D",
76 
77  if (PyType_Ready(&GetProjectedXF1D_Type) < 0) {
78  return -1;
79  }
80  Py_INCREF(&GetProjectedXF1D_Type);
81  PyModule_AddObject(module, "GetProjectedXF1D", (PyObject *)&GetProjectedXF1D_Type);
82 
83  if (PyType_Ready(&GetProjectedYF1D_Type) < 0) {
84  return -1;
85  }
86  Py_INCREF(&GetProjectedYF1D_Type);
87  PyModule_AddObject(module, "GetProjectedYF1D", (PyObject *)&GetProjectedYF1D_Type);
88 
89  if (PyType_Ready(&GetProjectedZF1D_Type) < 0) {
90  return -1;
91  }
92  Py_INCREF(&GetProjectedZF1D_Type);
93  PyModule_AddObject(module, "GetProjectedZF1D", (PyObject *)&GetProjectedZF1D_Type);
94 
95  if (PyType_Ready(&GetSteerableViewMapDensityF1D_Type) < 0) {
96  return -1;
97  }
99  PyModule_AddObject(
100  module, "GetSteerableViewMapDensityF1D", (PyObject *)&GetSteerableViewMapDensityF1D_Type);
101 
102  if (PyType_Ready(&GetViewMapGradientNormF1D_Type) < 0) {
103  return -1;
104  }
105  Py_INCREF(&GetViewMapGradientNormF1D_Type);
106  PyModule_AddObject(
107  module, "GetViewMapGradientNormF1D", (PyObject *)&GetViewMapGradientNormF1D_Type);
108 
109  if (PyType_Ready(&GetXF1D_Type) < 0) {
110  return -1;
111  }
112  Py_INCREF(&GetXF1D_Type);
113  PyModule_AddObject(module, "GetXF1D", (PyObject *)&GetXF1D_Type);
114 
115  if (PyType_Ready(&GetYF1D_Type) < 0) {
116  return -1;
117  }
118  Py_INCREF(&GetYF1D_Type);
119  PyModule_AddObject(module, "GetYF1D", (PyObject *)&GetYF1D_Type);
120 
121  if (PyType_Ready(&GetZF1D_Type) < 0) {
122  return -1;
123  }
124  Py_INCREF(&GetZF1D_Type);
125  PyModule_AddObject(module, "GetZF1D", (PyObject *)&GetZF1D_Type);
126 
127  if (PyType_Ready(&LocalAverageDepthF1D_Type) < 0) {
128  return -1;
129  }
130  Py_INCREF(&LocalAverageDepthF1D_Type);
131  PyModule_AddObject(module, "LocalAverageDepthF1D", (PyObject *)&LocalAverageDepthF1D_Type);
132 
133  if (PyType_Ready(&ZDiscontinuityF1D_Type) < 0) {
134  return -1;
135  }
136  Py_INCREF(&ZDiscontinuityF1D_Type);
137  PyModule_AddObject(module, "ZDiscontinuityF1D", (PyObject *)&ZDiscontinuityF1D_Type);
138 
139  return 0;
140 }
141 
142 //------------------------INSTANCE METHODS ----------------------------------
143 
145  "Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DDouble`\n"
146  "\n"
147  "Base class for unary functions (functors) that work on\n"
148  ":class:`Interface1D` and return a float value.\n"
149  "\n"
150  ".. method:: __init__()\n"
151  " __init__(integration_type)\n"
152  "\n"
153  " Builds a unary 1D function using the default constructor\n"
154  " or the integration method given as an argument.\n"
155  "\n"
156  " :arg integration_type: An integration method.\n"
157  " :type integration_type: :class:`IntegrationType`\n";
158 
160  PyObject *args,
161  PyObject *kwds)
162 {
163  static const char *kwlist[] = {"integration", nullptr};
164  PyObject *obj = nullptr;
165 
166  if (!PyArg_ParseTupleAndKeywords(
167  args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) {
168  return -1;
169  }
170 
171  if (!obj) {
172  self->uf1D_double = new UnaryFunction1D<double>();
173  }
174  else {
176  }
177 
178  self->uf1D_double->py_uf1D = (PyObject *)self;
179 
180  return 0;
181 }
182 
184 {
185  delete self->uf1D_double;
186  UnaryFunction1D_Type.tp_dealloc((PyObject *)self);
187 }
188 
190 {
191  return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_double);
192 }
193 
195  PyObject *args,
196  PyObject *kwds)
197 {
198  static const char *kwlist[] = {"inter", nullptr};
199  PyObject *obj = nullptr;
200 
201  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) {
202  return nullptr;
203  }
204 
205  if (typeid(*(self->uf1D_double)) == typeid(UnaryFunction1D<double>)) {
206  PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
207  return nullptr;
208  }
209  if (self->uf1D_double->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) {
210  if (!PyErr_Occurred()) {
211  string class_name(Py_TYPE(self)->tp_name);
212  PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
213  }
214  return nullptr;
215  }
216  return PyFloat_FromDouble(self->uf1D_double->result);
217 }
218 
219 /*----------------------UnaryFunction1DDouble get/setters ----------------------------*/
220 
221 PyDoc_STRVAR(integration_type_doc,
222  "The integration method.\n"
223  "\n"
224  ":type: :class:`IntegrationType`");
225 
226 static PyObject *integration_type_get(BPy_UnaryFunction1DDouble *self, void *UNUSED(closure))
227 {
228  return BPy_IntegrationType_from_IntegrationType(self->uf1D_double->getIntegrationType());
229 }
230 
232  PyObject *value,
233  void *UNUSED(closure))
234 {
235  if (!BPy_IntegrationType_Check(value)) {
236  PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType");
237  return -1;
238  }
239  self->uf1D_double->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value));
240  return 0;
241 }
242 
243 static PyGetSetDef BPy_UnaryFunction1DDouble_getseters[] = {
244  {"integration_type",
245  (getter)integration_type_get,
246  (setter)integration_type_set,
247  integration_type_doc,
248  nullptr},
249  {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
250 };
251 
252 /*-----------------------BPy_UnaryFunction1DDouble type definition ------------------------------*/
253 
255  PyVarObject_HEAD_INIT(nullptr, 0) "UnaryFunction1DDouble", /* tp_name */
256  sizeof(BPy_UnaryFunction1DDouble), /* tp_basicsize */
257  0, /* tp_itemsize */
258  (destructor)UnaryFunction1DDouble___dealloc__, /* tp_dealloc */
259  0, /* tp_vectorcall_offset */
260  nullptr, /* tp_getattr */
261  nullptr, /* tp_setattr */
262  nullptr, /* tp_reserved */
263  (reprfunc)UnaryFunction1DDouble___repr__, /* tp_repr */
264  nullptr, /* tp_as_number */
265  nullptr, /* tp_as_sequence */
266  nullptr, /* tp_as_mapping */
267  nullptr, /* tp_hash */
268  (ternaryfunc)UnaryFunction1DDouble___call__, /* tp_call */
269  nullptr, /* tp_str */
270  nullptr, /* tp_getattro */
271  nullptr, /* tp_setattro */
272  nullptr, /* tp_as_buffer */
273  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
274  UnaryFunction1DDouble___doc__, /* tp_doc */
275  nullptr, /* tp_traverse */
276  nullptr, /* tp_clear */
277  nullptr, /* tp_richcompare */
278  0, /* tp_weaklistoffset */
279  nullptr, /* tp_iter */
280  nullptr, /* tp_iternext */
281  nullptr, /* tp_methods */
282  nullptr, /* tp_members */
283  BPy_UnaryFunction1DDouble_getseters, /* tp_getset */
284  &UnaryFunction1D_Type, /* tp_base */
285  nullptr, /* tp_dict */
286  nullptr, /* tp_descr_get */
287  nullptr, /* tp_descr_set */
288  0, /* tp_dictoffset */
289  (initproc)UnaryFunction1DDouble___init__, /* tp_init */
290  nullptr, /* tp_alloc */
291  nullptr, /* tp_new */
292 };
293 
295 
296 #ifdef __cplusplus
297 }
298 #endif
#define UNUSED(x)
PyObject * BPy_IntegrationType_from_IntegrationType(IntegrationType i)
IntegrationType IntegrationType_from_BPy_IntegrationType(PyObject *obj)
PyTypeObject Curvature2DAngleF1D_Type
PyTypeObject DensityF1D_Type
PyTypeObject GetCompleteViewMapDensityF1D_Type
PyTypeObject GetDirectionalViewMapDensityF1D_Type
PyTypeObject GetProjectedXF1D_Type
PyTypeObject GetProjectedYF1D_Type
PyTypeObject GetProjectedZF1D_Type
PyTypeObject GetSteerableViewMapDensityF1D_Type
PyTypeObject GetViewMapGradientNormF1D_Type
PyTypeObject GetXF1D_Type
Definition: BPy_GetXF1D.cpp:60
PyTypeObject GetYF1D_Type
Definition: BPy_GetYF1D.cpp:59
PyTypeObject GetZF1D_Type
Definition: BPy_GetZF1D.cpp:60
PyTypeObject IntegrationType_Type
#define BPy_IntegrationType_Check(v)
PyTypeObject Interface1D_Type
PyTypeObject LocalAverageDepthF1D_Type
static char UnaryFunction1DDouble___doc__[]
PyDoc_STRVAR(integration_type_doc, "The integration method.\n" "\n" ":type: :class:`IntegrationType`")
static int UnaryFunction1DDouble___init__(BPy_UnaryFunction1DDouble *self, PyObject *args, PyObject *kwds)
static void UnaryFunction1DDouble___dealloc__(BPy_UnaryFunction1DDouble *self)
static PyObject * UnaryFunction1DDouble___call__(BPy_UnaryFunction1DDouble *self, PyObject *args, PyObject *kwds)
static PyObject * UnaryFunction1DDouble___repr__(BPy_UnaryFunction1DDouble *self)
static PyObject * integration_type_get(BPy_UnaryFunction1DDouble *self, void *UNUSED(closure))
int UnaryFunction1DDouble_Init(PyObject *module)
PyTypeObject UnaryFunction1DDouble_Type
static int integration_type_set(BPy_UnaryFunction1DDouble *self, PyObject *value, void *UNUSED(closure))
static PyGetSetDef BPy_UnaryFunction1DDouble_getseters[]
PyTypeObject UnaryFunction1D_Type
PyTypeObject ZDiscontinuityF1D_Type
PyObject * self
Definition: bpy_driver.c:165
inherits from class Rep
Definition: AppCanvas.cpp:18
static struct PyModuleDef module
Definition: python.cpp:972