diff options
Diffstat (limited to 'source/blender/freestyle/intern/python/Iterator')
20 files changed, 2176 insertions, 0 deletions
diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp new file mode 100644 index 00000000000..1f4b041cce8 --- /dev/null +++ b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp @@ -0,0 +1,167 @@ +#include "BPy_AdjacencyIterator.h" + +#include "../BPy_Convert.h" +#include "../Interface0D/BPy_ViewVertex.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +//------------------------INSTANCE METHODS ---------------------------------- + +static char AdjacencyIterator___doc__[] = +"Class hierarchy: :class:`Iterator` > :class:`AdjacencyIterator`\n" +"\n" +"Class for representing adjacency iterators used in the chaining\n" +"process. An AdjacencyIterator is created in the increment() and\n" +"decrement() methods of a :class:`ChainingIterator` and passed to the\n" +"traverse() method of the ChainingIterator.\n" +"\n" +".. method:: __init__(iVertex, iRestrictToSelection=True, iRestrictToUnvisited=True)\n" +"\n" +" Builds a AdjacencyIterator object.\n" +"\n" +" :arg iVertex: The vertex which is the next crossing.\n" +" :type iVertex: :class:`ViewVertex`\n" +" :arg iRestrictToSelection: Indicates whether to force the chaining\n" +" to stay within the set of selected ViewEdges or not.\n" +" :type iRestrictToSelection: bool\n" +" :arg iRestrictToUnvisited: Indicates whether a ViewEdge that has\n" +" already been chained must be ignored ot not.\n" +" :type iRestrictToUnvisited: bool\n" +"\n" +".. method:: __init__(it)\n" +"\n" +" Copy constructor.\n" +"\n" +" :arg it: An AdjacencyIterator object.\n" +" :type it: :class:`AdjacencyIterator`\n"; + +static int AdjacencyIterator___init__(BPy_AdjacencyIterator *self, PyObject *args ) +{ + PyObject *obj1 = 0, *obj2 = 0 , *obj3 = 0; + + if (! PyArg_ParseTuple(args, "|OOO", &obj1, &obj2, &obj3) ) + return -1; + + if( !obj1 && !obj2 && !obj3 ){ + self->a_it = new AdjacencyIterator(); + + } else if( BPy_AdjacencyIterator_Check(obj1) ) { + self->a_it = new AdjacencyIterator(*( ((BPy_AdjacencyIterator *) obj1)->a_it )); + + } else if( BPy_ViewVertex_Check(obj1) ) { + bool restrictToSelection = ( obj2 ) ? bool_from_PyBool(obj2) : true; + bool restrictToUnvisited = ( obj3 ) ? bool_from_PyBool(obj3) : true; + + self->a_it = new AdjacencyIterator( ((BPy_ViewVertex *) obj1)->vv, restrictToSelection, restrictToUnvisited ); + + } else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } + + self->py_it.it = self->a_it; + + return 0; + +} + +static PyObject * AdjacencyIterator_iternext(BPy_AdjacencyIterator *self) { + if (self->a_it->isEnd()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + ViewEdge *ve = self->a_it->operator*(); + self->a_it->increment(); + return BPy_ViewEdge_from_ViewEdge( *ve ); +} + +static char AdjacencyIterator_isIncoming___doc__[] = +".. method:: isIncoming()\n" +"\n" +" Returns true if the current ViewEdge is coming towards the\n" +" iteration vertex. False otherwise.\n" +"\n" +" :return: True if the current ViewEdge is coming towards the\n" +" iteration vertex\n" +" :rtype: bool\n"; + +static PyObject * AdjacencyIterator_isIncoming(BPy_AdjacencyIterator *self) { + return PyBool_from_bool(self->a_it->isIncoming()); +} + +static char AdjacencyIterator_getObject___doc__[] = +".. method:: getObject()\n" +"\n" +" Returns the pointed ViewEdge.\n" +"\n" +" :return: The pointed ViewEdge.\n" +" :rtype: :class:`ViewEdge`\n"; + +static PyObject * AdjacencyIterator_getObject(BPy_AdjacencyIterator *self) { + + ViewEdge *ve = self->a_it->operator*(); + if( ve ) + return BPy_ViewEdge_from_ViewEdge( *ve ); + + Py_RETURN_NONE; +} + +/*----------------------AdjacencyIterator instance definitions ----------------------------*/ +static PyMethodDef BPy_AdjacencyIterator_methods[] = { + {"isIncoming", ( PyCFunction ) AdjacencyIterator_isIncoming, METH_NOARGS, AdjacencyIterator_isIncoming___doc__}, + {"getObject", ( PyCFunction ) AdjacencyIterator_getObject, METH_NOARGS, AdjacencyIterator_getObject___doc__}, + {NULL, NULL, 0, NULL} +}; + +/*-----------------------BPy_AdjacencyIterator type definition ------------------------------*/ + +PyTypeObject AdjacencyIterator_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "AdjacencyIterator", /* tp_name */ + sizeof(BPy_AdjacencyIterator), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + AdjacencyIterator___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + PyObject_SelfIter, /* tp_iter */ + (iternextfunc)AdjacencyIterator_iternext, /* tp_iternext */ + BPy_AdjacencyIterator_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &Iterator_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)AdjacencyIterator___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ +}; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.h new file mode 100644 index 00000000000..733a9f2fcab --- /dev/null +++ b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.h @@ -0,0 +1,32 @@ +#ifndef FREESTYLE_PYTHON_ADJACENCYITERATOR_H +#define FREESTYLE_PYTHON_ADJACENCYITERATOR_H + +#include "../../stroke/ChainingIterators.h" +#include "../BPy_Iterator.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +#include <Python.h> + +extern PyTypeObject AdjacencyIterator_Type; + +#define BPy_AdjacencyIterator_Check(v) ( PyObject_IsInstance( (PyObject *) v, (PyObject *) &AdjacencyIterator_Type) ) + +/*---------------------------Python BPy_AdjacencyIterator structure definition----------*/ +typedef struct { + BPy_Iterator py_it; + AdjacencyIterator *a_it; +} BPy_AdjacencyIterator; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif + +#endif /* FREESTYLE_PYTHON_ADJACENCYITERATOR_H */ diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.cpp new file mode 100644 index 00000000000..aa6d10ddb5f --- /dev/null +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.cpp @@ -0,0 +1,205 @@ +#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" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +//------------------------INSTANCE METHODS ---------------------------------- + +static char ChainPredicateIterator___doc__[] = +"Class hierarchy: :class:`Iterator` > :class:`ViewEdgeIterator` > :class:`ChainingIterator` > :class:`ChainPredicateIterator`\n" +"\n" +"A \"generic\" user-controlled ViewEdge iterator. This iterator is in\n" +"particular built from a unary predicate and a binary predicate.\n" +"First, the unary predicate is evaluated for all potential next\n" +"ViewEdges in order to only keep the ones respecting a certain\n" +"constraint. Then, the binary predicate is evaluated on the current\n" +"ViewEdge together with each ViewEdge of the previous selection. The\n" +"first ViewEdge respecting both the unary predicate and the binary\n" +"predicate is kept as the next one. If none of the potential next\n" +"ViewEdge respects these two predicates, None is returned.\n" +"\n" +".. method:: __init__(iRestrictToSelection=True, iRestrictToUnvisited=True, begin=None, orientation=True)\n" +"\n" +" Builds a ChainPredicateIterator from a starting ViewEdge and its\n" +" orientation.\n" +"\n" +" :arg iRestrictToSelection: Indicates whether to force the chaining\n" +" to stay within the set of selected ViewEdges or not.\n" +" :type iRestrictToSelection: bool\n" +" :arg iRestrictToUnvisited: Indicates whether a ViewEdge that has\n" +" already been chained must be ignored ot not.\n" +" :type iRestrictToUnvisited: bool\n" +" :arg begin: The ViewEdge from where to start the iteration.\n" +" :type begin: :class:`ViewEdge` or None\n" +" :arg orientation: If true, we'll look for the next ViewEdge among\n" +" the ViewEdges that surround the ending ViewVertex of begin. If\n" +" false, we'll search over the ViewEdges surrounding the ending\n" +" ViewVertex of begin. \n" +" :type orientation: bool\n" +"\n" +".. method:: __init__(upred, bpred, iRestrictToSelection=True, iRestrictToUnvisited=True, begin=None, orientation=True)\n" +"\n" +" Builds a ChainPredicateIterator from a unary predicate, a binary\n" +" predicate, a starting ViewEdge and its orientation.\n" +"\n" +" :arg upred: The unary predicate that the next ViewEdge must satisfy.\n" +" :type upred: :class:`UnaryPredicate1D`\n" +" :arg bpred: The binary predicate that the next ViewEdge must\n" +" satisfy together with the actual pointed ViewEdge.\n" +" :type bpred: :class:`BinaryPredicate1D`\n" +" :arg iRestrictToSelection: Indicates whether to force the chaining\n" +" to stay within the set of selected ViewEdges or not.\n" +" :type iRestrictToSelection: bool\n" +" :arg iRestrictToUnvisited: Indicates whether a ViewEdge that has\n" +" already been chained must be ignored ot not.\n" +" :type iRestrictToUnvisited: bool\n" +" :arg begin: The ViewEdge from where to start the iteration.\n" +" :type begin: :class:`ViewEdge` or None\n" +" :arg orientation: If true, we'll look for the next ViewEdge among\n" +" the ViewEdges that surround the ending ViewVertex of begin. If\n" +" false, we'll search over the ViewEdges surrounding the ending\n" +" ViewVertex of begin.\n" +" :type orientation: bool\n" +"\n" +".. method:: __init__(brother)\n" +"\n" +" Copy constructor.\n" +"\n" +" :arg brother: A ChainPredicateIterator object.\n" +" :type brother: :class:`ChainPredicateIterator`\n"; + +static int ChainPredicateIterator___init__(BPy_ChainPredicateIterator *self, PyObject *args ) +{ + PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0, *obj4 = 0, *obj5 = 0, *obj6 = 0; + + if (!( PyArg_ParseTuple(args, "|OOOOOO", &obj1, &obj2, &obj3, &obj4, &obj5, &obj6) )) + return -1; + + if( obj1 && BPy_ChainPredicateIterator_Check(obj1) ) { + self->cp_it = new ChainPredicateIterator(*( ((BPy_ChainPredicateIterator *) obj1)->cp_it )); + self->upred = NULL; + self->bpred = NULL; + + } else if( obj1 && BPy_UnaryPredicate1D_Check(obj1) && + obj2 && BPy_BinaryPredicate1D_Check(obj2) ) { + + if (!((BPy_UnaryPredicate1D *) obj1)->up1D) { + PyErr_SetString(PyExc_TypeError, "1st argument: invalid UnaryPredicate1D object"); + return -1; + } + if (!((BPy_BinaryPredicate1D *) obj2)->bp1D) { + PyErr_SetString(PyExc_TypeError, "2nd argument: invalid BinaryPredicate1D object"); + return -1; + } + UnaryPredicate1D *up1D = ((BPy_UnaryPredicate1D *) obj1)->up1D; + BinaryPredicate1D *bp1D = ((BPy_BinaryPredicate1D *) obj2)->bp1D; + bool restrictToSelection = ( obj3 ) ? bool_from_PyBool(obj3) : true; + bool restrictToUnvisited = ( obj4 ) ? bool_from_PyBool(obj4) : true; + ViewEdge *begin; + if ( !obj5 || obj5 == Py_None ) + begin = NULL; + else if ( BPy_ViewEdge_Check(obj5) ) + begin = ((BPy_ViewEdge *) obj5)->ve; + else { + PyErr_SetString(PyExc_TypeError, "5th argument must be either a ViewEdge object or None"); + return -1; + } + bool orientation = ( obj6 ) ? bool_from_PyBool(obj6) : true; + + self->cp_it = new ChainPredicateIterator( *up1D, *bp1D, restrictToSelection, restrictToUnvisited, begin, orientation); + self->upred = obj1; + self->bpred = obj2; + Py_INCREF( self->upred ); + Py_INCREF( self->bpred ); + + } else { + bool restrictToSelection = ( obj1 ) ? bool_from_PyBool(obj1) : true; + bool restrictToUnvisited = ( obj2 ) ? bool_from_PyBool(obj2) : true; + ViewEdge *begin; + if ( !obj3 || obj3 == Py_None ) + begin = NULL; + else if ( BPy_ViewEdge_Check(obj3) ) + begin = ((BPy_ViewEdge *) obj3)->ve; + else { + PyErr_SetString(PyExc_TypeError, "3rd argument must be either a ViewEdge object or None"); + return -1; + } + bool orientation = ( obj4 ) ? bool_from_PyBool(obj4) : true; + + self->cp_it = new ChainPredicateIterator( restrictToSelection, restrictToUnvisited, begin, orientation); + self->upred = NULL; + self->bpred = NULL; + } + + 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; + +} + +static void ChainPredicateIterator___dealloc__(BPy_ChainPredicateIterator *self) +{ + Py_XDECREF( self->upred ); + Py_XDECREF( self->bpred ); + ChainingIterator_Type.tp_dealloc((PyObject *)self); +} + +/*-----------------------BPy_ChainPredicateIterator type definition ------------------------------*/ + +PyTypeObject ChainPredicateIterator_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "ChainPredicateIterator", /* tp_name */ + sizeof(BPy_ChainPredicateIterator), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)ChainPredicateIterator___dealloc__, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ChainPredicateIterator___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &ChainingIterator_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ChainPredicateIterator___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ +}; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.h new file mode 100644 index 00000000000..5a31ac407d5 --- /dev/null +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.h @@ -0,0 +1,35 @@ +#ifndef FREESTYLE_PYTHON_CHAINPREDICATEITERATOR_H +#define FREESTYLE_PYTHON_CHAINPREDICATEITERATOR_H + + +#include "../../stroke/ChainingIterators.h" + +#include "BPy_ChainingIterator.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +#include <Python.h> + +extern PyTypeObject ChainPredicateIterator_Type; + +#define BPy_ChainPredicateIterator_Check(v) ( PyObject_IsInstance( (PyObject *) v, (PyObject *) &ChainPredicateIterator_Type) ) + +/*---------------------------Python BPy_ChainPredicateIterator structure definition----------*/ +typedef struct { + BPy_ChainingIterator py_c_it; + ChainPredicateIterator *cp_it; + PyObject *upred; + PyObject *bpred; +} BPy_ChainPredicateIterator; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif + +#endif /* FREESTYLE_PYTHON_CHAINPREDICATEITERATOR_H */ diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp new file mode 100644 index 00000000000..caf43a800c5 --- /dev/null +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp @@ -0,0 +1,131 @@ +#include "BPy_ChainSilhouetteIterator.h" + +#include "../BPy_Convert.h" +#include "../Interface1D/BPy_ViewEdge.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +//------------------------INSTANCE METHODS ---------------------------------- + +// ChainSilhouetteIterator (bool iRestrictToSelection=true, ViewEdge *begin=NULL, bool orientation=true) +// ChainSilhouetteIterator (const ChainSilhouetteIterator &brother) + +static char ChainSilhouetteIterator___doc__[] = +"Class hierarchy: :class:`Iterator` > :class:`ViewEdgeIterator` > :class:`ChainingIterator` > :class:`ChainSilhouetteIterator`\n" +"\n" +"A ViewEdge Iterator used to follow ViewEdges the most naturally. For\n" +"example, it will follow visible ViewEdges of same nature. As soon, as\n" +"the nature or the visibility changes, the iteration stops (by setting\n" +"the pointed ViewEdge to 0). In the case of an iteration over a set of\n" +"ViewEdge that are both Silhouette and Crease, there will be a\n" +"precedence of the silhouette over the crease criterion.\n" +"\n" +".. method:: __init__(iRestrictToSelection=True, begin=None, orientation=True)\n" +"\n" +" Builds a ChainSilhouetteIterator from the first ViewEdge used for\n" +" iteration and its orientation.\n" +"\n" +" :arg iRestrictToSelection: Indicates whether to force the chaining\n" +" to stay within the set of selected ViewEdges or not.\n" +" :type iRestrictToSelection: bool\n" +" :arg begin: The ViewEdge from where to start the iteration.\n" +" :type begin: :class:`ViewEdge` or None\n" +" :arg orientation: If true, we'll look for the next ViewEdge among\n" +" the ViewEdges that surround the ending ViewVertex of begin. If\n" +" false, we'll search over the ViewEdges surrounding the ending\n" +" ViewVertex of begin.\n" +" :type orientation: bool\n" +"\n" +".. method:: __init__(brother)\n" +"\n" +" Copy constructor.\n" +"\n" +" :arg brother: A ChainSilhouetteIterator object.\n" +" :type brother: :class:`ChainSilhouetteIterator`\n"; + +static int ChainSilhouetteIterator___init__(BPy_ChainSilhouetteIterator *self, PyObject *args ) +{ + PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0; + + if (!( PyArg_ParseTuple(args, "|OOO", &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 ) ? bool_from_PyBool(obj1) : true; + ViewEdge *begin; + if ( !obj2 || obj2 == Py_None ) + begin = NULL; + else if ( BPy_ViewEdge_Check(obj2) ) + begin = ((BPy_ViewEdge *) obj2)->ve; + else { + PyErr_SetString(PyExc_TypeError, "2nd argument must be either a ViewEdge object or None"); + return -1; + } + bool orientation = ( 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; + +} + +/*-----------------------BPy_ChainSilhouetteIterator type definition ------------------------------*/ + +PyTypeObject ChainSilhouetteIterator_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "ChainSilhouetteIterator", /* tp_name */ + sizeof(BPy_ChainSilhouetteIterator), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ChainSilhouetteIterator___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &ChainingIterator_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ChainSilhouetteIterator___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ +}; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.h new file mode 100644 index 00000000000..912d397d279 --- /dev/null +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.h @@ -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_IsInstance( (PyObject *) v, (PyObject *) &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 */ diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp new file mode 100644 index 00000000000..ddb957c900e --- /dev/null +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp @@ -0,0 +1,236 @@ +#include "BPy_ChainingIterator.h" + +#include "../BPy_Convert.h" +#include "../Interface0D/BPy_ViewVertex.h" +#include "../Interface1D/BPy_ViewEdge.h" +#include "BPy_AdjacencyIterator.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +//------------------------INSTANCE METHODS ---------------------------------- + +static char ChainingIterator___doc__[] = +"Class hierarchy: :class:`Iterator` > :class:`ViewEdgeIterator` > :class:`ChainingIterator`\n" +"\n" +"Base class for chaining iterators. This class is designed to be\n" +"overloaded in order to describe chaining rules. It makes the\n" +"description of chaining rules easier. The two main methods that need\n" +"to overloaded are traverse() and init(). traverse() tells which\n" +":class:`ViewEdge` to follow, among the adjacent ones. If you specify\n" +"restriction rules (such as \"Chain only ViewEdges of the selection\"),\n" +"they will be included in the adjacency iterator (i.e, the adjacent\n" +"iterator will only stop on \"valid\" edges).\n" +"\n" +".. method:: __init__(iRestrictToSelection=True, iRestrictToUnvisited=True, begin=None, orientation=True)\n" +"\n" +" Builds a Chaining Iterator from the first ViewEdge used for\n" +" iteration and its orientation.\n" +"\n" +" :arg iRestrictToSelection: Indicates whether to force the chaining\n" +" to stay within the set of selected ViewEdges or not.\n" +" :type iRestrictToSelection: bool\n" +" :arg iRestrictToUnvisited: Indicates whether a ViewEdge that has\n" +" already been chained must be ignored ot not.\n" +" :type iRestrictToUnvisited: bool\n" +" :arg begin: The ViewEdge from which to start the chain.\n" +" :type begin: :class:`ViewEdge` or None\n" +" :arg orientation: The direction to follow to explore the graph. If\n" +" true, the direction indicated by the first ViewEdge is used.\n" +" :type orientation: bool\n" +"\n" +".. method:: __init__(brother)\n" +"\n" +" Copy constructor.\n" +"\n" +" :arg brother: \n" +" :type brother: ChainingIterator\n"; + +static int ChainingIterator___init__(BPy_ChainingIterator *self, PyObject *args ) +{ + PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0, *obj4 = 0; + + if (!( PyArg_ParseTuple(args, "|OOOO", &obj1, &obj2, &obj3, &obj4) )) + return -1; + + if( obj1 && BPy_ChainingIterator_Check(obj1) ) { + self->c_it = new ChainingIterator(*( ((BPy_ChainingIterator *) obj1)->c_it )); + + } else { + bool restrictToSelection = ( obj1 ) ? bool_from_PyBool(obj1) : true; + bool restrictToUnvisited = ( obj2 ) ? bool_from_PyBool(obj2) : true; + ViewEdge *begin; + if ( !obj3 || obj3 == Py_None ) + begin = NULL; + else if ( BPy_ViewEdge_Check(obj3) ) + begin = ((BPy_ViewEdge *) obj3)->ve; + else { + PyErr_SetString(PyExc_TypeError, "3rd argument must be either a ViewEdge object or None"); + return -1; + } + bool orientation = ( obj4 ) ? bool_from_PyBool(obj4) : true; + + self->c_it = new ChainingIterator( restrictToSelection, restrictToUnvisited, begin, orientation); + } + + self->py_ve_it.ve_it = self->c_it; + self->py_ve_it.py_it.it = self->c_it; + + self->c_it->py_c_it = (PyObject *) self; + + return 0; +} + +static char ChainingIterator_init___doc__[] = +".. method:: init()\n" +"\n" +" Initializes the iterator context. This method is called each\n" +" time a new chain is started. It can be used to reset some\n" +" history information that you might want to keep.\n"; + +static PyObject *ChainingIterator_init( BPy_ChainingIterator *self ) { + if( typeid(*(self->c_it)) == typeid(ChainingIterator) ) { + PyErr_SetString(PyExc_TypeError, "init() method not properly overridden"); + return NULL; + } + self->c_it->init(); + + Py_RETURN_NONE; +} + +static char ChainingIterator_traverse___doc__[] = +".. method:: traverse(it)\n" +"\n" +" This method iterates over the potential next ViewEdges and returns\n" +" the one that will be followed next. Returns the next ViewEdge to\n" +" follow or None when the end of the chain is reached.\n" +"\n" +" :arg it: The iterator over the ViewEdges adjacent to the end vertex\n" +" of the current ViewEdge. The adjacency iterator reflects the\n" +" restriction rules by only iterating over the valid ViewEdges.\n" +" :type it: :class:`AdjacencyIterator`\n" +" :return: Returns the next ViewEdge to follow, or None if chaining ends.\n" +" :rtype: :class:`ViewEdge` or None\n"; + +static PyObject *ChainingIterator_traverse( BPy_ChainingIterator *self, PyObject *args ) { + PyObject *py_a_it; + + if(!( PyArg_ParseTuple(args, "O!", &AdjacencyIterator_Type, &py_a_it) )) + return NULL; + + if( typeid(*(self->c_it)) == typeid(ChainingIterator) ) { + PyErr_SetString(PyExc_TypeError, "traverse() method not properly overridden"); + return NULL; + } + if( ((BPy_AdjacencyIterator *) py_a_it)->a_it ) + self->c_it->traverse(*( ((BPy_AdjacencyIterator *) py_a_it)->a_it )); + + Py_RETURN_NONE; +} + +static char ChainingIterator_getVertex___doc__[] = +".. method:: getVertex()\n" +"\n" +" Returns the vertex which is the next crossing.\n" +"\n" +" :return: The vertex which is the next crossing.\n" +" :rtype: :class:`ViewVertex`\n"; + +static PyObject *ChainingIterator_getVertex( BPy_ChainingIterator *self ) { + ViewVertex *v = self->c_it->getVertex(); + if( v ) + return Any_BPy_ViewVertex_from_ViewVertex( *v ); + + Py_RETURN_NONE; +} + +static char ChainingIterator_isIncrementing___doc__[] = +".. method:: isIncrementing()\n" +"\n" +" Returns true if the current iteration is an incrementation.\n" +"\n" +" :return: True if the current iteration is an incrementation.\n" +" :rtype: bool\n"; + +static PyObject *ChainingIterator_isIncrementing( BPy_ChainingIterator *self ) { + return PyBool_from_bool( self->c_it->isIncrementing() ); +} + +static char ChainingIterator_getObject___doc__[] = +".. method:: getObject()\n" +"\n" +" Returns the pointed ViewEdge.\n" +"\n" +" :return: The pointed ViewEdge.\n" +" :rtype: :class:`ViewEdge`\n"; + +static PyObject * ChainingIterator_getObject( BPy_ChainingIterator *self) { + + ViewEdge *ve = self->c_it->operator*(); + if( ve ) + return BPy_ViewEdge_from_ViewEdge( *ve ); + + Py_RETURN_NONE; +} + +/*----------------------ChainingIterator instance definitions ----------------------------*/ +static PyMethodDef BPy_ChainingIterator_methods[] = { + {"init", ( PyCFunction ) ChainingIterator_init, METH_NOARGS, ChainingIterator_init___doc__}, + {"traverse", ( PyCFunction ) ChainingIterator_traverse, METH_VARARGS, ChainingIterator_traverse___doc__}, + {"getVertex", ( PyCFunction ) ChainingIterator_getVertex, METH_NOARGS, ChainingIterator_getVertex___doc__}, + {"isIncrementing", ( PyCFunction ) ChainingIterator_isIncrementing, METH_NOARGS, ChainingIterator_isIncrementing___doc__}, + {"getObject", ( PyCFunction ) ChainingIterator_getObject, METH_NOARGS, ChainingIterator_getObject___doc__}, + {NULL, NULL, 0, NULL} +}; + +/*-----------------------BPy_ChainingIterator type definition ------------------------------*/ + +PyTypeObject ChainingIterator_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "ChainingIterator", /* tp_name */ + sizeof(BPy_ChainingIterator), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ChainingIterator___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + BPy_ChainingIterator_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &ViewEdgeIterator_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ChainingIterator___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ +}; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.h new file mode 100644 index 00000000000..2a00aa8072f --- /dev/null +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.h @@ -0,0 +1,33 @@ +#ifndef FREESTYLE_PYTHON_CHAININGITERATOR_H +#define FREESTYLE_PYTHON_CHAININGITERATOR_H + + +#include "../../stroke/ChainingIterators.h" + +#include "BPy_ViewEdgeIterator.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +#include <Python.h> + +extern PyTypeObject ChainingIterator_Type; + +#define BPy_ChainingIterator_Check(v) ( PyObject_IsInstance( (PyObject *) v, (PyObject *) &ChainingIterator_Type) ) + +/*---------------------------Python BPy_ChainingIterator structure definition----------*/ +typedef struct { + BPy_ViewEdgeIterator py_ve_it; + ChainingIterator *c_it; +} BPy_ChainingIterator; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif + +#endif /* FREESTYLE_PYTHON_CHAININGITERATOR_H */ diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp new file mode 100644 index 00000000000..f66d95b3a39 --- /dev/null +++ b/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp @@ -0,0 +1,171 @@ +#include "BPy_CurvePointIterator.h" + +#include "../BPy_Convert.h" +#include "BPy_Interface0DIterator.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +//------------------------INSTANCE METHODS ---------------------------------- + +static char CurvePointIterator___doc__[] = +"Class hierarchy: :class:`Iterator` > :class:`CurvePointIterator`\n" +"\n" +"Class representing an iterator on a curve. Allows an iterating\n" +"outside initial vertices. A CurvePoint is instanciated and returned\n" +"by getObject().\n" +"\n" +".. method:: __init__(step=0.0)\n" +"\n" +" Builds a CurvePointIterator object.\n" +"\n" +" :arg step: A resampling resolution with which the curve is resampled.\n" +" If zero, no resampling is done (i.e., the iterator iterates over\n" +" initial vertices).\n" +" :type step: float\n" +"\n" +".. method:: __init__(brother)\n" +"\n" +" Copy constructor.\n" +"\n" +" :arg brother: A CurvePointIterator object.\n" +" :type brother: :class:`CurvePointIterator`\n"; + +static int CurvePointIterator___init__(BPy_CurvePointIterator *self, PyObject *args ) +{ + PyObject *obj = 0; + + if (! PyArg_ParseTuple(args, "|O", &obj) ) + return -1; + + if( !obj ){ + self->cp_it = new CurveInternal::CurvePointIterator(); + + } else if( BPy_CurvePointIterator_Check(obj) ) { + self->cp_it = new CurveInternal::CurvePointIterator(*( ((BPy_CurvePointIterator *) obj)->cp_it )); + + } else if( PyFloat_Check(obj) ) { + self->cp_it = new CurveInternal::CurvePointIterator( PyFloat_AsDouble(obj) ); + + } else { + PyErr_SetString(PyExc_TypeError, "invalid argument"); + return -1; + } + + self->py_it.it = self->cp_it; + + return 0; +} + +static char CurvePointIterator_t___doc__[] = +".. method:: t()\n" +"\n" +" Returns the curvilinear abscissa.\n" +"\n" +" :return: The curvilinear abscissa.\n" +" :rtype: float\n"; + +static PyObject * CurvePointIterator_t( BPy_CurvePointIterator *self ) { + return PyFloat_FromDouble( self->cp_it->t() ); +} + +static char CurvePointIterator_u___doc__[] = +".. method:: u()\n" +"\n" +" Returns the point parameter in the curve (0<=u<=1).\n" +"\n" +" :return: The point parameter.\n" +" :rtype: float\n"; + +static PyObject * CurvePointIterator_u( BPy_CurvePointIterator *self ) { + return PyFloat_FromDouble( self->cp_it->u() ); +} + +static char CurvePointIterator_castToInterface0DIterator___doc__[] = +".. method:: castToInterface0DIterator()\n" +"\n" +" Returns an Interface0DIterator converted from this\n" +" CurvePointIterator. Useful for any call to a function of the\n" +" UnaryFunction0D type.\n" +"\n" +" :return: An Interface0DIterator object converted from the\n" +" iterator.\n" +" :rtype: :class:`Interface0DIterator`\n"; + +static PyObject * CurvePointIterator_castToInterface0DIterator( BPy_CurvePointIterator *self ) { + Interface0DIterator it( self->cp_it->castToInterface0DIterator() ); + return BPy_Interface0DIterator_from_Interface0DIterator( it, 0 ); +} + +static char CurvePointIterator_getObject___doc__[] = +".. method:: getObject()\n" +"\n" +" Returns a CurvePoint pointed by the iterator.\n" +"\n" +" :return: \n" +" :rtype: :class:`CurvePoint`\n"; + +static PyObject * CurvePointIterator_getObject(BPy_CurvePointIterator *self) { + return BPy_CurvePoint_from_CurvePoint( self->cp_it->operator*() ); +} + +/*----------------------CurvePointIterator instance definitions ----------------------------*/ +static PyMethodDef BPy_CurvePointIterator_methods[] = { + {"t", ( PyCFunction ) CurvePointIterator_t, METH_NOARGS, CurvePointIterator_t___doc__}, + {"u", ( PyCFunction ) CurvePointIterator_u, METH_NOARGS, CurvePointIterator_u___doc__}, + {"castToInterface0DIterator", ( PyCFunction ) CurvePointIterator_castToInterface0DIterator, METH_NOARGS, CurvePointIterator_castToInterface0DIterator___doc__}, + {"getObject", ( PyCFunction ) CurvePointIterator_getObject, METH_NOARGS, CurvePointIterator_getObject___doc__}, + {NULL, NULL, 0, NULL} +}; + +/*-----------------------BPy_CurvePointIterator type definition ------------------------------*/ + +PyTypeObject CurvePointIterator_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "CurvePointIterator", /* tp_name */ + sizeof(BPy_CurvePointIterator), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + CurvePointIterator___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + BPy_CurvePointIterator_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &Iterator_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)CurvePointIterator___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ +}; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.h new file mode 100644 index 00000000000..ad04c7208bb --- /dev/null +++ b/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.h @@ -0,0 +1,32 @@ +#ifndef FREESTYLE_PYTHON_CURVEPOINTITERATOR_H +#define FREESTYLE_PYTHON_CURVEPOINTITERATOR_H + +#include "../../stroke/CurveIterators.h" + +#include "../BPy_Iterator.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +#include <Python.h> + +extern PyTypeObject CurvePointIterator_Type; + +#define BPy_CurvePointIterator_Check(v) ( PyObject_IsInstance( (PyObject *) v, (PyObject *) &CurvePointIterator_Type) ) + +/*---------------------------Python BPy_CurvePointIterator structure definition----------*/ +typedef struct { + BPy_Iterator py_it; + CurveInternal::CurvePointIterator *cp_it; +} BPy_CurvePointIterator; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif + +#endif /* FREESTYLE_PYTHON_CURVEPOINTITERATOR_H */ diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp new file mode 100644 index 00000000000..6643913c32a --- /dev/null +++ b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp @@ -0,0 +1,151 @@ +#include "BPy_Interface0DIterator.h" + +#include "../BPy_Convert.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +//------------------------INSTANCE METHODS ---------------------------------- + +static char Interface0DIterator___doc__[] = +"Class hierarchy: :class:`Iterator` > :class:`Interface0DIterator`\n" +"\n" +"Class defining an iterator over Interface0D elements. An instance of\n" +"this iterator is always obtained from a 1D element.\n" +"\n" +".. method:: __init__(it)\n" +"\n" +" Copy constructor.\n" +"\n" +" :arg it: An Interface0DIterator object.\n" +" :type it: :class:`Interface0DIterator`\n"; + +static int Interface0DIterator___init__(BPy_Interface0DIterator *self, PyObject *args ) +{ + PyObject *obj = 0; + + if (!( PyArg_ParseTuple(args, "O!", &Interface0DIterator_Type, &obj) )) + return -1; + + self->if0D_it = new Interface0DIterator(*( ((BPy_Interface0DIterator *) obj)->if0D_it )); + self->py_it.it = self->if0D_it; + self->reversed = 0; + + return 0; +} + +static PyObject * Interface0DIterator_iternext( BPy_Interface0DIterator *self ) { + Interface0D *if0D; + if (self->reversed) { + if (self->if0D_it->isBegin()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + self->if0D_it->decrement(); + if0D = self->if0D_it->operator->(); + } else { + if (self->if0D_it->isEnd()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + if0D = self->if0D_it->operator->(); + self->if0D_it->increment(); + } + return Any_BPy_Interface0D_from_Interface0D( *if0D ); +} + +static char Interface0DIterator_t___doc__[] = +".. method:: t()\n" +"\n" +" Returns the curvilinear abscissa.\n" +"\n" +" :return: The curvilinear abscissa.\n" +" :rtype: float\n"; + +static PyObject * Interface0DIterator_t( BPy_Interface0DIterator *self ) { + return PyFloat_FromDouble( self->if0D_it->t() ); +} + +static char Interface0DIterator_u___doc__[] = +".. method:: u()\n" +"\n" +" Returns the point parameter in the curve 0<=u<=1.\n" +"\n" +" :return: The point parameter.\n" +" :rtype: float\n"; + +static PyObject * Interface0DIterator_u( BPy_Interface0DIterator *self ) { + return PyFloat_FromDouble( self->if0D_it->u() ); +} + +static char Interface0DIterator_getObject___doc__[] = +".. method:: getObject()\n" +"\n" +" Returns the pointed Interface0D.\n" +"\n" +" :return: The pointed Interface0D.\n" +" :rtype: :class:`Interface0D`\n"; + +static PyObject * Interface0DIterator_getObject(BPy_Interface0DIterator *self) { + return Any_BPy_Interface0D_from_Interface0D( self->if0D_it->operator*() ); +} + +/*----------------------Interface0DIterator instance definitions ----------------------------*/ +static PyMethodDef BPy_Interface0DIterator_methods[] = { + {"t", ( PyCFunction ) Interface0DIterator_t, METH_NOARGS, Interface0DIterator_t___doc__}, + {"u", ( PyCFunction ) Interface0DIterator_u, METH_NOARGS, Interface0DIterator_u___doc__}, + {"getObject", ( PyCFunction ) Interface0DIterator_getObject, METH_NOARGS, Interface0DIterator_getObject___doc__}, + {NULL, NULL, 0, NULL} +}; + +/*-----------------------BPy_Interface0DIterator type definition ------------------------------*/ + +PyTypeObject Interface0DIterator_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "Interface0DIterator", /* tp_name */ + sizeof(BPy_Interface0DIterator), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + Interface0DIterator___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + PyObject_SelfIter, /* tp_iter */ + (iternextfunc)Interface0DIterator_iternext, /* tp_iternext */ + BPy_Interface0DIterator_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &Iterator_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)Interface0DIterator___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ +}; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.h new file mode 100644 index 00000000000..1972763b2eb --- /dev/null +++ b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.h @@ -0,0 +1,33 @@ +#ifndef FREESTYLE_PYTHON_INTERFACE0DITERATOR_H +#define FREESTYLE_PYTHON_INTERFACE0DITERATOR_H + +#include "../../view_map/Interface0D.h" +#include "../BPy_Iterator.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +#include <Python.h> + +extern PyTypeObject Interface0DIterator_Type; + +#define BPy_Interface0DIterator_Check(v) ( PyObject_IsInstance( (PyObject *) v, (PyObject *) &Interface0DIterator_Type) ) + +/*---------------------------Python BPy_Interface0DIterator structure definition----------*/ +typedef struct { + BPy_Iterator py_it; + Interface0DIterator *if0D_it; + int reversed; +} BPy_Interface0DIterator; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif + +#endif /* FREESTYLE_PYTHON_INTERFACE0DITERATOR_H */ diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.cpp new file mode 100644 index 00000000000..ef40d994e27 --- /dev/null +++ b/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.cpp @@ -0,0 +1,181 @@ +#include "BPy_SVertexIterator.h" + +#include "../BPy_Convert.h" +#include "../Interface0D/BPy_SVertex.h" +#include "../Interface1D/BPy_FEdge.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +//------------------------INSTANCE METHODS ---------------------------------- + +static char SVertexIterator___doc__[] = +"Class hierarchy: :class:`Iterator` > :class:`SVertexIterator`\n" +"\n" +"Class representing an iterator over :class:`SVertex` of a\n" +":class:`ViewEdge`. An instance of an SVertexIterator can be obtained\n" +"from a ViewEdge by calling verticesBegin() or verticesEnd().\n" +"\n" +".. method:: __init__()\n" +"\n" +" Default constructor.\n" +"\n" +".. method:: __init__(it)\n" +"\n" +" Copy constructor.\n" +"\n" +" :arg it: An SVertexIterator object.\n" +" :type it: :class:`SVertexIterator`\n" +"\n" +".. method:: __init__(v, begin, prev, next, t)\n" +"\n" +" Builds an SVertexIterator that starts iteration from an SVertex\n" +" object v.\n" +"\n" +" :arg v: The SVertex from which the iterator starts iteration.\n" +" :type v: :class:`SVertex`\n" +" :arg begin: The first vertex of a view edge.\n" +" :type begin: :class:`SVertex`\n" +" :arg prev: The previous FEdge coming to v.\n" +" :type prev: :class:`FEdge`\n" +" :arg next: The next FEdge going out from v.\n" +" :type next: :class:`FEdge`\n" +" :arg t: The curvilinear abscissa at v.\n" +" :type t: float\n"; + +static int SVertexIterator___init__(BPy_SVertexIterator *self, PyObject *args ) +{ + PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0, *obj4 = 0; + float f = 0; + + if (! PyArg_ParseTuple(args, "|OOOOf", &obj1, &obj2, &obj3, &obj4, f) ) + return -1; + + if( !obj1 ){ + self->sv_it = new ViewEdgeInternal::SVertexIterator(); + + } else if( BPy_SVertexIterator_Check(obj1) ) { + self->sv_it = new ViewEdgeInternal::SVertexIterator(*( ((BPy_SVertexIterator *) obj1)->sv_it )); + + } else if( obj1 && BPy_SVertex_Check(obj1) && + obj2 && BPy_SVertex_Check(obj2) && + obj3 && BPy_FEdge_Check(obj3) && + obj4 && BPy_FEdge_Check(obj4) ) { + + self->sv_it = new ViewEdgeInternal::SVertexIterator( + ((BPy_SVertex *) obj1)->sv, + ((BPy_SVertex *) obj2)->sv, + ((BPy_FEdge *) obj3)->fe, + ((BPy_FEdge *) obj4)->fe, + f ); + + } else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } + + self->py_it.it = self->sv_it; + + return 0; +} + +static char SVertexIterator_t___doc__[] = +".. method:: t()\n" +"\n" +" Returns the curvilinear abscissa.\n" +"\n" +" :return: The curvilinear abscissa.\n" +" :rtype: float\n"; + +static PyObject * SVertexIterator_t( BPy_SVertexIterator *self ) { + return PyFloat_FromDouble( self->sv_it->t() ); +} + +static char SVertexIterator_u___doc__[] = +".. method:: u()\n" +"\n" +" Returns the point parameter (0<=u<=1).\n" +"\n" +" :return: The point parameter.\n" +" :rtype: float\n"; + +static PyObject * SVertexIterator_u( BPy_SVertexIterator *self ) { + return PyFloat_FromDouble( self->sv_it->u() ); +} + +static char SVertexIterator_getObject___doc__[] = +".. method:: getObject()\n" +"\n" +" Returns the pointed SVertex.\n" +"\n" +" :return: the pointed SVertex.\n" +" :rtype: :class:`SVertex`\n"; + +static PyObject * SVertexIterator_getObject( BPy_SVertexIterator *self) { + SVertex *sv = self->sv_it->operator->(); + + if( sv ) + return BPy_SVertex_from_SVertex( *sv ); + + Py_RETURN_NONE; +} + +/*----------------------SVertexIterator instance definitions ----------------------------*/ +static PyMethodDef BPy_SVertexIterator_methods[] = { + {"t", ( PyCFunction ) SVertexIterator_t, METH_NOARGS, SVertexIterator_t___doc__}, + {"u", ( PyCFunction ) SVertexIterator_u, METH_NOARGS, SVertexIterator_u___doc__}, + {"getObject", ( PyCFunction ) SVertexIterator_getObject, METH_NOARGS, SVertexIterator_getObject___doc__}, + {NULL, NULL, 0, NULL} +}; + +/*-----------------------BPy_SVertexIterator type definition ------------------------------*/ + +PyTypeObject SVertexIterator_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "SVertexIterator", /* tp_name */ + sizeof(BPy_SVertexIterator), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + SVertexIterator___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + BPy_SVertexIterator_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &Iterator_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)SVertexIterator___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ +}; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.h new file mode 100644 index 00000000000..b40f4d36420 --- /dev/null +++ b/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.h @@ -0,0 +1,33 @@ +#ifndef FREESTYLE_PYTHON_SVERTEXITERATOR_H +#define FREESTYLE_PYTHON_SVERTEXITERATOR_H + +#include "../../view_map/ViewMapIterators.h" + +#include "../BPy_Iterator.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +#include <Python.h> + +extern PyTypeObject SVertexIterator_Type; + +#define BPy_SVertexIterator_Check(v) ( PyObject_IsInstance( (PyObject *) v, (PyObject *) &SVertexIterator_Type) ) + +/*---------------------------Python BPy_SVertexIterator structure definition----------*/ +typedef struct { + BPy_Iterator py_it; + ViewEdgeInternal::SVertexIterator *sv_it; +} BPy_SVertexIterator; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif + +#endif /* FREESTYLE_PYTHON_SVERTEXITERATOR_H */ diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp new file mode 100644 index 00000000000..a9b2c4d774a --- /dev/null +++ b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp @@ -0,0 +1,197 @@ +#include "BPy_StrokeVertexIterator.h" + +#include "../BPy_Convert.h" +#include "BPy_Interface0DIterator.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +//------------------------INSTANCE METHODS ---------------------------------- + +static char StrokeVertexIterator___doc__[] = +"Class hierarchy: :class:`Iterator` > :class:`StrokeVertexIterator`\n" +"\n" +"Class defining an iterator designed to iterate over the\n" +":class:`StrokeVertex` of a :class:`Stroke`. An instance of a\n" +"StrokeVertexIterator can only be obtained from a Stroke by calling\n" +"strokeVerticesBegin() or strokeVerticesEnd(). It is iterating over\n" +"the same vertices as an :class:`Interface0DIterator`. The difference\n" +"resides in the object access. Indeed, an Interface0DIterator allows\n" +"only an access to an Interface0D whereas we could need to access the\n" +"specialized StrokeVertex type. In this case, one should use a\n" +"StrokeVertexIterator. The castToInterface0DIterator() method is\n" +"useful to get an Interface0DIterator from a StrokeVertexIterator in\n" +"order to call any functions of the UnaryFunction0D type.\n" +"\n" +".. method:: __init__()\n" +"\n" +" Default constructor.\n" +"\n" +".. method:: __init__(it)\n" +"\n" +" Copy constructor.\n" +"\n" +" :arg it: A StrokeVertexIterator object.\n" +" :type it: :class:`StrokeVertexIterator`\n"; + +static int StrokeVertexIterator___init__(BPy_StrokeVertexIterator *self, PyObject *args ) +{ + PyObject *obj = 0; + + if (! PyArg_ParseTuple(args, "|O", &obj) ) + return -1; + + if( !obj ){ + self->sv_it = new StrokeInternal::StrokeVertexIterator(); + + } else if( BPy_StrokeVertexIterator_Check(obj) ) { + self->sv_it = new StrokeInternal::StrokeVertexIterator(*( ((BPy_StrokeVertexIterator *) obj)->sv_it )); + + } else { + PyErr_SetString(PyExc_TypeError, "invalid argument"); + return -1; + } + + self->py_it.it = self->sv_it; + self->reversed = 0; + + return 0; +} + +static PyObject * StrokeVertexIterator_iternext( BPy_StrokeVertexIterator *self ) { + StrokeVertex *sv; + if (self->reversed) { + if (self->sv_it->isBegin()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + self->sv_it->decrement(); + sv = self->sv_it->operator->(); + } else { + if (self->sv_it->isEnd()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + sv = self->sv_it->operator->(); + self->sv_it->increment(); + } + return BPy_StrokeVertex_from_StrokeVertex( *sv ); +} + +static char StrokeVertexIterator_t___doc__[] = +".. method:: t()\n" +"\n" +" Returns the curvilinear abscissa of the current point.\n" +"\n" +" :return: The curvilinear abscissa of the current point.\n" +" :rtype: float\n"; + +static PyObject * StrokeVertexIterator_t( BPy_StrokeVertexIterator *self ) { + return PyFloat_FromDouble( self->sv_it->t() ); +} + +static char StrokeVertexIterator_u___doc__[] = +".. method:: u()\n" +"\n" +" Returns the point parameter in the stroke (0<=u<=1).\n" +"\n" +" :return: The point parameter in the stroke\n" +" :rtype: float\n"; + +static PyObject * StrokeVertexIterator_u( BPy_StrokeVertexIterator *self ) { + return PyFloat_FromDouble( self->sv_it->u() ); +} + +static char StrokeVertexIterator_castToInterface0DIterator___doc__[] = +".. method:: castToInterface0DIterator()\n" +"\n" +" Returns an Interface0DIterator converted from this\n" +" StrokeVertexIterator. Useful for any call to a function of the\n" +" UnaryFunction0D type.\n" +"\n" +" :return: An Interface0DIterator converted from the StrokeVertexIterator.\n" +" :rtype: :class:`Interface0DIterator`\n"; + +static PyObject * StrokeVertexIterator_castToInterface0DIterator( BPy_StrokeVertexIterator *self ) { + Interface0DIterator it( self->sv_it->castToInterface0DIterator() ); + return BPy_Interface0DIterator_from_Interface0DIterator( it, 0 ); +} + +static char StrokeVertexIterator_getObject___doc__[] = +".. method:: getObject()\n" +"\n" +" Returns the pointed StrokeVertex.\n" +"\n" +" :return: The pointed StrokeVertex.\n" +" :rtype: :class:`StrokeVertex`\n"; + +static PyObject * StrokeVertexIterator_getObject( BPy_StrokeVertexIterator *self) { + if (!self->reversed && self->sv_it->isEnd()) + Py_RETURN_NONE; + StrokeVertex *sv = self->sv_it->operator->(); + if( sv ) + return BPy_StrokeVertex_from_StrokeVertex( *sv ); + + Py_RETURN_NONE; +} + +/*----------------------StrokeVertexIterator instance definitions ----------------------------*/ +static PyMethodDef BPy_StrokeVertexIterator_methods[] = { + {"t", ( PyCFunction ) StrokeVertexIterator_t, METH_NOARGS, StrokeVertexIterator_t___doc__}, + {"u", ( PyCFunction ) StrokeVertexIterator_u, METH_NOARGS, StrokeVertexIterator_u___doc__}, + {"castToInterface0DIterator", ( PyCFunction ) StrokeVertexIterator_castToInterface0DIterator, METH_NOARGS, StrokeVertexIterator_castToInterface0DIterator___doc__}, + {"getObject", ( PyCFunction ) StrokeVertexIterator_getObject, METH_NOARGS, StrokeVertexIterator_getObject___doc__}, + {NULL, NULL, 0, NULL} +}; + +/*-----------------------BPy_StrokeVertexIterator type definition ------------------------------*/ + +PyTypeObject StrokeVertexIterator_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "StrokeVertexIterator", /* tp_name */ + sizeof(BPy_StrokeVertexIterator), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + StrokeVertexIterator___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + PyObject_SelfIter, /* tp_iter */ + (iternextfunc)StrokeVertexIterator_iternext, /* tp_iternext */ + BPy_StrokeVertexIterator_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &Iterator_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)StrokeVertexIterator___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ +}; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.h new file mode 100644 index 00000000000..0c4b6e4bb6c --- /dev/null +++ b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.h @@ -0,0 +1,33 @@ +#ifndef FREESTYLE_PYTHON_STROKEVERTEXITERATOR_H +#define FREESTYLE_PYTHON_STROKEVERTEXITERATOR_H + +#include "../../stroke/StrokeIterators.h" + +#include "../BPy_Iterator.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +#include <Python.h> + +extern PyTypeObject StrokeVertexIterator_Type; + +#define BPy_StrokeVertexIterator_Check(v) ( PyObject_IsInstance( (PyObject *) v, (PyObject *) &StrokeVertexIterator_Type) ) + +/*---------------------------Python BPy_StrokeVertexIterator structure definition----------*/ +typedef struct { + BPy_Iterator py_it; + StrokeInternal::StrokeVertexIterator *sv_it; + int reversed; +} BPy_StrokeVertexIterator; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif + +#endif /* FREESTYLE_PYTHON_STROKEVERTEXITERATOR_H */ diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp new file mode 100644 index 00000000000..660e00b7089 --- /dev/null +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp @@ -0,0 +1,266 @@ +#include "BPy_ViewEdgeIterator.h" + +#include "../BPy_Convert.h" +#include "../Interface1D/BPy_ViewEdge.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +//------------------------INSTANCE METHODS ---------------------------------- + +static char ViewEdgeIterator___doc__[] = +"Class hierarchy: :class:`Iterator` > :class:`ViewEdgeIterator`\n" +"\n" +"Base class for iterators over ViewEdges of the :class:`ViewMap` Graph.\n" +"Basically the increment() operator of this class should be able to\n" +"take the decision of \"where\" (on which ViewEdge) to go when pointing\n" +"on a given ViewEdge.\n" +"\n" +".. method:: __init__(begin=None, orientation=True)\n" +"\n" +" Builds a ViewEdgeIterator from a starting ViewEdge and its\n" +" orientation.\n" +"\n" +" :arg begin: The ViewEdge from where to start the iteration.\n" +" :type begin: :class:`ViewEdge` or None\n" +" :arg orientation: If true, we'll look for the next ViewEdge among\n" +" the ViewEdges that surround the ending ViewVertex of begin. If\n" +" false, we'll search over the ViewEdges surrounding the ending\n" +" ViewVertex of begin.\n" +" :type orientation: bool\n" +"\n" +".. method:: __init__(it)\n" +"\n" +" Copy constructor.\n" +"\n" +" :arg it: A ViewEdgeIterator object.\n" +" :type it: :class:`ViewEdgeIterator`\n"; + +static int ViewEdgeIterator___init__(BPy_ViewEdgeIterator *self, PyObject *args ) +{ + PyObject *obj1 = 0, *obj2 = 0; + + if (!( PyArg_ParseTuple(args, "O|O", &obj1, &obj2) )) + return -1; + + if( obj1 && BPy_ViewEdgeIterator_Check(obj1) ) { + self->ve_it = new ViewEdgeInternal::ViewEdgeIterator(*( ((BPy_ViewEdgeIterator *) obj1)->ve_it )); + + } else { + ViewEdge *begin; + if ( !obj1 || obj1 == Py_None ) + begin = NULL; + else if ( BPy_ViewEdge_Check(obj1) ) + begin = ((BPy_ViewEdge *) obj1)->ve; + else { + PyErr_SetString(PyExc_TypeError, "1st argument must be either a ViewEdge object or None"); + return -1; + } + bool orientation = ( obj2 ) ? bool_from_PyBool(obj2) : true; + + self->ve_it = new ViewEdgeInternal::ViewEdgeIterator( begin, orientation); + + } + + self->py_it.it = self->ve_it; + + return 0; +} + +static char ViewEdgeIterator_getCurrentEdge___doc__[] = +".. method:: getCurrentEdge()\n" +"\n" +" Returns the current pointed ViewEdge.\n" +"\n" +" :return: The current pointed ViewEdge.\n" +" :rtype: :class:`ViewEdge`\n"; + +static PyObject *ViewEdgeIterator_getCurrentEdge( BPy_ViewEdgeIterator *self ) { + ViewEdge *ve = self->ve_it->getCurrentEdge(); + if( ve ) + return BPy_ViewEdge_from_ViewEdge( *ve ); + + Py_RETURN_NONE; +} + +static char ViewEdgeIterator_setCurrentEdge___doc__[] = +".. method:: setCurrentEdge(edge)\n" +"\n" +" Sets the current pointed ViewEdge.\n" +"\n" +" :arg edge: The current pointed ViewEdge.\n" +" :type edge: :class:`ViewEdge`\n"; + +static PyObject *ViewEdgeIterator_setCurrentEdge( BPy_ViewEdgeIterator *self, PyObject *args ) { + PyObject *py_ve; + + if(!( PyArg_ParseTuple(args, "O!", &ViewEdge_Type, &py_ve) )) + return NULL; + + self->ve_it->setCurrentEdge( ((BPy_ViewEdge *) py_ve)->ve ); + + Py_RETURN_NONE; +} + +static char ViewEdgeIterator_getBegin___doc__[] = +".. method:: getBegin()\n" +"\n" +" Returns the first ViewEdge used for the iteration.\n" +"\n" +" :return: The first ViewEdge used for the iteration.\n" +" :rtype: :class:`ViewEdge`\n"; + +static PyObject *ViewEdgeIterator_getBegin( BPy_ViewEdgeIterator *self ) { + ViewEdge *ve = self->ve_it->getBegin(); + if( ve ) + return BPy_ViewEdge_from_ViewEdge( *ve ); + + Py_RETURN_NONE; +} + +static char ViewEdgeIterator_setBegin___doc__[] = +".. method:: setBegin(begin)\n" +"\n" +" Sets the first ViewEdge used for the iteration.\n" +"\n" +" :arg begin: The first ViewEdge used for the iteration.\n" +" :type begin: :class:`ViewEdge`\n"; + +static PyObject *ViewEdgeIterator_setBegin( BPy_ViewEdgeIterator *self, PyObject *args ) { + PyObject *py_ve; + + if(!( PyArg_ParseTuple(args, "O!", &ViewEdge_Type, &py_ve) )) + return NULL; + + self->ve_it->setBegin( ((BPy_ViewEdge *) py_ve)->ve ); + + Py_RETURN_NONE; +} + +static char ViewEdgeIterator_getOrientation___doc__[] = +".. method:: getOrientation()\n" +"\n" +" Returns the orientation of the pointed ViewEdge in the iteration.\n" +"\n" +" :return: The orientation of the pointed ViewEdge in the iteration.\n" +" :rtype: bool\n"; + +static PyObject *ViewEdgeIterator_getOrientation( BPy_ViewEdgeIterator *self ) { + return PyBool_from_bool( self->ve_it->getOrientation() ); +} + +static char ViewEdgeIterator_setOrientation___doc__[] = +".. method:: setOrientation(orientation)\n" +"\n" +" Sets the orientation of the pointed ViewEdge in the iteration.\n" +"\n" +" :arg orientation: If true, we'll look for the next ViewEdge among\n" +" the ViewEdges that surround the ending ViewVertex of begin. If\n" +" false, we'll search over the ViewEdges surrounding the ending\n" +" ViewVertex of begin.\n" +" :type orientation: bool\n"; + +static PyObject *ViewEdgeIterator_setOrientation( BPy_ViewEdgeIterator *self, PyObject *args ) { + PyObject *py_b; + + if(!( PyArg_ParseTuple(args, "O", &py_b) )) + return NULL; + + self->ve_it->setOrientation( bool_from_PyBool(py_b) ); + + Py_RETURN_NONE; +} + +static char ViewEdgeIterator_changeOrientation___doc__[] = +".. method:: changeOrientation()\n" +"\n" +" Changes the current orientation.\n"; + +static PyObject *ViewEdgeIterator_changeOrientation( BPy_ViewEdgeIterator *self ) { + self->ve_it->changeOrientation(); + + Py_RETURN_NONE; +} + +static char ViewEdgeIterator_getObject___doc__[] = +".. method:: getObject()\n" +"\n" +" Returns the pointed ViewEdge.\n" +"\n" +" :return: The pointed ViewEdge.\n" +" :rtype: :class:`ViewEdge`\n"; + +static PyObject * ViewEdgeIterator_getObject( BPy_ViewEdgeIterator *self) { + + ViewEdge *ve = self->ve_it->operator*(); + if( ve ) + return BPy_ViewEdge_from_ViewEdge( *ve ); + + Py_RETURN_NONE; +} + +/*----------------------ViewEdgeIterator instance definitions ----------------------------*/ +static PyMethodDef BPy_ViewEdgeIterator_methods[] = { + {"getCurrentEdge", ( PyCFunction ) ViewEdgeIterator_getCurrentEdge, METH_NOARGS, ViewEdgeIterator_getCurrentEdge___doc__}, + {"setCurrentEdge", ( PyCFunction ) ViewEdgeIterator_setCurrentEdge, METH_VARARGS, ViewEdgeIterator_setCurrentEdge___doc__}, + {"getBegin", ( PyCFunction ) ViewEdgeIterator_getBegin, METH_NOARGS, ViewEdgeIterator_getBegin___doc__}, + {"setBegin", ( PyCFunction ) ViewEdgeIterator_setBegin, METH_VARARGS, ViewEdgeIterator_setBegin___doc__}, + {"getOrientation", ( PyCFunction ) ViewEdgeIterator_getOrientation, METH_NOARGS, ViewEdgeIterator_getOrientation___doc__}, + {"setOrientation", ( PyCFunction ) ViewEdgeIterator_setOrientation, METH_VARARGS, ViewEdgeIterator_setOrientation___doc__}, + {"changeOrientation", ( PyCFunction ) ViewEdgeIterator_changeOrientation, METH_NOARGS, ViewEdgeIterator_changeOrientation___doc__}, + {"getObject", ( PyCFunction ) ViewEdgeIterator_getObject, METH_NOARGS, ViewEdgeIterator_getObject___doc__}, + {NULL, NULL, 0, NULL} +}; + +/*-----------------------BPy_ViewEdgeIterator type definition ------------------------------*/ + +PyTypeObject ViewEdgeIterator_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "ViewEdgeIterator", /* tp_name */ + sizeof(BPy_ViewEdgeIterator), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ViewEdgeIterator___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + BPy_ViewEdgeIterator_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &Iterator_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ViewEdgeIterator___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ +}; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.h new file mode 100644 index 00000000000..dce90efc8cf --- /dev/null +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.h @@ -0,0 +1,33 @@ +#ifndef FREESTYLE_PYTHON_VIEWEDGEITERATOR_H +#define FREESTYLE_PYTHON_VIEWEDGEITERATOR_H + + +#include "../../view_map/ViewMapIterators.h" + +#include "../BPy_Iterator.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +#include <Python.h> + +extern PyTypeObject ViewEdgeIterator_Type; + +#define BPy_ViewEdgeIterator_Check(v) ( PyObject_IsInstance( (PyObject *) v, (PyObject *) &ViewEdgeIterator_Type) ) + +/*---------------------------Python BPy_ViewEdgeIterator structure definition----------*/ +typedef struct { + BPy_Iterator py_it; + ViewEdgeInternal::ViewEdgeIterator *ve_it; +} BPy_ViewEdgeIterator; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif + +#endif /* FREESTYLE_PYTHON_VIEWEDGEITERATOR_H */ diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp new file mode 100644 index 00000000000..46eb7055217 --- /dev/null +++ b/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp @@ -0,0 +1,140 @@ +#include "BPy_orientedViewEdgeIterator.h" + +#include "../BPy_Convert.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +//------------------------INSTANCE METHODS ---------------------------------- + +static char orientedViewEdgeIterator___doc__[] = +"Class hierarchy: :class:`Iterator` > :class:`orientedViewEdgeIterator`\n" +"\n" +"Class representing an iterator over oriented ViewEdges around a\n" +":class:`ViewVertex`. This iterator allows a CCW iteration (in the image\n" +"plane). An instance of an orientedViewEdgeIterator can only be\n" +"obtained from a ViewVertex by calling edgesBegin() or edgesEnd().\n" +"\n" +".. method:: __init__()\n" +"\n" +" Default constructor.\n" +"\n" +".. method:: __init__(iBrother)\n" +"\n" +" Copy constructor.\n" +"\n" +" :arg iBrother: An orientedViewEdgeIterator object.\n" +" :type iBrother: :class:`orientedViewEdgeIterator`\n"; + +static int orientedViewEdgeIterator___init__(BPy_orientedViewEdgeIterator *self, PyObject *args ) +{ + PyObject *obj = 0; + + if (!( PyArg_ParseTuple(args, "|O", &obj) )) + return -1; + + if( !obj ) + self->ove_it = new ViewVertexInternal::orientedViewEdgeIterator(); + else if( BPy_orientedViewEdgeIterator_Check(obj) ) + self->ove_it = new ViewVertexInternal::orientedViewEdgeIterator(*( ((BPy_orientedViewEdgeIterator *) obj)->ove_it )); + else { + PyErr_SetString(PyExc_TypeError, "invalid argument"); + return -1; + } + + self->py_it.it = self->ove_it; + self->reversed = 0; + + return 0; +} + +static PyObject * orientedViewEdgeIterator_iternext( BPy_orientedViewEdgeIterator *self ) { + ViewVertex::directedViewEdge *dve; + if (self->reversed) { + if (self->ove_it->isBegin()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + self->ove_it->decrement(); + dve = self->ove_it->operator->(); + } else { + if (self->ove_it->isEnd()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + dve = self->ove_it->operator->(); + self->ove_it->increment(); + } + return BPy_directedViewEdge_from_directedViewEdge( *dve ); +} + +static char orientedViewEdgeIterator_getObject___doc__[] = +".. method:: getObject()\n" +"\n" +" Returns the pointed oriented ViewEdge.\n" +"\n" +" :return: A tuple of the pointed ViewEdge and a boolean value. If\n" +" the boolean value is true, the ViewEdge is incoming.\n" +" :rtype: (:class:`directedViewEdge`, bool)\n"; + +static PyObject * orientedViewEdgeIterator_getObject( BPy_orientedViewEdgeIterator *self) { + return BPy_directedViewEdge_from_directedViewEdge( self->ove_it->operator*() ); +} + +/*----------------------orientedViewEdgeIterator instance definitions ----------------------------*/ +static PyMethodDef BPy_orientedViewEdgeIterator_methods[] = { + {"getObject", ( PyCFunction ) orientedViewEdgeIterator_getObject, METH_NOARGS, orientedViewEdgeIterator_getObject___doc__}, + {NULL, NULL, 0, NULL} +}; + +/*-----------------------BPy_orientedViewEdgeIterator type definition ------------------------------*/ + +PyTypeObject orientedViewEdgeIterator_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orientedViewEdgeIterator", /* tp_name */ + sizeof(BPy_orientedViewEdgeIterator), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + orientedViewEdgeIterator___doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + PyObject_SelfIter, /* tp_iter */ + (iternextfunc)orientedViewEdgeIterator_iternext, /* tp_iternext */ + BPy_orientedViewEdgeIterator_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &Iterator_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)orientedViewEdgeIterator___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ +}; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.h new file mode 100644 index 00000000000..cd9edf1e224 --- /dev/null +++ b/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.h @@ -0,0 +1,34 @@ +#ifndef FREESTYLE_PYTHON_ORIENTEDVIEWEDGEITERATOR_H +#define FREESTYLE_PYTHON_ORIENTEDVIEWEDGEITERATOR_H + +#include "../../stroke/Stroke.h" +#include "../../view_map/ViewMapIterators.h" + +#include "../BPy_Iterator.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +#include <Python.h> + +extern PyTypeObject orientedViewEdgeIterator_Type; + +#define BPy_orientedViewEdgeIterator_Check(v) ( PyObject_IsInstance( (PyObject *) v, (PyObject *) &orientedViewEdgeIterator_Type) ) + +/*---------------------------Python BPy_orientedViewEdgeIterator structure definition----------*/ +typedef struct { + BPy_Iterator py_it; + ViewVertexInternal::orientedViewEdgeIterator *ove_it; + int reversed; +} BPy_orientedViewEdgeIterator; + +/////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +} +#endif + +#endif /* FREESTYLE_PYTHON_ORIENTEDVIEWEDGEITERATOR_H */ |