Blender  V3.3
BPy_ContextFunctions.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include "BPy_ContextFunctions.h"
8 #include "BPy_Convert.h"
9 
10 #include "../stroke/ContextFunctions.h"
11 
12 using namespace Freestyle;
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
19 
20 //------------------------ MODULE FUNCTIONS ----------------------------------
21 
23  ".. function:: get_time_stamp()\n"
24  "\n"
25  " Returns the system time stamp.\n"
26  "\n"
27  " :return: The system time stamp.\n"
28  " :rtype: int\n";
29 
30 static PyObject *ContextFunctions_get_time_stamp(PyObject * /*self*/)
31 {
32  return PyLong_FromLong(ContextFunctions::GetTimeStampCF());
33 }
34 
36  ".. method:: get_canvas_width()\n"
37  "\n"
38  " Returns the canvas width.\n"
39  "\n"
40  " :return: The canvas width.\n"
41  " :rtype: int\n";
42 
43 static PyObject *ContextFunctions_get_canvas_width(PyObject * /*self*/)
44 {
45  return PyLong_FromLong(ContextFunctions::GetCanvasWidthCF());
46 }
47 
49  ".. method:: get_canvas_height()\n"
50  "\n"
51  " Returns the canvas height.\n"
52  "\n"
53  " :return: The canvas height.\n"
54  " :rtype: int\n";
55 
56 static PyObject *ContextFunctions_get_canvas_height(PyObject * /*self*/)
57 {
58  return PyLong_FromLong(ContextFunctions::GetCanvasHeightCF());
59 }
60 
62  ".. method:: get_border()\n"
63  "\n"
64  " Returns the border.\n"
65  "\n"
66  " :return: A tuple of 4 numbers (xmin, ymin, xmax, ymax).\n"
67  " :rtype: tuple\n";
68 
69 static PyObject *ContextFunctions_get_border(PyObject * /*self*/)
70 {
72  PyObject *v = PyTuple_New(4);
74  PyLong_FromLong(border.getMin().x()),
75  PyLong_FromLong(border.getMin().y()),
76  PyLong_FromLong(border.getMax().x()),
77  PyLong_FromLong(border.getMax().y()));
78  return v;
79 }
80 
82  ".. function:: load_map(file_name, map_name, num_levels=4, sigma=1.0)\n"
83  "\n"
84  " Loads an image map for further reading.\n"
85  "\n"
86  " :arg file_name: The name of the image file.\n"
87  " :type file_name: str\n"
88  " :arg map_name: The name that will be used to access this image.\n"
89  " :type map_name: str\n"
90  " :arg num_levels: The number of levels in the map pyramid\n"
91  " (default = 4). If num_levels == 0, the complete pyramid is\n"
92  " built.\n"
93  " :type num_levels: int\n"
94  " :arg sigma: The sigma value of the gaussian function.\n"
95  " :type sigma: float\n";
96 
97 static PyObject *ContextFunctions_load_map(PyObject * /*self*/, PyObject *args, PyObject *kwds)
98 {
99  static const char *kwlist[] = {"file_name", "map_name", "num_levels", "sigma", nullptr};
100  char *fileName, *mapName;
101  unsigned nbLevels = 4;
102  float sigma = 1.0;
103 
104  if (!PyArg_ParseTupleAndKeywords(
105  args, kwds, "ss|If", (char **)kwlist, &fileName, &mapName, &nbLevels, &sigma)) {
106  return nullptr;
107  }
108  ContextFunctions::LoadMapCF(fileName, mapName, nbLevels, sigma);
109  Py_RETURN_NONE;
110 }
111 
113  ".. function:: read_map_pixel(map_name, level, x, y)\n"
114  "\n"
115  " Reads a pixel in a user-defined map.\n"
116  "\n"
117  " :arg map_name: The name of the map.\n"
118  " :type map_name: str\n"
119  " :arg level: The level of the pyramid in which we wish to read the\n"
120  " pixel.\n"
121  " :type level: int\n"
122  " :arg x: The x coordinate of the pixel we wish to read. The origin\n"
123  " is in the lower-left corner.\n"
124  " :type x: int\n"
125  " :arg y: The y coordinate of the pixel we wish to read. The origin\n"
126  " is in the lower-left corner.\n"
127  " :type y: int\n"
128  " :return: The floating-point value stored for that pixel.\n"
129  " :rtype: float\n";
130 
131 static PyObject *ContextFunctions_read_map_pixel(PyObject * /*self*/,
132  PyObject *args,
133  PyObject *kwds)
134 {
135  static const char *kwlist[] = {"map_name", "level", "x", "y", nullptr};
136  char *mapName;
137  int level;
138  unsigned x, y;
139 
140  if (!PyArg_ParseTupleAndKeywords(
141  args, kwds, "siII", (char **)kwlist, &mapName, &level, &x, &y)) {
142  return nullptr;
143  }
144  return PyFloat_FromDouble(ContextFunctions::ReadMapPixelCF(mapName, level, x, y));
145 }
146 
148  ".. function:: read_complete_view_map_pixel(level, x, y)\n"
149  "\n"
150  " Reads a pixel in the complete view map.\n"
151  "\n"
152  " :arg level: The level of the pyramid in which we wish to read the\n"
153  " pixel.\n"
154  " :type level: int\n"
155  " :arg x: The x coordinate of the pixel we wish to read. The origin\n"
156  " is in the lower-left corner.\n"
157  " :type x: int\n"
158  " :arg y: The y coordinate of the pixel we wish to read. The origin\n"
159  " is in the lower-left corner.\n"
160  " :type y: int\n"
161  " :return: The floating-point value stored for that pixel.\n"
162  " :rtype: float\n";
163 
164 static PyObject *ContextFunctions_read_complete_view_map_pixel(PyObject * /*self*/,
165  PyObject *args,
166  PyObject *kwds)
167 {
168  static const char *kwlist[] = {"level", "x", "y", nullptr};
169  int level;
170  unsigned x, y;
171 
172  if (!PyArg_ParseTupleAndKeywords(args, kwds, "iII", (char **)kwlist, &level, &x, &y)) {
173  return nullptr;
174  }
175  return PyFloat_FromDouble(ContextFunctions::ReadCompleteViewMapPixelCF(level, x, y));
176 }
177 
179  ".. function:: read_directional_view_map_pixel(orientation, level, x, y)\n"
180  "\n"
181  " Reads a pixel in one of the oriented view map images.\n"
182  "\n"
183  " :arg orientation: The number telling which orientation we want to\n"
184  " check.\n"
185  " :type orientation: int\n"
186  " :arg level: The level of the pyramid in which we wish to read the\n"
187  " pixel.\n"
188  " :type level: int\n"
189  " :arg x: The x coordinate of the pixel we wish to read. The origin\n"
190  " is in the lower-left corner.\n"
191  " :type x: int\n"
192  " :arg y: The y coordinate of the pixel we wish to read. The origin\n"
193  " is in the lower-left corner.\n"
194  " :type y: int\n"
195  " :return: The floating-point value stored for that pixel.\n"
196  " :rtype: float\n";
197 
198 static PyObject *ContextFunctions_read_directional_view_map_pixel(PyObject * /*self*/,
199  PyObject *args,
200  PyObject *kwds)
201 {
202  static const char *kwlist[] = {"orientation", "level", "x", "y", nullptr};
203  int orientation, level;
204  unsigned x, y;
205 
206  if (!PyArg_ParseTupleAndKeywords(
207  args, kwds, "iiII", (char **)kwlist, &orientation, &level, &x, &y)) {
208  return nullptr;
209  }
210  return PyFloat_FromDouble(
211  ContextFunctions::ReadDirectionalViewMapPixelCF(orientation, level, x, y));
212 }
213 
215  ".. function:: get_selected_fedge()\n"
216  "\n"
217  " Returns the selected FEdge.\n"
218  "\n"
219  " :return: The selected FEdge.\n"
220  " :rtype: :class:`FEdge`\n";
221 
222 static PyObject *ContextFunctions_get_selected_fedge(PyObject * /*self*/)
223 {
225  if (fe) {
226  return Any_BPy_FEdge_from_FEdge(*fe);
227  }
228  Py_RETURN_NONE;
229 }
230 
231 /*-----------------------ContextFunctions module docstring-------------------------------*/
232 
233 static char module_docstring[] = "The Blender Freestyle.ContextFunctions submodule\n\n";
234 
235 /*-----------------------ContextFunctions module functions definitions-------------------*/
236 
237 static PyMethodDef module_functions[] = {
238  {"get_time_stamp",
239  (PyCFunction)ContextFunctions_get_time_stamp,
240  METH_NOARGS,
242  {"get_canvas_width",
244  METH_NOARGS,
246  {"get_canvas_height",
248  METH_NOARGS,
250  {"get_border",
251  (PyCFunction)ContextFunctions_get_border,
252  METH_NOARGS,
254  {"load_map",
255  (PyCFunction)ContextFunctions_load_map,
256  METH_VARARGS | METH_KEYWORDS,
258  {"read_map_pixel",
259  (PyCFunction)ContextFunctions_read_map_pixel,
260  METH_VARARGS | METH_KEYWORDS,
262  {"read_complete_view_map_pixel",
264  METH_VARARGS | METH_KEYWORDS,
266  {"read_directional_view_map_pixel",
268  METH_VARARGS | METH_KEYWORDS,
270  {"get_selected_fedge",
272  METH_NOARGS,
274  {nullptr, nullptr, 0, nullptr},
275 };
276 
277 /*-----------------------ContextFunctions module definition--------------------------------*/
278 
279 static PyModuleDef module_definition = {
280  PyModuleDef_HEAD_INIT,
281  "Freestyle.ContextFunctions",
283  -1,
285 };
286 
287 //------------------- MODULE INITIALIZATION --------------------------------
288 
290 {
291  PyObject *m;
292 
293  if (module == nullptr) {
294  return -1;
295  }
296 
297  m = PyModule_Create(&module_definition);
298  if (m == nullptr) {
299  return -1;
300  }
301  Py_INCREF(m);
302  PyModule_AddObject(module, "ContextFunctions", m);
303 
304  return 0;
305 }
306 
308 
309 #ifdef __cplusplus
310 }
311 #endif
static char ContextFunctions_get_border___doc__[]
static PyObject * ContextFunctions_load_map(PyObject *, PyObject *args, PyObject *kwds)
static PyObject * ContextFunctions_get_canvas_height(PyObject *)
static char ContextFunctions_get_time_stamp___doc__[]
static PyObject * ContextFunctions_get_canvas_width(PyObject *)
static PyObject * ContextFunctions_get_border(PyObject *)
static char ContextFunctions_read_complete_view_map_pixel___doc__[]
static char ContextFunctions_read_map_pixel___doc__[]
static PyObject * ContextFunctions_get_time_stamp(PyObject *)
static PyObject * ContextFunctions_read_map_pixel(PyObject *, PyObject *args, PyObject *kwds)
static PyModuleDef module_definition
static char module_docstring[]
static char ContextFunctions_read_directional_view_map_pixel___doc__[]
static PyObject * ContextFunctions_read_directional_view_map_pixel(PyObject *, PyObject *args, PyObject *kwds)
static PyObject * ContextFunctions_read_complete_view_map_pixel(PyObject *, PyObject *args, PyObject *kwds)
static char ContextFunctions_load_map___doc__[]
int ContextFunctions_Init(PyObject *module)
static PyObject * ContextFunctions_get_selected_fedge(PyObject *)
static char ContextFunctions_get_canvas_width___doc__[]
static PyMethodDef module_functions[]
static char ContextFunctions_get_canvas_height___doc__[]
static char ContextFunctions_get_selected_fedge___doc__[]
PyObject * Any_BPy_FEdge_from_FEdge(FEdge &fe)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
ATTR_WARN_UNUSED_RESULT const BMVert * v
IconTextureDrawCall border
float ReadCompleteViewMapPixelCF(int level, unsigned x, unsigned y)
float ReadDirectionalViewMapPixelCF(int iOrientation, int level, unsigned x, unsigned y)
void LoadMapCF(const char *iFileName, const char *iMapName, unsigned iNbLevels, float iSigma)
float ReadMapPixelCF(const char *iMapName, int level, unsigned x, unsigned y)
inherits from class Rep
Definition: AppCanvas.cpp:18
static unsigned x[3]
Definition: RandGen.cpp:73
static struct PyModuleDef module
Definition: python.cpp:972
#define PyTuple_SET_ITEMS(op_arg,...)