Blender  V2.93
BPy_UnaryFunction0DDouble.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 "../Iterator/BPy_Interface0DIterator.h"
25 
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 using namespace Freestyle;
42 
44 
45 //-------------------MODULE INITIALIZATION--------------------------------
46 
48 {
49  if (module == nullptr) {
50  return -1;
51  }
52 
53  if (PyType_Ready(&UnaryFunction0DDouble_Type) < 0) {
54  return -1;
55  }
56  Py_INCREF(&UnaryFunction0DDouble_Type);
57  PyModule_AddObject(module, "UnaryFunction0DDouble", (PyObject *)&UnaryFunction0DDouble_Type);
58 
59  if (PyType_Ready(&DensityF0D_Type) < 0) {
60  return -1;
61  }
62  Py_INCREF(&DensityF0D_Type);
63  PyModule_AddObject(module, "DensityF0D", (PyObject *)&DensityF0D_Type);
64 
65  if (PyType_Ready(&LocalAverageDepthF0D_Type) < 0) {
66  return -1;
67  }
68  Py_INCREF(&LocalAverageDepthF0D_Type);
69  PyModule_AddObject(module, "LocalAverageDepthF0D", (PyObject *)&LocalAverageDepthF0D_Type);
70 
71  if (PyType_Ready(&Curvature2DAngleF0D_Type) < 0) {
72  return -1;
73  }
74  Py_INCREF(&Curvature2DAngleF0D_Type);
75  PyModule_AddObject(module, "Curvature2DAngleF0D", (PyObject *)&Curvature2DAngleF0D_Type);
76 
77  if (PyType_Ready(&GetProjectedXF0D_Type) < 0) {
78  return -1;
79  }
80  Py_INCREF(&GetProjectedXF0D_Type);
81  PyModule_AddObject(module, "GetProjectedXF0D", (PyObject *)&GetProjectedXF0D_Type);
82 
83  if (PyType_Ready(&GetProjectedYF0D_Type) < 0) {
84  return -1;
85  }
86  Py_INCREF(&GetProjectedYF0D_Type);
87  PyModule_AddObject(module, "GetProjectedYF0D", (PyObject *)&GetProjectedYF0D_Type);
88 
89  if (PyType_Ready(&GetProjectedZF0D_Type) < 0) {
90  return -1;
91  }
92  Py_INCREF(&GetProjectedZF0D_Type);
93  PyModule_AddObject(module, "GetProjectedZF0D", (PyObject *)&GetProjectedZF0D_Type);
94 
95  if (PyType_Ready(&GetXF0D_Type) < 0) {
96  return -1;
97  }
98  Py_INCREF(&GetXF0D_Type);
99  PyModule_AddObject(module, "GetXF0D", (PyObject *)&GetXF0D_Type);
100 
101  if (PyType_Ready(&GetYF0D_Type) < 0) {
102  return -1;
103  }
104  Py_INCREF(&GetYF0D_Type);
105  PyModule_AddObject(module, "GetYF0D", (PyObject *)&GetYF0D_Type);
106 
107  if (PyType_Ready(&GetZF0D_Type) < 0) {
108  return -1;
109  }
110  Py_INCREF(&GetZF0D_Type);
111  PyModule_AddObject(module, "GetZF0D", (PyObject *)&GetZF0D_Type);
112 
113  if (PyType_Ready(&ZDiscontinuityF0D_Type) < 0) {
114  return -1;
115  }
116  Py_INCREF(&ZDiscontinuityF0D_Type);
117  PyModule_AddObject(module, "ZDiscontinuityF0D", (PyObject *)&ZDiscontinuityF0D_Type);
118 
119  return 0;
120 }
121 
122 //------------------------INSTANCE METHODS ----------------------------------
123 
125  "Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DDouble`\n"
126  "\n"
127  "Base class for unary functions (functors) that work on\n"
128  ":class:`Interface0DIterator` and return a float value.\n"
129  "\n"
130  ".. method:: __init__()\n"
131  "\n"
132  " Default constructor.\n";
133 
135  PyObject *args,
136  PyObject *kwds)
137 {
138  static const char *kwlist[] = {nullptr};
139 
140  if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
141  return -1;
142  }
143  self->uf0D_double = new UnaryFunction0D<double>();
144  self->uf0D_double->py_uf0D = (PyObject *)self;
145  return 0;
146 }
147 
149 {
150  delete self->uf0D_double;
151  UnaryFunction0D_Type.tp_dealloc((PyObject *)self);
152 }
153 
155 {
156  return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_double);
157 }
158 
160  PyObject *args,
161  PyObject *kwds)
162 {
163  static const char *kwlist[] = {"it", nullptr};
164  PyObject *obj;
165 
166  if (!PyArg_ParseTupleAndKeywords(
167  args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) {
168  return nullptr;
169  }
170 
171  if (typeid(*(self->uf0D_double)) == typeid(UnaryFunction0D<double>)) {
172  PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
173  return nullptr;
174  }
175  if (self->uf0D_double->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) {
176  if (!PyErr_Occurred()) {
177  string class_name(Py_TYPE(self)->tp_name);
178  PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
179  }
180  return nullptr;
181  }
182  return PyFloat_FromDouble(self->uf0D_double->result);
183 }
184 
185 /*-----------------------BPy_UnaryFunction0DDouble type definition ------------------------------*/
186 
188  PyVarObject_HEAD_INIT(nullptr, 0) "UnaryFunction0DDouble", /* tp_name */
189  sizeof(BPy_UnaryFunction0DDouble), /* tp_basicsize */
190  0, /* tp_itemsize */
191  (destructor)UnaryFunction0DDouble___dealloc__, /* tp_dealloc */
192  0, /* tp_vectorcall_offset */
193  nullptr, /* tp_getattr */
194  nullptr, /* tp_setattr */
195  nullptr, /* tp_reserved */
196  (reprfunc)UnaryFunction0DDouble___repr__, /* tp_repr */
197  nullptr, /* tp_as_number */
198  nullptr, /* tp_as_sequence */
199  nullptr, /* tp_as_mapping */
200  nullptr, /* tp_hash */
201  (ternaryfunc)UnaryFunction0DDouble___call__, /* tp_call */
202  nullptr, /* tp_str */
203  nullptr, /* tp_getattro */
204  nullptr, /* tp_setattro */
205  nullptr, /* tp_as_buffer */
206  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
207  UnaryFunction0DDouble___doc__, /* tp_doc */
208  nullptr, /* tp_traverse */
209  nullptr, /* tp_clear */
210  nullptr, /* tp_richcompare */
211  0, /* tp_weaklistoffset */
212  nullptr, /* tp_iter */
213  nullptr, /* tp_iternext */
214  nullptr, /* tp_methods */
215  nullptr, /* tp_members */
216  nullptr, /* tp_getset */
217  &UnaryFunction0D_Type, /* tp_base */
218  nullptr, /* tp_dict */
219  nullptr, /* tp_descr_get */
220  nullptr, /* tp_descr_set */
221  0, /* tp_dictoffset */
222  (initproc)UnaryFunction0DDouble___init__, /* tp_init */
223  nullptr, /* tp_alloc */
224  nullptr, /* tp_new */
225 };
226 
228 
229 #ifdef __cplusplus
230 }
231 #endif
PyTypeObject Curvature2DAngleF0D_Type
PyTypeObject DensityF0D_Type
PyTypeObject GetProjectedXF0D_Type
PyTypeObject GetProjectedYF0D_Type
PyTypeObject GetProjectedZF0D_Type
PyTypeObject GetXF0D_Type
Definition: BPy_GetXF0D.cpp:67
PyTypeObject GetYF0D_Type
Definition: BPy_GetYF0D.cpp:67
PyTypeObject GetZF0D_Type
Definition: BPy_GetZF0D.cpp:67
PyTypeObject Interface0DIterator_Type
PyTypeObject LocalAverageDepthF0D_Type
static PyObject * UnaryFunction0DDouble___repr__(BPy_UnaryFunction0DDouble *self)
static void UnaryFunction0DDouble___dealloc__(BPy_UnaryFunction0DDouble *self)
int UnaryFunction0DDouble_Init(PyObject *module)
static char UnaryFunction0DDouble___doc__[]
static PyObject * UnaryFunction0DDouble___call__(BPy_UnaryFunction0DDouble *self, PyObject *args, PyObject *kwds)
static int UnaryFunction0DDouble___init__(BPy_UnaryFunction0DDouble *self, PyObject *args, PyObject *kwds)
PyTypeObject UnaryFunction0DDouble_Type
PyTypeObject UnaryFunction0D_Type
PyTypeObject ZDiscontinuityF0D_Type
static struct PyModuleDef module
PyObject * self
Definition: bpy_driver.c:185
inherits from class Rep
Definition: AppCanvas.cpp:32