32 if (module ==
nullptr) {
39 PyModule_AddObjectRef(module,
"Operators", (PyObject *)&
Operators_Type);
49 "Class defining the operators used in a style module. There are five\n"
50 "types of operators: Selection, chaining, splitting, sorting and\n"
51 "creation. All these operators are user controlled through functors,\n"
52 "predicates and shaders that are taken as arguments.\n");
55 Py_TYPE(self)->tp_free((PyObject *)self);
61 ".. staticmethod:: select(pred)\n"
63 " Selects the ViewEdges of the ViewMap verifying a specified\n"
66 " :param pred: The predicate expressing this condition.\n"
67 " :type pred: :class:`UnaryPredicate1D`\n");
70 static const char *kwlist[] = {
"pred",
nullptr};
71 PyObject *obj =
nullptr;
73 if (!PyArg_ParseTupleAndKeywords(args,
84 PyErr_SetString(PyExc_TypeError,
85 "Operators.select(): 1st argument: invalid UnaryPredicate1D object");
89 if (!PyErr_Occurred()) {
90 PyErr_SetString(PyExc_RuntimeError,
"Operators.select() failed");
100 ".. staticmethod:: chain(*args)\n"
102 " Accepted call signatures:\n"
104 " - ``chain(it, pred, modifier)``\n"
105 " - ``chain(it, pred)``\n"
107 " Builds a set of chains from the current set of ViewEdges. Each\n"
108 " ViewEdge of the current list starts a new chain. The chaining\n"
109 " operator then iterates over the ViewEdges of the ViewMap using the\n"
110 " user specified iterator. This operator only iterates using the\n"
111 " increment operator and is therefore unidirectional.\n"
113 " :param it: The iterator on the ViewEdges of the ViewMap. It contains\n"
114 " the chaining rule.\n"
115 " :type it: :class:`ViewEdgeIterator`\n"
116 " :param pred: The predicate on the ViewEdge that expresses the\n"
117 " stopping condition.\n"
118 " :type pred: :class:`UnaryPredicate1D`\n"
119 " :param modifier: A function that takes a ViewEdge as argument and\n"
120 " that is used to modify the processed ViewEdge state (the\n"
121 " timestamp incrementation is a typical illustration of such a modifier).\n"
122 " If this argument is not given, the time stamp is automatically managed.\n"
123 " :type modifier: :class:`UnaryFunction1DVoid`\n");
126 static const char *kwlist[] = {
"it",
"pred",
"modifier",
nullptr};
127 PyObject *obj1 =
nullptr, *obj2 =
nullptr, *obj3 =
nullptr;
129 if (!PyArg_ParseTupleAndKeywords(args,
147 PyErr_SetString(PyExc_TypeError,
148 "Operators.chain(): 1st argument: invalid ChainingIterator object");
152 PyErr_SetString(PyExc_TypeError,
153 "Operators.chain(): 2nd argument: invalid UnaryPredicate1D object");
160 if (!PyErr_Occurred()) {
161 PyErr_SetString(PyExc_RuntimeError,
"Operators.chain() failed");
168 PyErr_SetString(PyExc_TypeError,
169 "Operators.chain(): 3rd argument: invalid UnaryFunction1DVoid object");
176 if (!PyErr_Occurred()) {
177 PyErr_SetString(PyExc_RuntimeError,
"Operators.chain() failed");
187 Operators_bidirectional_chain_doc,
188 ".. staticmethod:: bidirectional_chain(*args)\n"
190 " Accepted call signatures:\n"
192 " - ``bidirectional_chain(it, pred)``\n"
193 " - ``bidirectional_chain(it)``\n"
195 " Builds a set of chains from the current set of ViewEdges. Each\n"
196 " ViewEdge of the current list potentially starts a new chain. The\n"
197 " chaining operator then iterates over the ViewEdges of the ViewMap\n"
198 " using the user specified iterator. This operator iterates both using\n"
199 " the increment and decrement operators and is therefore bidirectional.\n"
200 " This operator works with a ChainingIterator which contains the\n"
201 " chaining rules. It is this last one which can be told to chain only\n"
202 " edges that belong to the selection or not to process twice a ViewEdge\n"
203 " during the chaining. Each time a ViewEdge is added to a chain, its\n"
204 " chaining time stamp is incremented. This allows you to keep track of\n"
205 " the number of chains to which a ViewEdge belongs to.\n"
207 " :param it: The ChainingIterator on the ViewEdges of the ViewMap. It\n"
208 " contains the chaining rule.\n"
209 " :type it: :class:`ChainingIterator`\n"
210 " :param pred: The predicate on the ViewEdge that expresses the stopping condition.\n"
211 " This parameter is optional, you make not want to pass a stopping criterion\n"
212 " when the stopping criterion is already contained in the iterator definition.\n"
213 " :type pred: :class:`UnaryPredicate1D`\n");
218 static const char *kwlist[] = {
"it",
"pred",
nullptr};
219 PyObject *obj1 =
nullptr, *obj2 =
nullptr;
221 if (!PyArg_ParseTupleAndKeywords(args,
226 ":bidirectional_chain",
238 "Operators.bidirectional_chain(): 1st argument: invalid ChainingIterator object");
243 if (!PyErr_Occurred()) {
244 PyErr_SetString(PyExc_RuntimeError,
"Operators.bidirectional_chain() failed");
253 "Operators.bidirectional_chain(): 2nd argument: invalid UnaryPredicate1D object");
259 if (!PyErr_Occurred()) {
260 PyErr_SetString(PyExc_RuntimeError,
"Operators.bidirectional_chain() failed");
270 Operators_sequential_split_doc,
271 ".. staticmethod:: sequential_split(*args, **kwargs)\n"
273 " Accepted call signatures:\n"
275 " - ``sequential_split(starting_pred, stopping_pred, sampling=0.0)``\n"
276 " - ``sequential_split(pred, sampling=0.0)``\n"
278 " Splits each chain of the current set of chains in a sequential way.\n"
279 " The points of each chain are processed (with a specified sampling)\n"
280 " sequentially. The first point of the initial chain is the\n"
281 " first point of one of the resulting chains. The splitting ends when\n"
282 " no more chain can start.\n"
286 " By specifying a starting and stopping predicate allows\n"
287 " the chains to overlap rather than chains partitioning.\n"
289 " :param starting_pred: The predicate on a point that expresses the\n"
290 " starting condition. Each time this condition is verified, a new chain begins\n"
291 " :type starting_pred: :class:`UnaryPredicate0D`\n"
292 " :param stopping_pred: The predicate on a point that expresses the\n"
293 " stopping condition. The chain ends as soon as this predicate is verified.\n"
294 " :type stopping_pred: :class:`UnaryPredicate0D`\n"
295 " :param pred: The predicate on a point that expresses the splitting condition.\n"
296 " Each time the condition is verified, the chain is split into two chains.\n"
297 " The resulting set of chains is a partition of the initial chain\n"
298 " :type pred: :class:`UnaryPredicate0D`\n"
299 " :param sampling: The resolution used to sample the chain for the\n"
300 " predicates evaluation. (The chain is not actually resampled;\n"
301 " a virtual point only progresses along the curve using this\n"
303 " :type sampling: float\n");
308 static const char *kwlist_1[] = {
"starting_pred",
"stopping_pred",
"sampling",
nullptr};
309 static const char *kwlist_2[] = {
"pred",
"sampling",
nullptr};
310 PyObject *obj1 =
nullptr, *obj2 =
nullptr;
313 if (PyArg_ParseTupleAndKeywords(args,
330 "Operators.sequential_split(): 1st argument: invalid UnaryPredicate0D object");
336 "Operators.sequential_split(): 2nd argument: invalid UnaryPredicate0D object");
343 if (!PyErr_Occurred()) {
344 PyErr_SetString(PyExc_RuntimeError,
"Operators.sequential_split() failed");
349 else if ((
void)PyErr_Clear(),
351 PyArg_ParseTupleAndKeywords(args,
365 "Operators.sequential_split(): 1st argument: invalid UnaryPredicate0D object");
369 if (!PyErr_Occurred()) {
370 PyErr_SetString(PyExc_RuntimeError,
"Operators.sequential_split() failed");
376 PyErr_SetString(PyExc_TypeError,
"invalid argument(s)");
384 Operators_recursive_split_doc,
385 ".. staticmethod:: recursive_split(*args, **kwargs)\n"
387 " Accepted call signatures:\n"
389 " - ``recursive_split(func, pred_1d, sampling=0.0)``\n"
390 " - ``recursive_split(func, pred_0d, pred_1d, sampling=0.0)``\n"
392 " Splits the current set of chains in a recursive way. We process the\n"
393 " points of each chain (with a specified sampling) to find the point\n"
394 " minimizing a specified function. The chain is split in two at this\n"
395 " point and the two new chains are processed in the same way. The\n"
396 " recursivity level is controlled through a predicate 1D that expresses\n"
397 " a stopping condition on the chain that is about to be processed.\n"
399 " The user can also specify a 0D predicate to make a first selection on the points\n"
400 " that can potentially be split. A point that doesn't verify the 0D\n"
401 " predicate won't be candidate in realizing the min.\n"
403 " :param func: The Unary Function evaluated at each point of the chain.\n"
404 " The splitting point is the point minimizing this function.\n"
405 " :type func: :class:`UnaryFunction0DDouble`\n"
406 " :param pred_0d: The Unary Predicate 0D used to select the candidate\n"
407 " points where the split can occur. For example, it is very likely\n"
408 " that would rather have your chain splitting around its middle\n"
409 " point than around one of its extremities. A 0D predicate working\n"
410 " on the curvilinear abscissa allows to add this kind of constraints.\n"
411 " :type pred_0d: :class:`UnaryPredicate0D`\n"
412 " :param pred_1d: The Unary Predicate expressing the recursivity stopping\n"
413 " condition. This predicate is evaluated for each curve before it\n"
414 " actually gets split. If pred_1d(chain) is true, the curve won't be\n"
416 " :type pred_1d: :class:`UnaryPredicate1D`\n"
417 " :param sampling: The resolution used to sample the chain for the\n"
418 " predicates evaluation. (The chain is not actually resampled; a\n"
419 " virtual point only progresses along the curve using this\n"
421 " :type sampling: float\n");
426 static const char *kwlist_1[] = {
"func",
"pred_1d",
"sampling",
nullptr};
427 static const char *kwlist_2[] = {
"func",
"pred_0d",
"pred_1d",
"sampling",
nullptr};
428 PyObject *obj1 =
nullptr, *obj2 =
nullptr, *obj3 =
nullptr;
431 if (PyArg_ParseTupleAndKeywords(args,
448 "Operators.recursive_split(): 1st argument: invalid UnaryFunction0DDouble object");
454 "Operators.recursive_split(): 2nd argument: invalid UnaryPredicate1D object");
461 if (!PyErr_Occurred()) {
462 PyErr_SetString(PyExc_RuntimeError,
"Operators.recursive_split() failed");
467 else if ((
void)PyErr_Clear(),
469 PyArg_ParseTupleAndKeywords(args,
489 "Operators.recursive_split(): 1st argument: invalid UnaryFunction0DDouble object");
495 "Operators.recursive_split(): 2nd argument: invalid UnaryPredicate0D object");
501 "Operators.recursive_split(): 3rd argument: invalid UnaryPredicate1D object");
509 if (!PyErr_Occurred()) {
510 PyErr_SetString(PyExc_RuntimeError,
"Operators.recursive_split() failed");
516 PyErr_SetString(PyExc_TypeError,
"invalid argument(s)");
525 ".. staticmethod:: sort(pred)\n"
527 " Sorts the current set of chains (or viewedges) according to the\n"
528 " comparison predicate given as argument.\n"
530 " :param pred: The binary predicate used for the comparison.\n"
531 " :type pred: :class:`BinaryPredicate1D`\n");
534 static const char *kwlist[] = {
"pred",
nullptr};
535 PyObject *obj =
nullptr;
537 if (!PyArg_ParseTupleAndKeywords(args,
548 PyErr_SetString(PyExc_TypeError,
549 "Operators.sort(): 1st argument: invalid BinaryPredicate1D object");
553 if (!PyErr_Occurred()) {
554 PyErr_SetString(PyExc_RuntimeError,
"Operators.sort() failed");
563 Operators_create_doc,
564 ".. staticmethod:: create(pred, shaders)\n"
566 " Creates and shades the strokes from the current set of chains. A\n"
567 " predicate can be specified to make a selection pass on the chains.\n"
569 " :param pred: The predicate that a chain must verify in order to be\n"
570 " transform as a stroke.\n"
571 " :type pred: :class:`UnaryPredicate1D`\n"
572 " :param shaders: The list of shaders used to shade the strokes.\n"
573 " :type shaders: list[:class:`StrokeShader`]\n");
576 static const char *kwlist[] = {
"pred",
"shaders",
nullptr};
577 PyObject *obj1 =
nullptr, *obj2 =
nullptr;
579 if (!PyArg_ParseTupleAndKeywords(args,
593 PyErr_SetString(PyExc_TypeError,
594 "Operators.create(): 1st argument: invalid UnaryPredicate1D object");
598 shaders.reserve(PyList_Size(obj2));
599 for (
int i = 0; i < PyList_Size(obj2); i++) {
600 PyObject *py_ss = PyList_GET_ITEM(obj2, i);
602 PyErr_SetString(PyExc_TypeError,
603 "Operators.create(): 2nd argument must be a list of StrokeShader objects");
609 ss <<
"Operators.create(): item " << (i + 1)
610 <<
" of the shaders list is invalid likely due to missing call of "
611 "StrokeShader.__init__()";
612 PyErr_SetString(PyExc_TypeError, ss.str().c_str());
615 shaders.push_back(shader);
618 if (!PyErr_Occurred()) {
619 PyErr_SetString(PyExc_RuntimeError,
"Operators.create() failed");
629 ".. staticmethod:: reset(delete_strokes=True)\n"
631 " Resets the line stylization process to the initial state. The results of\n"
632 " stroke creation are accumulated if **delete_strokes** is set to False.\n"
634 " :param delete_strokes: Delete the strokes that are currently stored.\n"
635 " :type delete_strokes: bool\n");
638 static const char *kwlist[] = {
"delete_strokes",
nullptr};
639 PyObject *obj1 =
nullptr;
640 if (PyArg_ParseTupleAndKeywords(args,
653 PyErr_SetString(PyExc_RuntimeError,
"Operators.reset() failed");
661 Operators_get_viewedge_from_index_doc,
662 ".. staticmethod:: get_viewedge_from_index(i)\n"
664 " Returns the ViewEdge at the index in the current set of ViewEdges.\n"
666 " :param i: index (0 <= i < Operators.get_view_edges_size()).\n"
668 " :return: The ViewEdge object.\n"
669 " :rtype: :class:`ViewEdge`\n");
674 static const char *kwlist[] = {
"i",
nullptr};
677 if (!PyArg_ParseTupleAndKeywords(args,
680 ":get_viewedge_from_index",
687 PyErr_SetString(PyExc_IndexError,
"index out of range");
695 Operators_get_chain_from_index_doc,
696 ".. staticmethod:: get_chain_from_index(i)\n"
698 " Returns the Chain at the index in the current set of Chains.\n"
700 " :param i: index (0 <= i < Operators.get_chains_size()).\n"
702 " :return: The Chain object.\n"
703 " :rtype: :class:`Chain`\n");
708 static const char *kwlist[] = {
"i",
nullptr};
711 if (!PyArg_ParseTupleAndKeywords(args,
714 ":get_chain_from_index",
721 PyErr_SetString(PyExc_IndexError,
"index out of range");
729 Operators_get_stroke_from_index_doc,
730 ".. staticmethod:: get_stroke_from_index(i)\n"
732 " Returns the Stroke at the index in the current set of Strokes.\n"
734 " :param i: index (0 <= i < Operators.get_strokes_size()).\n"
736 " :return: The Stroke object.\n"
737 " :rtype: :class:`Stroke`\n");
742 static const char *kwlist[] = {
"i",
nullptr};
745 if (!PyArg_ParseTupleAndKeywords(args,
748 ":get_stroke_from_index",
755 PyErr_SetString(PyExc_IndexError,
"index out of range");
763 Operators_get_view_edges_size_doc,
764 ".. staticmethod:: get_view_edges_size()\n"
766 " Returns the number of ViewEdges.\n"
768 " :return: The number of ViewEdges.\n"
777 Operators_get_chains_size_doc,
778 ".. staticmethod:: get_chains_size()\n"
780 " Returns the number of Chains.\n"
782 " :return: The number of Chains.\n"
791 Operators_get_strokes_size_doc,
792 ".. staticmethod:: get_strokes_size()\n"
794 " Returns the number of Strokes.\n"
796 " :return: The number of Strokes.\n"
807# pragma clang diagnostic push
808# pragma clang diagnostic ignored "-Wcast-function-type"
810# pragma GCC diagnostic push
811# pragma GCC diagnostic ignored "-Wcast-function-type"
818 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
819 Operators_select_doc},
822 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
823 Operators_chain_doc},
824 {
"bidirectional_chain",
826 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
827 Operators_bidirectional_chain_doc},
830 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
831 Operators_sequential_split_doc},
834 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
835 Operators_recursive_split_doc},
838 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
842 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
843 Operators_create_doc},
846 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
847 Operators_reset_doc},
848 {
"get_viewedge_from_index",
850 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
851 Operators_get_viewedge_from_index_doc},
852 {
"get_chain_from_index",
854 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
855 Operators_get_chain_from_index_doc},
856 {
"get_stroke_from_index",
858 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
859 Operators_get_stroke_from_index_doc},
860 {
"get_view_edges_size",
862 METH_NOARGS | METH_STATIC,
863 Operators_get_view_edges_size_doc},
866 METH_NOARGS | METH_STATIC,
867 Operators_get_chains_size_doc},
870 METH_NOARGS | METH_STATIC,
871 Operators_get_strokes_size_doc},
872 {
nullptr,
nullptr, 0,
nullptr},
877# pragma clang diagnostic pop
879# pragma GCC diagnostic pop
886 PyVarObject_HEAD_INIT(
nullptr, 0)
PyTypeObject BinaryPredicate1D_Type
PyTypeObject ChainingIterator_Type
bool bool_from_PyBool(PyObject *b)
PyObject * BPy_Chain_from_Chain(Chain &c)
PyObject * BPy_Stroke_from_Stroke(Stroke &s)
PyObject * BPy_ViewEdge_from_ViewEdge(ViewEdge &ve)
PyDoc_STRVAR(FalseBP1D___doc__, "Class hierarchy: :class:`freestyle.types.BinaryPredicate1D` > :class:`FalseBP1D`\n" "\n" ".. method:: __call__(inter1, inter2)\n" "\n" " Always returns false.\n" "\n" " :param inter1: The first Interface1D object.\n" " :type inter1: :class:`freestyle.types.Interface1D`\n" " :param inter2: The second Interface1D object.\n" " :type inter2: :class:`freestyle.types.Interface1D`\n" " :return: False.\n" " :rtype: bool\n")
static PyObject * Operators_select(BPy_Operators *, PyObject *args, PyObject *kwds)
static PyMethodDef BPy_Operators_methods[]
static PyObject * Operators_reset(BPy_Operators *, PyObject *args, PyObject *kwds)
static PyObject * Operators_recursive_split(BPy_Operators *, PyObject *args, PyObject *kwds)
int Operators_Init(PyObject *module)
static PyObject * Operators_get_chain_from_index(BPy_Operators *, PyObject *args, PyObject *kwds)
static PyObject * Operators_get_stroke_from_index(BPy_Operators *, PyObject *args, PyObject *kwds)
static PyObject * Operators_sort(BPy_Operators *, PyObject *args, PyObject *kwds)
static PyObject * Operators_sequential_split(BPy_Operators *, PyObject *args, PyObject *kwds)
static PyObject * Operators_get_view_edges_size(BPy_Operators *)
static PyObject * Operators_get_strokes_size(BPy_Operators *)
static PyObject * Operators_get_viewedge_from_index(BPy_Operators *, PyObject *args, PyObject *kwds)
static void Operators_dealloc(BPy_Operators *self)
static PyObject * Operators_get_chains_size(BPy_Operators *)
PyTypeObject Operators_Type
static PyObject * Operators_create(BPy_Operators *, PyObject *args, PyObject *kwds)
static PyObject * Operators_chain(BPy_Operators *, PyObject *args, PyObject *kwds)
static PyObject * Operators_bidirectional_chain(BPy_Operators *, PyObject *args, PyObject *kwds)
#define BPy_StrokeShader_Check(v)
PyTypeObject UnaryFunction0DDouble_Type
PyTypeObject UnaryFunction1DVoid_Type
PyTypeObject UnaryPredicate0D_Type
PyTypeObject UnaryPredicate1D_Type
static int sort(BinaryPredicate1D &pred)
static ViewEdge * getViewEdgeFromIndex(uint i)
static int select(UnaryPredicate1D &pred)
static int chain(ViewEdgeInternal::ViewEdgeIterator &it, UnaryPredicate1D &pred, UnaryFunction1D_void &modifier)
static void reset(bool removeStrokes=true)
static uint getChainsSize()
static uint getViewEdgesSize()
static uint getStrokesSize()
static int sequentialSplit(UnaryPredicate0D &startingPred, UnaryPredicate0D &stoppingPred, float sampling=0.0f)
static int recursiveSplit(UnaryFunction0D< double > &func, UnaryPredicate1D &pred, float sampling=0)
static int bidirectionalChain(ChainingIterator &it, UnaryPredicate1D &pred)
static Stroke * getStrokeFromIndex(uint i)
static int create(UnaryPredicate1D &pred, vector< StrokeShader * > shaders)
static Chain * getChainFromIndex(uint i)