Blender V4.5
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");
31
32static PyObject *ContextFunctions_get_time_stamp(PyObject * /*self*/)
33{
34 return PyLong_FromLong(ContextFunctions::GetTimeStampCF());
35}
36
38 /* Wrap. */
39 ContextFunctions_get_canvas_width___doc__,
40 ".. method:: get_canvas_width()\n"
41 "\n"
42 " Returns the canvas width.\n"
43 "\n"
44 " :return: The canvas width.\n"
45 " :rtype: int\n");
46
47static PyObject *ContextFunctions_get_canvas_width(PyObject * /*self*/)
48{
49 return PyLong_FromLong(ContextFunctions::GetCanvasWidthCF());
50}
51
53 /* Wrap. */
54 ContextFunctions_get_canvas_height___doc__,
55 ".. method:: get_canvas_height()\n"
56 "\n"
57 " Returns the canvas height.\n"
58 "\n"
59 " :return: The canvas height.\n"
60 " :rtype: int\n");
61
62static PyObject *ContextFunctions_get_canvas_height(PyObject * /*self*/)
63{
64 return PyLong_FromLong(ContextFunctions::GetCanvasHeightCF());
65}
66
68 /* Wrap. */
69 ContextFunctions_get_border___doc__,
70 ".. method:: get_border()\n"
71 "\n"
72 " Returns the border.\n"
73 "\n"
74 " :return: A tuple of 4 numbers (xmin, ymin, xmax, ymax).\n"
75 " :rtype: tuple[int, int, int, int]\n");
76
77static PyObject *ContextFunctions_get_border(PyObject * /*self*/)
78{
80 PyObject *v = PyTuple_New(4);
82 PyLong_FromLong(border.getMin().x()),
83 PyLong_FromLong(border.getMin().y()),
84 PyLong_FromLong(border.getMax().x()),
85 PyLong_FromLong(border.getMax().y()));
86 return v;
87}
88
90 /* Wrap. */
91 ContextFunctions_load_map___doc__,
92 ".. function:: load_map(file_name, map_name, num_levels=4, sigma=1.0)\n"
93 "\n"
94 " Loads an image map for further reading.\n"
95 "\n"
96 " :arg file_name: The name of the image file.\n"
97 " :type file_name: str\n"
98 " :arg map_name: The name that will be used to access this image.\n"
99 " :type map_name: str\n"
100 " :arg num_levels: The number of levels in the map pyramid\n"
101 " (default = 4). If num_levels == 0, the complete pyramid is\n"
102 " built.\n"
103 " :type num_levels: int\n"
104 " :arg sigma: The sigma value of the gaussian function.\n"
105 " :type sigma: float\n");
106
107static PyObject *ContextFunctions_load_map(PyObject * /*self*/, PyObject *args, PyObject *kwds)
108{
109 static const char *kwlist[] = {"file_name", "map_name", "num_levels", "sigma", nullptr};
110 char *fileName, *mapName;
111 uint nbLevels = 4;
112 float sigma = 1.0;
113
114 if (!PyArg_ParseTupleAndKeywords(
115 args, kwds, "ss|If", (char **)kwlist, &fileName, &mapName, &nbLevels, &sigma))
116 {
117 return nullptr;
118 }
119 ContextFunctions::LoadMapCF(fileName, mapName, nbLevels, sigma);
120 Py_RETURN_NONE;
121}
122
124 /* Wrap. */
125 ContextFunctions_read_map_pixel___doc__,
126 ".. function:: read_map_pixel(map_name, level, x, y)\n"
127 "\n"
128 " Reads a pixel in a user-defined map.\n"
129 "\n"
130 " :arg map_name: The name of the map.\n"
131 " :type map_name: str\n"
132 " :arg level: The level of the pyramid in which we wish to read the\n"
133 " pixel.\n"
134 " :type level: int\n"
135 " :arg x: The x coordinate of the pixel we wish to read. The origin\n"
136 " is in the lower-left corner.\n"
137 " :type x: int\n"
138 " :arg y: The y coordinate of the pixel we wish to read. The origin\n"
139 " is in the lower-left corner.\n"
140 " :type y: int\n"
141 " :return: The floating-point value stored for that pixel.\n"
142 " :rtype: float\n");
143
144static PyObject *ContextFunctions_read_map_pixel(PyObject * /*self*/,
145 PyObject *args,
146 PyObject *kwds)
147{
148 static const char *kwlist[] = {"map_name", "level", "x", "y", nullptr};
149 char *mapName;
150 int level;
151 uint x, y;
152
153 if (!PyArg_ParseTupleAndKeywords(args, kwds, "siII", (char **)kwlist, &mapName, &level, &x, &y))
154 {
155 return nullptr;
156 }
157 return PyFloat_FromDouble(ContextFunctions::ReadMapPixelCF(mapName, level, x, y));
158}
159
161 /* Wrap. */
162 ContextFunctions_read_complete_view_map_pixel___doc__,
163 ".. function:: read_complete_view_map_pixel(level, x, y)\n"
164 "\n"
165 " Reads a pixel in the complete view map.\n"
166 "\n"
167 " :arg level: The level of the pyramid in which we wish to read the\n"
168 " pixel.\n"
169 " :type level: int\n"
170 " :arg x: The x coordinate of the pixel we wish to read. The origin\n"
171 " is in the lower-left corner.\n"
172 " :type x: int\n"
173 " :arg y: The y coordinate of the pixel we wish to read. The origin\n"
174 " is in the lower-left corner.\n"
175 " :type y: int\n"
176 " :return: The floating-point value stored for that pixel.\n"
177 " :rtype: float\n");
178
179static PyObject *ContextFunctions_read_complete_view_map_pixel(PyObject * /*self*/,
180 PyObject *args,
181 PyObject *kwds)
182{
183 static const char *kwlist[] = {"level", "x", "y", nullptr};
184 int level;
185 uint x, y;
186
187 if (!PyArg_ParseTupleAndKeywords(args, kwds, "iII", (char **)kwlist, &level, &x, &y)) {
188 return nullptr;
189 }
190 return PyFloat_FromDouble(ContextFunctions::ReadCompleteViewMapPixelCF(level, x, y));
191}
192
194 /* Wrap. */
195 ContextFunctions_read_directional_view_map_pixel___doc__,
196 ".. function:: read_directional_view_map_pixel(orientation, level, x, y)\n"
197 "\n"
198 " Reads a pixel in one of the oriented view map images.\n"
199 "\n"
200 " :arg orientation: The number telling which orientation we want to\n"
201 " check.\n"
202 " :type orientation: int\n"
203 " :arg level: The level of the pyramid in which we wish to read the\n"
204 " pixel.\n"
205 " :type level: int\n"
206 " :arg x: The x coordinate of the pixel we wish to read. The origin\n"
207 " is in the lower-left corner.\n"
208 " :type x: int\n"
209 " :arg y: The y coordinate of the pixel we wish to read. The origin\n"
210 " is in the lower-left corner.\n"
211 " :type y: int\n"
212 " :return: The floating-point value stored for that pixel.\n"
213 " :rtype: float\n");
214
215static PyObject *ContextFunctions_read_directional_view_map_pixel(PyObject * /*self*/,
216 PyObject *args,
217 PyObject *kwds)
218{
219 static const char *kwlist[] = {"orientation", "level", "x", "y", nullptr};
220 int orientation, level;
221 uint x, y;
222
223 if (!PyArg_ParseTupleAndKeywords(
224 args, kwds, "iiII", (char **)kwlist, &orientation, &level, &x, &y))
225 {
226 return nullptr;
227 }
228 return PyFloat_FromDouble(
230}
231
233 /* Wrap. */
234 ContextFunctions_get_selected_fedge___doc__,
235 ".. function:: get_selected_fedge()\n"
236 "\n"
237 " Returns the selected FEdge.\n"
238 "\n"
239 " :return: The selected FEdge.\n"
240 " :rtype: :class:`FEdge`\n");
241
242static PyObject *ContextFunctions_get_selected_fedge(PyObject * /*self*/)
243{
245 if (fe) {
246 return Any_BPy_FEdge_from_FEdge(*fe);
247 }
248 Py_RETURN_NONE;
249}
250
251/*-----------------------ContextFunctions module docstring-------------------------------*/
252
254 /* Wrap. */
255 module_docstring,
256 "The Blender Freestyle.ContextFunctions submodule\n"
257 "\n");
258
259/*-----------------------ContextFunctions module functions definitions-------------------*/
260
261#ifdef __GNUC__
262# ifdef __clang__
263# pragma clang diagnostic push
264# pragma clang diagnostic ignored "-Wcast-function-type"
265# else
266# pragma GCC diagnostic push
267# pragma GCC diagnostic ignored "-Wcast-function-type"
268# endif
269#endif
270
271static PyMethodDef module_functions[] = {
272 {"get_time_stamp",
274 METH_NOARGS,
275 ContextFunctions_get_time_stamp___doc__},
276 {"get_canvas_width",
278 METH_NOARGS,
279 ContextFunctions_get_canvas_width___doc__},
280 {"get_canvas_height",
282 METH_NOARGS,
283 ContextFunctions_get_canvas_height___doc__},
284 {"get_border",
285 (PyCFunction)ContextFunctions_get_border,
286 METH_NOARGS,
287 ContextFunctions_get_border___doc__},
288 {"load_map",
289 (PyCFunction)ContextFunctions_load_map,
290 METH_VARARGS | METH_KEYWORDS,
291 ContextFunctions_load_map___doc__},
292 {"read_map_pixel",
294 METH_VARARGS | METH_KEYWORDS,
295 ContextFunctions_read_map_pixel___doc__},
296 {"read_complete_view_map_pixel",
298 METH_VARARGS | METH_KEYWORDS,
299 ContextFunctions_read_complete_view_map_pixel___doc__},
300 {"read_directional_view_map_pixel",
302 METH_VARARGS | METH_KEYWORDS,
303 ContextFunctions_read_directional_view_map_pixel___doc__},
304 {"get_selected_fedge",
306 METH_NOARGS,
307 ContextFunctions_get_selected_fedge___doc__},
308 {nullptr, nullptr, 0, nullptr},
309};
310
311#ifdef __GNUC__
312# ifdef __clang__
313# pragma clang diagnostic pop
314# else
315# pragma GCC diagnostic pop
316# endif
317#endif
318
319/*-----------------------ContextFunctions module definition--------------------------------*/
320
321static PyModuleDef module_definition = {
322 /*m_base*/ PyModuleDef_HEAD_INIT,
323 /*m_name*/ "Freestyle.ContextFunctions",
324 /*m_doc*/ module_docstring,
325 /*m_size*/ -1,
326 /*m_methods*/ module_functions,
327 /*m_slots*/ nullptr,
328 /*m_traverse*/ nullptr,
329 /*m_clear*/ nullptr,
330 /*m_free*/ nullptr,
331};
332
333//------------------- MODULE INITIALIZATION --------------------------------
334
336{
337 PyObject *m;
338
339 if (module == nullptr) {
340 return -1;
341 }
342
343 m = PyModule_Create(&module_definition);
344 if (m == nullptr) {
345 return -1;
346 }
347 PyModule_AddObjectRef(module, "ContextFunctions", m);
348
349 return 0;
350}
351
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,...)