GPUTexture: Make GPU_texture_unbind_all faster on newer opengl version
[blender.git] / source / blender / freestyle / intern / python / UnaryFunction0D / BPy_UnaryFunction0DFloat.cpp
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
17 /** \file
18  * \ingroup freestyle
19  */
20
21 #include "BPy_UnaryFunction0DFloat.h"
22
23 #include "../BPy_Convert.h"
24 #include "../Iterator/BPy_Interface0DIterator.h"
25
26 #include "UnaryFunction0D_float/BPy_GetCurvilinearAbscissaF0D.h"
27 #include "UnaryFunction0D_float/BPy_GetParameterF0D.h"
28 #include "UnaryFunction0D_float/BPy_GetViewMapGradientNormF0D.h"
29 #include "UnaryFunction0D_float/BPy_ReadCompleteViewMapPixelF0D.h"
30 #include "UnaryFunction0D_float/BPy_ReadMapPixelF0D.h"
31 #include "UnaryFunction0D_float/BPy_ReadSteerableViewMapPixelF0D.h"
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 ///////////////////////////////////////////////////////////////////////////////////////////
38
39 //-------------------MODULE INITIALIZATION--------------------------------
40
41 int UnaryFunction0DFloat_Init(PyObject *module)
42 {
43   if (module == NULL) {
44     return -1;
45   }
46
47   if (PyType_Ready(&UnaryFunction0DFloat_Type) < 0) {
48     return -1;
49   }
50   Py_INCREF(&UnaryFunction0DFloat_Type);
51   PyModule_AddObject(module, "UnaryFunction0DFloat", (PyObject *)&UnaryFunction0DFloat_Type);
52
53   if (PyType_Ready(&GetCurvilinearAbscissaF0D_Type) < 0) {
54     return -1;
55   }
56   Py_INCREF(&GetCurvilinearAbscissaF0D_Type);
57   PyModule_AddObject(
58       module, "GetCurvilinearAbscissaF0D", (PyObject *)&GetCurvilinearAbscissaF0D_Type);
59
60   if (PyType_Ready(&GetParameterF0D_Type) < 0) {
61     return -1;
62   }
63   Py_INCREF(&GetParameterF0D_Type);
64   PyModule_AddObject(module, "GetParameterF0D", (PyObject *)&GetParameterF0D_Type);
65
66   if (PyType_Ready(&GetViewMapGradientNormF0D_Type) < 0) {
67     return -1;
68   }
69   Py_INCREF(&GetViewMapGradientNormF0D_Type);
70   PyModule_AddObject(
71       module, "GetViewMapGradientNormF0D", (PyObject *)&GetViewMapGradientNormF0D_Type);
72
73   if (PyType_Ready(&ReadCompleteViewMapPixelF0D_Type) < 0) {
74     return -1;
75   }
76   Py_INCREF(&ReadCompleteViewMapPixelF0D_Type);
77   PyModule_AddObject(
78       module, "ReadCompleteViewMapPixelF0D", (PyObject *)&ReadCompleteViewMapPixelF0D_Type);
79
80   if (PyType_Ready(&ReadMapPixelF0D_Type) < 0) {
81     return -1;
82   }
83   Py_INCREF(&ReadMapPixelF0D_Type);
84   PyModule_AddObject(module, "ReadMapPixelF0D", (PyObject *)&ReadMapPixelF0D_Type);
85
86   if (PyType_Ready(&ReadSteerableViewMapPixelF0D_Type) < 0) {
87     return -1;
88   }
89   Py_INCREF(&ReadSteerableViewMapPixelF0D_Type);
90   PyModule_AddObject(
91       module, "ReadSteerableViewMapPixelF0D", (PyObject *)&ReadSteerableViewMapPixelF0D_Type);
92
93   return 0;
94 }
95
96 //------------------------INSTANCE METHODS ----------------------------------
97
98 static char UnaryFunction0DFloat___doc__[] =
99     "Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DFloat`\n"
100     "\n"
101     "Base class for unary functions (functors) that work on\n"
102     ":class:`Interface0DIterator` and return a float value.\n"
103     "\n"
104     ".. method:: __init__()\n"
105     "\n"
106     "   Default constructor.\n";
107
108 static int UnaryFunction0DFloat___init__(BPy_UnaryFunction0DFloat *self,
109                                          PyObject *args,
110                                          PyObject *kwds)
111 {
112   static const char *kwlist[] = {NULL};
113
114   if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
115     return -1;
116   }
117   self->uf0D_float = new UnaryFunction0D<float>();
118   self->uf0D_float->py_uf0D = (PyObject *)self;
119   return 0;
120 }
121
122 static void UnaryFunction0DFloat___dealloc__(BPy_UnaryFunction0DFloat *self)
123 {
124   if (self->uf0D_float) {
125     delete self->uf0D_float;
126   }
127   UnaryFunction0D_Type.tp_dealloc((PyObject *)self);
128 }
129
130 static PyObject *UnaryFunction0DFloat___repr__(BPy_UnaryFunction0DFloat *self)
131 {
132   return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_float);
133 }
134
135 static PyObject *UnaryFunction0DFloat___call__(BPy_UnaryFunction0DFloat *self,
136                                                PyObject *args,
137                                                PyObject *kwds)
138 {
139   static const char *kwlist[] = {"it", NULL};
140   PyObject *obj;
141
142   if (!PyArg_ParseTupleAndKeywords(
143           args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) {
144     return NULL;
145   }
146
147   if (typeid(*(self->uf0D_float)) == typeid(UnaryFunction0D<float>)) {
148     PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
149     return NULL;
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 NULL;
157   }
158   return PyFloat_FromDouble(self->uf0D_float->result);
159 }
160
161 /*-----------------------BPy_UnaryFunction0DFloat type definition ------------------------------*/
162
163 PyTypeObject UnaryFunction0DFloat_Type = {
164     PyVarObject_HEAD_INIT(NULL, 0) "UnaryFunction0DFloat", /* tp_name */
165     sizeof(BPy_UnaryFunction0DFloat),                      /* tp_basicsize */
166     0,                                                     /* tp_itemsize */
167     (destructor)UnaryFunction0DFloat___dealloc__,          /* tp_dealloc */
168     0,                                                     /* tp_print */
169     0,                                                     /* tp_getattr */
170     0,                                                     /* tp_setattr */
171     0,                                                     /* tp_reserved */
172     (reprfunc)UnaryFunction0DFloat___repr__,               /* tp_repr */
173     0,                                                     /* tp_as_number */
174     0,                                                     /* tp_as_sequence */
175     0,                                                     /* tp_as_mapping */
176     0,                                                     /* tp_hash  */
177     (ternaryfunc)UnaryFunction0DFloat___call__,            /* tp_call */
178     0,                                                     /* tp_str */
179     0,                                                     /* tp_getattro */
180     0,                                                     /* tp_setattro */
181     0,                                                     /* tp_as_buffer */
182     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,              /* tp_flags */
183     UnaryFunction0DFloat___doc__,                          /* tp_doc */
184     0,                                                     /* tp_traverse */
185     0,                                                     /* tp_clear */
186     0,                                                     /* tp_richcompare */
187     0,                                                     /* tp_weaklistoffset */
188     0,                                                     /* tp_iter */
189     0,                                                     /* tp_iternext */
190     0,                                                     /* tp_methods */
191     0,                                                     /* tp_members */
192     0,                                                     /* tp_getset */
193     &UnaryFunction0D_Type,                                 /* tp_base */
194     0,                                                     /* tp_dict */
195     0,                                                     /* tp_descr_get */
196     0,                                                     /* tp_descr_set */
197     0,                                                     /* tp_dictoffset */
198     (initproc)UnaryFunction0DFloat___init__,               /* tp_init */
199     0,                                                     /* tp_alloc */
200     0,                                                     /* tp_new */
201 };
202
203 ///////////////////////////////////////////////////////////////////////////////////////////
204
205 #ifdef __cplusplus
206 }
207 #endif