From 149f3688a4663dbaf890f6f5e5a41c35ce6d5e56 Mon Sep 17 00:00:00 2001 From: Maxime Curioni Date: Fri, 1 Aug 2008 02:15:25 +0000 Subject: soc-2008-mxcurioni: moved Curve to FrsCurve, fixed bugs with some style modules having with strokes without a representation and iterators not being correctly routed. For example, the cartoon style module should work now. --- .../freestyle/intern/python/BPy_Convert.cpp | 35 ++- .../freestyle/intern/python/BPy_Freestyle.cpp | 4 +- .../freestyle/intern/python/BPy_FrsNoise.cpp | 239 ++++++++++++++++++++ .../blender/freestyle/intern/python/BPy_FrsNoise.h | 36 +++ .../freestyle/intern/python/BPy_Interface1D.cpp | 8 +- .../freestyle/intern/python/BPy_Iterator.cpp | 3 - .../blender/freestyle/intern/python/BPy_Noise.cpp | 239 -------------------- source/blender/freestyle/intern/python/BPy_Noise.h | 36 --- .../blender/freestyle/intern/python/Director.cpp | 23 +- source/blender/freestyle/intern/python/Director.h | 7 +- .../intern/python/Interface1D/BPy_Curve.cpp | 249 --------------------- .../intern/python/Interface1D/BPy_Curve.h | 31 --- .../intern/python/Interface1D/BPy_FrsCurve.cpp | 249 +++++++++++++++++++++ .../intern/python/Interface1D/BPy_FrsCurve.h | 31 +++ .../intern/python/Interface1D/Curve/BPy_Chain.cpp | 2 +- .../intern/python/Interface1D/Curve/BPy_Chain.h | 4 +- .../python/Iterator/BPy_AdjacencyIterator.cpp | 1 + .../python/Iterator/BPy_ChainPredicateIterator.cpp | 1 + .../python/Iterator/BPy_Interface0DIterator.cpp | 2 +- .../python/Iterator/BPy_ViewEdgeIterator.cpp | 2 +- 20 files changed, 619 insertions(+), 583 deletions(-) create mode 100644 source/blender/freestyle/intern/python/BPy_FrsNoise.cpp create mode 100644 source/blender/freestyle/intern/python/BPy_FrsNoise.h delete mode 100644 source/blender/freestyle/intern/python/BPy_Noise.cpp delete mode 100644 source/blender/freestyle/intern/python/BPy_Noise.h delete mode 100644 source/blender/freestyle/intern/python/Interface1D/BPy_Curve.cpp delete mode 100644 source/blender/freestyle/intern/python/Interface1D/BPy_Curve.h create mode 100644 source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp create mode 100644 source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.h (limited to 'source/blender/freestyle/intern') diff --git a/source/blender/freestyle/intern/python/BPy_Convert.cpp b/source/blender/freestyle/intern/python/BPy_Convert.cpp index 13e4f332c32..53a4e171e74 100644 --- a/source/blender/freestyle/intern/python/BPy_Convert.cpp +++ b/source/blender/freestyle/intern/python/BPy_Convert.cpp @@ -30,6 +30,8 @@ #include "Iterator/BPy_ViewEdgeIterator.h" #include "Iterator/BPy_orientedViewEdgeIterator.h" +#include "../stroke/StrokeRep.h" + #ifdef __cplusplus extern "C" { #endif @@ -242,6 +244,7 @@ Stroke::MediumType MediumType_from_BPy_MediumType( PyObject* obj ) { PyObject * BPy_AdjacencyIterator_from_AdjacencyIterator( AdjacencyIterator& a_it ) { PyObject *py_a_it = AdjacencyIterator_Type.tp_new( &AdjacencyIterator_Type, 0, 0 ); ((BPy_AdjacencyIterator *) py_a_it)->a_it = new AdjacencyIterator( a_it ); + ((BPy_AdjacencyIterator *) py_a_it)->py_it.it = ((BPy_AdjacencyIterator *) py_a_it)->a_it; return py_a_it; } @@ -249,62 +252,72 @@ PyObject * BPy_AdjacencyIterator_from_AdjacencyIterator( AdjacencyIterator& a_it PyObject * BPy_Interface0DIterator_from_Interface0DIterator( Interface0DIterator& if0D_it ) { PyObject *py_if0D_it = Interface0DIterator_Type.tp_new( &Interface0DIterator_Type, 0, 0 ); ((BPy_Interface0DIterator *) py_if0D_it)->if0D_it = new Interface0DIterator( if0D_it ); + ((BPy_Interface0DIterator *) py_if0D_it)->py_it.it = ((BPy_Interface0DIterator *) py_if0D_it)->if0D_it; return py_if0D_it; } PyObject * BPy_CurvePointIterator_from_CurvePointIterator( CurveInternal::CurvePointIterator& cp_it ) { PyObject *py_cp_it = CurvePointIterator_Type.tp_new( &CurvePointIterator_Type, 0, 0 ); - ((BPy_CurvePointIterator*) py_cp_it)->cp_it = new CurveInternal::CurvePointIterator( cp_it ); + ((BPy_CurvePointIterator *) py_cp_it)->cp_it = new CurveInternal::CurvePointIterator( cp_it ); + ((BPy_CurvePointIterator *) py_cp_it)->py_it.it = ((BPy_CurvePointIterator *) py_cp_it)->cp_it; return py_cp_it; } PyObject * BPy_StrokeVertexIterator_from_StrokeVertexIterator( StrokeInternal::StrokeVertexIterator& sv_it) { PyObject *py_sv_it = StrokeVertexIterator_Type.tp_new( &StrokeVertexIterator_Type, 0, 0 ); - ((BPy_StrokeVertexIterator*) py_sv_it)->sv_it = new StrokeInternal::StrokeVertexIterator( sv_it ); + ((BPy_StrokeVertexIterator *) py_sv_it)->sv_it = new StrokeInternal::StrokeVertexIterator( sv_it ); + ((BPy_StrokeVertexIterator *) py_sv_it)->py_it.it = ((BPy_StrokeVertexIterator *) py_sv_it)->sv_it; return py_sv_it; } PyObject * BPy_SVertexIterator_from_SVertexIterator( ViewEdgeInternal::SVertexIterator& sv_it ) { PyObject *py_sv_it = SVertexIterator_Type.tp_new( &SVertexIterator_Type, 0, 0 ); - ((BPy_SVertexIterator*) py_sv_it)->sv_it = new ViewEdgeInternal::SVertexIterator( sv_it ); - + ((BPy_SVertexIterator *) py_sv_it)->sv_it = new ViewEdgeInternal::SVertexIterator( sv_it ); + ((BPy_SVertexIterator *) py_sv_it)->py_it.it = ((BPy_SVertexIterator *) py_sv_it)->sv_it; + return py_sv_it; } + PyObject * BPy_orientedViewEdgeIterator_from_orientedViewEdgeIterator( ViewVertexInternal::orientedViewEdgeIterator& ove_it ) { PyObject *py_ove_it = orientedViewEdgeIterator_Type.tp_new( &orientedViewEdgeIterator_Type, 0, 0 ); ((BPy_orientedViewEdgeIterator *) py_ove_it)->ove_it = new ViewVertexInternal::orientedViewEdgeIterator( ove_it ); - + ((BPy_orientedViewEdgeIterator *) py_ove_it)->py_it.it = ((BPy_orientedViewEdgeIterator *) py_ove_it)->ove_it; + return py_ove_it; } PyObject * BPy_ViewEdgeIterator_from_ViewEdgeIterator( ViewEdgeInternal::ViewEdgeIterator& ve_it ) { PyObject *py_ve_it = ViewEdgeIterator_Type.tp_new( &ViewEdgeIterator_Type, 0, 0 ); - ((BPy_ViewEdgeIterator*) py_ve_it)->ve_it = new ViewEdgeInternal::ViewEdgeIterator( ve_it ); - + ((BPy_ViewEdgeIterator *) py_ve_it)->ve_it = new ViewEdgeInternal::ViewEdgeIterator( ve_it ); + ((BPy_ViewEdgeIterator *) py_ve_it)->py_it.it = ((BPy_ViewEdgeIterator *) py_ve_it)->ve_it; + return py_ve_it; } PyObject * BPy_ChainingIterator_from_ChainingIterator( ChainingIterator& c_it ) { PyObject *py_c_it = ChainingIterator_Type.tp_new( &ChainingIterator_Type, 0, 0 ); - ((BPy_ChainingIterator*) py_c_it)->c_it = new ChainingIterator( c_it ); - + ((BPy_ChainingIterator *) py_c_it)->c_it = new ChainingIterator( c_it ); + ((BPy_ChainingIterator *) py_c_it)->py_ve_it.py_it.it = ((BPy_ChainingIterator *) py_c_it)->c_it; + return py_c_it; } PyObject * BPy_ChainPredicateIterator_from_ChainPredicateIterator( ChainPredicateIterator& cp_it ) { PyObject *py_cp_it = ChainPredicateIterator_Type.tp_new( &ChainPredicateIterator_Type, 0, 0 ); - ((BPy_ChainPredicateIterator*) py_cp_it)->cp_it = new ChainPredicateIterator( cp_it ); + ((BPy_ChainPredicateIterator *) py_cp_it)->cp_it = new ChainPredicateIterator( cp_it ); + ((BPy_ChainPredicateIterator *) py_cp_it)->py_c_it.py_ve_it.py_it.it = ((BPy_ChainPredicateIterator *) py_cp_it)->cp_it; return py_cp_it; } PyObject * BPy_ChainSilhouetteIterator_from_ChainSilhouetteIterator( ChainSilhouetteIterator& cs_it ) { PyObject *py_cs_it = ChainSilhouetteIterator_Type.tp_new( &ChainSilhouetteIterator_Type, 0, 0 ); - ((BPy_ChainSilhouetteIterator*) py_cs_it)->cs_it = new ChainSilhouetteIterator( cs_it ); + ((BPy_ChainSilhouetteIterator *) py_cs_it)->cs_it = new ChainSilhouetteIterator( cs_it ); + ((BPy_ChainSilhouetteIterator *) py_cs_it)->py_c_it.py_ve_it.py_it.it = ((BPy_ChainSilhouetteIterator *) py_cs_it)->cs_it; return py_cs_it; } diff --git a/source/blender/freestyle/intern/python/BPy_Freestyle.cpp b/source/blender/freestyle/intern/python/BPy_Freestyle.cpp index 6348d30577c..b4170dc4f92 100644 --- a/source/blender/freestyle/intern/python/BPy_Freestyle.cpp +++ b/source/blender/freestyle/intern/python/BPy_Freestyle.cpp @@ -4,6 +4,7 @@ #include "BPy_BinaryPredicate0D.h" #include "BPy_BinaryPredicate1D.h" #include "BPy_Material.h" +#include "BPy_FrsNoise.h" #include "BPy_Id.h" #include "BPy_IntegrationType.h" #include "BPy_Interface0D.h" @@ -12,7 +13,6 @@ #include "BPy_MediumType.h" #include "BPy_Nature.h" #include "BPy_Operators.h" -#include "BPy_Noise.h" #include "BPy_SShape.h" #include "BPy_StrokeAttribute.h" #include "BPy_StrokeShader.h" @@ -148,13 +148,13 @@ PyObject *Freestyle_Init( void ) BinaryPredicate0D_Init( module ); BinaryPredicate1D_Init( module ); Material_Init( module ); + FrsNoise_Init( module ); Id_Init( module ); IntegrationType_Init( module ); Interface0D_Init( module ); Interface1D_Init( module ); Iterator_Init( module ); Operators_Init( module ); - Noise_Init( module ); SShape_Init( module ); StrokeAttribute_Init( module ); StrokeShader_Init( module ); diff --git a/source/blender/freestyle/intern/python/BPy_FrsNoise.cpp b/source/blender/freestyle/intern/python/BPy_FrsNoise.cpp new file mode 100644 index 00000000000..a9989b13c6d --- /dev/null +++ b/source/blender/freestyle/intern/python/BPy_FrsNoise.cpp @@ -0,0 +1,239 @@ +#include "BPy_FrsNoise.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +/*--------------- Python API function prototypes for FrsNoise instance -----------*/ +static int FrsNoise___init__(BPy_FrsNoise *self, PyObject *args, PyObject *kwds); +static void FrsNoise___dealloc__(BPy_FrsNoise *self); +static PyObject * FrsNoise___repr__(BPy_FrsNoise *self); + +static PyObject * FrsNoise_turbulence1( BPy_FrsNoise *self, PyObject *args); +static PyObject * FrsNoise_turbulence2( BPy_FrsNoise *self, PyObject *args); +static PyObject * FrsNoise_turbulence3( BPy_FrsNoise *self, PyObject *args); +static PyObject * FrsNoise_smoothNoise1( BPy_FrsNoise *self, PyObject *args); +static PyObject * FrsNoise_smoothNoise2( BPy_FrsNoise *self, PyObject *args); +static PyObject * FrsNoise_smoothNoise3( BPy_FrsNoise *self, PyObject *args); + +/*----------------------FrsNoise instance definitions ----------------------------*/ +static PyMethodDef BPy_FrsNoise_methods[] = { + {"turbulence1", ( PyCFunction ) FrsNoise_turbulence1, METH_VARARGS, "(float arg, float freq, float amp, unsigned oct=4))Returns a noise value for a 1D element"}, + {"turbulence2", ( PyCFunction ) FrsNoise_turbulence2, METH_VARARGS, "([x, y], float freq, float amp, unsigned oct=4)))Returns a noise value for a 2D element"}, + {"turbulence3", ( PyCFunction ) FrsNoise_turbulence3, METH_VARARGS, "([x, y, z], float freq, float amp, unsigned oct=4)))Returns a noise value for a 3D element"}, + {"smoothNoise1", ( PyCFunction ) FrsNoise_smoothNoise1, METH_VARARGS, "(float arg))Returns a smooth noise value for a 1D element "}, + {"smoothNoise2", ( PyCFunction ) FrsNoise_smoothNoise2, METH_VARARGS, "([x, y]))Returns a smooth noise value for a 2D element "}, + {"smoothNoise3", ( PyCFunction ) FrsNoise_smoothNoise3, METH_VARARGS, "([x, y, z))Returns a smooth noise value for a 3D element "}, + {NULL, NULL, 0, NULL} +}; + +/*-----------------------BPy_FrsNoise type definition ------------------------------*/ + +PyTypeObject FrsNoise_Type = { + PyObject_HEAD_INIT( NULL ) + 0, /* ob_size */ + "FrsNoise", /* tp_name */ + sizeof( BPy_FrsNoise ), /* tp_basicsize */ + 0, /* tp_itemsize */ + + /* methods */ + (destructor)FrsNoise___dealloc__, /* tp_dealloc */ + NULL, /* printfunc tp_print; */ + NULL, /* getattrfunc tp_getattr; */ + NULL, /* setattrfunc tp_setattr; */ + NULL, /* tp_compare */ + (reprfunc)FrsNoise___repr__, /* 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_FrsNoise_methods, /* struct PyMethodDef *tp_methods; */ + NULL, /* struct PyMemberDef *tp_members; */ + NULL, /* struct PyGetSetDef *tp_getset; */ + NULL, /* struct _typeobject *tp_base; */ + NULL, /* PyObject *tp_dict; */ + NULL, /* descrgetfunc tp_descr_get; */ + NULL, /* descrsetfunc tp_descr_set; */ + 0, /* long tp_dictoffset; */ + (initproc)FrsNoise___init__, /* initproc tp_init; */ + NULL, /* allocfunc tp_alloc; */ + PyType_GenericNew, /* 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-------------------------------- +PyMODINIT_FUNC FrsNoise_Init( PyObject *module ) +{ + if( module == NULL ) + return; + + if( PyType_Ready( &FrsNoise_Type ) < 0 ) + return; + + Py_INCREF( &FrsNoise_Type ); + PyModule_AddObject(module, "FrsNoise", (PyObject *)&FrsNoise_Type); +} + +//------------------------INSTANCE METHODS ---------------------------------- + +int FrsNoise___init__(BPy_FrsNoise *self, PyObject *args, PyObject *kwds) +{ + self->n = new Noise(); + return 0; +} + +void FrsNoise___dealloc__(BPy_FrsNoise* self) +{ + delete self->n; + self->ob_type->tp_free((PyObject*)self); +} + + +PyObject * FrsNoise___repr__(BPy_FrsNoise* self) +{ + return PyString_FromFormat("FrsNoise - address: %p", self->n ); +} + + +PyObject * FrsNoise_turbulence1( BPy_FrsNoise *self , PyObject *args) { + float f1, f2, f3; + unsigned int i; + + if(!( PyArg_ParseTuple(args, "fff|I", &f1, &f2, &f3, &i) )) { + cout << "ERROR: FrsNoise_turbulence1" << endl; + Py_RETURN_NONE; + } + + return PyFloat_FromDouble( self->n->turbulence1(f1, f2, f3, i) ); +} + +PyObject * FrsNoise_turbulence2( BPy_FrsNoise *self , PyObject *args) { + PyObject *obj1; + float f2, f3; + unsigned int i; + + if(!( PyArg_ParseTuple(args, "Off|I", &obj1, &f2, &f3, &i) && PyList_Check(obj1) && PyList_Size(obj1) > 1 )) { + cout << "ERROR: FrsNoise_turbulence2" << endl; + Py_RETURN_NONE; + } + + Vec2f v( PyFloat_AsDouble(PyList_GetItem(obj1, 0)), PyFloat_AsDouble(PyList_GetItem(obj1, 1)) ); + + return PyFloat_FromDouble( self->n->turbulence2(v, f2, f3, i) ); +} + +PyObject * FrsNoise_turbulence3( BPy_FrsNoise *self , PyObject *args) { + PyObject *obj1; + float f2, f3; + unsigned int i; + + if(!( PyArg_ParseTuple(args, "Off|I", &obj1, &f2, &f3, &i) && PyList_Check(obj1) && PyList_Size(obj1) > 2 )) { + cout << "ERROR: FrsNoise_turbulence3" << endl; + Py_RETURN_NONE; + } + + Vec3f v( PyFloat_AsDouble(PyList_GetItem(obj1, 0)), + PyFloat_AsDouble(PyList_GetItem(obj1, 1)), + PyFloat_AsDouble(PyList_GetItem(obj1, 2)) ); + + return PyFloat_FromDouble( self->n->turbulence3(v, f2, f3, i) ); +} + +PyObject * FrsNoise_smoothNoise1( BPy_FrsNoise *self , PyObject *args) { + float f; + + if(!( PyArg_ParseTuple(args, "f", &f) )) { + cout << "ERROR: FrsNoise_smoothNoise1" << endl; + Py_RETURN_NONE; + } + + return PyFloat_FromDouble( self->n->smoothNoise1(f) ); +} + +PyObject * FrsNoise_smoothNoise2( BPy_FrsNoise *self , PyObject *args) { + PyObject *obj; + + if(!( PyArg_ParseTuple(args, "O", &obj) && PyList_Check(obj) && PyList_Size(obj) > 1 )) { + cout << "ERROR: FrsNoise_smoothNoise2" << endl; + Py_RETURN_NONE; + } + + Vec2f v( PyFloat_AsDouble(PyList_GetItem(obj, 0)), PyFloat_AsDouble(PyList_GetItem(obj, 1)) ); + + return PyFloat_FromDouble( self->n->smoothNoise2(v) ); +} + +PyObject * FrsNoise_smoothNoise3( BPy_FrsNoise *self , PyObject *args) { + PyObject *obj; + + if(!( PyArg_ParseTuple(args, "O", &obj) && PyList_Check(obj) && PyList_Size(obj) > 2 )) { + cout << "ERROR: FrsNoise_smoothNoise3" << endl; + Py_RETURN_NONE; + } + + Vec3f v( PyFloat_AsDouble(PyList_GetItem(obj, 0)), + PyFloat_AsDouble(PyList_GetItem(obj, 1)), + PyFloat_AsDouble(PyList_GetItem(obj, 2)) ); + + return PyFloat_FromDouble( self->n->smoothNoise3(v) ); +} + + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/freestyle/intern/python/BPy_FrsNoise.h b/source/blender/freestyle/intern/python/BPy_FrsNoise.h new file mode 100644 index 00000000000..d0215fda9af --- /dev/null +++ b/source/blender/freestyle/intern/python/BPy_FrsNoise.h @@ -0,0 +1,36 @@ +#ifndef FREESTYLE_PYTHON_FRSNOISE_H +#define FREESTYLE_PYTHON_FRSNOISE_H + +#include "../geometry/Noise.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +#include + +extern PyTypeObject FrsNoise_Type; + +#define BPy_FrsNoise_Check(v) ( PyObject_IsInstance( (PyObject *) v, (PyObject *) &FrsNoise_Type) ) + +/*---------------------------Python BPy_FrsNoise structure definition----------*/ +typedef struct { + PyObject_HEAD + Noise *n; +} BPy_FrsNoise; + +/*---------------------------Python BPy_FrsNoise visible prototypes-----------*/ + +PyMODINIT_FUNC FrsNoise_Init( PyObject *module ); + + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif + + +#endif /* FREESTYLE_PYTHON_FRSNOISE_H */ diff --git a/source/blender/freestyle/intern/python/BPy_Interface1D.cpp b/source/blender/freestyle/intern/python/BPy_Interface1D.cpp index 509dfb23894..3db9531da4b 100644 --- a/source/blender/freestyle/intern/python/BPy_Interface1D.cpp +++ b/source/blender/freestyle/intern/python/BPy_Interface1D.cpp @@ -1,7 +1,7 @@ #include "BPy_Interface1D.h" #include "BPy_Convert.h" -#include "Interface1D/BPy_Curve.h" +#include "Interface1D/BPy_FrsCurve.h" #include "Interface1D/Curve/BPy_Chain.h" #include "Interface1D/BPy_FEdge.h" #include "Interface1D/FEdge/BPy_FEdgeSharp.h" @@ -142,10 +142,10 @@ PyMODINIT_FUNC Interface1D_Init( PyObject *module ) Py_INCREF( &Interface1D_Type ); PyModule_AddObject(module, "Interface1D", (PyObject *)&Interface1D_Type); - if( PyType_Ready( &Curve_Type ) < 0 ) + if( PyType_Ready( &FrsCurve_Type ) < 0 ) return; - Py_INCREF( &Curve_Type ); - PyModule_AddObject(module, "Curve", (PyObject *)&Curve_Type); + Py_INCREF( &FrsCurve_Type ); + PyModule_AddObject(module, "FrsCurve", (PyObject *)&FrsCurve_Type); if( PyType_Ready( &Chain_Type ) < 0 ) return; diff --git a/source/blender/freestyle/intern/python/BPy_Iterator.cpp b/source/blender/freestyle/intern/python/BPy_Iterator.cpp index cf6d8ed4877..23dd68e0aa8 100644 --- a/source/blender/freestyle/intern/python/BPy_Iterator.cpp +++ b/source/blender/freestyle/intern/python/BPy_Iterator.cpp @@ -227,14 +227,11 @@ PyObject * Iterator_isEnd(BPy_Iterator* self) { return PyBool_from_bool( self->it->isEnd() ); } -//%rename(getObject) Interface0DIterator::operator* PyObject * Iterator_getObject(BPy_Iterator* self) { return PyBool_from_bool( self->it->isEnd() ); } - - /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/BPy_Noise.cpp b/source/blender/freestyle/intern/python/BPy_Noise.cpp deleted file mode 100644 index f8d5d6b066d..00000000000 --- a/source/blender/freestyle/intern/python/BPy_Noise.cpp +++ /dev/null @@ -1,239 +0,0 @@ -#include "BPy_Noise.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/////////////////////////////////////////////////////////////////////////////////////////// - -/*--------------- Python API function prototypes for Noise instance -----------*/ -static int Noise___init__(BPy_Noise *self, PyObject *args, PyObject *kwds); -static void Noise___dealloc__(BPy_Noise *self); -static PyObject * Noise___repr__(BPy_Noise *self); - -static PyObject * Noise_turbulence1( BPy_Noise *self, PyObject *args); -static PyObject * Noise_turbulence2( BPy_Noise *self, PyObject *args); -static PyObject * Noise_turbulence3( BPy_Noise *self, PyObject *args); -static PyObject * Noise_smoothNoise1( BPy_Noise *self, PyObject *args); -static PyObject * Noise_smoothNoise2( BPy_Noise *self, PyObject *args); -static PyObject * Noise_smoothNoise3( BPy_Noise *self, PyObject *args); - -/*----------------------Noise instance definitions ----------------------------*/ -static PyMethodDef BPy_Noise_methods[] = { - {"turbulence1", ( PyCFunction ) Noise_turbulence1, METH_VARARGS, "(float arg, float freq, float amp, unsigned oct=4))Returns a noise value for a 1D element"}, - {"turbulence2", ( PyCFunction ) Noise_turbulence2, METH_VARARGS, "([x, y], float freq, float amp, unsigned oct=4)))Returns a noise value for a 2D element"}, - {"turbulence3", ( PyCFunction ) Noise_turbulence3, METH_VARARGS, "([x, y, z], float freq, float amp, unsigned oct=4)))Returns a noise value for a 3D element"}, - {"smoothNoise1", ( PyCFunction ) Noise_smoothNoise1, METH_VARARGS, "(float arg))Returns a smooth noise value for a 1D element "}, - {"smoothNoise2", ( PyCFunction ) Noise_smoothNoise2, METH_VARARGS, "([x, y]))Returns a smooth noise value for a 2D element "}, - {"smoothNoise3", ( PyCFunction ) Noise_smoothNoise3, METH_VARARGS, "([x, y, z))Returns a smooth noise value for a 3D element "}, - {NULL, NULL, 0, NULL} -}; - -/*-----------------------BPy_Noise type definition ------------------------------*/ - -PyTypeObject Noise_Type = { - PyObject_HEAD_INIT( NULL ) - 0, /* ob_size */ - "Noise", /* tp_name */ - sizeof( BPy_Noise ), /* tp_basicsize */ - 0, /* tp_itemsize */ - - /* methods */ - (destructor)Noise___dealloc__, /* tp_dealloc */ - NULL, /* printfunc tp_print; */ - NULL, /* getattrfunc tp_getattr; */ - NULL, /* setattrfunc tp_setattr; */ - NULL, /* tp_compare */ - (reprfunc)Noise___repr__, /* 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_Noise_methods, /* struct PyMethodDef *tp_methods; */ - NULL, /* struct PyMemberDef *tp_members; */ - NULL, /* struct PyGetSetDef *tp_getset; */ - NULL, /* struct _typeobject *tp_base; */ - NULL, /* PyObject *tp_dict; */ - NULL, /* descrgetfunc tp_descr_get; */ - NULL, /* descrsetfunc tp_descr_set; */ - 0, /* long tp_dictoffset; */ - (initproc)Noise___init__, /* initproc tp_init; */ - NULL, /* allocfunc tp_alloc; */ - PyType_GenericNew, /* 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-------------------------------- -PyMODINIT_FUNC Noise_Init( PyObject *module ) -{ - if( module == NULL ) - return; - - if( PyType_Ready( &Noise_Type ) < 0 ) - return; - - Py_INCREF( &Noise_Type ); - PyModule_AddObject(module, "Noise", (PyObject *)&Noise_Type); -} - -//------------------------INSTANCE METHODS ---------------------------------- - -int Noise___init__(BPy_Noise *self, PyObject *args, PyObject *kwds) -{ - self->n = new Noise(); - return 0; -} - -void Noise___dealloc__(BPy_Noise* self) -{ - delete self->n; - self->ob_type->tp_free((PyObject*)self); -} - - -PyObject * Noise___repr__(BPy_Noise* self) -{ - return PyString_FromFormat("Noise - address: %p", self->n ); -} - - -PyObject * Noise_turbulence1( BPy_Noise *self , PyObject *args) { - float f1, f2, f3; - unsigned int i; - - if(!( PyArg_ParseTuple(args, "fff|I", &f1, &f2, &f3, &i) )) { - cout << "ERROR: Noise_turbulence1" << endl; - Py_RETURN_NONE; - } - - return PyFloat_FromDouble( self->n->turbulence1(f1, f2, f3, i) ); -} - -PyObject * Noise_turbulence2( BPy_Noise *self , PyObject *args) { - PyObject *obj1; - float f2, f3; - unsigned int i; - - if(!( PyArg_ParseTuple(args, "Off|I", &obj1, &f2, &f3, &i) && PyList_Check(obj1) && PyList_Size(obj1) > 1 )) { - cout << "ERROR: Noise_turbulence2" << endl; - Py_RETURN_NONE; - } - - Vec2f v( PyFloat_AsDouble(PyList_GetItem(obj1, 0)), PyFloat_AsDouble(PyList_GetItem(obj1, 1)) ); - - return PyFloat_FromDouble( self->n->turbulence2(v, f2, f3, i) ); -} - -PyObject * Noise_turbulence3( BPy_Noise *self , PyObject *args) { - PyObject *obj1; - float f2, f3; - unsigned int i; - - if(!( PyArg_ParseTuple(args, "Off|I", &obj1, &f2, &f3, &i) && PyList_Check(obj1) && PyList_Size(obj1) > 2 )) { - cout << "ERROR: Noise_turbulence3" << endl; - Py_RETURN_NONE; - } - - Vec3f v( PyFloat_AsDouble(PyList_GetItem(obj1, 0)), - PyFloat_AsDouble(PyList_GetItem(obj1, 1)), - PyFloat_AsDouble(PyList_GetItem(obj1, 2)) ); - - return PyFloat_FromDouble( self->n->turbulence3(v, f2, f3, i) ); -} - -PyObject * Noise_smoothNoise1( BPy_Noise *self , PyObject *args) { - float f; - - if(!( PyArg_ParseTuple(args, "f", &f) )) { - cout << "ERROR: Noise_smoothNoise1" << endl; - Py_RETURN_NONE; - } - - return PyFloat_FromDouble( self->n->smoothNoise1(f) ); -} - -PyObject * Noise_smoothNoise2( BPy_Noise *self , PyObject *args) { - PyObject *obj; - - if(!( PyArg_ParseTuple(args, "O", &obj) && PyList_Check(obj) && PyList_Size(obj) > 1 )) { - cout << "ERROR: Noise_smoothNoise2" << endl; - Py_RETURN_NONE; - } - - Vec2f v( PyFloat_AsDouble(PyList_GetItem(obj, 0)), PyFloat_AsDouble(PyList_GetItem(obj, 1)) ); - - return PyFloat_FromDouble( self->n->smoothNoise2(v) ); -} - -PyObject * Noise_smoothNoise3( BPy_Noise *self , PyObject *args) { - PyObject *obj; - - if(!( PyArg_ParseTuple(args, "O", &obj) && PyList_Check(obj) && PyList_Size(obj) > 2 )) { - cout << "ERROR: Noise_smoothNoise3" << endl; - Py_RETURN_NONE; - } - - Vec3f v( PyFloat_AsDouble(PyList_GetItem(obj, 0)), - PyFloat_AsDouble(PyList_GetItem(obj, 1)), - PyFloat_AsDouble(PyList_GetItem(obj, 2)) ); - - return PyFloat_FromDouble( self->n->smoothNoise3(v) ); -} - - -/////////////////////////////////////////////////////////////////////////////////////////// - -#ifdef __cplusplus -} -#endif diff --git a/source/blender/freestyle/intern/python/BPy_Noise.h b/source/blender/freestyle/intern/python/BPy_Noise.h deleted file mode 100644 index 5dc8a1a4bd1..00000000000 --- a/source/blender/freestyle/intern/python/BPy_Noise.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef FREESTYLE_PYTHON_NOISE_H -#define FREESTYLE_PYTHON_NOISE_H - -#include "../geometry/Noise.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/////////////////////////////////////////////////////////////////////////////////////////// - -#include - -extern PyTypeObject Noise_Type; - -#define BPy_Noise_Check(v) ( PyObject_IsInstance( (PyObject *) v, (PyObject *) &Noise_Type) ) - -/*---------------------------Python BPy_Noise structure definition----------*/ -typedef struct { - PyObject_HEAD - Noise *n; -} BPy_Noise; - -/*---------------------------Python BPy_Noise visible prototypes-----------*/ - -PyMODINIT_FUNC Noise_Init( PyObject *module ); - - -/////////////////////////////////////////////////////////////////////////////////////////// - -#ifdef __cplusplus -} -#endif - - -#endif /* FREESTYLE_PYTHON_NOISE_H */ diff --git a/source/blender/freestyle/intern/python/Director.cpp b/source/blender/freestyle/intern/python/Director.cpp index d3aff4a65f2..42677919ca5 100644 --- a/source/blender/freestyle/intern/python/Director.cpp +++ b/source/blender/freestyle/intern/python/Director.cpp @@ -61,7 +61,6 @@ ViewEdge * Director_BPy_ChainingIterator_traverse( PyObject *obj, AdjacencyItera return ((BPy_ViewEdge *) result)->ve; } - // BPy_UnaryFunction{0D,1D}: __call__ // BPy_UnaryFunction0DDouble // BPy_UnaryFunction0DEdgeNature @@ -83,4 +82,26 @@ ViewEdge * Director_BPy_ChainingIterator_traverse( PyObject *obj, AdjacencyItera // BPy_UnaryFunction1DVectorViewShape // BPy_UnaryFunction1DVoid +// BPy_Iterator: increment, decrement, isBegin, isEnd +void Director_BPy_Iterator_increment( PyObject *obj ) { + PyObject_CallMethod( obj, "increment", "", 0 ); +} + +void Director_BPy_Iterator_decrement( PyObject *obj ) { + PyObject_CallMethod( obj, "decrement", "", 0 ); +} + +bool Director_BPy_Iterator_isBegin( PyObject *obj ) { + PyObject *result = PyObject_CallMethod( obj, "isBegin", "", 0 ); + + return bool_from_PyBool(result); +} + +bool Director_BPy_Iterator_isEnd( PyObject *obj ) { + PyObject *result = PyObject_CallMethod( obj, "isEnd", "", 0 ); + + return bool_from_PyBool(result); +} + + diff --git a/source/blender/freestyle/intern/python/Director.h b/source/blender/freestyle/intern/python/Director.h index 95ab16047a8..2a67be237f5 100644 --- a/source/blender/freestyle/intern/python/Director.h +++ b/source/blender/freestyle/intern/python/Director.h @@ -59,7 +59,10 @@ double Director_BPy_UnaryFunction0DDouble___call__( PyObject *obj, Interface0DIt // BPy_UnaryFunction1DVoid void Director_BPy_UnaryFunction1DVoid___call__( PyObject *obj, Interface1D& if1D); - - +// BPy_Iterator: increment, decrement, isBegin, isEnd +void Director_BPy_Iterator_increment( PyObject *obj ); +void Director_BPy_Iterator_decrement( PyObject *obj ); +bool Director_BPy_Iterator_isBegin( PyObject *obj ); +bool Director_BPy_Iterator_isEnd( PyObject *obj ); #endif // FREESTYLE_PYTHON_DIRECTOR diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_Curve.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_Curve.cpp deleted file mode 100644 index b0f043a6525..00000000000 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_Curve.cpp +++ /dev/null @@ -1,249 +0,0 @@ -#include "BPy_Curve.h" - -#include "../BPy_Convert.h" -#include "../BPy_Id.h" -#include "../Interface0D/BPy_CurvePoint.h" -#include "../Interface0D/BPy_SVertex.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/////////////////////////////////////////////////////////////////////////////////////////// - -/*--------------- Python API function prototypes for Curve instance -----------*/ -static int Curve___init__(BPy_Curve *self, PyObject *args, PyObject *kwds); -static PyObject * Curve_push_vertex_back( BPy_Curve *self, PyObject *args ); -static PyObject * Curve_push_vertex_front( BPy_Curve *self, PyObject *args ); -static PyObject * Curve_empty( BPy_Curve *self ); -static PyObject * Curve_nSegments( BPy_Curve *self ); -// point_iterator points_begin (float step=0) -static PyObject * Curve_verticesBegin( BPy_Curve *self ); -static PyObject * Curve_verticesEnd( BPy_Curve *self ); -static PyObject * Curve_pointsBegin( BPy_Curve *self, PyObject *args ); -static PyObject * Curve_pointsEnd( BPy_Curve *self, PyObject *args ); - -/*----------------------Curve instance definitions ----------------------------*/ -static PyMethodDef BPy_Curve_methods[] = { - {"push_vertex_back", ( PyCFunction ) Curve_push_vertex_back, METH_VARARGS, "(CurvePoint cp | SVertex sv) Adds a single vertex at the front of the Curve."}, - {"push_vertex_front", ( PyCFunction ) Curve_push_vertex_front, METH_VARARGS, "(CurvePoint cp | SVertex sv) Adds a single vertex at the end of the Curve."}, - {"empty", ( PyCFunction ) Curve_empty, METH_NOARGS, "() Returns true is the Curve doesn't have any Vertex yet."}, - {"nSegments", ( PyCFunction ) Curve_nSegments, METH_NOARGS, "() Returns the number of segments in the oplyline constituing the Curve."}, - {"verticesBegin", ( PyCFunction ) Curve_verticesBegin, METH_NOARGS, "() Returns an Interface0DIterator pointing onto the first vertex of the Curve and that can iterate over the vertices of the Curve."}, - {"verticesEnd", ( PyCFunction ) Curve_verticesEnd, METH_NOARGS, "() Returns an Interface0DIterator pointing after the last vertex of the Curve and that can iterate over the vertices of the Curve."}, - {"pointsBegin", ( PyCFunction ) Curve_pointsBegin, METH_VARARGS, "(float t=0) Returns an Interface0DIterator pointing onto the first point of the Curve and that can iterate over the points of the Curve at any resolution t. At each iteration a virtual temporary CurvePoint is created."}, - {"pointsEnd", ( PyCFunction ) Curve_pointsEnd, METH_VARARGS, "(float t=0) Returns an Interface0DIterator pointing after the last point of the Curve and that can iterate over the points of the Curve at any resolution t. At each iteration a virtual temporary CurvePoint is created."}, - {NULL, NULL, 0, NULL} -}; - -/*-----------------------BPy_Curve type definition ------------------------------*/ - -PyTypeObject Curve_Type = { - PyObject_HEAD_INIT( NULL ) - 0, /* ob_size */ - "Curve", /* tp_name */ - sizeof( BPy_Curve ), /* 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_Curve_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)Curve___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 Curve___init__(BPy_Curve *self, PyObject *args, PyObject *kwds) -{ - - PyObject *obj = 0; - - if (! PyArg_ParseTuple(args, "|O", &obj) ) - return -1; - - if( !obj ){ - self->c = new Curve(); - - } else if( BPy_Curve_Check(obj) ) { - if( ((BPy_Curve *) obj)->c ) - self->c = new Curve(*( ((BPy_Curve *) obj)->c )); - else - return -1; - - } else if( BPy_Id_Check(obj) ) { - if( ((BPy_Id *) obj)->id ) - self->c = new Curve(*( ((BPy_Id *) obj)->id )); - else - return -1; - - } else { - return -1; - } - - self->py_if1D.if1D = self->c; - - return 0; -} - - -PyObject * Curve_push_vertex_back( BPy_Curve *self, PyObject *args ) { - PyObject *obj; - - if(!( PyArg_ParseTuple(args, "O", &obj) )) { - cout << "ERROR: Curve_push_vertex_back" << endl; - Py_RETURN_NONE; - } - - if( BPy_CurvePoint_Check(obj) ) { - self->c->push_vertex_back( ((BPy_CurvePoint *) obj)->cp ); - } else if( BPy_SVertex_Check(obj) ) { - self->c->push_vertex_back( ((BPy_SVertex *) obj)->sv ); - } - - Py_RETURN_NONE; -} - -PyObject * Curve_push_vertex_front( BPy_Curve *self, PyObject *args ) { - PyObject *obj; - - if(!( PyArg_ParseTuple(args, "O", &obj) )) { - cout << "ERROR: Curve_push_vertex_front" << endl; - Py_RETURN_NONE; - } - - if( BPy_CurvePoint_Check(obj) ) { - self->c->push_vertex_front( ((BPy_CurvePoint *) obj)->cp ); - } else if( BPy_SVertex_Check(obj) ) { - self->c->push_vertex_front( ((BPy_SVertex *) obj)->sv ); - } - - Py_RETURN_NONE; - } - -PyObject * Curve_empty( BPy_Curve *self ) { - return PyBool_from_bool( self->c->empty() ); -} - -PyObject * Curve_nSegments( BPy_Curve *self ) { - return PyInt_FromLong( self->c->nSegments() ); -} - -// point_iterator points_begin (float step=0) -// not implemented - - -PyObject * Curve_verticesBegin( BPy_Curve *self ) { - Interface0DIterator if0D_it( self->c->verticesBegin() ); - return BPy_Interface0DIterator_from_Interface0DIterator( if0D_it ); -} - -PyObject * Curve_verticesEnd( BPy_Curve *self ) { - Interface0DIterator if0D_it( self->c->verticesEnd() ); - return BPy_Interface0DIterator_from_Interface0DIterator( if0D_it ); -} - - -PyObject * Curve_pointsBegin( BPy_Curve *self, PyObject *args ) { - float f = 0; - - if(!( PyArg_ParseTuple(args, "|f", &f) )) { - cout << "ERROR: FEdge_pointsBegin" << endl; - Py_RETURN_NONE; - } - - Interface0DIterator if0D_it( self->c->pointsBegin(f) ); - return BPy_Interface0DIterator_from_Interface0DIterator( if0D_it ); -} - -PyObject * Curve_pointsEnd( BPy_Curve *self, PyObject *args ) { - float f = 0; - - if(!( PyArg_ParseTuple(args, "|f", &f) )) { - cout << "ERROR: FEdge_pointsEnd" << endl; - Py_RETURN_NONE; - } - - Interface0DIterator if0D_it( self->c->pointsEnd(f) ); - return BPy_Interface0DIterator_from_Interface0DIterator( if0D_it ); -} - - - -/////////////////////////////////////////////////////////////////////////////////////////// - -#ifdef __cplusplus -} -#endif diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_Curve.h b/source/blender/freestyle/intern/python/Interface1D/BPy_Curve.h deleted file mode 100644 index fd29a7bf4f1..00000000000 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_Curve.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef FREESTYLE_PYTHON_CURVE_H -#define FREESTYLE_PYTHON_CURVE_H - -#include "../BPy_Interface1D.h" -#include "../../stroke/Curve.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/////////////////////////////////////////////////////////////////////////////////////////// - -#include - -extern PyTypeObject Curve_Type; - -#define BPy_Curve_Check(v) ( PyObject_IsInstance( (PyObject *) v, (PyObject *) &Curve_Type) ) - -/*---------------------------Python BPy_Curve structure definition----------*/ -typedef struct { - BPy_Interface1D py_if1D; - Curve *c; -} BPy_Curve; - -/////////////////////////////////////////////////////////////////////////////////////////// - -#ifdef __cplusplus -} -#endif - -#endif /* FREESTYLE_PYTHON_CURVE_H */ diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp new file mode 100644 index 00000000000..1506092511a --- /dev/null +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp @@ -0,0 +1,249 @@ +#include "BPy_FrsCurve.h" + +#include "../BPy_Convert.h" +#include "../BPy_Id.h" +#include "../Interface0D/BPy_CurvePoint.h" +#include "../Interface0D/BPy_SVertex.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +/*--------------- Python API function prototypes for FrsCurve instance -----------*/ +static int FrsCurve___init__(BPy_FrsCurve *self, PyObject *args, PyObject *kwds); +static PyObject * FrsCurve_push_vertex_back( BPy_FrsCurve *self, PyObject *args ); +static PyObject * FrsCurve_push_vertex_front( BPy_FrsCurve *self, PyObject *args ); +static PyObject * FrsCurve_empty( BPy_FrsCurve *self ); +static PyObject * FrsCurve_nSegments( BPy_FrsCurve *self ); +// point_iterator points_begin (float step=0) +static PyObject * FrsCurve_verticesBegin( BPy_FrsCurve *self ); +static PyObject * FrsCurve_verticesEnd( BPy_FrsCurve *self ); +static PyObject * FrsCurve_pointsBegin( BPy_FrsCurve *self, PyObject *args ); +static PyObject * FrsCurve_pointsEnd( BPy_FrsCurve *self, PyObject *args ); + +/*----------------------FrsCurve instance definitions ----------------------------*/ +static PyMethodDef BPy_FrsCurve_methods[] = { + {"push_vertex_back", ( PyCFunction ) FrsCurve_push_vertex_back, METH_VARARGS, "(CurvePoint cp | SVertex sv) Adds a single vertex at the front of the Curve."}, + {"push_vertex_front", ( PyCFunction ) FrsCurve_push_vertex_front, METH_VARARGS, "(CurvePoint cp | SVertex sv) Adds a single vertex at the end of the Curve."}, + {"empty", ( PyCFunction ) FrsCurve_empty, METH_NOARGS, "() Returns true is the Curve doesn't have any Vertex yet."}, + {"nSegments", ( PyCFunction ) FrsCurve_nSegments, METH_NOARGS, "() Returns the number of segments in the oplyline constituing the Curve."}, + {"verticesBegin", ( PyCFunction ) FrsCurve_verticesBegin, METH_NOARGS, "() Returns an Interface0DIterator pointing onto the first vertex of the Curve and that can iterate over the vertices of the Curve."}, + {"verticesEnd", ( PyCFunction ) FrsCurve_verticesEnd, METH_NOARGS, "() Returns an Interface0DIterator pointing after the last vertex of the Curve and that can iterate over the vertices of the Curve."}, + {"pointsBegin", ( PyCFunction ) FrsCurve_pointsBegin, METH_VARARGS, "(float t=0) Returns an Interface0DIterator pointing onto the first point of the Curve and that can iterate over the points of the Curve at any resolution t. At each iteration a virtual temporary CurvePoint is created."}, + {"pointsEnd", ( PyCFunction ) FrsCurve_pointsEnd, METH_VARARGS, "(float t=0) Returns an Interface0DIterator pointing after the last point of the Curve and that can iterate over the points of the Curve at any resolution t. At each iteration a virtual temporary CurvePoint is created."}, + {NULL, NULL, 0, NULL} +}; + +/*-----------------------BPy_FrsCurve type definition ------------------------------*/ + +PyTypeObject FrsCurve_Type = { + PyObject_HEAD_INIT( NULL ) + 0, /* ob_size */ + "FrsCurve", /* tp_name */ + sizeof( BPy_FrsCurve ), /* 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_FrsCurve_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)FrsCurve___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 FrsCurve___init__(BPy_FrsCurve *self, PyObject *args, PyObject *kwds) +{ + + PyObject *obj = 0; + + if (! PyArg_ParseTuple(args, "|O", &obj) ) + return -1; + + if( !obj ){ + self->c = new Curve(); + + } else if( BPy_FrsCurve_Check(obj) ) { + if( ((BPy_FrsCurve *) obj)->c ) + self->c = new Curve(*( ((BPy_FrsCurve *) obj)->c )); + else + return -1; + + } else if( BPy_Id_Check(obj) ) { + if( ((BPy_Id *) obj)->id ) + self->c = new Curve(*( ((BPy_Id *) obj)->id )); + else + return -1; + + } else { + return -1; + } + + self->py_if1D.if1D = self->c; + + return 0; +} + + +PyObject * FrsCurve_push_vertex_back( BPy_FrsCurve *self, PyObject *args ) { + PyObject *obj; + + if(!( PyArg_ParseTuple(args, "O", &obj) )) { + cout << "ERROR: FrsCurve_push_vertex_back" << endl; + Py_RETURN_NONE; + } + + if( BPy_CurvePoint_Check(obj) ) { + self->c->push_vertex_back( ((BPy_CurvePoint *) obj)->cp ); + } else if( BPy_SVertex_Check(obj) ) { + self->c->push_vertex_back( ((BPy_SVertex *) obj)->sv ); + } + + Py_RETURN_NONE; +} + +PyObject * FrsCurve_push_vertex_front( BPy_FrsCurve *self, PyObject *args ) { + PyObject *obj; + + if(!( PyArg_ParseTuple(args, "O", &obj) )) { + cout << "ERROR: FrsCurve_push_vertex_front" << endl; + Py_RETURN_NONE; + } + + if( BPy_CurvePoint_Check(obj) ) { + self->c->push_vertex_front( ((BPy_CurvePoint *) obj)->cp ); + } else if( BPy_SVertex_Check(obj) ) { + self->c->push_vertex_front( ((BPy_SVertex *) obj)->sv ); + } + + Py_RETURN_NONE; + } + +PyObject * FrsCurve_empty( BPy_FrsCurve *self ) { + return PyBool_from_bool( self->c->empty() ); +} + +PyObject * FrsCurve_nSegments( BPy_FrsCurve *self ) { + return PyInt_FromLong( self->c->nSegments() ); +} + +// point_iterator points_begin (float step=0) +// not implemented + + +PyObject * FrsCurve_verticesBegin( BPy_FrsCurve *self ) { + Interface0DIterator if0D_it( self->c->verticesBegin() ); + return BPy_Interface0DIterator_from_Interface0DIterator( if0D_it ); +} + +PyObject * FrsCurve_verticesEnd( BPy_FrsCurve *self ) { + Interface0DIterator if0D_it( self->c->verticesEnd() ); + return BPy_Interface0DIterator_from_Interface0DIterator( if0D_it ); +} + + +PyObject * FrsCurve_pointsBegin( BPy_FrsCurve *self, PyObject *args ) { + float f = 0; + + if(!( PyArg_ParseTuple(args, "|f", &f) )) { + cout << "ERROR: FEdge_pointsBegin" << endl; + Py_RETURN_NONE; + } + + Interface0DIterator if0D_it( self->c->pointsBegin(f) ); + return BPy_Interface0DIterator_from_Interface0DIterator( if0D_it ); +} + +PyObject * FrsCurve_pointsEnd( BPy_FrsCurve *self, PyObject *args ) { + float f = 0; + + if(!( PyArg_ParseTuple(args, "|f", &f) )) { + cout << "ERROR: FEdge_pointsEnd" << endl; + Py_RETURN_NONE; + } + + Interface0DIterator if0D_it( self->c->pointsEnd(f) ); + return BPy_Interface0DIterator_from_Interface0DIterator( if0D_it ); +} + + + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.h b/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.h new file mode 100644 index 00000000000..0829cf0ebf5 --- /dev/null +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.h @@ -0,0 +1,31 @@ +#ifndef FREESTYLE_PYTHON_FRSCURVE_H +#define FREESTYLE_PYTHON_FRSCURVE_H + +#include "../BPy_Interface1D.h" +#include "../../stroke/Curve.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +#include + +extern PyTypeObject FrsCurve_Type; + +#define BPy_FrsCurve_Check(v) ( PyObject_IsInstance( (PyObject *) v, (PyObject *) &FrsCurve_Type) ) + +/*---------------------------Python BPy_FrsCurve structure definition----------*/ +typedef struct { + BPy_Interface1D py_if1D; + Curve *c; +} BPy_FrsCurve; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif + +#endif /* FREESTYLE_PYTHON_FRSCURVE_H */ diff --git a/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.cpp b/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.cpp index 8b6240986b9..7116c574c76 100644 --- a/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.cpp @@ -84,7 +84,7 @@ PyTypeObject Chain_Type = { BPy_Chain_methods, /* struct PyMethodDef *tp_methods; */ NULL, /* struct PyMemberDef *tp_members; */ NULL, /* struct PyGetSetDef *tp_getset; */ - &Curve_Type, /* struct _typeobject *tp_base; */ + &FrsCurve_Type, /* struct _typeobject *tp_base; */ NULL, /* PyObject *tp_dict; */ NULL, /* descrgetfunc tp_descr_get; */ NULL, /* descrsetfunc tp_descr_set; */ diff --git a/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.h b/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.h index ade70c47f25..19f325ef513 100644 --- a/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.h +++ b/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.h @@ -1,7 +1,7 @@ #ifndef FREESTYLE_PYTHON_CHAIN_H #define FREESTYLE_PYTHON_CHAIN_H -#include "../BPy_Curve.h" +#include "../BPy_FrsCurve.h" #include "../../../stroke/Chain.h" #ifdef __cplusplus @@ -18,7 +18,7 @@ extern PyTypeObject Chain_Type; /*---------------------------Python BPy_Chain structure definition----------*/ typedef struct { - BPy_Curve py_c; + BPy_FrsCurve py_c; Chain *c; } BPy_Chain; diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp index 13c8382c3a2..139db9dd73f 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp @@ -134,6 +134,7 @@ int AdjacencyIterator___init__(BPy_AdjacencyIterator *self, PyObject *args ) } self->py_it.it = self->a_it; + return 0; } diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.cpp index c5ff61e239f..3d41e4b66c1 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.cpp @@ -142,6 +142,7 @@ int ChainPredicateIterator___init__(BPy_ChainPredicateIterator *self, PyObject * self->py_c_it.py_ve_it.ve_it = self->cp_it; self->py_c_it.py_ve_it.py_it.it = self->cp_it; + return 0; } diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp index 92c3a7dfc38..1b3a37b5518 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp @@ -123,8 +123,8 @@ int Interface0DIterator___init__(BPy_Interface0DIterator *self, PyObject *args ) self->if0D_it = new Interface0DIterator(*( ((BPy_Interface0DIterator *) obj)->if0D_it )); self->py_it.it = self->if0D_it; + return 0; - } PyObject * Interface0DIterator_t( BPy_Interface0DIterator *self ) { diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp index 1f3e3c05d91..0547c173249 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp @@ -143,7 +143,7 @@ int ViewEdgeIterator___init__(BPy_ViewEdgeIterator *self, PyObject *args ) } self->py_it.it = self->ve_it; - + return 0; } -- cgit v1.2.3