2008-07-23 07:56:08 +00:00
# include "BPy_SVertex.h"
2008-07-17 06:35:30 +00:00
2008-07-23 07:56:08 +00:00
# include "../BPy_Convert.h"
# include "../BPy_Id.h"
2008-07-24 20:39:13 +00:00
# include "../Interface1D/BPy_FEdge.h"
2008-07-17 06:35:30 +00:00
# ifdef __cplusplus
extern " C " {
# endif
///////////////////////////////////////////////////////////////////////////////////////////
/*--------------- Python API function prototypes for SVertex instance -----------*/
static int SVertex___init__ ( BPy_SVertex * self , PyObject * args , PyObject * kwds ) ;
static PyObject * SVertex___copy__ ( BPy_SVertex * self ) ;
static PyObject * SVertex_normals ( BPy_SVertex * self ) ;
static PyObject * SVertex_normalsSize ( BPy_SVertex * self ) ;
2008-07-25 00:18:10 +00:00
static PyObject * SVertex_viewvertex ( BPy_SVertex * self ) ;
2008-07-21 21:24:37 +00:00
static PyObject * SVertex_setPoint3D ( BPy_SVertex * self , PyObject * args ) ;
static PyObject * SVertex_setPoint2D ( BPy_SVertex * self , PyObject * args ) ;
2008-07-17 06:35:30 +00:00
static PyObject * SVertex_AddNormal ( BPy_SVertex * self , PyObject * args ) ;
2008-07-21 21:24:37 +00:00
static PyObject * SVertex_setId ( BPy_SVertex * self , PyObject * args ) ;
2008-07-18 02:55:23 +00:00
static PyObject * SVertex_AddFEdge ( BPy_SVertex * self , PyObject * args ) ;
2008-07-17 06:35:30 +00:00
/*----------------------SVertex instance definitions ----------------------------*/
static PyMethodDef BPy_SVertex_methods [ ] = {
{ " __copy__ " , ( PyCFunction ) SVertex___copy__ , METH_NOARGS , " ( ) Cloning method." } ,
{ " normals " , ( PyCFunction ) SVertex_normals , METH_NOARGS , " Returns the normals for this Vertex as a list. In a smooth surface, a vertex has exactly one normal. In a sharp surface, a vertex can have any number of normals. " } ,
{ " normalsSize " , ( PyCFunction ) SVertex_normalsSize , METH_NOARGS , " Returns the number of different normals for this vertex. " } ,
2008-07-25 00:18:10 +00:00
{ " viewvertex " , ( PyCFunction ) SVertex_viewvertex , METH_NOARGS , " If this SVertex is also a ViewVertex, this method returns a pointer onto this ViewVertex. 0 is returned otherwise. " } ,
2008-07-21 21:24:37 +00:00
{ " setPoint3D " , ( PyCFunction ) SVertex_setPoint3D , METH_VARARGS , " Sets the 3D coordinates of the SVertex. " } ,
{ " setPoint2D " , ( PyCFunction ) SVertex_setPoint2D , METH_VARARGS , " Sets the 3D projected coordinates of the SVertex. " } ,
2008-07-17 06:35:30 +00:00
{ " 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. " } ,
2008-07-21 21:24:37 +00:00
{ " setId " , ( PyCFunction ) SVertex_setId , METH_VARARGS , " Sets the Id. " } ,
2008-07-18 02:55:23 +00:00
{ " AddFEdge " , ( PyCFunction ) SVertex_AddFEdge , METH_VARARGS , " Add an FEdge to the list of edges emanating from this SVertex. " } ,
2008-07-17 06:35:30 +00:00
{ NULL , NULL , 0 , NULL }
} ;
/*-----------------------BPy_SVertex type definition ------------------------------*/
PyTypeObject SVertex_Type = {
PyObject_HEAD_INIT ( NULL )
0 , /* ob_size */
" SVertex " , /* tp_name */
sizeof ( BPy_SVertex ) , /* 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_SVertex_methods , /* struct PyMethodDef *tp_methods; */
NULL , /* struct PyMemberDef *tp_members; */
NULL , /* struct PyGetSetDef *tp_getset; */
& Interface0D_Type , /* struct _typeobject *tp_base; */
NULL , /* PyObject *tp_dict; */
NULL , /* descrgetfunc tp_descr_get; */
NULL , /* descrsetfunc tp_descr_set; */
0 , /* long tp_dictoffset; */
( initproc ) SVertex___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 SVertex___init__ ( BPy_SVertex * self , PyObject * args , PyObject * kwds )
{
PyObject * py_point = 0 ;
BPy_Id * py_id = 0 ;
2009-07-25 11:27:18 +00:00
2008-07-17 06:35:30 +00:00
2009-07-25 11:27:18 +00:00
if ( ! PyArg_ParseTuple ( args , " |OO! " , & py_point , & Id_Type , & py_id ) )
2008-07-17 06:35:30 +00:00
return - 1 ;
2009-07-25 11:27:18 +00:00
if ( py_point & & py_id ) {
Vec3r * v = Vec3r_ptr_from_PyObject ( py_point ) ;
if ( ! v ) {
PyErr_SetString ( PyExc_TypeError , " argument 1 must be a 3D vector (either a list of 3 elements or Vector) " ) ;
return - 1 ;
}
self - > sv = new SVertex ( * v , * ( py_id - > id ) ) ;
delete v ;
} else if ( ! py_point & & ! py_id ) {
2008-07-17 06:35:30 +00:00
self - > sv = new SVertex ( ) ;
2009-07-25 11:27:18 +00:00
} else {
PyErr_SetString ( PyExc_TypeError , " invalid argument(s) " ) ;
return - 1 ;
2008-07-17 06:35:30 +00:00
}
2009-07-25 11:27:18 +00:00
2008-07-17 06:35:30 +00:00
self - > py_if0D . if0D = self - > sv ;
return 0 ;
}
PyObject * SVertex___copy__ ( BPy_SVertex * self ) {
BPy_SVertex * py_svertex ;
py_svertex = ( BPy_SVertex * ) SVertex_Type . tp_new ( & SVertex_Type , 0 , 0 ) ;
py_svertex - > sv = self - > sv - > duplicate ( ) ;
py_svertex - > py_if0D . if0D = py_svertex - > sv ;
return ( PyObject * ) py_svertex ;
}
PyObject * SVertex_normals ( BPy_SVertex * self ) {
PyObject * py_normals ;
set < Vec3r > normals ;
py_normals = PyList_New ( NULL ) ;
normals = self - > sv - > normals ( ) ;
for ( set < Vec3r > : : iterator set_iterator = normals . begin ( ) ; set_iterator ! = normals . end ( ) ; set_iterator + + ) {
2008-07-18 02:55:23 +00:00
Vec3r v ( * set_iterator ) ;
PyList_Append ( py_normals , Vector_from_Vec3r ( v ) ) ;
2008-07-17 06:35:30 +00:00
}
return py_normals ;
}
PyObject * SVertex_normalsSize ( BPy_SVertex * self ) {
return PyInt_FromLong ( self - > sv - > normalsSize ( ) ) ;
}
2008-07-25 00:18:10 +00:00
PyObject * SVertex_viewvertex ( BPy_SVertex * self ) {
2009-07-19 23:17:30 +00:00
ViewVertex * vv = self - > sv - > viewvertex ( ) ;
if ( ! vv )
Py_RETURN_NONE ;
if ( typeid ( * vv ) = = typeid ( NonTVertex ) )
return BPy_NonTVertex_from_NonTVertex_ptr ( dynamic_cast < NonTVertex * > ( vv ) ) ;
else
return BPy_TVertex_from_TVertex_ptr ( dynamic_cast < TVertex * > ( vv ) ) ;
2008-07-25 00:18:10 +00:00
}
2008-07-21 21:24:37 +00:00
PyObject * SVertex_setPoint3D ( BPy_SVertex * self , PyObject * args ) {
2008-07-17 06:35:30 +00:00
PyObject * py_point ;
2009-07-25 11:27:18 +00:00
if ( ! ( PyArg_ParseTuple ( args , " O " , & py_point ) ) )
2009-04-04 15:26:12 +00:00
return NULL ;
2009-07-25 11:27:18 +00:00
Vec3r * v = Vec3r_ptr_from_PyObject ( py_point ) ;
if ( ! v ) {
PyErr_SetString ( PyExc_TypeError , " argument 1 must be a 3D vector (either a list of 3 elements or Vector) " ) ;
2009-04-04 15:26:12 +00:00
return NULL ;
2008-07-17 06:35:30 +00:00
}
2009-07-25 11:27:18 +00:00
self - > sv - > setPoint3D ( * v ) ;
delete v ;
2008-07-17 06:35:30 +00:00
Py_RETURN_NONE ;
}
2008-07-21 21:24:37 +00:00
PyObject * SVertex_setPoint2D ( BPy_SVertex * self , PyObject * args ) {
2008-07-17 06:35:30 +00:00
PyObject * py_point ;
2009-07-25 11:27:18 +00:00
if ( ! ( PyArg_ParseTuple ( args , " O " , & py_point ) ) )
2009-04-04 15:26:12 +00:00
return NULL ;
2009-07-25 11:27:18 +00:00
Vec3r * v = Vec3r_ptr_from_PyObject ( py_point ) ;
if ( ! v ) {
PyErr_SetString ( PyExc_TypeError , " argument 1 must be a 3D vector (either a list of 3 elements or Vector) " ) ;
2009-04-04 15:26:12 +00:00
return NULL ;
2008-07-17 06:35:30 +00:00
}
2009-07-25 11:27:18 +00:00
self - > sv - > setPoint2D ( * v ) ;
delete v ;
2008-07-09 08:24:13 +00:00
2008-07-17 06:35:30 +00:00
Py_RETURN_NONE ;
2008-07-09 08:24:13 +00:00
}
2008-07-17 06:35:30 +00:00
PyObject * SVertex_AddNormal ( BPy_SVertex * self , PyObject * args ) {
PyObject * py_normal ;
2008-07-09 08:24:13 +00:00
2009-07-25 11:27:18 +00:00
if ( ! ( PyArg_ParseTuple ( args , " O " , & py_normal ) ) )
2009-04-04 15:26:12 +00:00
return NULL ;
2009-07-25 11:27:18 +00:00
Vec3r * n = Vec3r_ptr_from_PyObject ( py_normal ) ;
if ( ! n ) {
PyErr_SetString ( PyExc_TypeError , " argument 1 must be a 3D vector (either a list of 3 elements or Vector) " ) ;
2009-04-04 15:26:12 +00:00
return NULL ;
2008-07-17 06:35:30 +00:00
}
2009-07-25 11:27:18 +00:00
self - > sv - > AddNormal ( * n ) ;
delete n ;
2008-07-09 08:24:13 +00:00
2008-07-17 06:35:30 +00:00
Py_RETURN_NONE ;
2008-07-09 08:24:13 +00:00
}
2008-07-21 21:24:37 +00:00
PyObject * SVertex_setId ( BPy_SVertex * self , PyObject * args ) {
2008-07-17 06:35:30 +00:00
BPy_Id * py_id ;
2008-07-09 08:24:13 +00:00
2009-04-04 15:26:12 +00:00
if ( ! PyArg_ParseTuple ( args , " O! " , & Id_Type , & py_id ) )
return NULL ;
2008-07-09 08:24:13 +00:00
2008-07-21 21:24:37 +00:00
self - > sv - > setId ( * ( py_id - > id ) ) ;
2008-07-09 08:24:13 +00:00
2008-07-17 06:35:30 +00:00
Py_RETURN_NONE ;
2008-07-09 08:24:13 +00:00
}
2008-07-18 02:55:23 +00:00
PyObject * SVertex_AddFEdge ( BPy_SVertex * self , PyObject * args ) {
PyObject * py_fe ;
2009-04-04 15:26:12 +00:00
if ( ! ( PyArg_ParseTuple ( args , " O! " , & FEdge_Type , & py_fe ) ) )
return NULL ;
2008-07-18 02:55:23 +00:00
self - > sv - > AddFEdge ( ( ( BPy_FEdge * ) py_fe ) - > fe ) ;
Py_RETURN_NONE ;
}
2008-07-17 06:35:30 +00:00
// virtual bool operator== (const SVertex &iBrother)
// ViewVertex * viewvertex ()
2008-07-18 02:55:23 +00:00
2008-07-09 08:24:13 +00:00
2008-07-17 06:35:30 +00:00
///////////////////////////////////////////////////////////////////////////////////////////
2008-07-09 08:24:13 +00:00
2008-07-17 06:35:30 +00:00
# ifdef __cplusplus
2008-07-09 08:24:13 +00:00
}
2008-07-17 06:35:30 +00:00
# endif
2008-07-09 08:24:13 +00:00