Blender V5.0
BPy_ContextFunctions.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10#include "BPy_Convert.h"
11
13
14#include "BLI_sys_types.h"
15
16using namespace Freestyle;
17
19
20//------------------------ MODULE FUNCTIONS ----------------------------------
21
23 /* Wrap. */
24 ContextFunctions_get_time_stamp___doc__,
25 ".. function:: get_time_stamp()\n"
26 "\n"
27 " Returns the system time stamp.\n"
28 "\n"
29 " :return: The system time stamp.\n"
30 " :rtype: int\n");
31static PyObject *ContextFunctions_get_time_stamp(PyObject * /*self*/)
32{
33 return PyLong_FromLong(ContextFunctions::GetTimeStampCF());
34}
35
37 /* Wrap. */
38 ContextFunctions_get_canvas_width___doc__,
39 ".. method:: get_canvas_width()\n"
40 "\n"
41 " Returns the canvas width.\n"
42 "\n"
43 " :return: The canvas width.\n"
44 " :rtype: int\n");
45static PyObject *ContextFunctions_get_canvas_width(PyObject * /*self*/)
46{
47 return PyLong_FromLong(ContextFunctions::GetCanvasWidthCF());
48}
49
51 /* Wrap. */
52 ContextFunctions_get_canvas_height___doc__,
53 ".. method:: get_canvas_height()\n"
54 "\n"
55 " Returns the canvas height.\n"
56 "\n"
57 " :return: The canvas height.\n"
58 " :rtype: int\n");
59static PyObject *ContextFunctions_get_canvas_height(PyObject * /*self*/)
60{
61 return PyLong_FromLong(ContextFunctions::GetCanvasHeightCF());
62}
63
65 /* Wrap. */
66 ContextFunctions_get_border___doc__,
67 ".. method:: get_border()\n"
68 "\n"
69 " Returns the border.\n"
70 "\n"
71 " :return: A tuple of 4 numbers (xmin, ymin, xmax, ymax).\n"
72 " :rtype: tuple[int, int, int, int]\n");
73static PyObject *ContextFunctions_get_border(PyObject * /*self*/)
74{
76 PyObject *v = PyTuple_New(4);
78 PyLong_FromLong(border.getMin().x()),
79 PyLong_FromLong(border.getMin().y()),
80 PyLong_FromLong(border.getMax().x()),
81 PyLong_FromLong(border.getMax().y()));
82 return v;
83}
84
86 /* Wrap. */
87 ContextFunctions_load_map___doc__,
88 ".. function:: load_map(file_name, map_name, num_levels=4, sigma=1.0)\n"
89 "\n"
90 " Loads an image map for further reading.\n"
91 "\n"
92 " :arg file_name: The name of the image file.\n"
93 " :type file_name: str\n"
94 " :arg map_name: The name that will be used to access this image.\n"
95 " :type map_name: str\n"
96 " :arg num_levels: The number of levels in the map pyramid\n"
97 " (default = 4). If num_levels == 0, the complete pyramid is\n"
98 " built.\n"
99 " :type num_levels: int\n"
100 " :arg sigma: The sigma value of the gaussian function.\n"
101 " :type sigma: float\n");
102static PyObject *ContextFunctions_load_map(PyObject * /*self*/, PyObject *args, PyObject *kwds)
103{
104 static const char *kwlist[] = {"file_name", "map_name", "num_levels", "sigma", nullptr};
105 char *fileName, *mapName;
106 uint nbLevels = 4;
107 float sigma = 1.0;
108
109 if (!PyArg_ParseTupleAndKeywords(
110 args, kwds, "ss|If", (char **)kwlist, &fileName, &mapName, &nbLevels, &sigma))
111 {
112 return nullptr;
113 }
114 ContextFunctions::LoadMapCF(fileName, mapName, nbLevels, sigma);
115 Py_RETURN_NONE;
116}
117
119 /* Wrap. */
120 ContextFunctions_read_map_pixel___doc__,
121 ".. function:: read_map_pixel(map_name, level, x, y)\n"
122 "\n"
123 " Reads a pixel in a user-defined map.\n"
124 "\n"
125 " :arg map_name: The name of the map.\n"
126 " :type map_name: str\n"
127 " :arg level: The level of the pyramid in which we wish to read the\n"
128 " pixel.\n"
129 " :type level: int\n"
130 " :arg x: The x coordinate of the pixel we wish to read. The origin\n"
131 " is in the lower-left corner.\n"
132 " :type x: int\n"
133 " :arg y: The y coordinate of the pixel we wish to read. The origin\n"
134 " is in the lower-left corner.\n"
135 " :type y: int\n"
136 " :return: The floating-point value stored for that pixel.\n"
137 " :rtype: float\n");
138static PyObject *ContextFunctions_read_map_pixel(PyObject * /*self*/,
139 PyObject *args,
140 PyObject *kwds)
141{
142 static const char *kwlist[] = {"map_name", "level", "x", "y", nullptr};
143 char *mapName;
144 int level;
145 uint x, y;
146
147 if (!PyArg_ParseTupleAndKeywords(args, kwds, "siII", (char **)kwlist, &mapName, &level, &x, &y))
148 {
149 return nullptr;
150 }
151 return PyFloat_FromDouble(ContextFunctions::ReadMapPixelCF(mapName, level, x, y));
152}
153
155 /* Wrap. */
156 ContextFunctions_read_complete_view_map_pixel___doc__,
157 ".. function:: read_complete_view_map_pixel(level, x, y)\n"
158 "\n"
159 " Reads a pixel in the complete view map.\n"
160 "\n"
161 " :arg level: The level of the pyramid in which we wish to read the\n"
162 " pixel.\n"
163 " :type level: int\n"
164 " :arg x: The x coordinate of the pixel we wish to read. The origin\n"
165 " is in the lower-left corner.\n"
166 " :type x: int\n"
167 " :arg y: The y coordinate of the pixel we wish to read. The origin\n"
168 " is in the lower-left corner.\n"
169 " :type y: int\n"
170 " :return: The floating-point value stored for that pixel.\n"
171 " :rtype: float\n");
172static PyObject *ContextFunctions_read_complete_view_map_pixel(PyObject * /*self*/,
173 PyObject *args,
174 PyObject *kwds)
175{
176 static const char *kwlist[] = {"level", "x", "y", nullptr};
177 int level;
178 uint x, y;
179
180 if (!PyArg_ParseTupleAndKeywords(args, kwds, "iII", (char **)kwlist, &level, &x, &y)) {
181 return nullptr;
182 }
183 return PyFloat_FromDouble(ContextFunctions::ReadCompleteViewMapPixelCF(level, x, y));
184}
185
187 /* Wrap. */
188 ContextFunctions_read_directional_view_map_pixel___doc__,
189 ".. function:: read_directional_view_map_pixel(orientation, level, x, y)\n"
190 "\n"
191 " Reads a pixel in one of the oriented view map images.\n"
192 "\n"
193 " :arg orientation: The number telling which orientation we want to\n"
194 " check.\n"
195 " :type orientation: int\n"
196 " :arg level: The level of the pyramid in which we wish to read the\n"
197 " pixel.\n"
198 " :type level: int\n"
199 " :arg x: The x coordinate of the pixel we wish to read. The origin\n"
200 " is in the lower-left corner.\n"
201 " :type x: int\n"
202 " :arg y: The y coordinate of the pixel we wish to read. The origin\n"
203 " is in the lower-left corner.\n"
204 " :type y: int\n"
205 " :return: The floating-point value stored for that pixel.\n"
206 " :rtype: float\n");
207static PyObject *ContextFunctions_read_directional_view_map_pixel(PyObject * /*self*/,
208 PyObject *args,
209 PyObject *kwds)
210{
211 static const char *kwlist[] = {"orientation", "level", "x", "y", nullptr};
212 int orientation, level;
213 uint x, y;
214
215 if (!PyArg_ParseTupleAndKeywords(
216 args, kwds, "iiII", (char **)kwlist, &orientation, &level, &x, &y))
217 {
218 return nullptr;
219 }
220 return PyFloat_FromDouble(
222}
223
225 /* Wrap. */
226 ContextFunctions_get_selected_fedge___doc__,
227 ".. function:: get_selected_fedge()\n"
228 "\n"
229 " Returns the selected FEdge.\n"
230 "\n"
231 " :return: The selected FEdge.\n"
232 " :rtype: :class:`FEdge`\n");
233static PyObject *ContextFunctions_get_selected_fedge(PyObject * /*self*/)
234{
236 if (fe) {
237 return Any_BPy_FEdge_from_FEdge(*fe);
238 }
239 Py_RETURN_NONE;
240}
241
242/*-----------------------ContextFunctions module docstring-------------------------------*/
243
245 /* Wrap. */
246 module_docstring,
247 "The Blender Freestyle.ContextFunctions submodule\n"
248 "\n");
249/*-----------------------ContextFunctions module functions definitions-------------------*/
250
251#ifdef __GNUC__
252# ifdef __clang__
253# pragma clang diagnostic push
254# pragma clang diagnostic ignored "-Wcast-function-type"
255# else
256# pragma GCC diagnostic push
257# pragma GCC diagnostic ignored "-Wcast-function-type"
258# endif
259#endif
260
261static PyMethodDef module_functions[] = {
262 {"get_time_stamp",
264 METH_NOARGS,
265 ContextFunctions_get_time_stamp___doc__},
266 {"get_canvas_width",
268 METH_NOARGS,
269 ContextFunctions_get_canvas_width___doc__},
270 {"get_canvas_height",
272 METH_NOARGS,
273 ContextFunctions_get_canvas_height___doc__},
274 {"get_border",
275 (PyCFunction)ContextFunctions_get_border,
276 METH_NOARGS,
277 ContextFunctions_get_border___doc__},
278 {"load_map",
279 (PyCFunction)ContextFunctions_load_map,
280 METH_VARARGS | METH_KEYWORDS,
281 ContextFunctions_load_map___doc__},
282 {"read_map_pixel",
284 METH_VARARGS | METH_KEYWORDS,
285 ContextFunctions_read_map_pixel___doc__},
286 {"read_complete_view_map_pixel",
288 METH_VARARGS | METH_KEYWORDS,
289 ContextFunctions_read_complete_view_map_pixel___doc__},
290 {"read_directional_view_map_pixel",
292 METH_VARARGS | METH_KEYWORDS,
293 ContextFunctions_read_directional_view_map_pixel___doc__},
294 {"get_selected_fedge",
296 METH_NOARGS,
297 ContextFunctions_get_selected_fedge___doc__},
298 {nullptr, nullptr, 0, nullptr},
299};
300
301#ifdef __GNUC__
302# ifdef __clang__
303# pragma clang diagnostic pop
304# else
305# pragma GCC diagnostic pop
306# endif
307#endif
308
309/*-----------------------ContextFunctions module definition--------------------------------*/
310
311static PyModuleDef module_definition = {
312 /*m_base*/ PyModuleDef_HEAD_INIT,
313 /*m_name*/ "Freestyle.ContextFunctions",
314 /*m_doc*/ module_docstring,
315 /*m_size*/ -1,
316 /*m_methods*/ module_functions,
317 /*m_slots*/ nullptr,
318 /*m_traverse*/ nullptr,
319 /*m_clear*/ nullptr,
320 /*m_free*/ nullptr,
321};
322
323//------------------- MODULE INITIALIZATION --------------------------------
324
326{
327 PyObject *m;
328
329 if (module == nullptr) {
330 return -1;
331 }
332
333 m = PyModule_Create(&module_definition);
334 if (m == nullptr) {
335 return -1;
336 }
337 PyModule_AddObjectRef(module, "ContextFunctions", m);
338
339 return 0;
340}
341
unsigned int uint
static PyObject * ContextFunctions_get_canvas_height(PyObject *)
static PyObject * ContextFunctions_load_map(PyObject *, PyObject *args, PyObject *kwds)
static PyObject * ContextFunctions_read_directional_view_map_pixel(PyObject *, PyObject *args, PyObject *kwds)
static PyObject * ContextFunctions_read_map_pixel(PyObject *, PyObject *args, PyObject *kwds)
static PyObject * ContextFunctions_get_border(PyObject *)
static PyModuleDef module_definition
static PyObject * ContextFunctions_get_canvas_width(PyObject *)
PyDoc_STRVAR(ContextFunctions_get_time_stamp___doc__, ".. function:: get_time_stamp()\n" "\n" " Returns the system time stamp.\n" "\n" " :return: The system time stamp.\n" " :rtype: int\n")
static PyObject * ContextFunctions_get_time_stamp(PyObject *)
static PyObject * ContextFunctions_get_selected_fedge(PyObject *)
static PyObject * ContextFunctions_read_complete_view_map_pixel(PyObject *, PyObject *args, PyObject *kwds)
int ContextFunctions_Init(PyObject *module)
static PyMethodDef module_functions[]
PyObject * Any_BPy_FEdge_from_FEdge(FEdge &fe)
Functions related to context queries.
ATTR_WARN_UNUSED_RESULT const BMVert * v
const Point & getMin() const
Definition BBox.h:67
const Point & getMax() const
Definition BBox.h:72
void LoadMapCF(const char *iFileName, const char *iMapName, uint iNbLevels, float iSigma)
float ReadDirectionalViewMapPixelCF(int iOrientation, int level, uint x, uint y)
float ReadCompleteViewMapPixelCF(int level, uint x, uint y)
float ReadMapPixelCF(const char *iMapName, int level, uint x, uint y)
inherits from class Rep
Definition AppCanvas.cpp:20
static struct PyModuleDef module
Definition python.cpp:796
#define PyTuple_SET_ITEMS(op_arg,...)