[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15877] branches/soc-2008-mxcurioni/source /blender/freestyle: soc-2008-mxcurioni: Tested SWIG-less environment more and understood why the former predicate methods were not working .
Maxime Curioni
maxime.curioni at gmail.com
Wed Jul 30 03:51:42 CEST 2008
Revision: 15877
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15877
Author: mxcurioni
Date: 2008-07-30 03:51:40 +0200 (Wed, 30 Jul 2008)
Log Message:
-----------
soc-2008-mxcurioni: Tested SWIG-less environment more and understood why the former predicate methods were not working. As St?\195?\169phane had mentioned a few months ago, Freestyle uses SWIG directors to provide cross-language polymorphism. The API and the system I had provided did not support that feature and only implementations in C++ were supported. To correct the problem, after researching how directors are implemented in SWIG, I provided the same functionality. So far, I only provided the code for the UnaryPredicate1D class and it works. The implementation is in intern/python/Director.cpp and Operators.cpp. I will port the remaining directors tonight and continue to test it.
To prevent strokes from piling up after each render, I clear the canvas at each render now (as it should have been all along)
Modified Paths:
--------------
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/api.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.h
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Operators.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Predicates1D.h
branches/soc-2008-mxcurioni/source/blender/freestyle/style_modules_blender/freestyle_init.py
branches/soc-2008-mxcurioni/source/blender/freestyle/style_modules_blender/logical_operators.py
Added Paths:
-----------
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Director.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Director.h
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/api.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/api.cpp 2008-07-30 00:05:19 UTC (rev 15876)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/api.cpp 2008-07-30 01:51:40 UTC (rev 15877)
@@ -42,6 +42,7 @@
if( view == NULL )
view = new AppGLWidget;
+ controller->Clear();
controller->setView(view);
}
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.cpp 2008-07-30 00:05:19 UTC (rev 15876)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.cpp 2008-07-30 01:51:40 UTC (rev 15877)
@@ -9,6 +9,7 @@
#include "Interface0D/CurvePoint/BPy_StrokeVertex.h"
#include "Interface0D/BPy_SVertex.h"
#include "Interface0D/BPy_ViewVertex.h"
+#include "BPy_Interface1D.h"
#include "Interface1D/BPy_FEdge.h"
#include "Interface1D/BPy_ViewEdge.h"
#include "BPy_Nature.h"
@@ -79,6 +80,14 @@
return py_if0D;
}
+PyObject * BPy_Interface1D_from_Interface1D( Interface1D& if1D ) {
+ PyObject *py_if1D = Interface1D_Type.tp_new( &Interface1D_Type, 0, 0 );
+ ((BPy_Interface1D *) py_if1D)->if1D = &if1D;
+
+ return py_if1D;
+}
+
+
PyObject * BPy_SVertex_from_SVertex( SVertex& sv ) {
PyObject *py_sv = SVertex_Type.tp_new( &SVertex_Type, 0, 0 );
((BPy_SVertex *) py_sv)->sv = new SVertex( sv );
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.h 2008-07-30 00:05:19 UTC (rev 15876)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Convert.h 2008-07-30 01:51:40 UTC (rev 15877)
@@ -17,6 +17,9 @@
// Interface0D, Interface0DIteratorNested, Interface0DIterator
#include "../view_map/Interface0D.h"
+// Interface1D
+#include "../view_map/Interface1D.h"
+
// Material
#include "../scene_graph/Material.h"
@@ -71,6 +74,7 @@
PyObject * BPy_FEdge_from_FEdge( FEdge& fe );
PyObject * BPy_Id_from_Id( Id& id );
PyObject * BPy_Interface0D_from_Interface0D( Interface0D& if0D );
+PyObject * BPy_Interface1D_from_Interface1D( Interface1D& if1D );
PyObject * BPy_IntegrationType_from_IntegrationType( int i );
PyObject * BPy_FrsMaterial_from_Material( Material& m );
PyObject * BPy_Nature_from_Nature( unsigned short n );
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Operators.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Operators.cpp 2008-07-30 00:05:19 UTC (rev 15876)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_Operators.cpp 2008-07-30 01:51:40 UTC (rev 15877)
@@ -164,7 +164,11 @@
Py_RETURN_NONE;
}
- Operators::select(*( ((BPy_UnaryPredicate1D *) obj)->up1D ));
+ UnaryPredicate1D *up1D = ((BPy_UnaryPredicate1D *) obj)->up1D;
+ if( PyObject_HasAttrString( obj, "__call__") )
+ up1D->setPythonObject( obj );
+
+ Operators::select(*up1D);
Py_RETURN_NONE;
}
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp 2008-07-30 00:05:19 UTC (rev 15876)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp 2008-07-30 01:51:40 UTC (rev 15877)
@@ -215,7 +215,7 @@
if( if1D )
return PyBool_from_bool( self->up1D->operator()(*if1D) );
-
+
Py_RETURN_NONE;
}
Added: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Director.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Director.cpp (rev 0)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Director.cpp 2008-07-30 01:51:40 UTC (rev 15877)
@@ -0,0 +1,12 @@
+#include "Director.h"
+
+#include "BPy_Convert.h"
+
+bool director_BPy_UnaryPredicate1D___call__( PyObject *py_up1D, Interface1D& if1D) {
+ cout << "Polymorphism works" << endl;
+
+ PyObject *method = PyObject_GetAttrString( py_up1D, "__call__");
+ PyObject *result = PyObject_CallFunction(method, "O", BPy_Interface1D_from_Interface1D(if1D) );
+
+ return bool_from_PyBool(result);
+}
Added: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Director.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Director.h (rev 0)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Director.h 2008-07-30 01:51:40 UTC (rev 15877)
@@ -0,0 +1,34 @@
+#ifndef FREESTYLE_PYTHON_DIRECTOR
+# define FREESTYLE_PYTHON_DIRECTOR
+
+#include "../view_map/Interface1D.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+///////////////////////////////////////////////////////////////////////////////////////////
+
+#include <Python.h>
+
+// SWIG directors
+// ----------------------------
+// ViewEdgeInternal::ViewEdgeIterator;
+// ChainingIterator;
+// ChainSilhouetteIterator;
+// ChainPredicateIterator;
+// UnaryPredicate0D;
+// UnaryPredicate1D;
+// BinaryPredicate1D;
+// StrokeShader;
+
+bool director_BPy_UnaryPredicate1D___call__( PyObject *py_up1D, Interface1D& if1D);
+
+///////////////////////////////////////////////////////////////////////////////////////////
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif // FREESTYLE_PYTHON_DIRECTOR
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp 2008-07-30 00:05:19 UTC (rev 15876)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp 2008-07-30 01:51:40 UTC (rev 15877)
@@ -111,7 +111,7 @@
{
PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0;
- if (!( PyArg_ParseTuple(args, "O|OO", &obj1, &obj2, &obj3) ))
+ if (!( PyArg_ParseTuple(args, "|OOO", &obj1, &obj2, &obj3) ))
return -1;
if( obj1 && BPy_ChainSilhouetteIterator_Check(obj1) ) {
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Predicates1D.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Predicates1D.h 2008-07-30 00:05:19 UTC (rev 15876)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Predicates1D.h 2008-07-30 01:51:40 UTC (rev 15877)
@@ -33,9 +33,11 @@
# include <string>
# include "../system/TimeStamp.h"
# include "../view_map/Interface1D.h"
-# include "../view_map/Functions1D.h"
+# include "../view_map/Functions1D.h"
# include "AdvancedFunctions1D.h"
+# include "../python/Director.h"
+
//
// UnaryPredicate1D (base class for predicates in 1D)
//
@@ -52,8 +54,13 @@
class UnaryPredicate1D
{
public:
+
+ PyObject *py_up1D;
+
/*! Default constructor. */
- UnaryPredicate1D() {}
+ UnaryPredicate1D() {
+ py_up1D = 0;
+ }
/*! Destructor. */
virtual ~UnaryPredicate1D() {}
/*! Returns the string of the name
@@ -71,9 +78,17 @@
* false otherwise.
*/
virtual bool operator()(Interface1D& inter) {
- cerr << "Warning: operator() not implemented" << endl;
- return false;
+
+ if( py_up1D ) {
+ return director_BPy_UnaryPredicate1D___call__(py_up1D, inter);
+ } else {
+ cerr << "Warning: operator() not implemented" << endl;
+ return false;
+ }
}
+
+ inline void setPythonObject(PyObject *_py_up1D) { py_up1D = _py_up1D; }
+
};
@@ -190,9 +205,9 @@
* by a different shape on each of its sides.
*/
class ContourUP1D : public UnaryPredicate1D
- {
- private:
- Functions1D::CurveNatureF1D _getNature;
+ {
+ private:
+ Functions1D::CurveNatureF1D _getNature;
public:
/*! Returns the string "ContourUP1D"*/
string getName() const {
@@ -217,8 +232,8 @@
* by no shape on one of its sides.
*/
class ExternalContourUP1D : public UnaryPredicate1D
- {
- private:
+ {
+ private:
Functions1D::CurveNatureF1D _getNature;
public:
/*! Returns the string "ExternalContourUP1D"*/
@@ -409,30 +424,30 @@
}
return false;
}
- };
-
- // ViewMapGradientNormBP1D
- /*! Returns true if the evaluation of the
- * Gradient norm Function is higher for Interface1D i1
- * than for i2.
- */
- class ViewMapGradientNormBP1D : public BinaryPredicate1D
- {
- private:
- Functions1D::GetViewMapGradientNormF1D _func;
- public:
- ViewMapGradientNormBP1D(int level, IntegrationType iType=MEAN, float sampling=2.0)
- : BinaryPredicate1D(), _func(level, iType, sampling) {
- }
- /*! Returns the string "ViewMapGradientNormBP1D"*/
- string getName() const {
- return "ViewMapGradientNormBP1D";
- }
- /*! The () operator. */
- bool operator()(Interface1D& i1, Interface1D& i2) {
- return (_func(i1) > _func(i2));
- }
};
+
+ // ViewMapGradientNormBP1D
+ /*! Returns true if the evaluation of the
+ * Gradient norm Function is higher for Interface1D i1
+ * than for i2.
+ */
+ class ViewMapGradientNormBP1D : public BinaryPredicate1D
+ {
+ private:
+ Functions1D::GetViewMapGradientNormF1D _func;
+ public:
+ ViewMapGradientNormBP1D(int level, IntegrationType iType=MEAN, float sampling=2.0)
+ : BinaryPredicate1D(), _func(level, iType, sampling) {
+ }
+ /*! Returns the string "ViewMapGradientNormBP1D"*/
+ string getName() const {
+ return "ViewMapGradientNormBP1D";
+ }
+ /*! The () operator. */
+ bool operator()(Interface1D& i1, Interface1D& i2) {
+ return (_func(i1) > _func(i2));
+ }
+ };
} // end of namespace Predicates1D
#endif // PREDICATES1D_H
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/style_modules_blender/freestyle_init.py
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list