2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * ***** END GPL LICENSE BLOCK *****
21 /** \file source/blender/freestyle/intern/python/BPy_ContextFunctions.cpp
25 #include "BPy_ContextFunctions.h"
26 #include "BPy_Convert.h"
28 #include "../stroke/ContextFunctions.h"
30 using namespace Freestyle;
36 ///////////////////////////////////////////////////////////////////////////////////////////
38 //------------------------ MODULE FUNCTIONS ----------------------------------
40 static char ContextFunctions_get_time_stamp___doc__[] =
41 ".. function:: get_time_stamp()\n"
43 " Returns the system time stamp.\n"
45 " :return: The system time stamp.\n"
49 ContextFunctions_get_time_stamp(PyObject * /*self*/)
51 return PyLong_FromLong(ContextFunctions::GetTimeStampCF());
54 static char ContextFunctions_get_canvas_width___doc__[] =
55 ".. method:: get_canvas_width()\n"
57 " Returns the canvas width.\n"
59 " :return: The canvas width.\n"
63 ContextFunctions_get_canvas_width(PyObject * /*self*/)
65 return PyLong_FromLong(ContextFunctions::GetCanvasWidthCF());
68 static char ContextFunctions_get_canvas_height___doc__[] =
69 ".. method:: get_canvas_height()\n"
71 " Returns the canvas height.\n"
73 " :return: The canvas height.\n"
77 ContextFunctions_get_canvas_height(PyObject * /*self*/)
79 return PyLong_FromLong(ContextFunctions::GetCanvasHeightCF());
82 static char ContextFunctions_get_border___doc__[] =
83 ".. method:: get_border()\n"
85 " Returns the border.\n"
87 " :return: A tuple of 4 numbers (xmin, ymin, xmax, ymax).\n"
91 ContextFunctions_get_border(PyObject * /*self*/)
93 BBox<Vec2i> border(ContextFunctions::GetBorderCF());
94 PyObject *v = PyTuple_New(4);
96 PyLong_FromLong(border.getMin().x()),
97 PyLong_FromLong(border.getMin().y()),
98 PyLong_FromLong(border.getMax().x()),
99 PyLong_FromLong(border.getMax().y()));
103 static char ContextFunctions_load_map___doc__[] =
104 ".. function:: load_map(file_name, map_name, num_levels=4, sigma=1.0)\n"
106 " Loads an image map for further reading.\n"
108 " :arg file_name: The name of the image file.\n"
109 " :type file_name: str\n"
110 " :arg map_name: The name that will be used to access this image.\n"
111 " :type map_name: str\n"
112 " :arg num_levels: The number of levels in the map pyramid\n"
113 " (default = 4). If num_levels == 0, the complete pyramid is\n"
115 " :type num_levels: int\n"
116 " :arg sigma: The sigma value of the gaussian function.\n"
117 " :type sigma: float\n";
120 ContextFunctions_load_map(PyObject * /*self*/, PyObject *args, PyObject *kwds)
122 static const char *kwlist[] = {"file_name", "map_name", "num_levels", "sigma", NULL};
123 char *fileName, *mapName;
124 unsigned nbLevels = 4;
127 if (!PyArg_ParseTupleAndKeywords(args, kwds, "ss|If", (char **)kwlist, &fileName, &mapName, &nbLevels, &sigma))
129 ContextFunctions::LoadMapCF(fileName, mapName, nbLevels, sigma);
133 static char ContextFunctions_read_map_pixel___doc__[] =
134 ".. function:: read_map_pixel(map_name, level, x, y)\n"
136 " Reads a pixel in a user-defined map.\n"
138 " :arg map_name: The name of the map.\n"
139 " :type map_name: str\n"
140 " :arg level: The level of the pyramid in which we wish to read the\n"
142 " :type level: int\n"
143 " :arg x: The x coordinate of the pixel we wish to read. The origin\n"
144 " is in the lower-left corner.\n"
146 " :arg y: The y coordinate of the pixel we wish to read. The origin\n"
147 " is in the lower-left corner.\n"
149 " :return: The floating-point value stored for that pixel.\n"
153 ContextFunctions_read_map_pixel(PyObject * /*self*/, PyObject *args, PyObject *kwds)
155 static const char *kwlist[] = {"map_name", "level", "x", "y", NULL};
160 if (!PyArg_ParseTupleAndKeywords(args, kwds, "siII", (char **)kwlist, &mapName, &level, &x, &y))
162 return PyFloat_FromDouble(ContextFunctions::ReadMapPixelCF(mapName, level, x, y));
165 static char ContextFunctions_read_complete_view_map_pixel___doc__[] =
166 ".. function:: read_complete_view_map_pixel(level, x, y)\n"
168 " Reads a pixel in the complete view map.\n"
170 " :arg level: The level of the pyramid in which we wish to read the\n"
172 " :type level: int\n"
173 " :arg x: The x coordinate of the pixel we wish to read. The origin\n"
174 " is in the lower-left corner.\n"
176 " :arg y: The y coordinate of the pixel we wish to read. The origin\n"
177 " is in the lower-left corner.\n"
179 " :return: The floating-point value stored for that pixel.\n"
183 ContextFunctions_read_complete_view_map_pixel(PyObject * /*self*/, PyObject *args, PyObject *kwds)
185 static const char *kwlist[] = {"level", "x", "y", NULL};
189 if (!PyArg_ParseTupleAndKeywords(args, kwds, "iII", (char **)kwlist, &level, &x, &y))
191 return PyFloat_FromDouble(ContextFunctions::ReadCompleteViewMapPixelCF(level, x, y));
194 static char ContextFunctions_read_directional_view_map_pixel___doc__[] =
195 ".. function:: read_directional_view_map_pixel(orientation, level, x, y)\n"
197 " Reads a pixel in one of the oriented view map images.\n"
199 " :arg orientation: The number telling which orientation we want to\n"
201 " :type orientation: int\n"
202 " :arg level: The level of the pyramid in which we wish to read the\n"
204 " :type level: int\n"
205 " :arg x: The x coordinate of the pixel we wish to read. The origin\n"
206 " is in the lower-left corner.\n"
208 " :arg y: The y coordinate of the pixel we wish to read. The origin\n"
209 " is in the lower-left corner.\n"
211 " :return: The floating-point value stored for that pixel.\n"
215 ContextFunctions_read_directional_view_map_pixel(PyObject * /*self*/, PyObject *args, PyObject *kwds)
217 static const char *kwlist[] = {"orientation", "level", "x", "y", NULL};
218 int orientation, level;
221 if (!PyArg_ParseTupleAndKeywords(args, kwds, "iiII", (char **)kwlist, &orientation, &level, &x, &y))
223 return PyFloat_FromDouble(ContextFunctions::ReadDirectionalViewMapPixelCF(orientation, level, x, y));
226 static char ContextFunctions_get_selected_fedge___doc__[] =
227 ".. function:: get_selected_fedge()\n"
229 " Returns the selected FEdge.\n"
231 " :return: The selected FEdge.\n"
232 " :rtype: :class:`FEdge`\n";
235 ContextFunctions_get_selected_fedge(PyObject * /*self*/)
237 FEdge *fe = ContextFunctions::GetSelectedFEdgeCF();
239 return Any_BPy_FEdge_from_FEdge(*fe);
243 /*-----------------------ContextFunctions module docstring-------------------------------*/
245 static char module_docstring[] = "The Blender Freestyle.ContextFunctions submodule\n\n";
247 /*-----------------------ContextFunctions module functions definitions-------------------*/
249 static PyMethodDef module_functions[] = {
250 {"get_time_stamp", (PyCFunction)ContextFunctions_get_time_stamp, METH_NOARGS,
251 ContextFunctions_get_time_stamp___doc__},
252 {"get_canvas_width", (PyCFunction)ContextFunctions_get_canvas_width, METH_NOARGS,
253 ContextFunctions_get_canvas_width___doc__},
254 {"get_canvas_height", (PyCFunction)ContextFunctions_get_canvas_height, METH_NOARGS,
255 ContextFunctions_get_canvas_height___doc__},
256 {"get_border", (PyCFunction)ContextFunctions_get_border, METH_NOARGS,
257 ContextFunctions_get_border___doc__},
258 {"load_map", (PyCFunction)ContextFunctions_load_map, METH_VARARGS | METH_KEYWORDS,
259 ContextFunctions_load_map___doc__},
260 {"read_map_pixel", (PyCFunction)ContextFunctions_read_map_pixel, METH_VARARGS | METH_KEYWORDS,
261 ContextFunctions_read_map_pixel___doc__},
262 {"read_complete_view_map_pixel", (PyCFunction)ContextFunctions_read_complete_view_map_pixel,
263 METH_VARARGS | METH_KEYWORDS,
264 ContextFunctions_read_complete_view_map_pixel___doc__},
265 {"read_directional_view_map_pixel", (PyCFunction)ContextFunctions_read_directional_view_map_pixel,
266 METH_VARARGS | METH_KEYWORDS,
267 ContextFunctions_read_directional_view_map_pixel___doc__},
268 {"get_selected_fedge", (PyCFunction)ContextFunctions_get_selected_fedge, METH_NOARGS,
269 ContextFunctions_get_selected_fedge___doc__},
270 {NULL, NULL, 0, NULL}
273 /*-----------------------ContextFunctions module definition--------------------------------*/
275 static PyModuleDef module_definition = {
276 PyModuleDef_HEAD_INIT,
277 "Freestyle.ContextFunctions",
283 //------------------- MODULE INITIALIZATION --------------------------------
285 int ContextFunctions_Init(PyObject *module)
292 m = PyModule_Create(&module_definition);
296 PyModule_AddObject(module, "ContextFunctions", m);
301 ///////////////////////////////////////////////////////////////////////////////////////////