soc-2008-mxcurioni: implemented (but did not test) ChainPredicateIterator and ChainSilhouetteIterator

This commit is contained in:
Maxime Curioni
2008-07-26 20:05:55 +00:00
parent 13364bf208
commit 5718639a79
6 changed files with 217 additions and 47 deletions

View File

@@ -65,6 +65,7 @@ python_sources = [
prefix + '/BPy_BBox.cpp',
prefix + '/BPy_BinaryPredicate0D.cpp',
prefix + '/BPy_BinaryPredicate1D.cpp',
prefix + '/BPy_FrsMaterial.cpp',
prefix + '/BPy_Id.cpp',
prefix + '/BPy_IntegrationType.cpp',
prefix + '/BPy_Interface0D.cpp',
@@ -76,7 +77,10 @@ python_sources = [
prefix + '/Interface0D/ViewVertex/BPy_TVertex.cpp',
prefix + '/BPy_Interface1D.cpp',
prefix + '/Interface1D/BPy_Curve.cpp',
prefix + '/Interface1D/Curve/BPy_Chain.cpp',
prefix + '/Interface1D/BPy_FEdge.cpp',
prefix + '/Interface1D/FEdge/BPy_FEdgeSharp.cpp',
prefix + '/Interface1D/FEdge/BPy_FEdgeSmooth.cpp',
prefix + '/Interface1D/BPy_Stroke.cpp',
prefix + '/Interface1D/BPy_ViewEdge.cpp',
prefix + '/BPy_Iterator.cpp',
@@ -87,6 +91,9 @@ python_sources = [
prefix + '/Iterator/BPy_SVertexIterator.cpp',
prefix + '/Iterator/BPy_orientedViewEdgeIterator.cpp',
prefix + '/Iterator/BPy_ViewEdgeIterator.cpp',
prefix + '/Iterator/BPy_ChainingIterator.cpp',
prefix + '/Iterator/BPy_ChainPredicateIterator.cpp',
prefix + '/Iterator/BPy_ChainSilhouetteIterator.cpp',
prefix + '/BPy_MediumType.cpp',
prefix + '/BPy_Nature.cpp',
prefix + '/BPy_SShape.cpp',

View File

@@ -9,8 +9,8 @@
#include "Iterator/BPy_orientedViewEdgeIterator.h"
#include "Iterator/BPy_ViewEdgeIterator.h"
#include "Iterator/BPy_ChainingIterator.h"
// #include "Iterator/BPy_ChainPredicateIterator.h"
// #include "Iterator/BPy_ChainSilhouetteIterator.h"
#include "Iterator/BPy_ChainPredicateIterator.h"
#include "Iterator/BPy_ChainSilhouetteIterator.h"
@@ -176,15 +176,15 @@ PyMODINIT_FUNC Iterator_Init( PyObject *module )
Py_INCREF( &ChainingIterator_Type );
PyModule_AddObject(module, "ChainingIterator", (PyObject *)&ChainingIterator_Type);
// if( PyType_Ready( &ChainPredicateIterator_Type ) < 0 )
// return;
// Py_INCREF( &ChainPredicateIterator_Type );
// PyModule_AddObject(module, "ChainPredicateIterator", (PyObject *)&ChainPredicateIterator_Type);
//
// if( PyType_Ready( &ChainSilhouetteIterator_Type ) < 0 )
// return;
// Py_INCREF( &ChainSilhouetteIterator_Type );
// PyModule_AddObject(module, "ChainSilhouetteIterator", (PyObject *)&ChainSilhouetteIterator_Type);
if( PyType_Ready( &ChainPredicateIterator_Type ) < 0 )
return;
Py_INCREF( &ChainPredicateIterator_Type );
PyModule_AddObject(module, "ChainPredicateIterator", (PyObject *)&ChainPredicateIterator_Type);
if( PyType_Ready( &ChainSilhouetteIterator_Type ) < 0 )
return;
Py_INCREF( &ChainSilhouetteIterator_Type );
PyModule_AddObject(module, "ChainSilhouetteIterator", (PyObject *)&ChainSilhouetteIterator_Type);
}

View File

@@ -1,7 +1,9 @@
#include "BPy_ChainPredicateIterator.h"
#include "../BPy_Convert.h"
#include "../BPy_BinaryPredicate1D.h"
#include "../Interface1D/BPy_ViewEdge.h"
#include "../BPy_UnaryPredicate1D.h"
#ifdef __cplusplus
extern "C" {
@@ -12,14 +14,9 @@ extern "C" {
/*--------------- Python API function prototypes for ChainPredicateIterator instance -----------*/
static int ChainPredicateIterator___init__(BPy_ChainPredicateIterator *self, PyObject *args);
static PyObject * ChainPredicateIterator_traverse( BPy_ViewEdgeIterator *self, PyObject *args );
/*----------------------ChainPredicateIterator instance definitions ----------------------------*/
static PyMethodDef BPy_ChainPredicateIterator_methods[] = {
{"traverse", ( PyCFunction ) ChainPredicateIterator_traverse, METH_VARARGS, "(AdjacencyIterator ai) This method iterates over the potential next ViewEdges and returns the one that will be followed next. Returns the next ViewEdge to follow or 0 when the end of the chain is reached. "},
{NULL, NULL, 0, NULL}
};
@@ -110,22 +107,27 @@ PyTypeObject ChainPredicateIterator_Type = {
//------------------------INSTANCE METHODS ----------------------------------
// ChainPredicateIterator (bool iRestrictToSelection=true, bool iRestrictToUnvisited=true, ViewEdge *begin=NULL, bool orientation=true)
// ChainPredicateIterator (UnaryPredicate1D &upred, BinaryPredicate1D &bpred, bool iRestrictToSelection=true, bool iRestrictToUnvisited=true, ViewEdge *begin=NULL, bool orientation=true)
// ChainPredicateIterator (const ChainPredicateIterator &brother)
int ChainPredicateIterator___init__(BPy_ChainPredicateIterator *self, PyObject *args )
{
PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0, *obj4 = 0;
PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0, *obj4 = 0, *obj5 = 0, *obj6 = 0;
if (!( PyArg_ParseTuple(args, "O|OOOOO", &obj1, &obj2, &obj3, &obj4) ))
if (!( PyArg_ParseTuple(args, "O|OOOOO", &obj1, &obj2, &obj3, &obj4, &obj5, &obj6) ))
return -1;
if( obj1 && BPy_ChainPredicateIterator_Check(obj1) ) {
self->c_it = new ChainPredicateIterator(*( ((BPy_ChainPredicateIterator *) obj1)->c_it ));
self->cp_it = new ChainPredicateIterator(*( ((BPy_ChainPredicateIterator *) obj1)->cp_it ));
} else if( obj1 && BPy_ChainPredicateIterator_Check(obj1) ) {
self->c_it = new ChainPredicateIterator(*( ((BPy_ChainPredicateIterator *) obj1)->c_it ));
} else if( obj1 && BPy_UnaryPredicate1D_Check(obj1) && ((BPy_UnaryPredicate1D *) obj1)->up1D &&
obj2 && BPy_BinaryPredicate1D_Check(obj2) && ((BPy_BinaryPredicate1D *) obj2)->bp1D ) {
UnaryPredicate1D *up1D = ((BPy_UnaryPredicate1D *) obj1)->up1D;
BinaryPredicate1D *bp1D = ((BPy_BinaryPredicate1D *) obj2)->bp1D;
bool restrictToSelection = ( obj3 && PyBool_Check(obj3) ) ? bool_from_PyBool(obj3) : true;
bool restrictToUnvisited = ( obj4 && PyBool_Check(obj4) ) ? bool_from_PyBool(obj4) : true;
ViewEdge *begin = ( obj5 && BPy_ViewEdge_Check(obj5) ) ? ((BPy_ViewEdge *) obj5)->ve : 0;
bool orientation = ( obj6 && PyBool_Check(obj6) ) ? bool_from_PyBool(obj6) : true;
self->cp_it = new ChainPredicateIterator( *up1D, *bp1D, restrictToSelection, restrictToUnvisited, begin, orientation);
} else {
bool restrictToSelection = ( obj1 && PyBool_Check(obj1) ) ? bool_from_PyBool(obj1) : true;
@@ -133,28 +135,15 @@ int ChainPredicateIterator___init__(BPy_ChainPredicateIterator *self, PyObject *
ViewEdge *begin = ( obj3 && BPy_ViewEdge_Check(obj3) ) ? ((BPy_ViewEdge *) obj3)->ve : 0;
bool orientation = ( obj4 && PyBool_Check(obj4) ) ? bool_from_PyBool(obj4) : true;
self->c_it = new ChainPredicateIterator( restrictToSelection, restrictToUnvisited, begin, orientation);
self->cp_it = new ChainPredicateIterator( restrictToSelection, restrictToUnvisited, begin, orientation);
}
self->py_ve_it.ve_it = self->c_it;
self->py_ve_it.py_it.it = self->c_it;
self->py_c_it.c_it = self->cp_it;
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;
}
//virtual ViewEdge * traverse (const AdjacencyIterator &it)
PyObject *ChainPredicateIterator_traverse( BPy_ViewEdgeIterator *self, PyObject *args ) {
PyObject *py_a_it;
if(!( PyArg_ParseTuple(args, "O", &py_a_it) && BPy_AdjacencyIterator_Check(py_a_it) )) {
cout << "ERROR: ChainPredicateIterator_traverse" << endl;
Py_RETURN_NONE;
}
if( ((BPy_AdjacencyIterator *) py_a_it)->a_it )
self->ve_it->traverse(*( ((BPy_AdjacencyIterator *) py_a_it)->a_it ));
Py_RETURN_NONE;
}

View File

@@ -2,9 +2,9 @@
#define FREESTYLE_PYTHON_CHAINPREDICATEITERATOR_H
#include "../../view_map/ChainingIterators.h"
#include "../../stroke/ChainingIterators.h"
#include "BPy_ChainPredicateIterator.h"
#include "BPy_ChainingIterator.h"
#ifdef __cplusplus
extern "C" {
@@ -20,7 +20,7 @@ extern PyTypeObject ChainPredicateIterator_Type;
/*---------------------------Python BPy_ChainPredicateIterator structure definition----------*/
typedef struct {
ChainingIterator py_c_it;
BPy_ChainingIterator py_c_it;
ChainPredicateIterator *cp_it;
} BPy_ChainPredicateIterator;

View File

@@ -0,0 +1,141 @@
#include "BPy_ChainSilhouetteIterator.h"
#include "../BPy_Convert.h"
#include "../Interface1D/BPy_ViewEdge.h"
#ifdef __cplusplus
extern "C" {
#endif
///////////////////////////////////////////////////////////////////////////////////////////
/*--------------- Python API function prototypes for ChainSilhouetteIterator instance -----------*/
static int ChainSilhouetteIterator___init__(BPy_ChainSilhouetteIterator *self, PyObject *args);
/*----------------------ChainSilhouetteIterator instance definitions ----------------------------*/
static PyMethodDef BPy_ChainSilhouetteIterator_methods[] = {
{NULL, NULL, 0, NULL}
};
/*-----------------------BPy_ChainSilhouetteIterator type definition ------------------------------*/
PyTypeObject ChainSilhouetteIterator_Type = {
PyObject_HEAD_INIT( NULL )
0, /* ob_size */
"ChainSilhouetteIterator", /* tp_name */
sizeof( BPy_ChainSilhouetteIterator ), /* 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_ChainSilhouetteIterator_methods, /* struct PyMethodDef *tp_methods; */
NULL, /* struct PyMemberDef *tp_members; */
NULL, /* struct PyGetSetDef *tp_getset; */
&ChainingIterator_Type, /* struct _typeobject *tp_base; */
NULL, /* PyObject *tp_dict; */
NULL, /* descrgetfunc tp_descr_get; */
NULL, /* descrsetfunc tp_descr_set; */
0, /* long tp_dictoffset; */
(initproc)ChainSilhouetteIterator___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
};
//------------------------INSTANCE METHODS ----------------------------------
// ChainSilhouetteIterator (bool iRestrictToSelection=true, ViewEdge *begin=NULL, bool orientation=true)
// ChainSilhouetteIterator (const ChainSilhouetteIterator &brother)
int ChainSilhouetteIterator___init__(BPy_ChainSilhouetteIterator *self, PyObject *args )
{
PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0;
if (!( PyArg_ParseTuple(args, "O|OO", &obj1, &obj2, &obj3) ))
return -1;
if( obj1 && BPy_ChainSilhouetteIterator_Check(obj1) ) {
self->cs_it = new ChainSilhouetteIterator(*( ((BPy_ChainSilhouetteIterator *) obj1)->cs_it ));
} else {
bool restrictToSelection = ( obj1 && PyBool_Check(obj1) ) ? bool_from_PyBool(obj1) : true;
ViewEdge *begin = ( obj2 && BPy_ViewEdge_Check(obj2) ) ? ((BPy_ViewEdge *) obj2)->ve : 0;
bool orientation = ( obj3 && PyBool_Check(obj3) ) ? bool_from_PyBool(obj3) : true;
self->cs_it = new ChainSilhouetteIterator( restrictToSelection, begin, orientation);
}
self->py_c_it.c_it = self->cs_it;
self->py_c_it.py_ve_it.ve_it = self->cs_it;
self->py_c_it.py_ve_it.py_it.it = self->cs_it;
return 0;
}
///////////////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,33 @@
#ifndef FREESTYLE_PYTHON_CHAINSILHOUETTEITERATOR_H
#define FREESTYLE_PYTHON_CHAINSILHOUETTEITERATOR_H
#include "../../stroke/ChainingIterators.h"
#include "BPy_ChainingIterator.h"
#ifdef __cplusplus
extern "C" {
#endif
///////////////////////////////////////////////////////////////////////////////////////////
#include <Python.h>
extern PyTypeObject ChainSilhouetteIterator_Type;
#define BPy_ChainSilhouetteIterator_Check(v) (( (PyObject *) v)->ob_type == &ChainSilhouetteIterator_Type)
/*---------------------------Python BPy_ChainSilhouetteIterator structure definition----------*/
typedef struct {
BPy_ChainingIterator py_c_it;
ChainSilhouetteIterator *cs_it;
} BPy_ChainSilhouetteIterator;
///////////////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
}
#endif
#endif /* FREESTYLE_PYTHON_CHAINSILHOUETTEITERATOR_H */