Blender  V2.93
BPy_UnaryFunction0DFloat.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 
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 using namespace Freestyle;
38 
40 
41 //-------------------MODULE INITIALIZATION--------------------------------
42 
44 {
45  if (module == nullptr) {
46  return -1;
47  }
48 
49  if (PyType_Ready(&UnaryFunction0DFloat_Type) < 0) {
50  return -1;
51  }
52  Py_INCREF(&UnaryFunction0DFloat_Type);
53  PyModule_AddObject(module, "UnaryFunction0DFloat", (PyObject *)&UnaryFunction0DFloat_Type);
54 
55  if (PyType_Ready(&GetCurvilinearAbscissaF0D_Type) < 0) {
56  return -1;
57  }
59  PyModule_AddObject(
60  module, "GetCurvilinearAbscissaF0D", (PyObject *)&GetCurvilinearAbscissaF0D_Type);
61 
62  if (PyType_Ready(&GetParameterF0D_Type) < 0) {
63  return -1;
64  }
65  Py_INCREF(&GetParameterF0D_Type);
66  PyModule_AddObject(module, "GetParameterF0D", (PyObject *)&GetParameterF0D_Type);
67 
68  if (PyType_Ready(&GetViewMapGradientNormF0D_Type) < 0) {
69  return -1;
70  }
72  PyModule_AddObject(
73  module, "GetViewMapGradientNormF0D", (PyObject *)&GetViewMapGradientNormF0D_Type);
74 
75  if (PyType_Ready(&ReadCompleteViewMapPixelF0D_Type) < 0) {
76  return -1;
77  }
79  PyModule_AddObject(
80  module, "ReadCompleteViewMapPixelF0D", (PyObject *)&ReadCompleteViewMapPixelF0D_Type);
81 
82  if (PyType_Ready(&ReadMapPixelF0D_Type) < 0) {
83  return -1;
84  }
85  Py_INCREF(&ReadMapPixelF0D_Type);
86  PyModule_AddObject(module, "ReadMapPixelF0D", (PyObject *)&ReadMapPixelF0D_Type);
87 
88  if (PyType_Ready(&ReadSteerableViewMapPixelF0D_Type) < 0) {
89  return -1;
90  }
92  PyModule_AddObject(
93  module, "ReadSteerableViewMapPixelF0D", (PyObject *)&ReadSteerableViewMapPixelF0D_Type);
94 
95  return 0;
96 }
97 
98 //------------------------INSTANCE METHODS ----------------------------------
99 
101  "Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DFloat`\n"
102  "\n"
103  "Base class for unary functions (functors) that work on\n"
104  ":class:`Interface0DIterator` and return a float value.\n"
105  "\n"
106  ".. method:: __init__()\n"
107  "\n"
108  " Default constructor.\n";
109 
111  PyObject *args,
112  PyObject *kwds)
113 {
114  static const char *kwlist[] = {nullptr};
115 
116  if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
117  return -1;
118  }
119  self->uf0D_float = new UnaryFunction0D<float>();
120  self->uf0D_float->py_uf0D = (PyObject *)self;
121  return 0;
122 }
123 
125 {
126  delete self->uf0D_float;
127  UnaryFunction0D_Type.tp_dealloc((PyObject *)self);
128 }
129 
131 {
132  return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_float);
133 }
134 
136  PyObject *args,
137  PyObject *kwds)
138 {
139  static const char *kwlist[] = {"it", nullptr};
140  PyObject *obj;
141 
142  if (!PyArg_ParseTupleAndKeywords(
143  args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) {
144  return nullptr;
145  }
146 
147  if (typeid(*(self->uf0D_float)) == typeid(UnaryFunction0D<float>)) {
148  PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
149  return nullptr;
150  }
151  if (self->uf0D_float->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) {
152  if (!PyErr_Occurred()) {
153  string class_name(Py_TYPE(self)->tp_name);
154  PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
155  }
156  return nullptr;
157  }
158  return PyFloat_FromDouble(self->uf0D_float->result);
159 }
160 
161 /*-----------------------BPy_UnaryFunction0DFloat type definition ------------------------------*/
162 
164  PyVarObject_HEAD_INIT(nullptr, 0) "UnaryFunction0DFloat", /* tp_name */
165  sizeof(BPy_UnaryFunction0DFloat), /* tp_basicsize */
166  0, /* tp_itemsize */
167  (destructor)UnaryFunction0DFloat___dealloc__, /* tp_dealloc */
168  0, /* tp_vectorcall_offset */
169  nullptr, /* tp_getattr */
170  nullptr, /* tp_setattr */
171  nullptr, /* tp_reserved */
172  (reprfunc)UnaryFunction0DFloat___repr__, /* tp_repr */
173  nullptr, /* tp_as_number */
174  nullptr, /* tp_as_sequence */
175  nullptr, /* tp_as_mapping */
176  nullptr, /* tp_hash */
177  (ternaryfunc)UnaryFunction0DFloat___call__, /* tp_call */
178  nullptr, /* tp_str */
179  nullptr, /* tp_getattro */
180  nullptr, /* tp_setattro */
181  nullptr, /* tp_as_buffer */
182  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
183  UnaryFunction0DFloat___doc__, /* tp_doc */
184  nullptr, /* tp_traverse */
185  nullptr, /* tp_clear */
186  nullptr, /* tp_richcompare */
187  0, /* tp_weaklistoffset */
188  nullptr, /* tp_iter */
189  nullptr, /* tp_iternext */
190  nullptr, /* tp_methods */
191  nullptr, /* tp_members */
192  nullptr, /* tp_getset */
193  &UnaryFunction0D_Type, /* tp_base */
194  nullptr, /* tp_dict */
195  nullptr, /* tp_descr_get */
196  nullptr, /* tp_descr_set */
197  0, /* tp_dictoffset */
198  (initproc)UnaryFunction0DFloat___init__, /* tp_init */
199  nullptr, /* tp_alloc */
200  nullptr, /* tp_new */
201 };
202 
204 
205 #ifdef __cplusplus
206 }
207 #endif
PyTypeObject GetCurvilinearAbscissaF0D_Type
PyTypeObject GetParameterF0D_Type
PyTypeObject GetViewMapGradientNormF0D_Type
PyTypeObject Interface0DIterator_Type
PyTypeObject ReadCompleteViewMapPixelF0D_Type
PyTypeObject ReadMapPixelF0D_Type
PyTypeObject ReadSteerableViewMapPixelF0D_Type
static PyObject * UnaryFunction0DFloat___call__(BPy_UnaryFunction0DFloat *self, PyObject *args, PyObject *kwds)
static char UnaryFunction0DFloat___doc__[]
static PyObject * UnaryFunction0DFloat___repr__(BPy_UnaryFunction0DFloat *self)
static int UnaryFunction0DFloat___init__(BPy_UnaryFunction0DFloat *self, PyObject *args, PyObject *kwds)
static void UnaryFunction0DFloat___dealloc__(BPy_UnaryFunction0DFloat *self)
int UnaryFunction0DFloat_Init(PyObject *module)
PyTypeObject UnaryFunction0DFloat_Type
PyTypeObject UnaryFunction0D_Type
static struct PyModuleDef module
PyObject * self
Definition: bpy_driver.c:185
inherits from class Rep
Definition: AppCanvas.cpp:32