Blender  V2.93
BPy_ContextFunctions.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "BPy_ContextFunctions.h"
22 #include "BPy_Convert.h"
23 
24 #include "../stroke/ContextFunctions.h"
25 
26 using namespace Freestyle;
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
33 
34 //------------------------ MODULE FUNCTIONS ----------------------------------
35 
37  ".. function:: get_time_stamp()\n"
38  "\n"
39  " Returns the system time stamp.\n"
40  "\n"
41  " :return: The system time stamp.\n"
42  " :rtype: int\n";
43 
44 static PyObject *ContextFunctions_get_time_stamp(PyObject * /*self*/)
45 {
46  return PyLong_FromLong(ContextFunctions::GetTimeStampCF());
47 }
48 
50  ".. method:: get_canvas_width()\n"
51  "\n"
52  " Returns the canvas width.\n"
53  "\n"
54  " :return: The canvas width.\n"
55  " :rtype: int\n";
56 
57 static PyObject *ContextFunctions_get_canvas_width(PyObject * /*self*/)
58 {
59  return PyLong_FromLong(ContextFunctions::GetCanvasWidthCF());
60 }
61 
63  ".. method:: get_canvas_height()\n"
64  "\n"
65  " Returns the canvas height.\n"
66  "\n"
67  " :return: The canvas height.\n"
68  " :rtype: int\n";
69 
70 static PyObject *ContextFunctions_get_canvas_height(PyObject * /*self*/)
71 {
72  return PyLong_FromLong(ContextFunctions::GetCanvasHeightCF());
73 }
74 
76  ".. method:: get_border()\n"
77  "\n"
78  " Returns the border.\n"
79  "\n"
80  " :return: A tuple of 4 numbers (xmin, ymin, xmax, ymax).\n"
81  " :rtype: tuple\n";
82 
83 static PyObject *ContextFunctions_get_border(PyObject * /*self*/)
84 {
86  PyObject *v = PyTuple_New(4);
88  PyLong_FromLong(border.getMin().x()),
89  PyLong_FromLong(border.getMin().y()),
90  PyLong_FromLong(border.getMax().x()),
91  PyLong_FromLong(border.getMax().y()));
92  return v;
93 }
94 
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 
111 static 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  unsigned nbLevels = 4;
116  float sigma = 1.0;
117 
118  if (!PyArg_ParseTupleAndKeywords(
119  args, kwds, "ss|If", (char **)kwlist, &fileName, &mapName, &nbLevels, &sigma)) {
120  return nullptr;
121  }
122  ContextFunctions::LoadMapCF(fileName, mapName, nbLevels, sigma);
123  Py_RETURN_NONE;
124 }
125 
127  ".. function:: read_map_pixel(map_name, level, x, y)\n"
128  "\n"
129  " Reads a pixel in a user-defined map.\n"
130  "\n"
131  " :arg map_name: The name of the map.\n"
132  " :type map_name: str\n"
133  " :arg level: The level of the pyramid in which we wish to read the\n"
134  " pixel.\n"
135  " :type level: int\n"
136  " :arg x: The x coordinate of the pixel we wish to read. The origin\n"
137  " is in the lower-left corner.\n"
138  " :type x: int\n"
139  " :arg y: The y coordinate of the pixel we wish to read. The origin\n"
140  " is in the lower-left corner.\n"
141  " :type y: int\n"
142  " :return: The floating-point value stored for that pixel.\n"
143  " :rtype: float\n";
144 
145 static PyObject *ContextFunctions_read_map_pixel(PyObject * /*self*/,
146  PyObject *args,
147  PyObject *kwds)
148 {
149  static const char *kwlist[] = {"map_name", "level", "x", "y", nullptr};
150  char *mapName;
151  int level;
152  unsigned x, y;
153 
154  if (!PyArg_ParseTupleAndKeywords(
155  args, kwds, "siII", (char **)kwlist, &mapName, &level, &x, &y)) {
156  return nullptr;
157  }
158  return PyFloat_FromDouble(ContextFunctions::ReadMapPixelCF(mapName, level, x, y));
159 }
160 
162  ".. function:: read_complete_view_map_pixel(level, x, y)\n"
163  "\n"
164  " Reads a pixel in the complete view map.\n"
165  "\n"
166  " :arg level: The level of the pyramid in which we wish to read the\n"
167  " pixel.\n"
168  " :type level: int\n"
169  " :arg x: The x coordinate of the pixel we wish to read. The origin\n"
170  " is in the lower-left corner.\n"
171  " :type x: int\n"
172  " :arg y: The y coordinate of the pixel we wish to read. The origin\n"
173  " is in the lower-left corner.\n"
174  " :type y: int\n"
175  " :return: The floating-point value stored for that pixel.\n"
176  " :rtype: float\n";
177 
178 static PyObject *ContextFunctions_read_complete_view_map_pixel(PyObject * /*self*/,
179  PyObject *args,
180  PyObject *kwds)
181 {
182  static const char *kwlist[] = {"level", "x", "y", nullptr};
183  int level;
184  unsigned x, y;
185 
186  if (!PyArg_ParseTupleAndKeywords(args, kwds, "iII", (char **)kwlist, &level, &x, &y)) {
187  return nullptr;
188  }
189  return PyFloat_FromDouble(ContextFunctions::ReadCompleteViewMapPixelCF(level, x, y));
190 }
191 
193  ".. function:: read_directional_view_map_pixel(orientation, level, x, y)\n"
194  "\n"
195  " Reads a pixel in one of the oriented view map images.\n"
196  "\n"
197  " :arg orientation: The number telling which orientation we want to\n"
198  " check.\n"
199  " :type orientation: int\n"
200  " :arg level: The level of the pyramid in which we wish to read the\n"
201  " pixel.\n"
202  " :type level: int\n"
203  " :arg x: The x coordinate of the pixel we wish to read. The origin\n"
204  " is in the lower-left corner.\n"
205  " :type x: int\n"
206  " :arg y: The y coordinate of the pixel we wish to read. The origin\n"
207  " is in the lower-left corner.\n"
208  " :type y: int\n"
209  " :return: The floating-point value stored for that pixel.\n"
210  " :rtype: float\n";
211 
212 static PyObject *ContextFunctions_read_directional_view_map_pixel(PyObject * /*self*/,
213  PyObject *args,
214  PyObject *kwds)
215 {
216  static const char *kwlist[] = {"orientation", "level", "x", "y", nullptr};
217  int orientation, level;
218  unsigned x, y;
219 
220  if (!PyArg_ParseTupleAndKeywords(
221  args, kwds, "iiII", (char **)kwlist, &orientation, &level, &x, &y)) {
222  return nullptr;
223  }
224  return PyFloat_FromDouble(
225  ContextFunctions::ReadDirectionalViewMapPixelCF(orientation, level, x, y));
226 }
227 
229  ".. function:: get_selected_fedge()\n"
230  "\n"
231  " Returns the selected FEdge.\n"
232  "\n"
233  " :return: The selected FEdge.\n"
234  " :rtype: :class:`FEdge`\n";
235 
236 static PyObject *ContextFunctions_get_selected_fedge(PyObject * /*self*/)
237 {
239  if (fe) {
240  return Any_BPy_FEdge_from_FEdge(*fe);
241  }
242  Py_RETURN_NONE;
243 }
244 
245 /*-----------------------ContextFunctions module docstring-------------------------------*/
246 
247 static char module_docstring[] = "The Blender Freestyle.ContextFunctions submodule\n\n";
248 
249 /*-----------------------ContextFunctions module functions definitions-------------------*/
250 
251 static PyMethodDef module_functions[] = {
252  {"get_time_stamp",
253  (PyCFunction)ContextFunctions_get_time_stamp,
254  METH_NOARGS,
256  {"get_canvas_width",
258  METH_NOARGS,
260  {"get_canvas_height",
262  METH_NOARGS,
264  {"get_border",
265  (PyCFunction)ContextFunctions_get_border,
266  METH_NOARGS,
268  {"load_map",
269  (PyCFunction)ContextFunctions_load_map,
270  METH_VARARGS | METH_KEYWORDS,
272  {"read_map_pixel",
273  (PyCFunction)ContextFunctions_read_map_pixel,
274  METH_VARARGS | METH_KEYWORDS,
276  {"read_complete_view_map_pixel",
278  METH_VARARGS | METH_KEYWORDS,
280  {"read_directional_view_map_pixel",
282  METH_VARARGS | METH_KEYWORDS,
284  {"get_selected_fedge",
286  METH_NOARGS,
288  {nullptr, nullptr, 0, nullptr},
289 };
290 
291 /*-----------------------ContextFunctions module definition--------------------------------*/
292 
293 static PyModuleDef module_definition = {
294  PyModuleDef_HEAD_INIT,
295  "Freestyle.ContextFunctions",
297  -1,
299 };
300 
301 //------------------- MODULE INITIALIZATION --------------------------------
302 
304 {
305  PyObject *m;
306 
307  if (module == nullptr) {
308  return -1;
309  }
310 
311  m = PyModule_Create(&module_definition);
312  if (m == nullptr) {
313  return -1;
314  }
315  Py_INCREF(m);
316  PyModule_AddObject(module, "ContextFunctions", m);
317 
318  return 0;
319 }
320 
322 
323 #ifdef __cplusplus
324 }
325 #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
static struct PyModuleDef module
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:32
static unsigned x[3]
Definition: RandGen.cpp:87
#define PyTuple_SET_ITEMS(op_arg,...)