Blender  V2.93
BPy_UnaryFunction1DDouble.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
22 
23 #include "../BPy_Convert.h"
24 #include "../BPy_IntegrationType.h"
25 #include "../BPy_Interface1D.h"
26 
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 using namespace Freestyle;
47 
49 
50 //-------------------MODULE INITIALIZATION--------------------------------
51 
53 {
54  if (module == nullptr) {
55  return -1;
56  }
57 
58  if (PyType_Ready(&UnaryFunction1DDouble_Type) < 0) {
59  return -1;
60  }
61  Py_INCREF(&UnaryFunction1DDouble_Type);
62  PyModule_AddObject(module, "UnaryFunction1DDouble", (PyObject *)&UnaryFunction1DDouble_Type);
63 
64  if (PyType_Ready(&DensityF1D_Type) < 0) {
65  return -1;
66  }
67  Py_INCREF(&DensityF1D_Type);
68  PyModule_AddObject(module, "DensityF1D", (PyObject *)&DensityF1D_Type);
69 
70  if (PyType_Ready(&Curvature2DAngleF1D_Type) < 0) {
71  return -1;
72  }
73  Py_INCREF(&Curvature2DAngleF1D_Type);
74  PyModule_AddObject(module, "Curvature2DAngleF1D", (PyObject *)&Curvature2DAngleF1D_Type);
75 
76  if (PyType_Ready(&GetCompleteViewMapDensityF1D_Type) < 0) {
77  return -1;
78  }
80  PyModule_AddObject(
81  module, "GetCompleteViewMapDensityF1D", (PyObject *)&GetCompleteViewMapDensityF1D_Type);
82 
83  if (PyType_Ready(&GetDirectionalViewMapDensityF1D_Type) < 0) {
84  return -1;
85  }
87  PyModule_AddObject(module,
88  "GetDirectionalViewMapDensityF1D",
90 
91  if (PyType_Ready(&GetProjectedXF1D_Type) < 0) {
92  return -1;
93  }
94  Py_INCREF(&GetProjectedXF1D_Type);
95  PyModule_AddObject(module, "GetProjectedXF1D", (PyObject *)&GetProjectedXF1D_Type);
96 
97  if (PyType_Ready(&GetProjectedYF1D_Type) < 0) {
98  return -1;
99  }
100  Py_INCREF(&GetProjectedYF1D_Type);
101  PyModule_AddObject(module, "GetProjectedYF1D", (PyObject *)&GetProjectedYF1D_Type);
102 
103  if (PyType_Ready(&GetProjectedZF1D_Type) < 0) {
104  return -1;
105  }
106  Py_INCREF(&GetProjectedZF1D_Type);
107  PyModule_AddObject(module, "GetProjectedZF1D", (PyObject *)&GetProjectedZF1D_Type);
108 
109  if (PyType_Ready(&GetSteerableViewMapDensityF1D_Type) < 0) {
110  return -1;
111  }
113  PyModule_AddObject(
114  module, "GetSteerableViewMapDensityF1D", (PyObject *)&GetSteerableViewMapDensityF1D_Type);
115 
116  if (PyType_Ready(&GetViewMapGradientNormF1D_Type) < 0) {
117  return -1;
118  }
119  Py_INCREF(&GetViewMapGradientNormF1D_Type);
120  PyModule_AddObject(
121  module, "GetViewMapGradientNormF1D", (PyObject *)&GetViewMapGradientNormF1D_Type);
122 
123  if (PyType_Ready(&GetXF1D_Type) < 0) {
124  return -1;
125  }
126  Py_INCREF(&GetXF1D_Type);
127  PyModule_AddObject(module, "GetXF1D", (PyObject *)&GetXF1D_Type);
128 
129  if (PyType_Ready(&GetYF1D_Type) < 0) {
130  return -1;
131  }
132  Py_INCREF(&GetYF1D_Type);
133  PyModule_AddObject(module, "GetYF1D", (PyObject *)&GetYF1D_Type);
134 
135  if (PyType_Ready(&GetZF1D_Type) < 0) {
136  return -1;
137  }
138  Py_INCREF(&GetZF1D_Type);
139  PyModule_AddObject(module, "GetZF1D", (PyObject *)&GetZF1D_Type);
140 
141  if (PyType_Ready(&LocalAverageDepthF1D_Type) < 0) {
142  return -1;
143  }
144  Py_INCREF(&LocalAverageDepthF1D_Type);
145  PyModule_AddObject(module, "LocalAverageDepthF1D", (PyObject *)&LocalAverageDepthF1D_Type);
146 
147  if (PyType_Ready(&ZDiscontinuityF1D_Type) < 0) {
148  return -1;
149  }
150  Py_INCREF(&ZDiscontinuityF1D_Type);
151  PyModule_AddObject(module, "ZDiscontinuityF1D", (PyObject *)&ZDiscontinuityF1D_Type);
152 
153  return 0;
154 }
155 
156 //------------------------INSTANCE METHODS ----------------------------------
157 
159  "Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DDouble`\n"
160  "\n"
161  "Base class for unary functions (functors) that work on\n"
162  ":class:`Interface1D` and return a float value.\n"
163  "\n"
164  ".. method:: __init__()\n"
165  " __init__(integration_type)\n"
166  "\n"
167  " Builds a unary 1D function using the default constructor\n"
168  " or the integration method given as an argument.\n"
169  "\n"
170  " :arg integration_type: An integration method.\n"
171  " :type integration_type: :class:`IntegrationType`\n";
172 
174  PyObject *args,
175  PyObject *kwds)
176 {
177  static const char *kwlist[] = {"integration", nullptr};
178  PyObject *obj = nullptr;
179 
180  if (!PyArg_ParseTupleAndKeywords(
181  args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) {
182  return -1;
183  }
184 
185  if (!obj) {
186  self->uf1D_double = new UnaryFunction1D<double>();
187  }
188  else {
190  }
191 
192  self->uf1D_double->py_uf1D = (PyObject *)self;
193 
194  return 0;
195 }
196 
198 {
199  delete self->uf1D_double;
200  UnaryFunction1D_Type.tp_dealloc((PyObject *)self);
201 }
202 
204 {
205  return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_double);
206 }
207 
209  PyObject *args,
210  PyObject *kwds)
211 {
212  static const char *kwlist[] = {"inter", nullptr};
213  PyObject *obj = nullptr;
214 
215  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) {
216  return nullptr;
217  }
218 
219  if (typeid(*(self->uf1D_double)) == typeid(UnaryFunction1D<double>)) {
220  PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
221  return nullptr;
222  }
223  if (self->uf1D_double->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) {
224  if (!PyErr_Occurred()) {
225  string class_name(Py_TYPE(self)->tp_name);
226  PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
227  }
228  return nullptr;
229  }
230  return PyFloat_FromDouble(self->uf1D_double->result);
231 }
232 
233 /*----------------------UnaryFunction1DDouble get/setters ----------------------------*/
234 
235 PyDoc_STRVAR(integration_type_doc,
236  "The integration method.\n"
237  "\n"
238  ":type: :class:`IntegrationType`");
239 
240 static PyObject *integration_type_get(BPy_UnaryFunction1DDouble *self, void *UNUSED(closure))
241 {
242  return BPy_IntegrationType_from_IntegrationType(self->uf1D_double->getIntegrationType());
243 }
244 
246  PyObject *value,
247  void *UNUSED(closure))
248 {
249  if (!BPy_IntegrationType_Check(value)) {
250  PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType");
251  return -1;
252  }
253  self->uf1D_double->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value));
254  return 0;
255 }
256 
257 static PyGetSetDef BPy_UnaryFunction1DDouble_getseters[] = {
258  {"integration_type",
259  (getter)integration_type_get,
260  (setter)integration_type_set,
261  integration_type_doc,
262  nullptr},
263  {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
264 };
265 
266 /*-----------------------BPy_UnaryFunction1DDouble type definition ------------------------------*/
267 
269  PyVarObject_HEAD_INIT(nullptr, 0) "UnaryFunction1DDouble", /* tp_name */
270  sizeof(BPy_UnaryFunction1DDouble), /* tp_basicsize */
271  0, /* tp_itemsize */
272  (destructor)UnaryFunction1DDouble___dealloc__, /* tp_dealloc */
273  0, /* tp_vectorcall_offset */
274  nullptr, /* tp_getattr */
275  nullptr, /* tp_setattr */
276  nullptr, /* tp_reserved */
277  (reprfunc)UnaryFunction1DDouble___repr__, /* tp_repr */
278  nullptr, /* tp_as_number */
279  nullptr, /* tp_as_sequence */
280  nullptr, /* tp_as_mapping */
281  nullptr, /* tp_hash */
282  (ternaryfunc)UnaryFunction1DDouble___call__, /* tp_call */
283  nullptr, /* tp_str */
284  nullptr, /* tp_getattro */
285  nullptr, /* tp_setattro */
286  nullptr, /* tp_as_buffer */
287  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
288  UnaryFunction1DDouble___doc__, /* tp_doc */
289  nullptr, /* tp_traverse */
290  nullptr, /* tp_clear */
291  nullptr, /* tp_richcompare */
292  0, /* tp_weaklistoffset */
293  nullptr, /* tp_iter */
294  nullptr, /* tp_iternext */
295  nullptr, /* tp_methods */
296  nullptr, /* tp_members */
297  BPy_UnaryFunction1DDouble_getseters, /* tp_getset */
298  &UnaryFunction1D_Type, /* tp_base */
299  nullptr, /* tp_dict */
300  nullptr, /* tp_descr_get */
301  nullptr, /* tp_descr_set */
302  0, /* tp_dictoffset */
303  (initproc)UnaryFunction1DDouble___init__, /* tp_init */
304  nullptr, /* tp_alloc */
305  nullptr, /* tp_new */
306 };
307 
309 
310 #ifdef __cplusplus
311 }
312 #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:74
PyTypeObject GetYF1D_Type
Definition: BPy_GetYF1D.cpp:73
PyTypeObject GetZF1D_Type
Definition: BPy_GetZF1D.cpp:74
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
static struct PyModuleDef module
PyObject * self
Definition: bpy_driver.c:185
inherits from class Rep
Definition: AppCanvas.cpp:32