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