[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15617] branches/soc-2008-mxcurioni/source /blender/freestyle: soc-2008-mxcurioni: FEdge class added.

Maxime Curioni maxime.curioni at gmail.com
Fri Jul 18 04:55:23 CEST 2008


Revision: 15617
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15617
Author:   mxcurioni
Date:     2008-07-18 04:55:23 +0200 (Fri, 18 Jul 2008)

Log Message:
-----------
soc-2008-mxcurioni: FEdge class added. Modifed converting functions to passing-by-reference format. Improved the type checking for FEdge and CurvePoint. Modified FEdge C++ class to test for null vertices. Updated previous classes to support FEdge.

So far, whenever a Python object is created from its corresponding C++ object, the input object reference is copied into a new object. Due to Freestyle's functions (especially regarding the way it is iterated), it is currently impossible to deal with a pointer-based Python object. It is not a real drawback, just an aspect to keep in mind.

Modified Paths:
--------------
    branches/soc-2008-mxcurioni/source/blender/freestyle/SConscript
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Convert.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Convert.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/CurvePoint.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/SVertex.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface1D/FEdge.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface1D.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/view_map/Silhouette.h

Added Paths:
-----------
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/SVertex.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface1D/FEdge.h

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/SConscript
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/SConscript	2008-07-17 20:46:12 UTC (rev 15616)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/SConscript	2008-07-18 02:55:23 UTC (rev 15617)
@@ -68,7 +68,8 @@
 					prefix + '/Interface0D.cpp',
 					prefix + '/Interface0D/CurvePoint.cpp',
 					prefix + '/Interface0D/SVertex.cpp',
-					prefix + '/Interface1D.cpp'
+					prefix + '/Interface1D.cpp',
+					prefix + '/Interface1D/FEdge.cpp'
 				]
 
 sources = 	system_sources + image_sources + geometry_sources + scene_graph_sources \

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Convert.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Convert.cpp	2008-07-17 20:46:12 UTC (rev 15616)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Convert.cpp	2008-07-18 02:55:23 UTC (rev 15617)
@@ -9,71 +9,64 @@
 
 
 PyObject *PyBool_from_bool( bool b ){
-	// SWIG_From_bool
 	return PyBool_FromLong( b ? 1 : 0);
 }
 
 
-PyObject *Vector_from_Vec2f( Vec2f vec ) {
+PyObject *Vector_from_Vec2f( Vec2f& vec ) {
 	float vec_data[2]; // because vec->_coord is protected
 
-	if( &vec != 0 ){
-		vec_data[0] = vec.x();		vec_data[1] = vec.y();
-		return newVectorObject( vec_data, 2, Py_NEW);
-	} 
-
-	Py_RETURN_NONE;
+	vec_data[0] = vec.x();		vec_data[1] = vec.y();
+	return newVectorObject( vec_data, 2, Py_NEW);
 }
 
-PyObject *Vector_from_Vec3f( Vec3f vec ) {
+PyObject *Vector_from_Vec3f( Vec3f& vec ) {
 	float vec_data[3]; // because vec->_coord is protected
 	
-	if( &vec != 0 ){
-		vec_data[0] = vec.x();		vec_data[1] = vec.y(); 		vec_data[2] = vec.z(); 
-		return newVectorObject( vec_data, 3, Py_NEW);
-	} 
-
-	Py_RETURN_NONE;
+	vec_data[0] = vec.x();		vec_data[1] = vec.y(); 		vec_data[2] = vec.z(); 
+	return newVectorObject( vec_data, 3, Py_NEW);
 }
 
-PyObject *Vector_from_Vec3r( Vec3r vec ) {
+PyObject *Vector_from_Vec3r( Vec3r& vec ) {
 	float vec_data[3]; // because vec->_coord is protected
 	
-	if( &vec != 0 ){
-		vec_data[0] = vec.x();		vec_data[1] = vec.y(); 		vec_data[2] = vec.z(); 
-		return newVectorObject( vec_data, 3, Py_NEW);
-	} 
+	vec_data[0] = vec.x();		vec_data[1] = vec.y(); 		vec_data[2] = vec.z(); 
+	return newVectorObject( vec_data, 3, Py_NEW);
+}
 
-	Py_RETURN_NONE;
+PyObject *BPy_Id_from_Id( Id& id ) {
+	PyObject *py_id = Id_Type.tp_new( &Id_Type, 0, 0 );
+	((BPy_Id *) py_id)->id = new Id( id.getFirst(), id.getSecond() );
+
+	return py_id;
 }
 
-PyObject *BPy_Id_from_Id( Id id ) {
-	BPy_Id *py_id;
-	
-	if( &id != 0 ) {
-		py_id = (BPy_Id *) Id_Type.tp_new( &Id_Type, 0, 0 );
-		py_id->id = new Id( id.getFirst(), id.getSecond() );
+PyObject *BPy_Interface0D_from_Interface0D( Interface0D& if0D ) {
+	PyObject *py_if0D =  Interface0D_Type.tp_new( &Interface0D_Type, 0, 0 );
+	((BPy_Interface0D *) py_if0D)->if0D = &if0D;
 
-		return (PyObject *)py_id;
-	}
-	
-	Py_RETURN_NONE;
+	return py_if0D;
 }
 
-PyObject *BPy_SVertex_from_SVertex( SVertex sv ) {
-	BPy_SVertex *py_sv;
+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 );
+	((BPy_SVertex *) py_sv)->py_if0D.if0D = ((BPy_SVertex *) py_sv)->sv;
 
-	if( &sv != 0 ) {
-		py_sv = (BPy_SVertex *) SVertex_Type.tp_new( &SVertex_Type, 0, 0 );
-		py_sv->sv = new SVertex( sv );
-		py_sv->py_if0D.if0D = py_sv->sv;
+	return py_sv;
+}
 
-		return (PyObject *)py_sv;
-	}
+PyObject *BPy_FEdge_from_FEdge( FEdge& fe ) {
+	PyObject *py_fe = FEdge_Type.tp_new( &FEdge_Type, 0, 0 );
+	((BPy_FEdge *) py_fe)->fe = new FEdge( fe );
+	((BPy_FEdge *) py_fe)->py_if1D.if1D = ((BPy_FEdge *) py_fe)->fe;
 
-	Py_RETURN_NONE;
+	return py_fe;
 }
+
 	
+
+
 ///////////////////////////////////////////////////////////////////////////////////////////
 
 #ifdef __cplusplus

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Convert.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Convert.h	2008-07-17 20:46:12 UTC (rev 15616)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Convert.h	2008-07-18 02:55:23 UTC (rev 15617)
@@ -5,7 +5,9 @@
 using namespace Geometry;
 
 #include "Id.h"
+#include "Interface0D.h"
 #include "Interface0D/SVertex.h"
+#include "Interface1D/FEdge.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -17,14 +19,16 @@
 #include "api2_2x/vector.h"
 #include "api2_2x/gen_utils.h"
 
-PyObject *PyBool_from_bool( bool b );
+PyObject * PyBool_from_bool( bool b );
 
-PyObject *Vector_from_Vec2f( Vec2f v );
-PyObject *Vector_from_Vec3f( Vec3f v );
-PyObject *Vector_from_Vec3r( Vec3r v );
+PyObject * Vector_from_Vec2f( Vec2f& v );
+PyObject * Vector_from_Vec3f( Vec3f& v );
+PyObject * Vector_from_Vec3r( Vec3r& v );
 
-PyObject *BPy_Id_from_Id( Id id );
-PyObject *BPy_SVertex_from_SVertex( SVertex sv );
+PyObject * BPy_Id_from_Id( Id& id );
+PyObject * BPy_SVertex_from_SVertex( SVertex& sv );
+PyObject * BPy_FEdge_from_FEdge( FEdge& fe );
+PyObject * BPy_Interface0D_from_Interface0D( Interface0D& if0D );
 
 ///////////////////////////////////////////////////////////////////////////////////////////
 

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/CurvePoint.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/CurvePoint.cpp	2008-07-17 20:46:12 UTC (rev 15616)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/CurvePoint.cpp	2008-07-18 02:55:23 UTC (rev 15617)
@@ -1,7 +1,6 @@
 #include "CurvePoint.h"
 
 #include "../Convert.h"
-#include "../../stroke/Curve.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -166,15 +165,15 @@
 }
 
 PyObject * CurvePoint_A( BPy_CurvePoint *self ) {
-	if( self->cp->A() )
-		return BPy_SVertex_from_SVertex( *(self->cp->A()) );
+	if( SVertex *A = self->cp->A() )
+		return BPy_SVertex_from_SVertex( *A );
 
 	Py_RETURN_NONE;
 }
 
 PyObject * CurvePoint_B( BPy_CurvePoint *self ) {
-	if( self->cp->B() )
-		return BPy_SVertex_from_SVertex( *(self->cp->B()) );
+	if( SVertex *B = self->cp->B() )
+		return BPy_SVertex_from_SVertex( *B );
 
 	Py_RETURN_NONE;
 }

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/SVertex.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/SVertex.cpp	2008-07-17 20:46:12 UTC (rev 15616)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/SVertex.cpp	2008-07-18 02:55:23 UTC (rev 15617)
@@ -18,6 +18,8 @@
 static PyObject * SVertex_SetPoint2D( BPy_SVertex *self , PyObject *args);
 static PyObject * SVertex_AddNormal( BPy_SVertex *self , PyObject *args);
 static PyObject * SVertex_SetId( BPy_SVertex *self , PyObject *args);
+static PyObject *SVertex_AddFEdge( BPy_SVertex *self , PyObject *args);
+
 /*----------------------SVertex instance definitions ----------------------------*/
 static PyMethodDef BPy_SVertex_methods[] = {
 	{"__copy__", ( PyCFunction ) SVertex___copy__, METH_NOARGS, "( )Cloning method."},
@@ -27,6 +29,7 @@
 	{"SetPoint2D", ( PyCFunction ) SVertex_SetPoint2D, METH_VARARGS, "Sets the 3D projected coordinates of the SVertex." },
 	{"AddNormal", ( PyCFunction ) SVertex_AddNormal, METH_VARARGS, "Adds a normal to the Svertex's set of normals. If the same normal is already in the set, nothing changes." },
 	{"SetId", ( PyCFunction ) SVertex_SetId, METH_VARARGS, "Sets the Id." },
+	{"AddFEdge", ( PyCFunction ) SVertex_AddFEdge, METH_VARARGS, "Add an FEdge to the list of edges emanating from this SVertex." },	
 	{NULL, NULL, 0, NULL}
 };
 
@@ -163,7 +166,8 @@
 	normals = self->sv->normals();
 		
 	for( set< Vec3r >::iterator set_iterator = normals.begin(); set_iterator != normals.end(); set_iterator++ ) {
-		PyList_Append( py_normals, Vector_from_Vec3r(*set_iterator) );
+		Vec3r v( *set_iterator );
+		PyList_Append( py_normals, Vector_from_Vec3r(v) );
 	}
 	
 	return py_normals;
@@ -215,8 +219,6 @@
 		cout << "ERROR: SVertex_AddNormal" << endl;
 		Py_RETURN_NONE;
 	}
-	
-	cout << "yoyo" << endl;
 
 	Vec3r n( 	PyFloat_AsDouble( PyList_GetItem(py_normal, 0) ),
 				PyFloat_AsDouble( PyList_GetItem(py_normal, 1) ),
@@ -239,10 +241,24 @@
 	Py_RETURN_NONE;
 }
 
+PyObject *SVertex_AddFEdge( BPy_SVertex *self , PyObject *args) {
+	PyObject *py_fe;
+
+	if(!( PyArg_ParseTuple(args, "O", &py_fe) && BPy_FEdge_Check(py_fe) )) {
+		cout << "ERROR: SVertex_AddFEdge" << endl;
+		Py_RETURN_NONE;
+	}
+	
+	self->sv->AddFEdge( ((BPy_FEdge *) py_fe)->fe );
+
+	Py_RETURN_NONE;
+}
+
+
 // virtual bool 	operator== (const SVertex &iBrother)
 // ViewVertex * 	viewvertex ()
-// void 	AddFEdge (FEdge *iFEdge)
 
+
 ///////////////////////////////////////////////////////////////////////////////////////////
 
 #ifdef __cplusplus

Added: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/SVertex.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/SVertex.h	                        (rev 0)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/SVertex.h	2008-07-18 02:55:23 UTC (rev 15617)
@@ -0,0 +1,33 @@
+#ifndef FREESTYLE_PYTHON_SVERTEX_H
+#define FREESTYLE_PYTHON_SVERTEX_H
+
+#include "../../view_map/Silhouette.h"
+#include "../Interface0D.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+///////////////////////////////////////////////////////////////////////////////////////////
+
+#include <Python.h>
+
+extern PyTypeObject SVertex_Type;
+
+#define BPy_SVertex_Check(v) \
+    ((v)->ob_type == &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 */

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D.cpp

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list