diff options
author | Maxime Curioni <maxime.curioni@gmail.com> | 2008-07-18 06:55:23 +0400 |
---|---|---|
committer | Maxime Curioni <maxime.curioni@gmail.com> | 2008-07-18 06:55:23 +0400 |
commit | d3973dac717da1557a9a8d50f5c13e25ae75eaa8 (patch) | |
tree | de60800b4b5d74989680f746dbfcb99934c7f825 /source | |
parent | e4748940c0a61171d5c4e45d8d5a9637d05ac429 (diff) |
soc-2008-mxcurioni: FEdge class added. Modifed converting functions to passing-by-reference format. Improved the type checking for FEdge and CurvePoint. Modified FEdge C++ class to test for null vertices. Updated previous classes to support FEdge.
So far, whenever a Python object is created from its corresponding C++ object, the input object reference is copied into a new object. Due to Freestyle's functions (especially regarding the way it is iterated), it is currently impossible to deal with a pointer-based Python object. It is not a real drawback, just an aspect to keep in mind.
Diffstat (limited to 'source')
11 files changed, 429 insertions, 252 deletions
diff --git a/source/blender/freestyle/SConscript b/source/blender/freestyle/SConscript index 42d78a393eb..5a7745292a4 100644 --- a/source/blender/freestyle/SConscript +++ b/source/blender/freestyle/SConscript @@ -68,7 +68,8 @@ python_sources = [ prefix + '/Interface0D.cpp', prefix + '/Interface0D/CurvePoint.cpp', prefix + '/Interface0D/SVertex.cpp', - prefix + '/Interface1D.cpp' + prefix + '/Interface1D.cpp', + prefix + '/Interface1D/FEdge.cpp' ] sources = system_sources + image_sources + geometry_sources + scene_graph_sources \ diff --git a/source/blender/freestyle/intern/python/Convert.cpp b/source/blender/freestyle/intern/python/Convert.cpp index 59b2406f480..47ad6f3c0ad 100644 --- a/source/blender/freestyle/intern/python/Convert.cpp +++ b/source/blender/freestyle/intern/python/Convert.cpp @@ -9,71 +9,64 @@ extern "C" { PyObject *PyBool_from_bool( bool b ){ - // SWIG_From_bool return PyBool_FromLong( b ? 1 : 0); } -PyObject *Vector_from_Vec2f( Vec2f vec ) { +PyObject *Vector_from_Vec2f( Vec2f& vec ) { float vec_data[2]; // because vec->_coord is protected - if( &vec != 0 ){ - vec_data[0] = vec.x(); vec_data[1] = vec.y(); - return newVectorObject( vec_data, 2, Py_NEW); - } - - Py_RETURN_NONE; + vec_data[0] = vec.x(); vec_data[1] = vec.y(); + return newVectorObject( vec_data, 2, Py_NEW); } -PyObject *Vector_from_Vec3f( Vec3f vec ) { +PyObject *Vector_from_Vec3f( Vec3f& vec ) { float vec_data[3]; // because vec->_coord is protected - if( &vec != 0 ){ - vec_data[0] = vec.x(); vec_data[1] = vec.y(); vec_data[2] = vec.z(); - return newVectorObject( vec_data, 3, Py_NEW); - } - - Py_RETURN_NONE; + vec_data[0] = vec.x(); vec_data[1] = vec.y(); vec_data[2] = vec.z(); + return newVectorObject( vec_data, 3, Py_NEW); } -PyObject *Vector_from_Vec3r( Vec3r vec ) { +PyObject *Vector_from_Vec3r( Vec3r& vec ) { float vec_data[3]; // because vec->_coord is protected - if( &vec != 0 ){ - vec_data[0] = vec.x(); vec_data[1] = vec.y(); vec_data[2] = vec.z(); - return newVectorObject( vec_data, 3, Py_NEW); - } + vec_data[0] = vec.x(); vec_data[1] = vec.y(); vec_data[2] = vec.z(); + return newVectorObject( vec_data, 3, Py_NEW); +} - Py_RETURN_NONE; +PyObject *BPy_Id_from_Id( Id& id ) { + PyObject *py_id = Id_Type.tp_new( &Id_Type, 0, 0 ); + ((BPy_Id *) py_id)->id = new Id( id.getFirst(), id.getSecond() ); + + return py_id; } -PyObject *BPy_Id_from_Id( Id id ) { - BPy_Id *py_id; - - if( &id != 0 ) { - py_id = (BPy_Id *) Id_Type.tp_new( &Id_Type, 0, 0 ); - py_id->id = new Id( id.getFirst(), id.getSecond() ); +PyObject *BPy_Interface0D_from_Interface0D( Interface0D& if0D ) { + PyObject *py_if0D = Interface0D_Type.tp_new( &Interface0D_Type, 0, 0 ); + ((BPy_Interface0D *) py_if0D)->if0D = &if0D; - return (PyObject *)py_id; - } - - Py_RETURN_NONE; + return py_if0D; } -PyObject *BPy_SVertex_from_SVertex( SVertex sv ) { - BPy_SVertex *py_sv; +PyObject *BPy_SVertex_from_SVertex( SVertex& sv ) { + PyObject *py_sv = SVertex_Type.tp_new( &SVertex_Type, 0, 0 ); + ((BPy_SVertex *) py_sv)->sv = new SVertex( sv ); + ((BPy_SVertex *) py_sv)->py_if0D.if0D = ((BPy_SVertex *) py_sv)->sv; - if( &sv != 0 ) { - py_sv = (BPy_SVertex *) SVertex_Type.tp_new( &SVertex_Type, 0, 0 ); - py_sv->sv = new SVertex( sv ); - py_sv->py_if0D.if0D = py_sv->sv; + return py_sv; +} - return (PyObject *)py_sv; - } +PyObject *BPy_FEdge_from_FEdge( FEdge& fe ) { + PyObject *py_fe = FEdge_Type.tp_new( &FEdge_Type, 0, 0 ); + ((BPy_FEdge *) py_fe)->fe = new FEdge( fe ); + ((BPy_FEdge *) py_fe)->py_if1D.if1D = ((BPy_FEdge *) py_fe)->fe; - Py_RETURN_NONE; + return py_fe; } + + + /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/Convert.h b/source/blender/freestyle/intern/python/Convert.h index ba8e3ea02d2..edd62b1f24a 100644 --- a/source/blender/freestyle/intern/python/Convert.h +++ b/source/blender/freestyle/intern/python/Convert.h @@ -5,7 +5,9 @@ using namespace Geometry; #include "Id.h" +#include "Interface0D.h" #include "Interface0D/SVertex.h" +#include "Interface1D/FEdge.h" #ifdef __cplusplus extern "C" { @@ -17,14 +19,16 @@ extern "C" { #include "api2_2x/vector.h" #include "api2_2x/gen_utils.h" -PyObject *PyBool_from_bool( bool b ); +PyObject * PyBool_from_bool( bool b ); -PyObject *Vector_from_Vec2f( Vec2f v ); -PyObject *Vector_from_Vec3f( Vec3f v ); -PyObject *Vector_from_Vec3r( Vec3r v ); +PyObject * Vector_from_Vec2f( Vec2f& v ); +PyObject * Vector_from_Vec3f( Vec3f& v ); +PyObject * Vector_from_Vec3r( Vec3r& v ); -PyObject *BPy_Id_from_Id( Id id ); -PyObject *BPy_SVertex_from_SVertex( SVertex sv ); +PyObject * BPy_Id_from_Id( Id& id ); +PyObject * BPy_SVertex_from_SVertex( SVertex& sv ); +PyObject * BPy_FEdge_from_FEdge( FEdge& fe ); +PyObject * BPy_Interface0D_from_Interface0D( Interface0D& if0D ); /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Interface0D.cpp b/source/blender/freestyle/intern/python/Interface0D.cpp index 27804b3d276..39c2146e015 100644 --- a/source/blender/freestyle/intern/python/Interface0D.cpp +++ b/source/blender/freestyle/intern/python/Interface0D.cpp @@ -3,6 +3,7 @@ #include "Convert.h" #include "Interface0D/CurvePoint.h" #include "Interface0D/SVertex.h" +#include "Interface1D/FEdge.h" #ifdef __cplusplus extern "C" { @@ -24,7 +25,7 @@ static PyObject *Interface0D_getProjectedX( BPy_Interface0D *self ); static PyObject *Interface0D_getProjectedY( BPy_Interface0D *self ); static PyObject *Interface0D_getProjectedZ( BPy_Interface0D *self ); static PyObject *Interface0D_getPoint2D( BPy_Interface0D *self ); -static PyObject *Interface0D_getFEdge( BPy_Interface0D *self ); +static PyObject *Interface0D_getFEdge( BPy_Interface0D *self, PyObject *args ); static PyObject *Interface0D_getId( BPy_Interface0D *self ); static PyObject *Interface0D_getNature( BPy_Interface0D *self ); @@ -39,7 +40,7 @@ static PyMethodDef BPy_Interface0D_methods[] = { {"getProjectedY", ( PyCFunction ) Interface0D_getProjectedY, METH_NOARGS, "() Returns the 2D y coordinate of the point."}, {"getProjectedZ", ( PyCFunction ) Interface0D_getProjectedZ, METH_NOARGS, "() Returns the 2D z coordinate of the point."}, {"getPoint2D", ( PyCFunction ) Interface0D_getPoint2D, METH_NOARGS, "() Returns the 2D point."}, - {"getFEdge", ( PyCFunction ) Interface0D_getFEdge, METH_NOARGS, "() Returns the FEdge that lies between this Interface0D and the Interface0D given as argument."}, + {"getFEdge", ( PyCFunction ) Interface0D_getFEdge, METH_VARARGS, "(Interface0D i) Returns the FEdge that lies between this Interface0D and the Interface0D given as argument."}, {"getId", ( PyCFunction ) Interface0D_getId, METH_NOARGS, "() Returns the Id of the point."}, {"getNature", ( PyCFunction ) Interface0D_getNature, METH_NOARGS, "() Returns the nature of the point."}, {NULL, NULL, 0, NULL} @@ -193,7 +194,8 @@ PyObject *Interface0D_getZ( BPy_Interface0D *self ) { PyObject *Interface0D_getPoint3D( BPy_Interface0D *self ) { - return Vector_from_Vec3f( self->if0D->getPoint3D() ); + Vec3f v( self->if0D->getPoint3D() ); + return Vector_from_Vec3f( v ); } @@ -213,22 +215,36 @@ PyObject *Interface0D_getProjectedZ( BPy_Interface0D *self ) { PyObject *Interface0D_getPoint2D( BPy_Interface0D *self ) { - return Vector_from_Vec2f( self->if0D->getPoint2D() ); + Vec2f v( self->if0D->getPoint2D() ); + return Vector_from_Vec2f( v ); } -PyObject *Interface0D_getFEdge( BPy_Interface0D *self ) { - // FEdge +PyObject *Interface0D_getFEdge( BPy_Interface0D *self, PyObject *args ) { + PyObject *py_if0D; + + if(!( PyArg_ParseTuple(args, "O", &py_if0D) && BPy_Interface0D_Check(py_if0D) )) { + cout << "ERROR: Interface0D_getFEdge" << endl; + Py_RETURN_NONE; + } + + FEdge *fe = self->if0D->getFEdge(*( ((BPy_Interface0D *) py_if0D)->if0D )); + if( fe ) + return BPy_FEdge_from_FEdge( *fe ); + + Py_RETURN_NONE; } PyObject *Interface0D_getId( BPy_Interface0D *self ) { - return BPy_Id_from_Id( self->if0D->getId() ); + Id id( self->if0D->getId() ); + return BPy_Id_from_Id( id ); } PyObject *Interface0D_getNature( BPy_Interface0D *self ) { // VertexNature + Py_RETURN_NONE; } diff --git a/source/blender/freestyle/intern/python/Interface0D/CurvePoint.cpp b/source/blender/freestyle/intern/python/Interface0D/CurvePoint.cpp index 5a81f07973d..f76fc9c9931 100644 --- a/source/blender/freestyle/intern/python/Interface0D/CurvePoint.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/CurvePoint.cpp @@ -1,7 +1,6 @@ #include "CurvePoint.h" #include "../Convert.h" -#include "../../stroke/Curve.h" #ifdef __cplusplus extern "C" { @@ -166,15 +165,15 @@ PyObject * CurvePoint___copy__( BPy_CurvePoint *self ) { } PyObject * CurvePoint_A( BPy_CurvePoint *self ) { - if( self->cp->A() ) - return BPy_SVertex_from_SVertex( *(self->cp->A()) ); + if( SVertex *A = self->cp->A() ) + return BPy_SVertex_from_SVertex( *A ); Py_RETURN_NONE; } PyObject * CurvePoint_B( BPy_CurvePoint *self ) { - if( self->cp->B() ) - return BPy_SVertex_from_SVertex( *(self->cp->B()) ); + if( SVertex *B = self->cp->B() ) + return BPy_SVertex_from_SVertex( *B ); Py_RETURN_NONE; } diff --git a/source/blender/freestyle/intern/python/Interface0D/SVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/SVertex.cpp index fd5b372a1d9..eb91d7daf10 100644 --- a/source/blender/freestyle/intern/python/Interface0D/SVertex.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/SVertex.cpp @@ -18,6 +18,8 @@ static PyObject * SVertex_SetPoint3D( BPy_SVertex *self , PyObject *args); static PyObject * SVertex_SetPoint2D( BPy_SVertex *self , PyObject *args); static PyObject * SVertex_AddNormal( BPy_SVertex *self , PyObject *args); static PyObject * SVertex_SetId( BPy_SVertex *self , PyObject *args); +static PyObject *SVertex_AddFEdge( BPy_SVertex *self , PyObject *args); + /*----------------------SVertex instance definitions ----------------------------*/ static PyMethodDef BPy_SVertex_methods[] = { {"__copy__", ( PyCFunction ) SVertex___copy__, METH_NOARGS, "( )Cloning method."}, @@ -27,6 +29,7 @@ static PyMethodDef BPy_SVertex_methods[] = { {"SetPoint2D", ( PyCFunction ) SVertex_SetPoint2D, METH_VARARGS, "Sets the 3D projected coordinates of the SVertex." }, {"AddNormal", ( PyCFunction ) SVertex_AddNormal, METH_VARARGS, "Adds a normal to the Svertex's set of normals. If the same normal is already in the set, nothing changes." }, {"SetId", ( PyCFunction ) SVertex_SetId, METH_VARARGS, "Sets the Id." }, + {"AddFEdge", ( PyCFunction ) SVertex_AddFEdge, METH_VARARGS, "Add an FEdge to the list of edges emanating from this SVertex." }, {NULL, NULL, 0, NULL} }; @@ -163,7 +166,8 @@ PyObject * SVertex_normals( BPy_SVertex *self ) { normals = self->sv->normals(); for( set< Vec3r >::iterator set_iterator = normals.begin(); set_iterator != normals.end(); set_iterator++ ) { - PyList_Append( py_normals, Vector_from_Vec3r(*set_iterator) ); + Vec3r v( *set_iterator ); + PyList_Append( py_normals, Vector_from_Vec3r(v) ); } return py_normals; @@ -215,8 +219,6 @@ PyObject *SVertex_AddNormal( BPy_SVertex *self , PyObject *args) { cout << "ERROR: SVertex_AddNormal" << endl; Py_RETURN_NONE; } - - cout << "yoyo" << endl; Vec3r n( PyFloat_AsDouble( PyList_GetItem(py_normal, 0) ), PyFloat_AsDouble( PyList_GetItem(py_normal, 1) ), @@ -239,9 +241,23 @@ PyObject *SVertex_SetId( BPy_SVertex *self , PyObject *args) { Py_RETURN_NONE; } +PyObject *SVertex_AddFEdge( BPy_SVertex *self , PyObject *args) { + PyObject *py_fe; + + if(!( PyArg_ParseTuple(args, "O", &py_fe) && BPy_FEdge_Check(py_fe) )) { + cout << "ERROR: SVertex_AddFEdge" << endl; + Py_RETURN_NONE; + } + + self->sv->AddFEdge( ((BPy_FEdge *) py_fe)->fe ); + + Py_RETURN_NONE; +} + + // virtual bool operator== (const SVertex &iBrother) // ViewVertex * viewvertex () -// void AddFEdge (FEdge *iFEdge) + /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Interface0D/SVertex.h b/source/blender/freestyle/intern/python/Interface0D/SVertex.h new file mode 100644 index 00000000000..ac89133ab55 --- /dev/null +++ b/source/blender/freestyle/intern/python/Interface0D/SVertex.h @@ -0,0 +1,33 @@ +#ifndef FREESTYLE_PYTHON_SVERTEX_H +#define FREESTYLE_PYTHON_SVERTEX_H + +#include "../../view_map/Silhouette.h" +#include "../Interface0D.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +#include <Python.h> + +extern PyTypeObject SVertex_Type; + +#define BPy_SVertex_Check(v) \ + ((v)->ob_type == &SVertex_Type) + +/*---------------------------Python BPy_SVertex structure definition----------*/ +typedef struct { + BPy_Interface0D py_if0D; + SVertex *sv; +} BPy_SVertex; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif + +#endif /* FREESTYLE_PYTHON_SVERTEX_H */ diff --git a/source/blender/freestyle/intern/python/Interface1D.cpp b/source/blender/freestyle/intern/python/Interface1D.cpp index 27c5f4d08ff..971403b3354 100644 --- a/source/blender/freestyle/intern/python/Interface1D.cpp +++ b/source/blender/freestyle/intern/python/Interface1D.cpp @@ -1,6 +1,7 @@ #include "Interface1D.h" #include "Convert.h" +#include "Interface1D/FEdge.h" #ifdef __cplusplus extern "C" { @@ -128,9 +129,14 @@ PyMODINIT_FUNC Interface1D_Init( PyObject *module ) if( PyType_Ready( &Interface1D_Type ) < 0 ) return; - Py_INCREF( &Interface1D_Type ); PyModule_AddObject(module, "Interface1D", (PyObject *)&Interface1D_Type); + + if( PyType_Ready( &FEdge_Type ) < 0 ) + return; + Py_INCREF( &FEdge_Type ); + PyModule_AddObject(module, "FEdge", (PyObject *)&FEdge_Type); + } //------------------------INSTANCE METHODS ---------------------------------- @@ -169,11 +175,13 @@ PyObject *Interface1D_getLength2D( BPy_Interface1D *self ) { } PyObject *Interface1D_getId( BPy_Interface1D *self ) { - return BPy_Id_from_Id( self->if1D->getId() ); + Id id( self->if1D->getId() ); + return BPy_Id_from_Id( id ); } PyObject *Interface1D_getNature( BPy_Interface1D *self ) { // EdgeNature + Py_RETURN_NONE; } PyObject *Interface1D_getTimeStamp( BPy_Interface1D *self ) { diff --git a/source/blender/freestyle/intern/python/Interface1D/FEdge.cpp b/source/blender/freestyle/intern/python/Interface1D/FEdge.cpp index 862456d2b7c..e8e5c6787e3 100644 --- a/source/blender/freestyle/intern/python/Interface1D/FEdge.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/FEdge.cpp @@ -1,252 +1,325 @@ - PyObject *_wrap_FEdge_getExactTypeName(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_FEdge_getLength2D(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_FEdge_getId(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_FEdge_userdata_set(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_FEdge_userdata_get(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_new_FEdge__SWIG_0(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_new_FEdge__SWIG_1(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_new_FEdge__SWIG_2(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_new_FEdge(PyObject *self, PyObject *args) { -} - - - PyObject *_wrap_delete_FEdge(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_FEdge_dupplicate(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_FEdge_vertexA(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_FEdge_vertexB(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_FEdge_getNature(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_FEdge_nextEdge(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_FEdge_previousEdge(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_FEdge_shape__SWIG_0(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_FEdge_invisibility(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_FEdge_viewedge(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_FEdge_center3d(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_FEdge_center2d(PyObject *self , PyObject *args) { -} - +#include "FEdge.h" + +#include "../Convert.h" +#include "../Interface0D/SVertex.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +/*--------------- Python API function prototypes for FEdge instance -----------*/ +static int FEdge___init__(BPy_FEdge *self, PyObject *args, PyObject *kwds); +static PyObject * FEdge___copy__( BPy_FEdge *self ); +static PyObject * FEdge_vertexA( BPy_FEdge *self ); +static PyObject * FEdge_vertexB( BPy_FEdge *self ); +static PyObject * FEdge___getitem__( BPy_FEdge *self, PyObject *args ); +static PyObject * FEdge_nextEdge( BPy_FEdge *self ); +static PyObject * FEdge_previousEdge( BPy_FEdge *self ); +static PyObject * FEdge_getVertices( BPy_FEdge *self ); +static PyObject * FEdge_getPoints( BPy_FEdge *self ); +static PyObject * FEdge_isSmooth( BPy_FEdge *self ); +static PyObject * FEdge_SetVertexA( BPy_FEdge *self , PyObject *args); +static PyObject * FEdge_SetVertexB( BPy_FEdge *self , PyObject *args); +static PyObject * FEdge_SetId( BPy_FEdge *self , PyObject *args); +static PyObject * FEdge_SetNextEdge( BPy_FEdge *self , PyObject *args); +static PyObject * FEdge_SetPreviousEdge( BPy_FEdge *self , PyObject *args); +static PyObject * FEdge_SetSmooth( BPy_FEdge *self , PyObject *args); + +/*----------------------FEdge instance definitions ----------------------------*/ +static PyMethodDef BPy_FEdge_methods[] = { + {"__copy__", ( PyCFunction ) FEdge___copy__, METH_NOARGS, "() Cloning method."}, + {"vertexA", ( PyCFunction ) FEdge_vertexA, METH_NOARGS, "() Returns the first SVertex."}, + {"vertexB", ( PyCFunction ) FEdge_vertexB, METH_NOARGS, "() Returns the second SVertex."}, + {"__getitem__", ( PyCFunction ) FEdge___getitem__, METH_VARARGS, "(int i) Returns the first SVertex if i=0, the seccond SVertex if i=1."}, + {"nextEdge", ( PyCFunction ) FEdge_nextEdge, METH_NOARGS, "() Returns the FEdge following this one in the ViewEdge. If this FEdge is the last of the ViewEdge, 0 is returned."}, + {"previousEdge", ( PyCFunction ) FEdge_previousEdge, METH_NOARGS, "Returns the Edge preceding this one in the ViewEdge. If this FEdge is the first one of the ViewEdge, 0 is returned."}, + {"getVertices", ( PyCFunction ) FEdge_getVertices, METH_NOARGS, "Returns the vertices"}, + {"getPoints", ( PyCFunction ) FEdge_getPoints, METH_NOARGS, "Returns the points. The difference with getVertices() is that here we can iterate over points of the 1D element at any given sampling. At each call, a virtual point is created."}, + {"isSmooth", ( PyCFunction ) FEdge_isSmooth, METH_NOARGS, "() Returns true if this FEdge is a smooth FEdge."}, + {"SetVertexA", ( PyCFunction ) FEdge_SetVertexA, METH_VARARGS, "(SVertex v) Sets the first SVertex. ."}, + {"SetVertexB", ( PyCFunction ) FEdge_SetVertexB, METH_VARARGS, "(SVertex v) Sets the second SVertex. "}, + {"SetId", ( PyCFunction ) FEdge_SetId, METH_VARARGS, "(Id id) Sets the FEdge Id ."}, + {"SetNextEdge", ( PyCFunction ) FEdge_SetNextEdge, METH_VARARGS, "(FEdge e) Sets the pointer to the next FEdge. "}, + {"SetPreviousEdge", ( PyCFunction ) FEdge_SetPreviousEdge, METH_VARARGS, "(FEdge e) Sets the pointer to the previous FEdge. "}, + {"SetSmooth", ( PyCFunction ) FEdge_SetSmooth, METH_VARARGS, "(bool b) Sets the flag telling whether this FEdge is smooth or sharp. true for Smooth, false for Sharp. "}, + {NULL, NULL, 0, NULL} +}; + +/*-----------------------BPy_FEdge type definition ------------------------------*/ + +PyTypeObject FEdge_Type = { + PyObject_HEAD_INIT( NULL ) + 0, /* ob_size */ + "FEdge", /* tp_name */ + sizeof( BPy_FEdge ), /* tp_basicsize */ + 0, /* tp_itemsize */ + + /* methods */ + NULL, /* tp_dealloc */ + NULL, /* printfunc tp_print; */ + NULL, /* getattrfunc tp_getattr; */ + NULL, /* setattrfunc tp_setattr; */ + NULL, /* tp_compare */ + NULL, /* tp_repr */ + + /* Method suites for standard classes */ + + NULL, /* PyNumberMethods *tp_as_number; */ + NULL, /* PySequenceMethods *tp_as_sequence; */ + NULL, /* PyMappingMethods *tp_as_mapping; */ + + /* More standard operations (here for binary compatibility) */ + + NULL, /* hashfunc tp_hash; */ + NULL, /* ternaryfunc tp_call; */ + NULL, /* reprfunc tp_str; */ + NULL, /* getattrofunc tp_getattro; */ + NULL, /* setattrofunc tp_setattro; */ + + /* Functions to access object as input/output buffer */ + NULL, /* PyBufferProcs *tp_as_buffer; */ + + /*** Flags to define presence of optional/expanded features ***/ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* long tp_flags; */ + + NULL, /* char *tp_doc; Documentation string */ + /*** Assigned meaning in release 2.0 ***/ + /* call function for all accessible objects */ + NULL, /* traverseproc tp_traverse; */ + + /* delete references to contained objects */ + NULL, /* inquiry tp_clear; */ + + /*** Assigned meaning in release 2.1 ***/ + /*** rich comparisons ***/ + NULL, /* richcmpfunc tp_richcompare; */ + + /*** weak reference enabler ***/ + 0, /* long tp_weaklistoffset; */ + + /*** Added in release 2.2 ***/ + /* Iterators */ + NULL, /* getiterfunc tp_iter; */ + NULL, /* iternextfunc tp_iternext; */ + + /*** Attribute descriptor and subclassing stuff ***/ + BPy_FEdge_methods, /* struct PyMethodDef *tp_methods; */ + NULL, /* struct PyMemberDef *tp_members; */ + NULL, /* struct PyGetSetDef *tp_getset; */ + &Interface1D_Type, /* struct _typeobject *tp_base; */ + NULL, /* PyObject *tp_dict; */ + NULL, /* descrgetfunc tp_descr_get; */ + NULL, /* descrsetfunc tp_descr_set; */ + 0, /* long tp_dictoffset; */ + (initproc)FEdge___init__, /* initproc tp_init; */ + NULL, /* allocfunc tp_alloc; */ + NULL, /* newfunc tp_new; */ + + /* Low-level free-memory routine */ + NULL, /* freefunc tp_free; */ + + /* For PyObject_IS_GC */ + NULL, /* inquiry tp_is_gc; */ + NULL, /* PyObject *tp_bases; */ + + /* method resolution order */ + NULL, /* PyObject *tp_mro; */ + NULL, /* PyObject *tp_cache; */ + NULL, /* PyObject *tp_subclasses; */ + NULL, /* PyObject *tp_weaklist; */ + NULL +}; + +//-------------------MODULE INITIALIZATION-------------------------------- + - PyObject *_wrap_FEdge_aFace(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_FEdge_getOccludeeIntersection(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_FEdge_getOccludeeEmpty(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_FEdge_isSmooth(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_FEdge_SetVertexA(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_FEdge_SetVertexB(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_FEdge_SetId(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_FEdge_SetNextEdge(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_FEdge_SetPreviousEdge(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_FEdge_SetNature(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_FEdge_SetViewEdge(PyObject *self , PyObject *args) { -} +//------------------------INSTANCE METHODS ---------------------------------- + +int FEdge___init__(BPy_FEdge *self, PyObject *args, PyObject *kwds) +{ + PyObject *obj1 = 0, *obj2 = 0; - PyObject *_wrap_FEdge_SetaFace(PyObject *self , PyObject *args) { -} - + if (! PyArg_ParseTuple(args, "|OO", &obj1, &obj2) ) + return -1; - PyObject *_wrap_FEdge_SetOccludeeIntersection(PyObject *self , PyObject *args) { -} + if( !obj1 && !obj2 ){ + self->fe = new FEdge(); + } else if( BPy_SVertex_Check(obj1) && BPy_SVertex_Check(obj2) ) { + self->fe = new FEdge( ((BPy_SVertex *) obj1)->sv, ((BPy_SVertex *) obj2)->sv ); + } else { + return -1; + } + self->py_if1D.if1D = self->fe; - PyObject *_wrap_FEdge_SetOccludeeEmpty(PyObject *self , PyObject *args) { + return 0; } - PyObject *_wrap_FEdge_SetSmooth(PyObject *self , PyObject *args) { -} - +PyObject * FEdge___copy__( BPy_FEdge *self ) { + BPy_FEdge *py_fe; + + py_fe = (BPy_FEdge *) FEdge_Type.tp_new( &FEdge_Type, 0, 0 ); + + py_fe->fe = new FEdge( *(self->fe) ); + py_fe->py_if1D.if1D = py_fe->fe; - PyObject *_wrap_FEdge_CommonVertex(PyObject *self , PyObject *args) { + return (PyObject *) py_fe; } - - PyObject *_wrap_FEdge_min2d(PyObject *self , PyObject *args) { +PyObject * FEdge_vertexA( BPy_FEdge *self ) { + if( self->fe->vertexA() ){ + return BPy_SVertex_from_SVertex( *(self->fe->vertexA()) ); + } + + Py_RETURN_NONE; } - - PyObject *_wrap_FEdge_max2d(PyObject *self , PyObject *args) { +PyObject * FEdge_vertexB( BPy_FEdge *self ) { + if( self->fe->vertexB() ){ + return BPy_SVertex_from_SVertex( *(self->fe->vertexB()) ); + } + + Py_RETURN_NONE; } - PyObject *_wrap_FEdge_shape_id(PyObject *self , PyObject *args) { -} +PyObject * FEdge___getitem__( BPy_FEdge *self, PyObject *args ) { + int i; + if(!( PyArg_ParseTuple(args, "i", &i) && (i == 0 || i == 1) )) { + cout << "ERROR: FEdge___getitem__" << endl; + Py_RETURN_NONE; + } + + if( SVertex *v = self->fe->operator[](i) ) + return BPy_SVertex_from_SVertex( *v ); - PyObject *_wrap_FEdge_shape__SWIG_1(PyObject *self , PyObject *args) { + Py_RETURN_NONE; } +PyObject * FEdge_nextEdge( BPy_FEdge *self ) { + if( FEdge *fe = self->fe->nextEdge() ) + return BPy_FEdge_from_FEdge( *fe ); - PyObject *_wrap_FEdge_shape(PyObject *self, PyObject *args) { + Py_RETURN_NONE; } +PyObject * FEdge_previousEdge( BPy_FEdge *self ) { + if( FEdge *fe = self->fe->previousEdge() ) + return BPy_FEdge_from_FEdge( *fe ); - PyObject *_wrap_FEdge_shape_importance(PyObject *self , PyObject *args) { + Py_RETURN_NONE; } - - PyObject *_wrap_FEdge_qi(PyObject *self , PyObject *args) { +PyObject * FEdge_isSmooth( BPy_FEdge *self ) { + return PyBool_from_bool( self->fe->isSmooth() ); } + +PyObject *FEdge_SetVertexA( BPy_FEdge *self , PyObject *args) { + PyObject *py_sv; + if(!( PyArg_ParseTuple(args, "O", &py_sv) && BPy_SVertex_Check(py_sv) )) { + cout << "ERROR: FEdge_SetVertexA" << endl; + Py_RETURN_NONE; + } - PyObject *_wrap_FEdge_occluders_begin(PyObject *self , PyObject *args) { -} - + self->fe->SetVertexA( ((BPy_SVertex *) py_sv)->sv ); - PyObject *_wrap_FEdge_occluders_end(PyObject *self , PyObject *args) { + Py_RETURN_NONE; } +PyObject *FEdge_SetVertexB( BPy_FEdge *self , PyObject *args) { + PyObject *py_sv; - PyObject *_wrap_FEdge_occluders_empty(PyObject *self , PyObject *args) { -} + if(!( PyArg_ParseTuple(args, "O", &py_sv) && BPy_SVertex_Check(py_sv) )) { + cout << "ERROR: FEdge_SetVertexB" << endl; + Py_RETURN_NONE; + } + self->fe->SetVertexB( ((BPy_SVertex *) py_sv)->sv ); - PyObject *_wrap_FEdge_occluders_size(PyObject *self , PyObject *args) { + Py_RETURN_NONE; } +PyObject *FEdge_SetId( BPy_FEdge *self , PyObject *args) { + PyObject *py_id; - PyObject *_wrap_FEdge_occludee(PyObject *self , PyObject *args) { -} + if(!( PyArg_ParseTuple(args, "O", &py_id) && BPy_Id_Check(py_id) )) { + cout << "ERROR: FEdge_SetId" << endl; + Py_RETURN_NONE; + } + self->fe->SetId(*( ((BPy_Id *) py_id)->id )); - PyObject *_wrap_FEdge_occluded_shape(PyObject *self , PyObject *args) { + Py_RETURN_NONE; } - PyObject *_wrap_FEdge_occludee_empty(PyObject *self , PyObject *args) { -} - +PyObject *FEdge_SetNextEdge( BPy_FEdge *self , PyObject *args) { + PyObject *py_fe; - PyObject *_wrap_FEdge_z_discontinuity(PyObject *self , PyObject *args) { -} + if(!( PyArg_ParseTuple(args, "O", &py_fe) && BPy_FEdge_Check(py_fe) )) { + cout << "ERROR: FEdge_SetNextEdge" << endl; + Py_RETURN_NONE; + } + self->fe->SetNextEdge( ((BPy_FEdge *) py_fe)->fe ); - PyObject *_wrap_FEdge_viewedge_nature(PyObject *self , PyObject *args) { + Py_RETURN_NONE; } +PyObject *FEdge_SetPreviousEdge( BPy_FEdge *self , PyObject *args) { + PyObject *py_fe; - PyObject *_wrap_FEdge_orientation2d(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_FEdge_orientation3d(PyObject *self , PyObject *args) { -} + if(!( PyArg_ParseTuple(args, "O", &py_fe) && BPy_FEdge_Check(py_fe) )) { + cout << "ERROR: FEdge_SetPreviousEdge" << endl; + Py_RETURN_NONE; + } + self->fe->SetPreviousEdge( ((BPy_FEdge *) py_fe)->fe ); - PyObject *_wrap_FEdge_verticesBegin(PyObject *self , PyObject *args) { + Py_RETURN_NONE; } +PyObject *FEdge_SetSmooth( BPy_FEdge *self , PyObject *args) { + int b; - PyObject *_wrap_FEdge_verticesEnd(PyObject *self , PyObject *args) { -} + if(!( PyArg_ParseTuple(args, "i", &b) )) { + cout << "ERROR: FEdge_SetSmooth" << endl; + Py_RETURN_NONE; + } + self->fe->SetSmooth( (bool) b ); - PyObject *_wrap_FEdge_pointsBegin__SWIG_0(PyObject *self , PyObject *args) { + Py_RETURN_NONE; } - - PyObject *_wrap_FEdge_pointsBegin__SWIG_1(PyObject *self , PyObject *args) { +PyObject *FEdge_getVertices( BPy_FEdge *self ) { + PyObject *py_vertices = PyList_New(NULL); + + for( Interface0DIterator it = self->fe->verticesBegin(); it != self->fe->verticesEnd(); it++ ) { + PyList_Append( py_vertices, BPy_Interface0D_from_Interface0D( *it ) ); + } + + return py_vertices; } - - PyObject *_wrap_FEdge_pointsBegin(PyObject *self, PyObject *args) { +PyObject *FEdge_getPoints( BPy_FEdge *self ) { + PyObject *py_points = PyList_New(NULL); + + for( Interface0DIterator it = self->fe->pointsBegin(); it != self->fe->pointsEnd(); it++ ) { + PyList_Append( py_points, BPy_Interface0D_from_Interface0D( *it ) ); + } + + return py_points; } +/////////////////////////////////////////////////////////////////////////////////////////// - PyObject *_wrap_FEdge_pointsEnd__SWIG_0(PyObject *self , PyObject *args) { +#ifdef __cplusplus } - - - PyObject *_wrap_FEdge_pointsEnd__SWIG_1(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_FEdge_pointsEnd(PyObject *self, PyObject *args) { -} - - +#endif diff --git a/source/blender/freestyle/intern/python/Interface1D/FEdge.h b/source/blender/freestyle/intern/python/Interface1D/FEdge.h new file mode 100644 index 00000000000..39c9c56e391 --- /dev/null +++ b/source/blender/freestyle/intern/python/Interface1D/FEdge.h @@ -0,0 +1,32 @@ +#ifndef FREESTYLE_PYTHON_FEDGE_H +#define FREESTYLE_PYTHON_FEDGE_H + +#include "../Interface1D.h" +#include "../../view_map/Silhouette.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +#include <Python.h> + +extern PyTypeObject FEdge_Type; + +#define BPy_FEdge_Check(v) \ + ((v)->ob_type == &FEdge_Type) + +/*---------------------------Python BPy_FEdge structure definition----------*/ +typedef struct { + BPy_Interface1D py_if1D; + FEdge *fe; +} BPy_FEdge; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif + +#endif /* FREESTYLE_PYTHON_FEDGE_H */ diff --git a/source/blender/freestyle/intern/view_map/Silhouette.h b/source/blender/freestyle/intern/view_map/Silhouette.h index c6a1763eec6..15947fe3ba4 100755 --- a/source/blender/freestyle/intern/view_map/Silhouette.h +++ b/source/blender/freestyle/intern/view_map/Silhouette.h @@ -412,6 +412,8 @@ public: /*! Default constructor */ inline FEdge() { userdata = NULL; + _VertexA = NULL; + _VertexB = NULL; _Nature = Nature::NO_FEATURE; _NextEdge = NULL; _PreviousEdge = NULL; |