soc-2008-mxcurioni: Tested SWIG-less environment more and understood why the former predicate methods were not working. As Stéphane 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)
This commit is contained in:
@@ -42,6 +42,7 @@ extern "C" {
|
||||
if( view == NULL )
|
||||
view = new AppGLWidget;
|
||||
|
||||
controller->Clear();
|
||||
controller->setView(view);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 @@ PyObject * BPy_Interface0D_from_Interface0D( Interface0D& if0D ) {
|
||||
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 );
|
||||
|
||||
@@ -17,6 +17,9 @@ using namespace Geometry;
|
||||
// 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_directedViewEdge_from_directedViewEdge( ViewVertex::directedViewE
|
||||
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 );
|
||||
|
||||
@@ -164,7 +164,11 @@ PyObject * Operators_select(BPy_Operators* self, PyObject *args)
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ PyObject * UnaryPredicate1D___call__( BPy_UnaryPredicate1D *self, PyObject *args
|
||||
|
||||
if( if1D )
|
||||
return PyBool_from_bool( self->up1D->operator()(*if1D) );
|
||||
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
12
source/blender/freestyle/intern/python/Director.cpp
Normal file
12
source/blender/freestyle/intern/python/Director.cpp
Normal file
@@ -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);
|
||||
}
|
||||
34
source/blender/freestyle/intern/python/Director.h
Normal file
34
source/blender/freestyle/intern/python/Director.h
Normal file
@@ -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
|
||||
@@ -111,7 +111,7 @@ int ChainSilhouetteIterator___init__(BPy_ChainSilhouetteIterator *self, PyObject
|
||||
{
|
||||
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) ) {
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
# 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 @@ public:
|
||||
* 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; }
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -49,16 +49,16 @@ class StrokeShader(Blender.Freestyle.StrokeShader):
|
||||
pass
|
||||
|
||||
class UnaryFunction0D(Blender.Freestyle.UnaryFunction0D):
|
||||
pass
|
||||
def __call__(*args): return Blender.Freestyle.UnaryFunction0D.__call__(*args)
|
||||
|
||||
class UnaryFunction1D(Blender.Freestyle.UnaryFunction1D):
|
||||
pass
|
||||
def __call__(*args): return Blender.Freestyle.UnaryFunction1D.__call__(*args)
|
||||
|
||||
class UnaryPredicate0D(Blender.Freestyle.UnaryPredicate0D):
|
||||
pass
|
||||
|
||||
class UnaryPredicate1D(Blender.Freestyle.UnaryPredicate1D):
|
||||
def __call__(*args): return Blender.Freestyle.UnaryPredicate1D.__call__(*args)
|
||||
pass
|
||||
|
||||
class ViewMap(Blender.Freestyle.ViewMap):
|
||||
pass
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
from freestyle_init import *
|
||||
|
||||
class AndUP1D(ContourUP1D):
|
||||
class AndUP1D(UnaryPredicate1D):
|
||||
def __init__(self, pred1, pred2):
|
||||
ContourUP1D.__init__(self)
|
||||
UnaryPredicate1D.__init__(self)
|
||||
self.__pred1 = pred1
|
||||
self.__pred2 = pred2
|
||||
|
||||
@@ -12,9 +12,9 @@ class AndUP1D(ContourUP1D):
|
||||
def __call__(self, inter):
|
||||
return self.__pred1(inter) and self.__pred2(inter)
|
||||
|
||||
class OrUP1D(ContourUP1D):
|
||||
class OrUP1D(UnaryPredicate1D):
|
||||
def __init__(self, pred1, pred2):
|
||||
ContourUP1D.__init__(self)
|
||||
UnaryPredicate1D.__init__(self)
|
||||
self.__pred1 = pred1
|
||||
self.__pred2 = pred2
|
||||
|
||||
@@ -24,9 +24,9 @@ class OrUP1D(ContourUP1D):
|
||||
def __call__(self, inter):
|
||||
return self.__pred1(inter) or self.__pred2(inter)
|
||||
|
||||
class NotUP1D(ContourUP1D):
|
||||
class NotUP1D(UnaryPredicate1D):
|
||||
def __init__(self, pred):
|
||||
ContourUP1D.__init__(self)
|
||||
UnaryPredicate1D.__init__(self)
|
||||
self.__pred = pred
|
||||
|
||||
def getName(self):
|
||||
|
||||
Reference in New Issue
Block a user