Blender V5.3
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.hh"
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 ".. function:: 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 ".. function:: 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 ".. function:: 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 " :param file_name: The name of the image file.\n"
93 " :type file_name: str\n"
94 " :param map_name: The name that will be used to access this image.\n"
95 " :type map_name: str\n"
96 " :param 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 " :param 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(args,
110 kwds,
111 "s" /* `file_name` */
112 "s" /* `map_name` */
113 "|" /* Optional arguments. */
114 "I" /* `num_levels` */
115 "f" /* `sigma` */
116 ":load_map",
117 (char **)kwlist,
118 &fileName,
119 &mapName,
120 &nbLevels,
121 &sigma))
122 {
123 return nullptr;
124 }
125 ContextFunctions::LoadMapCF(fileName, mapName, nbLevels, sigma);
126 Py_RETURN_NONE;
127}
128
130 /* Wrap. */
131 ContextFunctions_read_map_pixel___doc__,
132 ".. function:: read_map_pixel(map_name, level, x, y)\n"
133 "\n"
134 " Reads a pixel in a user-defined map.\n"
135 "\n"
136 " :param map_name: The name of the map.\n"
137 " :type map_name: str\n"
138 " :param level: The level of the pyramid in which we wish to read the\n"
139 " pixel.\n"
140 " :type level: int\n"
141 " :param x: The x coordinate of the pixel we wish to read. The origin\n"
142 " is in the lower-left corner.\n"
143 " :type x: int\n"
144 " :param y: The y coordinate of the pixel we wish to read. The origin\n"
145 " is in the lower-left corner.\n"
146 " :type y: int\n"
147 " :return: The floating-point value stored for that pixel.\n"
148 " :rtype: float\n");
149static PyObject *ContextFunctions_read_map_pixel(PyObject * /*self*/,
150 PyObject *args,
151 PyObject *kwds)
152{
153 static const char *kwlist[] = {"map_name", "level", "x", "y", nullptr};
154 char *mapName;
155 int level;
156 uint x, y;
157
158 if (!PyArg_ParseTupleAndKeywords(args,
159 kwds,
160 "s" /* `map_name` */
161 "i" /* `level` */
162 "I" /* `x` */
163 "I" /* `y` */
164 ":read_map_pixel",
165 (char **)kwlist,
166 &mapName,
167 &level,
168 &x,
169 &y))
170 {
171 return nullptr;
172 }
173 return PyFloat_FromDouble(ContextFunctions::ReadMapPixelCF(mapName, level, x, y));
174}
175
177 /* Wrap. */
178 ContextFunctions_read_complete_view_map_pixel___doc__,
179 ".. function:: read_complete_view_map_pixel(level, x, y)\n"
180 "\n"
181 " Reads a pixel in the complete view map.\n"
182 "\n"
183 " :param level: The level of the pyramid in which we wish to read the\n"
184 " pixel.\n"
185 " :type level: int\n"
186 " :param x: The x coordinate of the pixel we wish to read. The origin\n"
187 " is in the lower-left corner.\n"
188 " :type x: int\n"
189 " :param y: The y coordinate of the pixel we wish to read. The origin\n"
190 " is in the lower-left corner.\n"
191 " :type y: int\n"
192 " :return: The floating-point value stored for that pixel.\n"
193 " :rtype: float\n");
194static PyObject *ContextFunctions_read_complete_view_map_pixel(PyObject * /*self*/,
195 PyObject *args,
196 PyObject *kwds)
197{
198 static const char *kwlist[] = {"level", "x", "y", nullptr};
199 int level;
200 uint x, y;
201
202 if (!PyArg_ParseTupleAndKeywords(args,
203 kwds,
204 "i" /* `level` */
205 "I" /* `x` */
206 "I" /* `y` */
207 ":read_complete_view_map_pixel",
208 (char **)kwlist,
209 &level,
210 &x,
211 &y))
212 {
213 return nullptr;
214 }
215 return PyFloat_FromDouble(ContextFunctions::ReadCompleteViewMapPixelCF(level, x, y));
216}
217
219 /* Wrap. */
220 ContextFunctions_read_directional_view_map_pixel___doc__,
221 ".. function:: read_directional_view_map_pixel(orientation, level, x, y)\n"
222 "\n"
223 " Reads a pixel in one of the oriented view map images.\n"
224 "\n"
225 " :param orientation: The number telling which orientation we want to\n"
226 " check.\n"
227 " :type orientation: int\n"
228 " :param level: The level of the pyramid in which we wish to read the\n"
229 " pixel.\n"
230 " :type level: int\n"
231 " :param x: The x coordinate of the pixel we wish to read. The origin\n"
232 " is in the lower-left corner.\n"
233 " :type x: int\n"
234 " :param y: The y coordinate of the pixel we wish to read. The origin\n"
235 " is in the lower-left corner.\n"
236 " :type y: int\n"
237 " :return: The floating-point value stored for that pixel.\n"
238 " :rtype: float\n");
239static PyObject *ContextFunctions_read_directional_view_map_pixel(PyObject * /*self*/,
240 PyObject *args,
241 PyObject *kwds)
242{
243 static const char *kwlist[] = {"orientation", "level", "x", "y", nullptr};
244 int orientation, level;
245 uint x, y;
246
247 if (!PyArg_ParseTupleAndKeywords(args,
248 kwds,
249 "i" /* `orientation` */
250 "i" /* `level` */
251 "I" /* `x` */
252 "I" /* `y` */
253 ":read_directional_view_map_pixel",
254 (char **)kwlist,
255 &orientation,
256 &level,
257 &x,
258 &y))
259 {
260 return nullptr;
261 }
262 return PyFloat_FromDouble(
264}
265
267 /* Wrap. */
268 ContextFunctions_get_selected_fedge___doc__,
269 ".. function:: get_selected_fedge()\n"
270 "\n"
271 " Returns the selected FEdge.\n"
272 "\n"
273 " :return: The selected FEdge.\n"
274 " :rtype: :class:`FEdge`\n");
275static PyObject *ContextFunctions_get_selected_fedge(PyObject * /*self*/)
276{
278 if (fe) {
279 return Any_BPy_FEdge_from_FEdge(*fe);
280 }
281 Py_RETURN_NONE;
282}
283
284/*-----------------------ContextFunctions module docstring-------------------------------*/
285
287 /* Wrap. */
288 module_docstring,
289 "The Blender Freestyle.ContextFunctions submodule\n"
290 "\n");
291/*-----------------------ContextFunctions module functions definitions-------------------*/
292
293#ifdef __GNUC__
294# ifdef __clang__
295# pragma clang diagnostic push
296# pragma clang diagnostic ignored "-Wcast-function-type"
297# else
298# pragma GCC diagnostic push
299# pragma GCC diagnostic ignored "-Wcast-function-type"
300# endif
301#endif
302
303static PyMethodDef module_functions[] = {
304 {"get_time_stamp",
306 METH_NOARGS,
307 ContextFunctions_get_time_stamp___doc__},
308 {"get_canvas_width",
310 METH_NOARGS,
311 ContextFunctions_get_canvas_width___doc__},
312 {"get_canvas_height",
314 METH_NOARGS,
315 ContextFunctions_get_canvas_height___doc__},
316 {"get_border",
317 (PyCFunction)ContextFunctions_get_border,
318 METH_NOARGS,
319 ContextFunctions_get_border___doc__},
320 {"load_map",
321 (PyCFunction)ContextFunctions_load_map,
322 METH_VARARGS | METH_KEYWORDS,
323 ContextFunctions_load_map___doc__},
324 {"read_map_pixel",
326 METH_VARARGS | METH_KEYWORDS,
327 ContextFunctions_read_map_pixel___doc__},
328 {"read_complete_view_map_pixel",
330 METH_VARARGS | METH_KEYWORDS,
331 ContextFunctions_read_complete_view_map_pixel___doc__},
332 {"read_directional_view_map_pixel",
334 METH_VARARGS | METH_KEYWORDS,
335 ContextFunctions_read_directional_view_map_pixel___doc__},
336 {"get_selected_fedge",
338 METH_NOARGS,
339 ContextFunctions_get_selected_fedge___doc__},
340 {nullptr, nullptr, 0, nullptr},
341};
342
343#ifdef __GNUC__
344# ifdef __clang__
345# pragma clang diagnostic pop
346# else
347# pragma GCC diagnostic pop
348# endif
349#endif
350
351/*-----------------------ContextFunctions module definition--------------------------------*/
352
353static PyModuleDef module_definition = {
354 /*m_base*/ PyModuleDef_HEAD_INIT,
355 /*m_name*/ "Freestyle.ContextFunctions",
356 /*m_doc*/ module_docstring,
357 /*m_size*/ -1,
358 /*m_methods*/ module_functions,
359 /*m_slots*/ nullptr,
360 /*m_traverse*/ nullptr,
361 /*m_clear*/ nullptr,
362 /*m_free*/ nullptr,
363};
364
365//------------------- MODULE INITIALIZATION --------------------------------
366
367int ContextFunctions_Init(PyObject *module)
368{
369 PyObject *m;
370
371 if (module == nullptr) {
372 return -1;
373 }
374
375 m = PyModule_Create(&module_definition);
376 if (m == nullptr) {
377 return -1;
378 }
379 PyModule_AddObjectRef(module, "ContextFunctions", m);
380
381 return 0;
382}
383
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 *)
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)
PyDoc_STRVAR(FalseBP1D___doc__, "Class hierarchy: :class:`freestyle.types.BinaryPredicate1D` > :class:`FalseBP1D`\n" "\n" ".. method:: __call__(inter1, inter2)\n" "\n" " Always returns false.\n" "\n" " :param inter1: The first Interface1D object.\n" " :type inter1: :class:`freestyle.types.Interface1D`\n" " :param inter2: The second Interface1D object.\n" " :type inter2: :class:`freestyle.types.Interface1D`\n" " :return: False.\n" " :rtype: bool\n")
Functions related to context queries.
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
#define PyTuple_SET_ITEMS(op_arg,...)