This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/freestyle/intern/python/BPy_ContextFunctions.cpp

326 lines
11 KiB
C++
Raw Normal View History

2013-02-23 18:32:28 +00:00
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/** \file
* \ingroup freestyle
2013-02-23 18:32:28 +00:00
*/
#include "BPy_ContextFunctions.h"
#include "BPy_Convert.h"
#include "../stroke/ContextFunctions.h"
Attempt to fix a potential name conflict between Freestyle and the compositor. A crash in the Freestyle renderer was reported by Ton on IRC with a stack trace below. Note that #2 is in Freestyle, whereas #1 is in the compositor. The problem was observed in a debug build on OS X 10.7 (gcc 4.2, openmp disabled, no llvm). ---------------------------------------------------------------------- Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: 13 at address: 0x0000000000000000 [Switching to process 72386 thread 0xf303] 0x0000000100c129f3 in NodeBase::~NodeBase (this=0x10e501c80) at COM_NodeBase.cpp:43 43 delete (this->m_outputsockets.back()); Current language: auto; currently c++ (gdb) where #0 0x0000000100c129f3 in NodeBase::~NodeBase (this=0x10e501c80) at COM_NodeBase.cpp:43 #1 0x0000000100c29066 in Node::~Node (this=0x10e501c80) at COM_Node.h:49 #2 0x000000010089c273 in NodeShape::~NodeShape (this=0x10e501c80) at NodeShape.cpp:43 #3 0x000000010089910b in NodeGroup::destroy (this=0x10e501da0) at NodeGroup.cpp:61 #4 0x00000001008990cd in NodeGroup::destroy (this=0x10e5014b0) at NodeGroup.cpp:59 #5 0x00000001008990cd in NodeGroup::destroy (this=0x114e18da0) at NodeGroup.cpp:59 #6 0x00000001007e6602 in Controller::ClearRootNode (this=0x114e19640) at Controller.cpp:329 #7 0x00000001007ea52e in Controller::LoadMesh (this=0x114e19640, re=0x10aba4638, srl=0x1140f5258) at Controller.cpp:302 #8 0x00000001008030ad in prepare (re=0x10aba4638, srl=0x1140f5258) at FRS_freestyle.cpp:302 #9 0x000000010080457a in FRS_do_stroke_rendering (re=0x10aba4638, srl=0x1140f5258) at FRS_freestyle.cpp:600 #10 0x00000001006aeb9d in add_freestyle (re=0x10aba4638) at pipeline.c:1584 #11 0x00000001006aceb7 in do_render_3d (re=0x10aba4638) at pipeline.c:1094 #12 0x00000001006ae061 in do_render_fields_blur_3d (re=0x10aba4638) at pipeline.c:1367 #13 0x00000001006afa16 in do_render_composite_fields_blur_3d (re=0x10aba4638) at pipeline.c:1815 #14 0x00000001006b04e4 in do_render_all_options (re=0x10aba4638) at pipeline.c:2021 ---------------------------------------------------------------------- Apparently a name conflict between the two Blender modules is taking place. The present commit hence intends to address it by putting all the Freestyle C++ classes in the namespace 'Freestyle'. This revision will also prevent potential name conflicts with other Blender modules in the future. Special thanks to Lukas Toenne for the help with C++ namespace.
2013-04-09 00:46:49 +00:00
using namespace Freestyle;
#ifdef __cplusplus
extern "C" {
#endif
///////////////////////////////////////////////////////////////////////////////////////////
//------------------------ MODULE FUNCTIONS ----------------------------------
static char 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 * /*self*/)
{
return PyLong_FromLong(ContextFunctions::GetTimeStampCF());
}
static char ContextFunctions_get_canvas_width___doc__[] =
".. method:: get_canvas_width()\n"
"\n"
" Returns the canvas width.\n"
"\n"
" :return: The canvas width.\n"
" :rtype: int\n";
static PyObject *ContextFunctions_get_canvas_width(PyObject * /*self*/)
{
return PyLong_FromLong(ContextFunctions::GetCanvasWidthCF());
}
static char ContextFunctions_get_canvas_height___doc__[] =
".. method:: get_canvas_height()\n"
"\n"
" Returns the canvas height.\n"
"\n"
" :return: The canvas height.\n"
" :rtype: int\n";
static PyObject *ContextFunctions_get_canvas_height(PyObject * /*self*/)
{
return PyLong_FromLong(ContextFunctions::GetCanvasHeightCF());
}
static char ContextFunctions_get_border___doc__[] =
".. method:: get_border()\n"
"\n"
" Returns the border.\n"
"\n"
" :return: A tuple of 4 numbers (xmin, ymin, xmax, ymax).\n"
" :rtype: tuple\n";
static PyObject *ContextFunctions_get_border(PyObject * /*self*/)
{
BBox<Vec2i> border(ContextFunctions::GetBorderCF());
PyObject *v = PyTuple_New(4);
PyTuple_SET_ITEMS(v,
PyLong_FromLong(border.getMin().x()),
PyLong_FromLong(border.getMin().y()),
PyLong_FromLong(border.getMax().x()),
PyLong_FromLong(border.getMax().y()));
return v;
}
static char ContextFunctions_load_map___doc__[] =
".. function:: load_map(file_name, map_name, num_levels=4, sigma=1.0)\n"
"\n"
" Loads an image map for further reading.\n"
"\n"
" :arg file_name: The name of the image file.\n"
" :type file_name: str\n"
" :arg map_name: The name that will be used to access this image.\n"
" :type map_name: str\n"
" :arg num_levels: The number of levels in the map pyramid\n"
" (default = 4). If num_levels == 0, the complete pyramid is\n"
" built.\n"
" :type num_levels: int\n"
" :arg sigma: The sigma value of the gaussian function.\n"
" :type sigma: float\n";
static PyObject *ContextFunctions_load_map(PyObject * /*self*/, PyObject *args, PyObject *kwds)
{
static const char *kwlist[] = {"file_name", "map_name", "num_levels", "sigma", NULL};
char *fileName, *mapName;
unsigned nbLevels = 4;
float sigma = 1.0;
if (!PyArg_ParseTupleAndKeywords(
args, kwds, "ss|If", (char **)kwlist, &fileName, &mapName, &nbLevels, &sigma)) {
return NULL;
}
ContextFunctions::LoadMapCF(fileName, mapName, nbLevels, sigma);
Py_RETURN_NONE;
}
static char ContextFunctions_read_map_pixel___doc__[] =
".. function:: read_map_pixel(map_name, level, x, y)\n"
"\n"
" Reads a pixel in a user-defined map.\n"
"\n"
" :arg map_name: The name of the map.\n"
" :type map_name: str\n"
" :arg level: The level of the pyramid in which we wish to read the\n"
" pixel.\n"
" :type level: int\n"
" :arg x: The x coordinate of the pixel we wish to read. The origin\n"
" is in the lower-left corner.\n"
" :type x: int\n"
" :arg y: The y coordinate of the pixel we wish to read. The origin\n"
" is in the lower-left corner.\n"
" :type y: int\n"
" :return: The floating-point value stored for that pixel.\n"
" :rtype: float\n";
static PyObject *ContextFunctions_read_map_pixel(PyObject * /*self*/,
PyObject *args,
PyObject *kwds)
{
static const char *kwlist[] = {"map_name", "level", "x", "y", NULL};
char *mapName;
int level;
unsigned x, y;
if (!PyArg_ParseTupleAndKeywords(
args, kwds, "siII", (char **)kwlist, &mapName, &level, &x, &y)) {
return NULL;
}
return PyFloat_FromDouble(ContextFunctions::ReadMapPixelCF(mapName, level, x, y));
}
static char ContextFunctions_read_complete_view_map_pixel___doc__[] =
".. function:: read_complete_view_map_pixel(level, x, y)\n"
"\n"
" Reads a pixel in the complete view map.\n"
"\n"
" :arg level: The level of the pyramid in which we wish to read the\n"
" pixel.\n"
" :type level: int\n"
" :arg x: The x coordinate of the pixel we wish to read. The origin\n"
" is in the lower-left corner.\n"
" :type x: int\n"
" :arg y: The y coordinate of the pixel we wish to read. The origin\n"
" is in the lower-left corner.\n"
" :type y: int\n"
" :return: The floating-point value stored for that pixel.\n"
" :rtype: float\n";
static PyObject *ContextFunctions_read_complete_view_map_pixel(PyObject * /*self*/,
PyObject *args,
PyObject *kwds)
{
static const char *kwlist[] = {"level", "x", "y", NULL};
int level;
unsigned x, y;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "iII", (char **)kwlist, &level, &x, &y)) {
return NULL;
}
return PyFloat_FromDouble(ContextFunctions::ReadCompleteViewMapPixelCF(level, x, y));
}
static char ContextFunctions_read_directional_view_map_pixel___doc__[] =
".. function:: read_directional_view_map_pixel(orientation, level, x, y)\n"
"\n"
" Reads a pixel in one of the oriented view map images.\n"
"\n"
" :arg orientation: The number telling which orientation we want to\n"
" check.\n"
" :type orientation: int\n"
" :arg level: The level of the pyramid in which we wish to read the\n"
" pixel.\n"
" :type level: int\n"
" :arg x: The x coordinate of the pixel we wish to read. The origin\n"
" is in the lower-left corner.\n"
" :type x: int\n"
" :arg y: The y coordinate of the pixel we wish to read. The origin\n"
" is in the lower-left corner.\n"
" :type y: int\n"
" :return: The floating-point value stored for that pixel.\n"
" :rtype: float\n";
static PyObject *ContextFunctions_read_directional_view_map_pixel(PyObject * /*self*/,
PyObject *args,
PyObject *kwds)
{
static const char *kwlist[] = {"orientation", "level", "x", "y", NULL};
int orientation, level;
unsigned x, y;
if (!PyArg_ParseTupleAndKeywords(
args, kwds, "iiII", (char **)kwlist, &orientation, &level, &x, &y)) {
return NULL;
}
return PyFloat_FromDouble(
ContextFunctions::ReadDirectionalViewMapPixelCF(orientation, level, x, y));
}
static char ContextFunctions_get_selected_fedge___doc__[] =
".. function:: get_selected_fedge()\n"
"\n"
" Returns the selected FEdge.\n"
"\n"
" :return: The selected FEdge.\n"
" :rtype: :class:`FEdge`\n";
static PyObject *ContextFunctions_get_selected_fedge(PyObject * /*self*/)
{
FEdge *fe = ContextFunctions::GetSelectedFEdgeCF();
if (fe) {
return Any_BPy_FEdge_from_FEdge(*fe);
}
Py_RETURN_NONE;
}
/*-----------------------ContextFunctions module docstring-------------------------------*/
static char module_docstring[] = "The Blender Freestyle.ContextFunctions submodule\n\n";
/*-----------------------ContextFunctions module functions definitions-------------------*/
static PyMethodDef module_functions[] = {
{"get_time_stamp",
(PyCFunction)ContextFunctions_get_time_stamp,
METH_NOARGS,
ContextFunctions_get_time_stamp___doc__},
{"get_canvas_width",
(PyCFunction)ContextFunctions_get_canvas_width,
METH_NOARGS,
ContextFunctions_get_canvas_width___doc__},
{"get_canvas_height",
(PyCFunction)ContextFunctions_get_canvas_height,
METH_NOARGS,
ContextFunctions_get_canvas_height___doc__},
{"get_border",
(PyCFunction)ContextFunctions_get_border,
METH_NOARGS,
ContextFunctions_get_border___doc__},
{"load_map",
(PyCFunction)ContextFunctions_load_map,
METH_VARARGS | METH_KEYWORDS,
ContextFunctions_load_map___doc__},
{"read_map_pixel",
(PyCFunction)ContextFunctions_read_map_pixel,
METH_VARARGS | METH_KEYWORDS,
ContextFunctions_read_map_pixel___doc__},
{"read_complete_view_map_pixel",
(PyCFunction)ContextFunctions_read_complete_view_map_pixel,
METH_VARARGS | METH_KEYWORDS,
ContextFunctions_read_complete_view_map_pixel___doc__},
{"read_directional_view_map_pixel",
(PyCFunction)ContextFunctions_read_directional_view_map_pixel,
METH_VARARGS | METH_KEYWORDS,
ContextFunctions_read_directional_view_map_pixel___doc__},
{"get_selected_fedge",
(PyCFunction)ContextFunctions_get_selected_fedge,
METH_NOARGS,
ContextFunctions_get_selected_fedge___doc__},
{NULL, NULL, 0, NULL},
};
/*-----------------------ContextFunctions module definition--------------------------------*/
static PyModuleDef module_definition = {
PyModuleDef_HEAD_INIT,
"Freestyle.ContextFunctions",
module_docstring,
-1,
module_functions,
};
//------------------- MODULE INITIALIZATION --------------------------------
int ContextFunctions_Init(PyObject *module)
{
PyObject *m;
if (module == NULL) {
return -1;
}
m = PyModule_Create(&module_definition);
if (m == NULL) {
return -1;
}
Py_INCREF(m);
PyModule_AddObject(module, "ContextFunctions", m);
return 0;
}
///////////////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
}
#endif