diff options
Diffstat (limited to 'source/blender/freestyle/intern/python/Interface0D')
12 files changed, 1800 insertions, 0 deletions
diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp b/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp new file mode 100644 index 00000000000..e213edd5c79 --- /dev/null +++ b/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp @@ -0,0 +1,278 @@ +#include "BPy_CurvePoint.h" + +#include "../BPy_Convert.h" +#include "../Interface0D/BPy_SVertex.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +//------------------------INSTANCE METHODS ---------------------------------- + +static char CurvePoint___doc__[] = +"Class hierarchy: :class:`Interface0D` > :class:`CurvePoint`\n" +"\n" +"Class to represent a point of a curve. A CurvePoint can be any point\n" +"of a 1D curve (it doesn't have to be a vertex of the curve). Any\n" +":class:`Interface1D` is built upon ViewEdges, themselves built upon\n" +"FEdges. Therefore, a curve is basically a polyline made of a list of\n" +":class:`SVertex` objects. Thus, a CurvePoint is built by linearly\n" +"interpolating two :class:`SVertex` instances. CurvePoint can be used\n" +"as virtual points while querying 0D information along a curve at a\n" +"given resolution.\n" +"\n" +".. method:: __init__()\n" +"\n" +" Defult constructor.\n" +"\n" +".. method:: __init__(iBrother)\n" +"\n" +" Copy constructor.\n" +"\n" +" :arg iBrother: A CurvePoint object.\n" +" :type iBrother: :class:`CurvePoint`\n" +"\n" +".. method:: __init__(iA, iB, t2d)\n" +"\n" +" Builds a CurvePoint from two SVertex and an interpolation parameter.\n" +"\n" +" :arg iA: The first SVertex.\n" +" :type iA: :class:`SVertex`\n" +" :arg iB: The second SVertex.\n" +" :type iB: :class:`SVertex`\n" +" :arg t2d: A 2D interpolation parameter used to linearly interpolate\n" +" iA and iB.\n" +" :type t2d: float\n" +"\n" +".. method:: __init__(iA, iB, t2d)\n" +"\n" +" Builds a CurvePoint from two CurvePoint and an interpolation\n" +" parameter.\n" +"\n" +" :arg iA: The first CurvePoint.\n" +" :type iA: :class:`CurvePoint`\n" +" :arg iB: The second CurvePoint.\n" +" :type iB: :class:`CurvePoint`\n" +" :arg t2d: The 2D interpolation parameter used to linearly\n" +" interpolate iA and iB.\n" +" :type t2d: float\n"; + +static int CurvePoint___init__(BPy_CurvePoint *self, PyObject *args, PyObject *kwds) +{ + + PyObject *obj1 = 0, *obj2 = 0 , *obj3 = 0; + + if (! PyArg_ParseTuple(args, "|OOO!", &obj1, &obj2, &PyFloat_Type, &obj3) ) + return -1; + + if( !obj1 ){ + self->cp = new CurvePoint(); + + } else if( !obj2 && BPy_CurvePoint_Check(obj1) ) { + self->cp = new CurvePoint( *(((BPy_CurvePoint *) obj1)->cp) ); + + } else if( obj3 && BPy_SVertex_Check(obj1) && BPy_SVertex_Check(obj2) ) { + self->cp = new CurvePoint( ((BPy_SVertex *) obj1)->sv, + ((BPy_SVertex *) obj2)->sv, + PyFloat_AsDouble( obj3 ) ); + + } else if( obj3 && BPy_CurvePoint_Check(obj1) && BPy_CurvePoint_Check(obj2) ) { + CurvePoint *cp1 = ((BPy_CurvePoint *) obj1)->cp; + CurvePoint *cp2 = ((BPy_CurvePoint *) obj2)->cp; + if( !cp1 || cp1->A() == 0 || cp1->B() == 0 ) { + PyErr_SetString(PyExc_TypeError, "argument 1 is an invalid CurvePoint object"); + return -1; + } + if( !cp2 || cp2->A() == 0 || cp2->B() == 0 ) { + PyErr_SetString(PyExc_TypeError, "argument 2 is an invalid CurvePoint object"); + return -1; + } + self->cp = new CurvePoint( cp1, cp2, PyFloat_AsDouble( obj3 ) ); + + } else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } + + self->py_if0D.if0D = self->cp; + self->py_if0D.borrowed = 0; + + return 0; +} + +static char CurvePoint_A___doc__[] = +".. method:: A()\n" +"\n" +" Returns the first SVertex upon which the CurvePoint is built.\n" +"\n" +" :return: The first SVertex.\n" +" :rtype: :class:`SVertex`\n"; + +static PyObject * CurvePoint_A( BPy_CurvePoint *self ) { + SVertex *A = self->cp->A(); + if( A ) + return BPy_SVertex_from_SVertex( *A ); + + Py_RETURN_NONE; +} + +static char CurvePoint_B___doc__[] = +".. method:: B()\n" +"\n" +" Returns the second SVertex upon which the CurvePoint is built.\n" +"\n" +" :return: The second SVertex.\n" +" :rtype: :class:`SVertex`\n"; + +static PyObject * CurvePoint_B( BPy_CurvePoint *self ) { + SVertex *B = self->cp->B(); + if( B ) + return BPy_SVertex_from_SVertex( *B ); + + Py_RETURN_NONE; +} + +static char CurvePoint_t2d___doc__[] = +".. method:: t2d()\n" +"\n" +" Returns the 2D interpolation parameter.\n" +"\n" +" :return: The 2D interpolation parameter.\n" +" :rtype: float\n"; + +static PyObject * CurvePoint_t2d( BPy_CurvePoint *self ) { + return PyFloat_FromDouble( self->cp->t2d() ); +} + +static char CurvePoint_setA___doc__[] = +".. method:: setA(iA)\n" +"\n" +" Sets the first SVertex upon which to build the CurvePoint.\n" +"\n" +" :arg iA: The first SVertex.\n" +" :type iA: :class:`SVertex`\n"; + +static PyObject *CurvePoint_setA( BPy_CurvePoint *self , PyObject *args) { + PyObject *py_sv; + + if(!( PyArg_ParseTuple(args, "O!", &SVertex_Type, &py_sv) )) + return NULL; + + self->cp->setA( ((BPy_SVertex *) py_sv)->sv ); + + Py_RETURN_NONE; +} + +static char CurvePoint_setB___doc__[] = +".. method:: setB(iB)\n" +"\n" +" Sets the first SVertex upon which to build the CurvePoint.\n" +"\n" +" :arg iB: The second SVertex.\n" +" :type iB: :class:`SVertex`\n"; + +static PyObject *CurvePoint_setB( BPy_CurvePoint *self , PyObject *args) { + PyObject *py_sv; + + if(!( PyArg_ParseTuple(args, "O!", &SVertex_Type, &py_sv) )) + return NULL; + + self->cp->setB( ((BPy_SVertex *) py_sv)->sv ); + + Py_RETURN_NONE; +} + +static char CurvePoint_setT2d___doc__[] = +".. method:: setT2d(t)\n" +"\n" +" Sets the 2D interpolation parameter to use.\n" +"\n" +" :arg t: The 2D interpolation parameter.\n" +" :type t: float\n"; + +static PyObject *CurvePoint_setT2d( BPy_CurvePoint *self , PyObject *args) { + float t; + + if(!( PyArg_ParseTuple(args, "f", &t) )) + return NULL; + + self->cp->setT2d( t ); + + Py_RETURN_NONE; +} + +static char CurvePoint_curvatureFredo___doc__[] = +".. method:: curvatureFredo()\n" +"\n" +" Returns the angle in radians.\n" +"\n" +" :return: The angle in radians.\n" +" :rtype: float\n"; + +static PyObject *CurvePoint_curvatureFredo( BPy_CurvePoint *self , PyObject *args) { + return PyFloat_FromDouble( self->cp->curvatureFredo() ); +} + +///bool operator== (const CurvePoint &b) + +/*----------------------CurvePoint instance definitions ----------------------------*/ +static PyMethodDef BPy_CurvePoint_methods[] = { + {"A", ( PyCFunction ) CurvePoint_A, METH_NOARGS, CurvePoint_A___doc__}, + {"B", ( PyCFunction ) CurvePoint_B, METH_NOARGS, CurvePoint_B___doc__}, + {"t2d", ( PyCFunction ) CurvePoint_t2d, METH_NOARGS, CurvePoint_t2d___doc__}, + {"setA", ( PyCFunction ) CurvePoint_setA, METH_VARARGS, CurvePoint_setA___doc__}, + {"setB", ( PyCFunction ) CurvePoint_setB, METH_VARARGS, CurvePoint_setB___doc__}, + {"setT2d", ( PyCFunction ) CurvePoint_setT2d, METH_VARARGS, CurvePoint_setT2d___doc__}, + {"curvatureFredo", ( PyCFunction ) CurvePoint_curvatureFredo, METH_NOARGS, CurvePoint_curvatureFredo___doc__}, + {NULL, NULL, 0, NULL} +}; + +/*-----------------------BPy_CurvePoint type definition ------------------------------*/ +PyTypeObject CurvePoint_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "CurvePoint", /* tp_name */ + sizeof(BPy_CurvePoint), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + CurvePoint___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + BPy_CurvePoint_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &Interface0D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)CurvePoint___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ +}; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.h b/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.h new file mode 100644 index 00000000000..b4c22645503 --- /dev/null +++ b/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.h @@ -0,0 +1,31 @@ +#ifndef FREESTYLE_PYTHON_CURVEPOINT_H +#define FREESTYLE_PYTHON_CURVEPOINT_H + +#include "../BPy_Interface0D.h" +#include "../../stroke/Curve.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +#include <Python.h> + +extern PyTypeObject CurvePoint_Type; + +#define BPy_CurvePoint_Check(v) ( PyObject_IsInstance( (PyObject *) v, (PyObject *) &CurvePoint_Type) ) + +/*---------------------------Python BPy_CurvePoint structure definition----------*/ +typedef struct { + BPy_Interface0D py_if0D; + CurvePoint *cp; +} BPy_CurvePoint; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif + +#endif /* FREESTYLE_PYTHON_CURVEPOINT_H */ diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp new file mode 100644 index 00000000000..cd0131ad570 --- /dev/null +++ b/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp @@ -0,0 +1,338 @@ +#include "BPy_SVertex.h" + +#include "../BPy_Convert.h" +#include "../BPy_Id.h" +#include "../Interface1D/BPy_FEdge.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +static char SVertex___doc__[] = +"Class hierarchy: :class:`Interface0D` > :class:`SVertex`\n" +"\n" +"Class to define a vertex of the embedding.\n" +"\n" +".. method:: __init__()\n" +"\n" +" Default constructor.\n" +"\n" +".. method:: __init__(iBrother)\n" +"\n" +" Copy constructor.\n" +"\n" +" :arg iBrother: A SVertex object.\n" +" :type iBrother: :class:`SVertex`\n" +"\n" +".. method:: __init__(iPoint3D, id)\n" +"\n" +" Builds a SVertex from 3D coordinates and an Id.\n" +"\n" +" :arg iPoint3D: A three-dimensional vector.\n" +" :type iPoint3D: :class:`mathutils.Vector`\n" +" :arg id: An Id object.\n" +" :type id: :class:`Id`\n"; + +//------------------------INSTANCE METHODS ---------------------------------- + +static int SVertex___init__(BPy_SVertex *self, PyObject *args, PyObject *kwds) +{ + PyObject *py_point = 0; + BPy_Id *py_id = 0; + + + if (! PyArg_ParseTuple(args, "|OO!", &py_point, &Id_Type, &py_id) ) + return -1; + + if( !py_point ) { + self->sv = new SVertex(); + + } else if( !py_id && BPy_SVertex_Check(py_point) ) { + self->sv = new SVertex( *(((BPy_SVertex *)py_point)->sv) ); + + } else 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 { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } + + self->py_if0D.if0D = self->sv; + self->py_if0D.borrowed = 0; + + return 0; +} + +static char SVertex_normals___doc__[] = +".. method:: normals()\n" +"\n" +" Returns the normals for this Vertex as a list. In a smooth surface,\n" +" a vertex has exactly one normal. In a sharp surface, a vertex can\n" +" have any number of normals.\n" +"\n" +" :return: A list of normals.\n" +" :rtype: List of :class:`mathutils.Vector` objects\n"; + +static PyObject * SVertex_normals( BPy_SVertex *self ) { + PyObject *py_normals; + set< Vec3r > normals; + + py_normals = PyList_New(0); + normals = self->sv->normals(); + + for( set< Vec3r >::iterator set_iterator = normals.begin(); set_iterator != normals.end(); set_iterator++ ) { + Vec3r v( *set_iterator ); + PyList_Append( py_normals, Vector_from_Vec3r(v) ); + } + + return py_normals; +} + +static char SVertex_normalsSize___doc__[] = +".. method:: normalsSize()\n" +"\n" +" Returns the number of different normals for this vertex.\n" +"\n" +" :return: The number of normals.\n" +" :rtype: int\n"; + +static PyObject * SVertex_normalsSize( BPy_SVertex *self ) { + return PyLong_FromLong( self->sv->normalsSize() ); +} + +static char SVertex_viewvertex___doc__[] = +".. method:: viewvertex()\n" +"\n" +" If this SVertex is also a ViewVertex, this method returns the\n" +" ViewVertex. None is returned otherwise.\n" +"\n" +" :return: The ViewVertex object.\n" +" :rtype: :class:`ViewVertex`\n"; + +static PyObject * SVertex_viewvertex( BPy_SVertex *self ) { + ViewVertex *vv = self->sv->viewvertex(); + if( vv ) + return Any_BPy_ViewVertex_from_ViewVertex( *vv ); + + Py_RETURN_NONE; +} + +static char SVertex_setPoint3D___doc__[] = +".. method:: setPoint3D(p)\n" +"\n" +" Sets the 3D coordinates of the SVertex.\n" +"\n" +" :arg p: A three-dimensional vector.\n" +" :type p: :class:`mathutils.Vector`, list or tuple of 3 real numbers\n"; + +static PyObject *SVertex_setPoint3D( BPy_SVertex *self , PyObject *args) { + PyObject *py_point; + + if(!( PyArg_ParseTuple(args, "O", &py_point) )) + return NULL; + 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 NULL; + } + self->sv->setPoint3D( *v ); + delete v; + + Py_RETURN_NONE; +} + +static char SVertex_setPoint2D___doc__[] = +".. method:: setPoint2D(p)\n" +"\n" +" Sets the 2D projected coordinates of the SVertex.\n" +"\n" +" :arg p: A three-dimensional vector.\n" +" :type p: :class:`mathutils.Vector`, list or tuple of 3 real numbers\n"; + +static PyObject *SVertex_setPoint2D( BPy_SVertex *self , PyObject *args) { + PyObject *py_point; + + if(!( PyArg_ParseTuple(args, "O", &py_point) )) + return NULL; + 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 NULL; + } + self->sv->setPoint2D( *v ); + delete v; + + Py_RETURN_NONE; +} + +static char SVertex_AddNormal___doc__[] = +".. method:: AddNormal(n)\n" +"\n" +" Adds a normal to the SVertex's set of normals. If the same normal\n" +" is already in the set, nothing changes.\n" +"\n" +" :arg n: A three-dimensional vector.\n" +" :type n: :class:`mathutils.Vector`, list or tuple of 3 real numbers\n"; + +static PyObject *SVertex_AddNormal( BPy_SVertex *self , PyObject *args) { + PyObject *py_normal; + + if(!( PyArg_ParseTuple(args, "O", &py_normal) )) + return NULL; + 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)"); + return NULL; + } + self->sv->AddNormal( *n ); + delete n; + + Py_RETURN_NONE; +} + +static char SVertex_setId___doc__[] = +".. method:: setId(id)\n" +"\n" +" Sets the identifier of the SVertex.\n" +"\n" +" :arg id: The identifier.\n" +" :type id: :class:`Id`\n"; + +static PyObject *SVertex_setId( BPy_SVertex *self , PyObject *args) { + BPy_Id *py_id; + + if( !PyArg_ParseTuple(args, "O!", &Id_Type, &py_id) ) + return NULL; + + self->sv->setId( *(py_id->id) ); + + Py_RETURN_NONE; +} + +static char SVertex_AddFEdge___doc__[] = +".. method:: AddFEdge(fe)\n" +"\n" +" Add an FEdge to the list of edges emanating from this SVertex.\n" +"\n" +" :arg fe: An FEdge.\n" +" :type fe: :class:`FEdge`\n"; + +static PyObject *SVertex_AddFEdge( BPy_SVertex *self , PyObject *args) { + PyObject *py_fe; + + if(!( PyArg_ParseTuple(args, "O!", &FEdge_Type, &py_fe) )) + return NULL; + + self->sv->AddFEdge( ((BPy_FEdge *) py_fe)->fe ); + + Py_RETURN_NONE; +} + +static char SVertex_curvatures___doc__[] = +".. method:: curvatures()\n" +"\n" +" Returns curvature information in the form of a seven-element tuple\n" +" (K1, e1, K2, e2, Kr, er, dKr), where K1 and K2 are scalar values\n" +" representing the first (maximum) and second (minimum) principal\n" +" curvatures at this SVertex, respectively; e1 and e2 are\n" +" three-dimensional vectors representing the first and second principal\n" +" directions, i.e. the directions of the normal plane where the\n" +" curvature takes its maximum and minimum values, respectively; and Kr,\n" +" er and dKr are the radial curvature, radial direction, and the\n" +" derivative of the radial curvature at this SVertex, repectively.\n" +" :return: curvature information expressed by a seven-element tuple\n" +" (K1, e1, K2, e2, Kr, er, dKr).\n" +" :rtype: tuple\n"; + +static PyObject *SVertex_curvatures( BPy_SVertex *self , PyObject *args) { + const CurvatureInfo *info = self->sv->getCurvatureInfo(); + if (!info) + Py_RETURN_NONE; + Vec3r e1(info->e1.x(), info->e1.y(), info->e1.z()); + Vec3r e2(info->e2.x(), info->e2.y(), info->e2.z()); + Vec3r er(info->er.x(), info->er.y(), info->er.z()); + PyObject *retval = PyTuple_New(7); + PyTuple_SetItem( retval, 0, PyFloat_FromDouble(info->K1)); + PyTuple_SetItem( retval, 2, Vector_from_Vec3r(e1)); + PyTuple_SetItem( retval, 1, PyFloat_FromDouble(info->K2)); + PyTuple_SetItem( retval, 3, Vector_from_Vec3r(e2)); + PyTuple_SetItem( retval, 4, PyFloat_FromDouble(info->Kr)); + PyTuple_SetItem( retval, 5, Vector_from_Vec3r(er)); + PyTuple_SetItem( retval, 6, PyFloat_FromDouble(info->dKr)); + return retval; +} + +// virtual bool operator== (const SVertex &iBrother) +// ViewVertex * viewvertex () + +/*----------------------SVertex instance definitions ----------------------------*/ +static PyMethodDef BPy_SVertex_methods[] = { + {"normals", ( PyCFunction ) SVertex_normals, METH_NOARGS, SVertex_normals___doc__}, + {"normalsSize", ( PyCFunction ) SVertex_normalsSize, METH_NOARGS, SVertex_normalsSize___doc__}, + {"viewvertex", ( PyCFunction ) SVertex_viewvertex, METH_NOARGS, SVertex_viewvertex___doc__}, + {"setPoint3D", ( PyCFunction ) SVertex_setPoint3D, METH_VARARGS, SVertex_setPoint3D___doc__}, + {"setPoint2D", ( PyCFunction ) SVertex_setPoint2D, METH_VARARGS, SVertex_setPoint2D___doc__}, + {"AddNormal", ( PyCFunction ) SVertex_AddNormal, METH_VARARGS, SVertex_AddNormal___doc__}, + {"setId", ( PyCFunction ) SVertex_setId, METH_VARARGS, SVertex_setId___doc__}, + {"AddFEdge", ( PyCFunction ) SVertex_AddFEdge, METH_VARARGS, SVertex_AddFEdge___doc__}, + {"curvatures", ( PyCFunction ) SVertex_curvatures, METH_NOARGS, SVertex_curvatures___doc__}, + {NULL, NULL, 0, NULL} +}; + +/*-----------------------BPy_SVertex type definition ------------------------------*/ +PyTypeObject SVertex_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "SVertex", /* tp_name */ + sizeof(BPy_SVertex), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + SVertex___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + BPy_SVertex_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &Interface0D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)SVertex___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ +}; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif + diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.h b/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.h new file mode 100644 index 00000000000..7d310f2b7dc --- /dev/null +++ b/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.h @@ -0,0 +1,32 @@ +#ifndef FREESTYLE_PYTHON_SVERTEX_H +#define FREESTYLE_PYTHON_SVERTEX_H + +#include "../../view_map/Silhouette.h" +#include "../BPy_Interface0D.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +#include <Python.h> + +extern PyTypeObject SVertex_Type; + +#define BPy_SVertex_Check(v) ( PyObject_IsInstance( (PyObject *) v, (PyObject *) &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/Interface0D/BPy_ViewVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp new file mode 100644 index 00000000000..c1fe6875ea7 --- /dev/null +++ b/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp @@ -0,0 +1,195 @@ +#include "BPy_ViewVertex.h" + +#include "../BPy_Convert.h" +#include "../Interface1D/BPy_ViewEdge.h" +#include "../BPy_Nature.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +//------------------------INSTANCE METHODS ---------------------------------- + +static char ViewVertex___doc__[] = +"Class hierarchy: :class:`Interface0D` > :class:`ViewVertex`\n" +"\n" +"Class to define a view vertex. A view vertex is a feature vertex\n" +"corresponding to a point of the image graph, where the characteristics\n" +"of an edge (e.g., nature and visibility) might change. A\n" +":class:`ViewVertex` can be of two kinds: A :class:`TVertex` when it\n" +"corresponds to the intersection between two ViewEdges or a\n" +":class:`NonTVertex` when it corresponds to a vertex of the initial\n" +"input mesh (it is the case for vertices such as corners for example).\n" +"Thus, this class can be specialized into two classes, the\n" +":class:`TVertex` class and the :class:`NonTVertex` class.\n" +"\n" +".. method:: __init__()\n" +"\n" +" Default constructor.\n" +"\n" +".. method:: __init__(iBrother)\n" +"\n" +" Copy constructor.\n" +"\n" +" :arg iBrother: A ViewVertex object.\n" +" :type iBrother: :class:`ViewVertex`\n"; + +static int ViewVertex___init__( BPy_ViewVertex *self, PyObject *args, PyObject *kwds ) +{ + if( !PyArg_ParseTuple(args, "") ) + return -1; + self->vv = 0; // ViewVertex is abstract + self->py_if0D.if0D = self->vv; + self->py_if0D.borrowed = 0; + return 0; +} + +static char ViewVertex_setNature___doc__[] = +".. method:: setNature(iNature)\n" +"\n" +" Sets the nature of the vertex.\n" +"\n" +" :arg iNature: A Nature object.\n" +" :type iNature: :class:`Nature`\n"; + +static PyObject * ViewVertex_setNature( BPy_ViewVertex *self, PyObject *args ) { + PyObject *py_n; + + if( !self->vv ) + Py_RETURN_NONE; + + if(!( PyArg_ParseTuple(args, "O!", &Nature_Type, &py_n) )) + return NULL; + + PyObject *i = (PyObject *) &( ((BPy_Nature *) py_n)->i ); + ((ViewVertex *) self->py_if0D.if0D)->setNature( PyLong_AsLong(i) ); + + Py_RETURN_NONE; +} + +static char ViewVertex_edgesBegin___doc__[] = +".. method:: edgesBegin()\n" +"\n" +" Returns an iterator over the ViewEdges that goes to or comes from\n" +" this ViewVertex pointing to the first ViewEdge of the list. The\n" +" orientedViewEdgeIterator allows to iterate in CCW order over these\n" +" ViewEdges and to get the orientation for each ViewEdge\n" +" (incoming/outgoing).\n" +"\n" +" :return: An orientedViewEdgeIterator pointing to the first ViewEdge.\n" +" :rtype: :class:`orientedViewEdgeIterator`\n"; + +static PyObject * ViewVertex_edgesBegin( BPy_ViewVertex *self ) { + if( !self->vv ) + Py_RETURN_NONE; + + ViewVertexInternal::orientedViewEdgeIterator ove_it( self->vv->edgesBegin() ); + return BPy_orientedViewEdgeIterator_from_orientedViewEdgeIterator( ove_it, 0 ); +} + +static char ViewVertex_edgesEnd___doc__[] = +".. method:: edgesEnd()\n" +"\n" +" Returns an orientedViewEdgeIterator over the ViewEdges around this\n" +" ViewVertex, pointing after the last ViewEdge.\n" +"\n" +" :return: An orientedViewEdgeIterator pointing after the last ViewEdge.\n" +" :rtype: :class:`orientedViewEdgeIterator`\n"; + +static PyObject * ViewVertex_edgesEnd( BPy_ViewVertex *self ) { +#if 0 + if( !self->vv ) + Py_RETURN_NONE; + + ViewVertexInternal::orientedViewEdgeIterator ove_it( self->vv->edgesEnd() ); + return BPy_orientedViewEdgeIterator_from_orientedViewEdgeIterator( ove_it, 1 ); +#else + PyErr_SetString(PyExc_NotImplementedError, "edgesEnd method currently disabled"); + return NULL; +#endif +} + +static char ViewVertex_edgesIterator___doc__[] = +".. method:: edgesIterator(iEdge)\n" +"\n" +" Returns an orientedViewEdgeIterator pointing to the ViewEdge given\n" +" as argument.\n" +"\n" +" :arg iEdge: A ViewEdge object.\n" +" :type iEdge: :class:`ViewEdge`\n" +" :return: An orientedViewEdgeIterator pointing to the given ViewEdge.\n" +" :rtype: :class:`orientedViewEdgeIterator`\n"; + +static PyObject * ViewVertex_edgesIterator( BPy_ViewVertex *self, PyObject *args ) { + PyObject *py_ve; + + if( !self->vv ) + Py_RETURN_NONE; + + if(!( PyArg_ParseTuple(args, "O!", &ViewEdge_Type, &py_ve) )) + return NULL; + + ViewEdge *ve = ((BPy_ViewEdge *) py_ve)->ve; + ViewVertexInternal::orientedViewEdgeIterator ove_it( self->vv->edgesIterator( ve ) ); + return BPy_orientedViewEdgeIterator_from_orientedViewEdgeIterator( ove_it, 0 ); +} + +/*----------------------ViewVertex instance definitions ----------------------------*/ +static PyMethodDef BPy_ViewVertex_methods[] = { + {"setNature", ( PyCFunction ) ViewVertex_setNature, METH_VARARGS, ViewVertex_setNature___doc__}, + {"edgesBegin", ( PyCFunction ) ViewVertex_edgesBegin, METH_NOARGS, ViewVertex_edgesBegin___doc__}, + {"edgesEnd", ( PyCFunction ) ViewVertex_edgesEnd, METH_NOARGS, ViewVertex_edgesEnd___doc__}, + {"edgesIterator", ( PyCFunction ) ViewVertex_edgesIterator, METH_VARARGS, ViewVertex_edgesIterator___doc__}, + {NULL, NULL, 0, NULL} +}; + +/*-----------------------BPy_ViewVertex type definition ------------------------------*/ +PyTypeObject ViewVertex_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "ViewVertex", /* tp_name */ + sizeof(BPy_ViewVertex), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ViewVertex___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + BPy_ViewVertex_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &Interface0D_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ViewVertex___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ +}; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif + diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.h b/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.h new file mode 100644 index 00000000000..26c06b50d71 --- /dev/null +++ b/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.h @@ -0,0 +1,31 @@ +#ifndef FREESTYLE_PYTHON_VIEWVERTEX_H +#define FREESTYLE_PYTHON_VIEWVERTEX_H + +#include "../../view_map/ViewMap.h" +#include "../BPy_Interface0D.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +#include <Python.h> + +extern PyTypeObject ViewVertex_Type; + +#define BPy_ViewVertex_Check(v) ( PyObject_IsInstance( (PyObject *) v, (PyObject *) &ViewVertex_Type) ) + +/*---------------------------Python BPy_ViewVertex structure definition----------*/ +typedef struct { + BPy_Interface0D py_if0D; + ViewVertex *vv; +} BPy_ViewVertex; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif + +#endif /* FREESTYLE_PYTHON_VIEWVERTEX_H */ diff --git a/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp new file mode 100644 index 00000000000..80b9defd95e --- /dev/null +++ b/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp @@ -0,0 +1,400 @@ +#include "BPy_StrokeVertex.h" + +#include "../../BPy_Convert.h" +#include "../../BPy_StrokeAttribute.h" +#include "../../Interface0D/BPy_SVertex.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +//------------------------INSTANCE METHODS ---------------------------------- + +static char StrokeVertex___doc__[] = +"Class hierarchy: :class:`Interface0D` > :class:`CurvePoint` > :class:`StrokeVertex`\n" +"\n" +"Class to define a stroke vertex.\n" +"\n" +".. method:: __init__()\n" +"\n" +" Default constructor.\n" +"\n" +".. method:: __init__(iBrother)\n" +"\n" +" Copy constructor.\n" +"\n" +" :arg iBrother: A StrokeVertex object.\n" +" :type iBrother: :class:`StrokeVertex`\n" +"\n" +".. method:: __init__(iA, iB, t3)\n" +"\n" +" Builds a stroke vertex from 2 stroke vertices and an interpolation\n" +" parameter.\n" +"\n" +" :arg iA: The first StrokeVertex.\n" +" :type iA: :class:`StrokeVertex`\n" +" :arg iB: The second StrokeVertex.\n" +" :type iB: :class:`StrokeVertex`\n" +" :arg t3: An interpolation parameter.\n" +" :type t3: float\n" +"\n" +".. method:: __init__(iPoint)\n" +"\n" +" Builds a stroke vertex from a CurvePoint\n" +"\n" +" :arg iPoint: A CurvePoint object.\n" +" :type iPoint: :class:`CurvePoint`\n" +"\n" +".. method:: __init__(iSVertex)\n" +"\n" +" Builds a stroke vertex from a SVertex\n" +"\n" +" :arg iSVertex: An SVertex object.\n" +" :type iSVertex: :class:`SVertex`\n" +"\n" +".. method:: __init__(iSVertex, iAttribute)\n" +"\n" +" Builds a stroke vertex from an SVertex and a StrokeAttribute object.\n" +"\n" +" :arg iSVertex: An SVertex object.\n" +" :type iSVertex: :class:`SVertex`\n" +" :arg iAttribute: A StrokeAttribute object.\n" +" :type iAttribute: :class:`StrokeAttribute`\n"; + +static int StrokeVertex___init__(BPy_StrokeVertex *self, PyObject *args, PyObject *kwds) +{ + + PyObject *obj1 = 0, *obj2 = 0 , *obj3 = 0; + + if (! PyArg_ParseTuple(args, "|OOO!", &obj1, &obj2, &PyFloat_Type, &obj3) ) + return -1; + + if( !obj1 ){ + self->sv = new StrokeVertex(); + + } else if( !obj2 && BPy_StrokeVertex_Check(obj1) && ((BPy_StrokeVertex *) obj1)->sv ) { + self->sv = new StrokeVertex( *(((BPy_StrokeVertex *) obj1)->sv) ); + + } else if( !obj2 && BPy_CurvePoint_Check(obj1) && ((BPy_CurvePoint *) obj1)->cp ) { + self->sv = new StrokeVertex( ((BPy_CurvePoint *) obj1)->cp ); + + } else if( !obj2 && BPy_SVertex_Check(obj1) && ((BPy_SVertex *) obj1)->sv ) { + self->sv = new StrokeVertex( ((BPy_SVertex *) obj1)->sv ); + + } else if( obj3 && BPy_StrokeVertex_Check(obj1) && BPy_StrokeVertex_Check(obj2) ) { + StrokeVertex *sv1 = ((BPy_StrokeVertex *) obj1)->sv; + StrokeVertex *sv2 = ((BPy_StrokeVertex *) obj2)->sv; + if( !sv1 || ( sv1->A() == 0 && sv1->B() == 0 ) ) { + PyErr_SetString(PyExc_TypeError, "argument 1 is an invalid StrokeVertex object"); + return -1; + } + if( !sv2 || ( sv2->A() == 0 && sv2->B() == 0 ) ) { + PyErr_SetString(PyExc_TypeError, "argument 2 is an invalid StrokeVertex object"); + return -1; + } + self->sv = new StrokeVertex( sv1, sv2, PyFloat_AsDouble( obj3 ) ); + + } else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } + + self->py_cp.cp = self->sv; + self->py_cp.py_if0D.if0D = self->sv; + self->py_cp.py_if0D.borrowed = 0; + + return 0; +} + +static char StrokeVertex_x___doc__[] = +".. method:: x()\n" +"\n" +" Returns the 2D point X coordinate.\n" +"\n" +" :return: The X coordinate.\n" +" :rtype: float\n"; + +static PyObject * StrokeVertex_x( BPy_StrokeVertex *self ) { + return PyFloat_FromDouble( self->sv->x() ); +} + +static char StrokeVertex_y___doc__[] = +".. method:: y()\n" +"\n" +" Returns the 2D point Y coordinate.\n" +"\n" +" :return: The Y coordinate.\n" +" :rtype: float\n"; + +static PyObject * StrokeVertex_y( BPy_StrokeVertex *self ) { + return PyFloat_FromDouble( self->sv->y() ); +} + +static char StrokeVertex_getPoint___doc__[] = +".. method:: getPoint()\n" +"\n" +" Returns the 2D point coordinates as a two-dimensional vector.\n" +"\n" +" :return: The 2D coordinates.\n" +" :rtype: :class:`mathutils.Vector`\n"; + +static PyObject * StrokeVertex_getPoint( BPy_StrokeVertex *self ) { + Vec2f v( self->sv->getPoint() ); + return Vector_from_Vec2f( v ); +} + +static char StrokeVertex_attribute___doc__[] = +".. method:: attribute()\n" +"\n" +" Returns the StrokeAttribute for this StrokeVertex.\n" +"\n" +" :return: The StrokeAttribute object.\n" +" :rtype: :class:`StrokeAttribute`\n"; + +static PyObject * StrokeVertex_attribute( BPy_StrokeVertex *self ) { + return BPy_StrokeAttribute_from_StrokeAttribute( self->sv->attribute() ); +} + +static char StrokeVertex_curvilinearAbscissa___doc__[] = +".. method:: curvilinearAbscissa()\n" +"\n" +" Returns the curvilinear abscissa.\n" +"\n" +" :return: The curvilinear abscissa.\n" +" :rtype: float\n"; + +static PyObject * StrokeVertex_curvilinearAbscissa( BPy_StrokeVertex *self ) { + return PyFloat_FromDouble( self->sv->curvilinearAbscissa() ); +} + +static char StrokeVertex_strokeLength___doc__[] = +".. method:: strokeLength()\n" +"\n" +" Returns the length of the Stroke to which this StrokeVertex belongs\n" +"\n" +" :return: The stroke length.\n" +" :rtype: float\n"; + +static PyObject * StrokeVertex_strokeLength( BPy_StrokeVertex *self ) { + return PyFloat_FromDouble( self->sv->strokeLength() ); +} + +static char StrokeVertex_u___doc__[] = +".. method:: u()\n" +"\n" +" Returns the curvilinear abscissa of this StrokeVertex in the Stroke\n" +"\n" +" :return: The curvilinear abscissa.\n" +" :rtype: float\n"; + +static PyObject * StrokeVertex_u( BPy_StrokeVertex *self ) { + return PyFloat_FromDouble( self->sv->u() ); +} + +static char StrokeVertex_setX___doc__[] = +".. method:: setX(x)\n" +"\n" +" Sets the 2D point X coordinate.\n" +"\n" +" :arg x: The X coordinate.\n" +" :type x: float\n"; + +static PyObject *StrokeVertex_setX( BPy_StrokeVertex *self , PyObject *args) { + double r; + + if(!( PyArg_ParseTuple(args, "d", &r) )) + return NULL; + + self->sv->setX( r ); + + Py_RETURN_NONE; +} + +static char StrokeVertex_setY___doc__[] = +".. method:: setY(y)\n" +"\n" +" Sets the 2D point Y coordinate.\n" +"\n" +" :arg y: The Y coordinate.\n" +" :type y: float\n"; + +static PyObject *StrokeVertex_setY( BPy_StrokeVertex *self , PyObject *args) { + double r; + + if(!( PyArg_ParseTuple(args, "d", &r) )) + return NULL; + + self->sv->setY( r ); + + Py_RETURN_NONE; +} + +static char StrokeVertex_setPoint___doc__[] = +".. method:: setPoint(x, y)\n" +"\n" +" Sets the 2D point X and Y coordinates.\n" +"\n" +" :arg x: The X coordinate.\n" +" :type x: float\n" +" :arg y: The Y coordinate.\n" +" :type y: float\n" +"\n" +".. method:: setPoint(p)\n" +"\n" +" Sets the 2D point X and Y coordinates.\n" +"\n" +" :arg p: A two-dimensional vector.\n" +" :type p: :class:`mathutils.Vector`, list or tuple of 2 real numbers\n"; + +static PyObject *StrokeVertex_setPoint( BPy_StrokeVertex *self , PyObject *args) { + PyObject *obj1 = 0, *obj2 = 0; + + if(!( PyArg_ParseTuple(args, "O|O", &obj1, &obj2) )) + return NULL; + + if( obj1 && !obj2 ){ + Vec2f *v = Vec2f_ptr_from_PyObject(obj1); + if( !v ) { + PyErr_SetString(PyExc_TypeError, "argument 1 must be a 2D vector (either a list of 2 elements or Vector)"); + return NULL; + } + self->sv->setPoint( *v ); + delete v; + } else if( PyFloat_Check(obj1) && obj2 && PyFloat_Check(obj2) ){ + self->sv->setPoint( PyFloat_AsDouble(obj1), PyFloat_AsDouble(obj2) ); + } else { + PyErr_SetString(PyExc_TypeError, "invalid arguments"); + return NULL; + } + + Py_RETURN_NONE; +} + +static char StrokeVertex_setAttribute___doc__[] = +".. method:: setAttribute(iAttribute)\n" +"\n" +" Sets the attribute.\n" +"\n" +" :arg iAttribute: A StrokeAttribute object.\n" +" :type iAttribute: :class:`StrokeAttribute`\n"; + +static PyObject *StrokeVertex_setAttribute( BPy_StrokeVertex *self , PyObject *args) { + PyObject *py_sa; + + if(!( PyArg_ParseTuple(args, "O!", &StrokeAttribute_Type, &py_sa) )) + return NULL; + + self->sv->setAttribute(*( ((BPy_StrokeAttribute *) py_sa)->sa )); + + Py_RETURN_NONE; +} + +static char StrokeVertex_setCurvilinearAbscissa___doc__[] = +".. method:: setCurvilinearAbscissa(iAbscissa)\n" +"\n" +" Sets the curvilinear abscissa of this StrokeVertex in the Stroke\n" +"\n" +" :arg iAbscissa: The curvilinear abscissa.\n" +" :type iAbscissa: float\n"; + +static PyObject *StrokeVertex_setCurvilinearAbscissa( BPy_StrokeVertex *self , PyObject *args) { + double r; + + if(!( PyArg_ParseTuple(args, "d", &r) )) + return NULL; + + self->sv->setCurvilinearAbscissa( r ); + + Py_RETURN_NONE; +} + +static char StrokeVertex_setStrokeLength___doc__[] = +".. method:: setStrokeLength(iLength)\n" +"\n" +" Sets the stroke length (it is only a value retained by the\n" +" StrokeVertex, and it won't change the real stroke length).\n" +"\n" +" :arg iLength: The stroke length.\n" +" :type iLength: float\n"; + +static PyObject *StrokeVertex_setStrokeLength( BPy_StrokeVertex *self , PyObject *args) { + double r; + + if(!( PyArg_ParseTuple(args, "d", &r) )) + return NULL; + + self->sv->setStrokeLength( r ); + + Py_RETURN_NONE; +} + +// real operator[] (const int i) const +// real & operator[] (const int i) + +/*----------------------StrokeVertex instance definitions ----------------------------*/ +static PyMethodDef BPy_StrokeVertex_methods[] = { + {"x", ( PyCFunction ) StrokeVertex_x, METH_NOARGS, StrokeVertex_x___doc__}, + {"y", ( PyCFunction ) StrokeVertex_y, METH_NOARGS, StrokeVertex_y___doc__}, + {"getPoint", ( PyCFunction ) StrokeVertex_getPoint, METH_NOARGS, StrokeVertex_getPoint___doc__}, + {"attribute", ( PyCFunction ) StrokeVertex_attribute, METH_NOARGS, StrokeVertex_attribute___doc__}, + {"curvilinearAbscissa", ( PyCFunction ) StrokeVertex_curvilinearAbscissa, METH_NOARGS, StrokeVertex_curvilinearAbscissa___doc__}, + {"strokeLength", ( PyCFunction ) StrokeVertex_strokeLength, METH_NOARGS, StrokeVertex_strokeLength___doc__}, + {"u", ( PyCFunction ) StrokeVertex_u, METH_NOARGS, StrokeVertex_u___doc__}, + {"setX", ( PyCFunction ) StrokeVertex_setX, METH_VARARGS, StrokeVertex_setX___doc__}, + {"setY", ( PyCFunction ) StrokeVertex_setY, METH_VARARGS, StrokeVertex_setY___doc__}, + {"setPoint", ( PyCFunction ) StrokeVertex_setPoint, METH_VARARGS, StrokeVertex_setPoint___doc__}, + {"setAttribute", ( PyCFunction ) StrokeVertex_setAttribute, METH_VARARGS, StrokeVertex_setAttribute___doc__}, + {"setCurvilinearAbscissa", ( PyCFunction ) StrokeVertex_setCurvilinearAbscissa, METH_VARARGS, StrokeVertex_setCurvilinearAbscissa___doc__}, + {"setStrokeLength", ( PyCFunction ) StrokeVertex_setStrokeLength, METH_VARARGS, StrokeVertex_setStrokeLength___doc__}, + {NULL, NULL, 0, NULL} +}; + +/*-----------------------BPy_StrokeVertex type definition ------------------------------*/ +PyTypeObject StrokeVertex_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "StrokeVertex", /* tp_name */ + sizeof(BPy_StrokeVertex), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + StrokeVertex___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + BPy_StrokeVertex_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &CurvePoint_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)StrokeVertex___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ +}; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.h b/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.h new file mode 100644 index 00000000000..2a84e2480f0 --- /dev/null +++ b/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.h @@ -0,0 +1,31 @@ +#ifndef FREESTYLE_PYTHON_STROKEVERTEX_H +#define FREESTYLE_PYTHON_STROKEVERTEX_H + +#include "../BPy_CurvePoint.h" +#include "../../../stroke/Stroke.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +#include <Python.h> + +extern PyTypeObject StrokeVertex_Type; + +#define BPy_StrokeVertex_Check(v) ( PyObject_IsInstance( (PyObject *) v, (PyObject *) &StrokeVertex_Type) ) + +/*---------------------------Python BPy_StrokeVertex structure definition----------*/ +typedef struct { + BPy_CurvePoint py_cp; + StrokeVertex *sv; +} BPy_StrokeVertex; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif + +#endif /* FREESTYLE_PYTHON_STROKEVERTEX_H */ diff --git a/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.cpp new file mode 100644 index 00000000000..ebb2920353d --- /dev/null +++ b/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.cpp @@ -0,0 +1,153 @@ +#include "BPy_NonTVertex.h" + +#include "../../BPy_Convert.h" +#include "../BPy_SVertex.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +//------------------------INSTANCE METHODS ---------------------------------- + +static char NonTVertex___doc__[] = +"Class hierarchy: :class:`Interface0D` > :class:`ViewVertex` > :class:`NonTVertex`\n" +"\n" +"View vertex for corners, cusps, etc. associated to a single SVertex.\n" +"Can be associated to 2 or more view edges.\n" +"\n" +".. method:: __init__()\n" +"\n" +" Default constructor.\n" +"\n" +".. method:: __init__(iBrother)\n" +"\n" +" Copy constructor.\n" +"\n" +" :arg iBrother: A NonTVertex object.\n" +" :type iBrother: :class:`NonTVertex`\n" +"\n" +".. method:: __init__(iSVertex)\n" +"\n" +" Builds a NonTVertex from a SVertex.\n" +"\n" +" :arg iSVertex: An SVertex object.\n" +" :type iSVertex: :class:`SVertex`\n"; + +static int NonTVertex___init__(BPy_NonTVertex *self, PyObject *args, PyObject *kwds) +{ + + PyObject *obj = 0; + + if (! PyArg_ParseTuple(args, "|O!", &SVertex_Type, &obj) ) + return -1; + + if( !obj ){ + self->ntv = new NonTVertex(); + + } else if( ((BPy_SVertex *) obj)->sv ) { + self->ntv = new NonTVertex( ((BPy_SVertex *) obj)->sv ); + + } else { + PyErr_SetString(PyExc_TypeError, "invalid argument"); + return -1; + } + + self->py_vv.vv = self->ntv; + self->py_vv.py_if0D.if0D = self->ntv; + self->py_vv.py_if0D.borrowed = 0; + + return 0; +} + +static char NonTVertex_svertex___doc__[] = +".. method:: svertex()\n" +"\n" +" Returns the SVertex on top of which this NonTVertex is built.\n" +"\n" +" :return: The SVertex on top of which this NonTVertex is built.\n" +" :rtype: :class:`SVertex`\n"; + +static PyObject * NonTVertex_svertex( BPy_NonTVertex *self ) { + SVertex *v = self->ntv->svertex(); + if( v ){ + return BPy_SVertex_from_SVertex( *v ); + } + + Py_RETURN_NONE; +} + +static char NonTVertex_setSVertex___doc__[] = +".. method:: setSVertex(iSVertex)\n" +"\n" +" Sets the SVertex on top of which this NonTVertex is built.\n" +"\n" +" :arg iSVertex: The SVertex on top of which this NonTVertex is built.\n" +" :type iSVertex: :class:`SVertex`\n"; + +static PyObject * NonTVertex_setSVertex( BPy_NonTVertex *self, PyObject *args) { + PyObject *py_sv; + + if(!( PyArg_ParseTuple(args, "O!", &SVertex_Type, &py_sv) )) + return NULL; + + self->ntv->setSVertex( ((BPy_SVertex *) py_sv)->sv ); + + Py_RETURN_NONE; +} + +/*----------------------NonTVertex instance definitions ----------------------------*/ +static PyMethodDef BPy_NonTVertex_methods[] = { + {"svertex", ( PyCFunction ) NonTVertex_svertex, METH_NOARGS, NonTVertex_svertex___doc__}, + {"setSVertex", ( PyCFunction ) NonTVertex_setSVertex, METH_VARARGS, NonTVertex_setSVertex___doc__}, + {NULL, NULL, 0, NULL} +}; + +/*-----------------------BPy_NonTVertex type definition ------------------------------*/ +PyTypeObject NonTVertex_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "NonTVertex", /* tp_name */ + sizeof(BPy_NonTVertex), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + NonTVertex___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + BPy_NonTVertex_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &ViewVertex_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)NonTVertex___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ +}; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.h b/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.h new file mode 100644 index 00000000000..071194d2d42 --- /dev/null +++ b/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.h @@ -0,0 +1,31 @@ +#ifndef FREESTYLE_PYTHON_NONTVERTEX_H +#define FREESTYLE_PYTHON_NONTVERTEX_H + +#include "../BPy_ViewVertex.h" +#include "../../../view_map/ViewMap.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +#include <Python.h> + +extern PyTypeObject NonTVertex_Type; + +#define BPy_NonTVertex_Check(v) ( PyObject_IsInstance( (PyObject *) v, (PyObject *) &NonTVertex_Type) ) + +/*---------------------------Python BPy_NonTVertex structure definition----------*/ +typedef struct { + BPy_ViewVertex py_vv; + NonTVertex *ntv; +} BPy_NonTVertex; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif + +#endif /* FREESTYLE_PYTHON_NONTVERTEX_H */ diff --git a/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.cpp new file mode 100644 index 00000000000..14add743a37 --- /dev/null +++ b/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.cpp @@ -0,0 +1,249 @@ +#include "BPy_TVertex.h" + +#include "../../BPy_Convert.h" +#include "../BPy_SVertex.h" +#include "../../BPy_Id.h" +#include "../../Interface1D/BPy_FEdge.h" +#include "../../Interface1D/BPy_ViewEdge.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +//------------------------INSTANCE METHODS ---------------------------------- + +static char TVertex___doc__[] = +"Class hierarchy: :class:`Interface0D` > :class:`ViewVertex` > :class:`TVertex`\n" +"\n" +"Class to define a T vertex, i.e. an intersection between two edges.\n" +"It points towards two SVertex and four ViewEdges. Among the\n" +"ViewEdges, two are front and the other two are back. Basically a\n" +"front edge hides part of a back edge. So, among the back edges, one\n" +"is of invisibility N and the other of invisibility N+1.\n" +"\n" +".. method:: __init__()\n" +"\n" +" Default constructor.\n" +"\n" +".. method:: __init__(iBrother)\n" +"\n" +" Copy constructor.\n" +"\n" +" :arg iBrother: A TVertex object.\n" +" :type iBrother: :class:`TVertex`\n"; + +static int TVertex___init__(BPy_TVertex *self, PyObject *args, PyObject *kwds) +{ + if( !PyArg_ParseTuple(args, "") ) + return -1; + self->tv = new TVertex(); + self->py_vv.vv = self->tv; + self->py_vv.py_if0D.if0D = self->tv; + self->py_vv.py_if0D.borrowed = 0; + + return 0; +} + +static char TVertex_frontSVertex___doc__[] = +".. method:: frontSVertex()\n" +"\n" +" Returns the SVertex that is closer to the viewpoint.\n" +"\n" +" :return: The SVertex that is closer to the viewpoint.\n" +" :rtype: :class:`SVertex`\n"; + +static PyObject * TVertex_frontSVertex( BPy_TVertex *self ) { + SVertex *v = self->tv->frontSVertex(); + if( v ){ + return BPy_SVertex_from_SVertex( *v ); + } + + Py_RETURN_NONE; +} + +static char TVertex_backSVertex___doc__[] = +".. method:: backSVertex()\n" +"\n" +" Returns the SVertex that is further away from the viewpoint.\n" +"\n" +" :return: The SVertex that is further away from the viewpoint.\n" +" :rtype: :class:`SVertex`\n"; + +static PyObject * TVertex_backSVertex( BPy_TVertex *self ) { + SVertex *v = self->tv->backSVertex(); + if( v ){ + return BPy_SVertex_from_SVertex( *v ); + } + + Py_RETURN_NONE; +} + +static char TVertex_setFrontSVertex___doc__[] = +".. method:: setFrontSVertex(iFrontSVertex)\n" +"\n" +" Sets the SVertex that is closer to the viewpoint.\n" +"\n" +" :arg iFrontSVertex: An SVertex object.\n" +" :type iFrontSVertex: :class:`SVertex`\n"; + +static PyObject * TVertex_setFrontSVertex( BPy_TVertex *self, PyObject *args) { + PyObject *py_sv; + + if(!( PyArg_ParseTuple(args, "O!", &SVertex_Type, &py_sv) )) + return NULL; + + self->tv->setFrontSVertex( ((BPy_SVertex *) py_sv)->sv ); + + Py_RETURN_NONE; +} + +static char TVertex_setBackSVertex___doc__[] = +".. method:: setBackSVertex(iBackSVertex)\n" +"\n" +" Sets the SVertex that is further away from the viewpoint.\n" +"\n" +" :arg iBackSVertex: An SVertex object.\n" +" :type iBackSVertex: :class:`SVertex`\n"; + +static PyObject * TVertex_setBackSVertex( BPy_TVertex *self, PyObject *args) { + PyObject *py_sv; + + if(!( PyArg_ParseTuple(args, "O", &SVertex_Type, &py_sv) )) + return NULL; + + self->tv->setBackSVertex( ((BPy_SVertex *) py_sv)->sv ); + + Py_RETURN_NONE; +} + +static char TVertex_setId___doc__[] = +".. method:: setId(iId)\n" +"\n" +" Sets the Id.\n" +"\n" +" :arg iId: An Id object.\n" +" :type iId: :class:`Id`\n"; + +static PyObject * TVertex_setId( BPy_TVertex *self, PyObject *args) { + PyObject *py_id; + + if(!( PyArg_ParseTuple(args, "O!", &Id_Type, &py_id) )) + return NULL; + + if( ((BPy_Id *) py_id)->id ) + self->tv->setId(*( ((BPy_Id *) py_id)->id )); + + Py_RETURN_NONE; +} + +static char TVertex_getSVertex___doc__[] = +".. method:: getSVertex(iFEdge)\n" +"\n" +" Returns the SVertex (among the 2) belonging to the given FEdge.\n" +"\n" +" :arg iFEdge: An FEdge object.\n" +" :type iFEdge: :class:`FEdge`\n" +" :return: The SVertex belonging to the given FEdge.\n" +" :rtype: :class:`SVertex`\n"; + +static PyObject * TVertex_getSVertex( BPy_TVertex *self, PyObject *args) { + PyObject *py_fe; + + if(!( PyArg_ParseTuple(args, "O!", &FEdge_Type, &py_fe) )) + return NULL; + + SVertex *sv = self->tv->getSVertex( ((BPy_FEdge *) py_fe)->fe ); + if( sv ){ + return BPy_SVertex_from_SVertex( *sv ); + } + + Py_RETURN_NONE; +} + +static char TVertex_mate___doc__[] = +".. method:: mate(iEdgeA)\n" +"\n" +" Returns the mate edge of the ViewEdge given as argument. If the\n" +" ViewEdge is frontEdgeA, frontEdgeB is returned. If the ViewEdge is\n" +" frontEdgeB, frontEdgeA is returned. Same for back edges.\n" +"\n" +" :arg iEdgeA: A ViewEdge object.\n" +" :type iEdgeA: :class:`ViewEdge`\n" +" :return: The mate edge of the given ViewEdge.\n" +" :rtype: :class:`ViewEdge`\n"; + +static PyObject * TVertex_mate( BPy_TVertex *self, PyObject *args) { + PyObject *py_ve; + + if(!( PyArg_ParseTuple(args, "O!", &ViewEdge_Type, &py_ve) )) + return NULL; + + ViewEdge *ve = self->tv->mate( ((BPy_ViewEdge *) py_ve)->ve ); + if( ve ){ + return BPy_ViewEdge_from_ViewEdge( *ve ); + } + + Py_RETURN_NONE; +} + +/*----------------------TVertex instance definitions ----------------------------*/ +static PyMethodDef BPy_TVertex_methods[] = { + {"frontSVertex", ( PyCFunction ) TVertex_frontSVertex, METH_NOARGS, TVertex_frontSVertex___doc__}, + {"backSVertex", ( PyCFunction ) TVertex_backSVertex, METH_NOARGS, TVertex_backSVertex___doc__}, + {"setFrontSVertex", ( PyCFunction ) TVertex_setFrontSVertex, METH_VARARGS, TVertex_setFrontSVertex___doc__}, + {"setBackSVertex", ( PyCFunction ) TVertex_setBackSVertex, METH_VARARGS, TVertex_setBackSVertex___doc__}, + {"setId", ( PyCFunction ) TVertex_setId, METH_VARARGS, TVertex_setId___doc__}, + {"getSVertex", ( PyCFunction ) TVertex_getSVertex, METH_VARARGS, TVertex_getSVertex___doc__}, + {"mate", ( PyCFunction ) TVertex_mate, METH_VARARGS, TVertex_mate___doc__}, + {NULL, NULL, 0, NULL} +}; + +/*-----------------------BPy_TVertex type definition ------------------------------*/ +PyTypeObject TVertex_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "TVertex", /* tp_name */ + sizeof(BPy_TVertex), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + TVertex___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + BPy_TVertex_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &ViewVertex_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)TVertex___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ +}; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.h b/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.h new file mode 100644 index 00000000000..12fe5c0cb43 --- /dev/null +++ b/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.h @@ -0,0 +1,31 @@ +#ifndef FREESTYLE_PYTHON_TVERTEX_H +#define FREESTYLE_PYTHON_TVERTEX_H + +#include "../BPy_ViewVertex.h" +#include "../../../view_map/ViewMap.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +#include <Python.h> + +extern PyTypeObject TVertex_Type; + +#define BPy_TVertex_Check(v) ( PyObject_IsInstance( (PyObject *) v, (PyObject *) &TVertex_Type) ) + +/*---------------------------Python BPy_TVertex structure definition----------*/ +typedef struct { + BPy_ViewVertex py_vv; + TVertex *tv; +} BPy_TVertex; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif + +#endif /* FREESTYLE_PYTHON_TVERTEX_H */ |