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.
This commit is contained in:
Maxime Curioni
2008-07-18 02:55:23 +00:00
parent e4748940c0
commit d3973dac71
11 changed files with 474 additions and 297 deletions

View File

@@ -68,7 +68,8 @@ python_sources = [
prefix + '/Interface0D.cpp', prefix + '/Interface0D.cpp',
prefix + '/Interface0D/CurvePoint.cpp', prefix + '/Interface0D/CurvePoint.cpp',
prefix + '/Interface0D/SVertex.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 \ sources = system_sources + image_sources + geometry_sources + scene_graph_sources \

View File

@@ -9,71 +9,64 @@ extern "C" {
PyObject *PyBool_from_bool( bool b ){ PyObject *PyBool_from_bool( bool b ){
// SWIG_From_bool
return PyBool_FromLong( b ? 1 : 0); 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 float vec_data[2]; // because vec->_coord is protected
if( &vec != 0 ){ vec_data[0] = vec.x(); vec_data[1] = vec.y();
vec_data[0] = vec.x(); vec_data[1] = vec.y(); return newVectorObject( vec_data, 2, Py_NEW);
return newVectorObject( vec_data, 2, Py_NEW);
}
Py_RETURN_NONE;
} }
PyObject *Vector_from_Vec3f( Vec3f vec ) { PyObject *Vector_from_Vec3f( Vec3f& vec ) {
float vec_data[3]; // because vec->_coord is protected 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();
vec_data[0] = vec.x(); vec_data[1] = vec.y(); vec_data[2] = vec.z(); return newVectorObject( vec_data, 3, Py_NEW);
return newVectorObject( vec_data, 3, Py_NEW);
}
Py_RETURN_NONE;
} }
PyObject *Vector_from_Vec3r( Vec3r vec ) { PyObject *Vector_from_Vec3r( Vec3r& vec ) {
float vec_data[3]; // because vec->_coord is protected 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();
vec_data[0] = vec.x(); vec_data[1] = vec.y(); vec_data[2] = vec.z(); return newVectorObject( vec_data, 3, Py_NEW);
return newVectorObject( vec_data, 3, Py_NEW);
}
Py_RETURN_NONE;
} }
PyObject *BPy_Id_from_Id( Id id ) { PyObject *BPy_Id_from_Id( Id& id ) {
BPy_Id *py_id; PyObject *py_id = Id_Type.tp_new( &Id_Type, 0, 0 );
((BPy_Id *) py_id)->id = new Id( id.getFirst(), id.getSecond() );
if( &id != 0 ) {
py_id = (BPy_Id *) Id_Type.tp_new( &Id_Type, 0, 0 );
py_id->id = new Id( id.getFirst(), id.getSecond() );
return (PyObject *)py_id; return py_id;
}
Py_RETURN_NONE;
} }
PyObject *BPy_SVertex_from_SVertex( SVertex sv ) { PyObject *BPy_Interface0D_from_Interface0D( Interface0D& if0D ) {
BPy_SVertex *py_sv; PyObject *py_if0D = Interface0D_Type.tp_new( &Interface0D_Type, 0, 0 );
((BPy_Interface0D *) py_if0D)->if0D = &if0D;
if( &sv != 0 ) { return py_if0D;
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 (PyObject *)py_sv;
}
Py_RETURN_NONE;
} }
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;
return 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;
return py_fe;
}
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus #ifdef __cplusplus

View File

@@ -5,7 +5,9 @@
using namespace Geometry; using namespace Geometry;
#include "Id.h" #include "Id.h"
#include "Interface0D.h"
#include "Interface0D/SVertex.h" #include "Interface0D/SVertex.h"
#include "Interface1D/FEdge.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -17,14 +19,16 @@ extern "C" {
#include "api2_2x/vector.h" #include "api2_2x/vector.h"
#include "api2_2x/gen_utils.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_Vec2f( Vec2f& v );
PyObject *Vector_from_Vec3f( Vec3f v ); PyObject * Vector_from_Vec3f( Vec3f& v );
PyObject *Vector_from_Vec3r( Vec3r v ); PyObject * Vector_from_Vec3r( Vec3r& v );
PyObject *BPy_Id_from_Id( Id id ); PyObject * BPy_Id_from_Id( Id& id );
PyObject *BPy_SVertex_from_SVertex( SVertex sv ); PyObject * BPy_SVertex_from_SVertex( SVertex& sv );
PyObject * BPy_FEdge_from_FEdge( FEdge& fe );
PyObject * BPy_Interface0D_from_Interface0D( Interface0D& if0D );
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -3,6 +3,7 @@
#include "Convert.h" #include "Convert.h"
#include "Interface0D/CurvePoint.h" #include "Interface0D/CurvePoint.h"
#include "Interface0D/SVertex.h" #include "Interface0D/SVertex.h"
#include "Interface1D/FEdge.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -24,7 +25,7 @@ static PyObject *Interface0D_getProjectedX( BPy_Interface0D *self );
static PyObject *Interface0D_getProjectedY( BPy_Interface0D *self ); static PyObject *Interface0D_getProjectedY( BPy_Interface0D *self );
static PyObject *Interface0D_getProjectedZ( BPy_Interface0D *self ); static PyObject *Interface0D_getProjectedZ( BPy_Interface0D *self );
static PyObject *Interface0D_getPoint2D( 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_getId( BPy_Interface0D *self );
static PyObject *Interface0D_getNature( 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."}, {"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."}, {"getProjectedZ", ( PyCFunction ) Interface0D_getProjectedZ, METH_NOARGS, "() Returns the 2D z coordinate of the point."},
{"getPoint2D", ( PyCFunction ) Interface0D_getPoint2D, METH_NOARGS, "() Returns the 2D 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."}, {"getId", ( PyCFunction ) Interface0D_getId, METH_NOARGS, "() Returns the Id of the point."},
{"getNature", ( PyCFunction ) Interface0D_getNature, METH_NOARGS, "() Returns the nature of the point."}, {"getNature", ( PyCFunction ) Interface0D_getNature, METH_NOARGS, "() Returns the nature of the point."},
{NULL, NULL, 0, NULL} {NULL, NULL, 0, NULL}
@@ -193,7 +194,8 @@ PyObject *Interface0D_getZ( BPy_Interface0D *self ) {
PyObject *Interface0D_getPoint3D( 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 ) { 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 ) { PyObject *Interface0D_getFEdge( BPy_Interface0D *self, PyObject *args ) {
// FEdge 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 ) { 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 ) { PyObject *Interface0D_getNature( BPy_Interface0D *self ) {
// VertexNature // VertexNature
Py_RETURN_NONE;
} }

View File

@@ -1,7 +1,6 @@
#include "CurvePoint.h" #include "CurvePoint.h"
#include "../Convert.h" #include "../Convert.h"
#include "../../stroke/Curve.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -166,15 +165,15 @@ PyObject * CurvePoint___copy__( BPy_CurvePoint *self ) {
} }
PyObject * CurvePoint_A( BPy_CurvePoint *self ) { PyObject * CurvePoint_A( BPy_CurvePoint *self ) {
if( self->cp->A() ) if( SVertex *A = self->cp->A() )
return BPy_SVertex_from_SVertex( *(self->cp->A()) ); return BPy_SVertex_from_SVertex( *A );
Py_RETURN_NONE; Py_RETURN_NONE;
} }
PyObject * CurvePoint_B( BPy_CurvePoint *self ) { PyObject * CurvePoint_B( BPy_CurvePoint *self ) {
if( self->cp->B() ) if( SVertex *B = self->cp->B() )
return BPy_SVertex_from_SVertex( *(self->cp->B()) ); return BPy_SVertex_from_SVertex( *B );
Py_RETURN_NONE; Py_RETURN_NONE;
} }

View File

@@ -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_SetPoint2D( BPy_SVertex *self , PyObject *args);
static PyObject * SVertex_AddNormal( 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_SetId( BPy_SVertex *self , PyObject *args);
static PyObject *SVertex_AddFEdge( BPy_SVertex *self , PyObject *args);
/*----------------------SVertex instance definitions ----------------------------*/ /*----------------------SVertex instance definitions ----------------------------*/
static PyMethodDef BPy_SVertex_methods[] = { static PyMethodDef BPy_SVertex_methods[] = {
{"__copy__", ( PyCFunction ) SVertex___copy__, METH_NOARGS, " Cloning method."}, {"__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." }, {"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." }, {"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." }, {"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} {NULL, NULL, 0, NULL}
}; };
@@ -163,7 +166,8 @@ PyObject * SVertex_normals( BPy_SVertex *self ) {
normals = self->sv->normals(); normals = self->sv->normals();
for( set< Vec3r >::iterator set_iterator = normals.begin(); set_iterator != normals.end(); set_iterator++ ) { 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; return py_normals;
@@ -215,8 +219,6 @@ PyObject *SVertex_AddNormal( BPy_SVertex *self , PyObject *args) {
cout << "ERROR: SVertex_AddNormal" << endl; cout << "ERROR: SVertex_AddNormal" << endl;
Py_RETURN_NONE; Py_RETURN_NONE;
} }
cout << "yoyo" << endl;
Vec3r n( PyFloat_AsDouble( PyList_GetItem(py_normal, 0) ), Vec3r n( PyFloat_AsDouble( PyList_GetItem(py_normal, 0) ),
PyFloat_AsDouble( PyList_GetItem(py_normal, 1) ), PyFloat_AsDouble( PyList_GetItem(py_normal, 1) ),
@@ -239,9 +241,23 @@ PyObject *SVertex_SetId( BPy_SVertex *self , PyObject *args) {
Py_RETURN_NONE; 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) // virtual bool operator== (const SVertex &iBrother)
// ViewVertex * viewvertex () // ViewVertex * viewvertex ()
// void AddFEdge (FEdge *iFEdge)
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -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 */

View File

@@ -1,6 +1,7 @@
#include "Interface1D.h" #include "Interface1D.h"
#include "Convert.h" #include "Convert.h"
#include "Interface1D/FEdge.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -128,9 +129,14 @@ PyMODINIT_FUNC Interface1D_Init( PyObject *module )
if( PyType_Ready( &Interface1D_Type ) < 0 ) if( PyType_Ready( &Interface1D_Type ) < 0 )
return; return;
Py_INCREF( &Interface1D_Type ); Py_INCREF( &Interface1D_Type );
PyModule_AddObject(module, "Interface1D", (PyObject *)&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 ---------------------------------- //------------------------INSTANCE METHODS ----------------------------------
@@ -169,11 +175,13 @@ PyObject *Interface1D_getLength2D( BPy_Interface1D *self ) {
} }
PyObject *Interface1D_getId( 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 ) { PyObject *Interface1D_getNature( BPy_Interface1D *self ) {
// EdgeNature // EdgeNature
Py_RETURN_NONE;
} }
PyObject *Interface1D_getTimeStamp( BPy_Interface1D *self ) { PyObject *Interface1D_getTimeStamp( BPy_Interface1D *self ) {

View File

@@ -1,252 +1,325 @@
PyObject *_wrap_FEdge_getExactTypeName(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--------------------------------
//------------------------INSTANCE METHODS ----------------------------------
int FEdge___init__(BPy_FEdge *self, PyObject *args, PyObject *kwds)
{
PyObject *obj1 = 0, *obj2 = 0;
if (! PyArg_ParseTuple(args, "|OO", &obj1, &obj2) )
return -1;
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;
return 0;
} }
PyObject *_wrap_FEdge_getLength2D(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;
return (PyObject *) py_fe;
}
PyObject * FEdge_vertexA( BPy_FEdge *self ) {
if( self->fe->vertexA() ){
return BPy_SVertex_from_SVertex( *(self->fe->vertexA()) );
}
Py_RETURN_NONE;
}
PyObject * FEdge_vertexB( BPy_FEdge *self ) {
if( self->fe->vertexB() ){
return BPy_SVertex_from_SVertex( *(self->fe->vertexB()) );
}
Py_RETURN_NONE;
} }
PyObject *_wrap_FEdge_getId(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 );
Py_RETURN_NONE;
}
PyObject * FEdge_nextEdge( BPy_FEdge *self ) {
if( FEdge *fe = self->fe->nextEdge() )
return BPy_FEdge_from_FEdge( *fe );
Py_RETURN_NONE;
}
PyObject * FEdge_previousEdge( BPy_FEdge *self ) {
if( FEdge *fe = self->fe->previousEdge() )
return BPy_FEdge_from_FEdge( *fe );
Py_RETURN_NONE;
}
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;
}
self->fe->SetVertexA( ((BPy_SVertex *) py_sv)->sv );
Py_RETURN_NONE;
}
PyObject *FEdge_SetVertexB( BPy_FEdge *self , PyObject *args) {
PyObject *py_sv;
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 );
Py_RETURN_NONE;
}
PyObject *FEdge_SetId( BPy_FEdge *self , PyObject *args) {
PyObject *py_id;
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 ));
Py_RETURN_NONE;
} }
PyObject *_wrap_FEdge_userdata_set(PyObject *self , PyObject *args) { PyObject *FEdge_SetNextEdge( BPy_FEdge *self , PyObject *args) {
PyObject *py_fe;
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 );
Py_RETURN_NONE;
} }
PyObject *FEdge_SetPreviousEdge( BPy_FEdge *self , PyObject *args) {
PyObject *py_fe;
PyObject *_wrap_FEdge_userdata_get(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 );
Py_RETURN_NONE;
} }
PyObject *FEdge_SetSmooth( BPy_FEdge *self , PyObject *args) {
int b;
PyObject *_wrap_new_FEdge__SWIG_0(PyObject *self , PyObject *args) { if(!( PyArg_ParseTuple(args, "i", &b) )) {
cout << "ERROR: FEdge_SetSmooth" << endl;
Py_RETURN_NONE;
}
self->fe->SetSmooth( (bool) b );
Py_RETURN_NONE;
} }
PyObject *FEdge_getVertices( BPy_FEdge *self ) {
PyObject *_wrap_new_FEdge__SWIG_1(PyObject *self , PyObject *args) { 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 *FEdge_getPoints( BPy_FEdge *self ) {
PyObject *_wrap_new_FEdge__SWIG_2(PyObject *self , PyObject *args) { 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_new_FEdge(PyObject *self, PyObject *args) { #ifdef __cplusplus
} }
#endif
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) {
}
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) {
}
PyObject *_wrap_FEdge_SetaFace(PyObject *self , PyObject *args) {
}
PyObject *_wrap_FEdge_SetOccludeeIntersection(PyObject *self , PyObject *args) {
}
PyObject *_wrap_FEdge_SetOccludeeEmpty(PyObject *self , PyObject *args) {
}
PyObject *_wrap_FEdge_SetSmooth(PyObject *self , PyObject *args) {
}
PyObject *_wrap_FEdge_CommonVertex(PyObject *self , PyObject *args) {
}
PyObject *_wrap_FEdge_min2d(PyObject *self , PyObject *args) {
}
PyObject *_wrap_FEdge_max2d(PyObject *self , PyObject *args) {
}
PyObject *_wrap_FEdge_shape_id(PyObject *self , PyObject *args) {
}
PyObject *_wrap_FEdge_shape__SWIG_1(PyObject *self , PyObject *args) {
}
PyObject *_wrap_FEdge_shape(PyObject *self, PyObject *args) {
}
PyObject *_wrap_FEdge_shape_importance(PyObject *self , PyObject *args) {
}
PyObject *_wrap_FEdge_qi(PyObject *self , PyObject *args) {
}
PyObject *_wrap_FEdge_occluders_begin(PyObject *self , PyObject *args) {
}
PyObject *_wrap_FEdge_occluders_end(PyObject *self , PyObject *args) {
}
PyObject *_wrap_FEdge_occluders_empty(PyObject *self , PyObject *args) {
}
PyObject *_wrap_FEdge_occluders_size(PyObject *self , PyObject *args) {
}
PyObject *_wrap_FEdge_occludee(PyObject *self , PyObject *args) {
}
PyObject *_wrap_FEdge_occluded_shape(PyObject *self , PyObject *args) {
}
PyObject *_wrap_FEdge_occludee_empty(PyObject *self , PyObject *args) {
}
PyObject *_wrap_FEdge_z_discontinuity(PyObject *self , PyObject *args) {
}
PyObject *_wrap_FEdge_viewedge_nature(PyObject *self , PyObject *args) {
}
PyObject *_wrap_FEdge_orientation2d(PyObject *self , PyObject *args) {
}
PyObject *_wrap_FEdge_orientation3d(PyObject *self , PyObject *args) {
}
PyObject *_wrap_FEdge_verticesBegin(PyObject *self , PyObject *args) {
}
PyObject *_wrap_FEdge_verticesEnd(PyObject *self , PyObject *args) {
}
PyObject *_wrap_FEdge_pointsBegin__SWIG_0(PyObject *self , PyObject *args) {
}
PyObject *_wrap_FEdge_pointsBegin__SWIG_1(PyObject *self , PyObject *args) {
}
PyObject *_wrap_FEdge_pointsBegin(PyObject *self, PyObject *args) {
}
PyObject *_wrap_FEdge_pointsEnd__SWIG_0(PyObject *self , PyObject *args) {
}
PyObject *_wrap_FEdge_pointsEnd__SWIG_1(PyObject *self , PyObject *args) {
}
PyObject *_wrap_FEdge_pointsEnd(PyObject *self, PyObject *args) {
}

View File

@@ -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 */

View File

@@ -412,6 +412,8 @@ public:
/*! Default constructor */ /*! Default constructor */
inline FEdge() { inline FEdge() {
userdata = NULL; userdata = NULL;
_VertexA = NULL;
_VertexB = NULL;
_Nature = Nature::NO_FEATURE; _Nature = Nature::NO_FEATURE;
_NextEdge = NULL; _NextEdge = NULL;
_PreviousEdge = NULL; _PreviousEdge = NULL;