soc-2008-mxcurioni: updated support for Nature class.

This commit is contained in:
Maxime Curioni
2008-07-20 05:01:29 +00:00
parent 16d7d12123
commit ab722884d3
10 changed files with 84 additions and 41 deletions

View File

@@ -69,13 +69,14 @@ python_sources = [
prefix + '/Interface0D.cpp',
prefix + '/Interface0D/CurvePoint.cpp',
prefix + '/Interface0D/SVertex.cpp',
prefix + '/Interface0D/ViewVertex.cpp',
prefix + '/Interface1D.cpp',
prefix + '/Interface1D/FEdge.cpp',
prefix + '/Nature.cpp',
prefix + '/UnaryFunction0D.cpp',
prefix + '/UnaryFunction1D.cpp',
prefix + '/UnaryPredicate0D.cpp',
prefix + '/UnaryPredicate1D.cpp'
prefix + '/UnaryPredicate1D.cpp',
]
sources = system_sources + image_sources + geometry_sources + scene_graph_sources \

View File

@@ -8,47 +8,47 @@ extern "C" {
///////////////////////////////////////////////////////////////////////////////////////////
PyObject *PyBool_from_bool( bool b ){
PyObject * PyBool_from_bool( bool b ){
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
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
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
vec_data[0] = vec.x(); vec_data[1] = vec.y(); vec_data[2] = vec.z();
return newVectorObject( vec_data, 3, Py_NEW);
}
PyObject *BPy_Id_from_Id( Id& id ) {
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_Interface0D_from_Interface0D( Interface0D& if0D ) {
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 py_if0D;
}
PyObject *BPy_SVertex_from_SVertex( SVertex& 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;
@@ -56,7 +56,7 @@ PyObject *BPy_SVertex_from_SVertex( SVertex& sv ) {
return py_sv;
}
PyObject *BPy_FEdge_from_FEdge( FEdge& fe ) {
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;
@@ -64,6 +64,16 @@ PyObject *BPy_FEdge_from_FEdge( FEdge& fe ) {
return py_fe;
}
PyObject * BPy_Nature_from_Nature( unsigned short n ) {
PyObject *py_n = Nature_Type.tp_new( &Nature_Type, 0, 0 );
PyObject *args = PyTuple_New(1);
PyTuple_SetItem( args, 0, PyInt_FromLong(n) );
Nature_Type.tp_init( py_n, args, 0 );
Py_DECREF(args);
return py_n;
}
///////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -9,6 +9,7 @@ using namespace Geometry;
#include "Interface0D.h"
#include "Interface0D/SVertex.h"
#include "Interface1D/FEdge.h"
#include "Nature.h"
#ifdef __cplusplus
extern "C" {
@@ -30,6 +31,7 @@ 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 );
PyObject * BPy_Nature_from_Nature( unsigned short n );
///////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -3,7 +3,9 @@
#include "Convert.h"
#include "Interface0D/CurvePoint.h"
#include "Interface0D/SVertex.h"
#include "Interface0D/ViewVertex.h"
#include "Interface1D/FEdge.h"
#include "Nature.h"
#ifdef __cplusplus
extern "C" {
@@ -152,6 +154,11 @@ PyMODINIT_FUNC Interface0D_Init( PyObject *module )
Py_INCREF( &SVertex_Type );
PyModule_AddObject(module, "SVertex", (PyObject *)&SVertex_Type);
if( PyType_Ready( &ViewVertex_Type ) < 0 )
return;
Py_INCREF( &ViewVertex_Type );
PyModule_AddObject(module, "ViewVertex", (PyObject *)&ViewVertex_Type);
}
//------------------------INSTANCE METHODS ----------------------------------
@@ -243,8 +250,7 @@ PyObject *Interface0D_getId( BPy_Interface0D *self ) {
PyObject *Interface0D_getNature( BPy_Interface0D *self ) {
// VertexNature
Py_RETURN_NONE;
return BPy_Nature_from_Nature( self->if0D->getNature() );
}

View File

@@ -1,7 +1,6 @@
#include "SVertex.h"
#include "ViewVertex.h"
#include "../Convert.h"
#include "../Id.h"
#ifdef __cplusplus
extern "C" {
@@ -11,12 +10,12 @@ extern "C" {
/*--------------- Python API function prototypes for ViewVertex instance -----------*/
static int ViewVertex___init__(BPy_ViewVertex *self);
//static PyObject * ViewVertex___copy__( BPy_ViewVertex *self );
static PyObject * ViewVertex_setNature( BPy_ViewVertex *self, PyObject *args );
/*----------------------ViewVertex instance definitions ----------------------------*/
static PyMethodDef BPy_ViewVertex_methods[] = {
// {"__copy__", ( PyCFunction ) ViewVertex___copy__, METH_NOARGS, " Cloning method."},
{"setNature", ( PyCFunction ) ViewVertex_setNature, METH_VARARGS, "Nature n Sets the nature of the vertex."},
{NULL, NULL, 0, NULL}
};
@@ -112,12 +111,7 @@ PyTypeObject ViewVertex_Type = {
int ViewVertex___init__(BPy_ViewVertex *self )
{
PyObject *py_point = 0;
BPy_Id *py_id = 0;
self->vv = new ViewVertex();
self->py_if0D.if0D = self->vv;
self->py_if0D.if0D = new Interface0D();
return 0;
}
@@ -127,11 +121,26 @@ int ViewVertex___init__(BPy_ViewVertex *self )
// py_vv = (BPy_ViewVertex *) ViewVertex_Type.tp_new( &ViewVertex_Type, 0, 0 );
//
// py_vv->vv = self->vv->duplicate();
// py_svertex->py_if0D.if0D = py_svertex->sv;
// py_svertex->py_if0D.if->sv;
//
// return (PyObject *) py_svertex;
// }
PyObject * ViewVertex_setNature( BPy_ViewVertex *self, PyObject *args ) {
PyObject *py_n;
if(!( PyArg_ParseTuple(args, "O", &py_n) && BPy_Nature_Check(py_n) )) {
cout << "ERROR: ViewVertex_setNature" << endl;
Py_RETURN_NONE;
}
PyObject *i = (PyObject *) &( ((BPy_Nature *) py_n)->i );
((ViewVertex *) self->py_if0D.if0D)->setNature( PyInt_AsLong(i) );
Py_RETURN_NONE;
}
///////////////////////////////////////////////////////////////////////////////////////////
@@ -141,9 +150,7 @@ int ViewVertex___init__(BPy_ViewVertex *self )
// virtual string getExactTypeName () const
// ViewVertex ()
// virtual ~ViewVertex ()
// virtual Nature::VertexNature getNature () const
// void setNature (Nature::VertexNature iNature)
// virtual ViewVertexInternal::orientedViewEdgeIterator edgesBegin ()=0
// virtual ViewVertexInternal::orientedViewEdgeIterator edgesEnd ()=0

View File

@@ -21,7 +21,6 @@ extern PyTypeObject ViewVertex_Type;
/*---------------------------Python BPy_ViewVertex structure definition----------*/
typedef struct {
BPy_Interface0D py_if0D;
ViewVertex *vv;
} BPy_ViewVertex;
///////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -180,8 +180,7 @@ PyObject *Interface1D_getId( BPy_Interface1D *self ) {
}
PyObject *Interface1D_getNature( BPy_Interface1D *self ) {
// EdgeNature
Py_RETURN_NONE;
return BPy_Nature_from_Nature( self->if1D->getNature() );
}
PyObject *Interface1D_getTimeStamp( BPy_Interface1D *self ) {

View File

@@ -26,6 +26,7 @@ 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);
static PyObject * FEdge_SetNature( BPy_FEdge *self, PyObject *args );
/*----------------------FEdge instance definitions ----------------------------*/
static PyMethodDef BPy_FEdge_methods[] = {
@@ -44,6 +45,7 @@ static PyMethodDef BPy_FEdge_methods[] = {
{"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. "},
{"SetNature", ( PyCFunction ) FEdge_SetNature, METH_VARARGS, "(Nature n) Sets the nature of this FEdge. "},
{NULL, NULL, 0, NULL}
};
@@ -298,6 +300,20 @@ PyObject *FEdge_SetSmooth( BPy_FEdge *self , PyObject *args) {
Py_RETURN_NONE;
}
PyObject * FEdge_SetNature( BPy_FEdge *self, PyObject *args ) {
PyObject *py_n;
if(!( PyArg_ParseTuple(args, "O", &py_n) && BPy_Nature_Check(py_n) )) {
cout << "ERROR: FEdge_setNature" << endl;
Py_RETURN_NONE;
}
PyObject *i = (PyObject *) &( ((BPy_Nature *) py_n)->i );
((FEdge *) self->py_if1D.if1D)->SetNature( PyInt_AsLong(i) );
Py_RETURN_NONE;
}
PyObject *FEdge_getVertices( BPy_FEdge *self ) {
PyObject *py_vertices = PyList_New(NULL);

View File

@@ -123,13 +123,13 @@ PyMODINIT_FUNC Nature_Init( PyObject *module )
tmp = PyInt_FromLong( Nature::CUSP ); PyDict_SetItemString( Nature_Type.tp_dict, "CUSP", tmp); Py_DECREF(tmp);
// EdgeNature
tmp = PyInt_FromLong( Nature::NO_FEATURE ); PyDict_SetItemString( Nature_Type.tp_dict, "NO_FEATURE", tmp); Py_DECREF(tmp);
tmp = PyInt_FromLong( Nature::SILHOUETTE ); PyDict_SetItemString( Nature_Type.tp_dict, "SILHOUETTE", tmp); Py_DECREF(tmp);
tmp = PyInt_FromLong( Nature::BORDER ); PyDict_SetItemString( Nature_Type.tp_dict, "BORDER", tmp); Py_DECREF(tmp);
tmp = PyInt_FromLong( Nature::CREASE ); PyDict_SetItemString( Nature_Type.tp_dict, "CREASE", tmp); Py_DECREF(tmp);
tmp = PyInt_FromLong( Nature::RIDGE ); PyDict_SetItemString( Nature_Type.tp_dict, "RIDGE", tmp); Py_DECREF(tmp);
tmp = PyInt_FromLong( Nature::VALLEY ); PyDict_SetItemString( Nature_Type.tp_dict, "VALLEY", tmp); Py_DECREF(tmp);
tmp = PyInt_FromLong( Nature::SUGGESTIVE_CONTOUR ); PyDict_SetItemString( Nature_Type.tp_dict, "SUGGESTIVE_CONTOUR", tmp); Py_DECREF(tmp);
tmp = BPy_Nature_from_Nature( Nature::NO_FEATURE ); PyDict_SetItemString( Nature_Type.tp_dict, "NO_FEATURE", tmp); Py_DECREF(tmp);
tmp = BPy_Nature_from_Nature( Nature::SILHOUETTE ); PyDict_SetItemString( Nature_Type.tp_dict, "SILHOUETTE", tmp); Py_DECREF(tmp);
tmp = BPy_Nature_from_Nature( Nature::BORDER ); PyDict_SetItemString( Nature_Type.tp_dict, "BORDER", tmp); Py_DECREF(tmp);
tmp = BPy_Nature_from_Nature( Nature::CREASE ); PyDict_SetItemString( Nature_Type.tp_dict, "CREASE", tmp); Py_DECREF(tmp);
tmp = BPy_Nature_from_Nature( Nature::RIDGE ); PyDict_SetItemString( Nature_Type.tp_dict, "RIDGE", tmp); Py_DECREF(tmp);
tmp = BPy_Nature_from_Nature( Nature::VALLEY ); PyDict_SetItemString( Nature_Type.tp_dict, "VALLEY", tmp); Py_DECREF(tmp);
tmp = BPy_Nature_from_Nature( Nature::SUGGESTIVE_CONTOUR ); PyDict_SetItemString( Nature_Type.tp_dict, "SUGGESTIVE_CONTOUR", tmp); Py_DECREF(tmp);
}

View File

@@ -280,10 +280,11 @@ public:
// this vertex in CCW order (order defined in 2D in the image plan)
virtual edge_iterator edges_begin() = 0;
virtual const_edge_iterator edges_begin() const = 0;
virtual edge_iterator edges_end() = 0;
virtual const_edge_iterator edges_end() const = 0;
virtual edge_iterator edges_end() = 0;
virtual const_edge_iterator edges_end() const = 0;
virtual edge_iterator edges_iterator(ViewEdge *iEdge) = 0;
virtual const_edge_iterator edges_iterator(ViewEdge *iEdge) const = 0;
virtual const_edge_iterator edges_iterator(ViewEdge *iEdge) const = 0;
// Iterator access
/*! Returns an iterator over the ViewEdges that goes to or comes from
@@ -292,14 +293,16 @@ public:
* and to get the orientation for each ViewEdge (incoming/outgoing).
*/
virtual ViewVertexInternal::orientedViewEdgeIterator edgesBegin() = 0;
/*! Returns an orientedViewEdgeIterator over the ViewEdges around this ViewVertex,
* pointing after the last ViewEdge.
*/
virtual ViewVertexInternal::orientedViewEdgeIterator edgesEnd() = 0;
virtual ViewVertexInternal::orientedViewEdgeIterator edgesEnd() = 0;
/*! Returns an orientedViewEdgeIterator pointing to the ViewEdge
* given as argument.
*/
virtual ViewVertexInternal::orientedViewEdgeIterator edgesIterator(ViewEdge *iEdge) = 0;
virtual ViewVertexInternal::orientedViewEdgeIterator edgesIterator(ViewEdge *iEdge) = 0;
};