62 "Class defining the operators used in a style module. There are five\n"
63 "types of operators: Selection, chaining, splitting, sorting and\n"
64 "creation. All these operators are user controlled through functors,\n"
65 "predicates and shaders that are taken as arguments.");
69 Py_TYPE(
self)->tp_free((PyObject *)
self);
73 ".. staticmethod:: select(pred)\n"
75 " Selects the ViewEdges of the ViewMap verifying a specified\n"
78 " :arg pred: The predicate expressing this condition.\n"
79 " :type pred: :class:`UnaryPredicate1D`");
83 static const char *kwlist[] = {
"pred",
nullptr};
84 PyObject *obj =
nullptr;
86 if (!PyArg_ParseTupleAndKeywords(
91 PyErr_SetString(PyExc_TypeError,
92 "Operators.select(): 1st argument: invalid UnaryPredicate1D object");
96 if (!PyErr_Occurred()) {
97 PyErr_SetString(PyExc_RuntimeError,
"Operators.select() failed");
105 ".. staticmethod:: chain(it, pred, modifier)\n"
108 " Builds a set of chains from the current set of ViewEdges. Each\n"
109 " ViewEdge of the current list starts a new chain. The chaining\n"
110 " operator then iterates over the ViewEdges of the ViewMap using the\n"
111 " user specified iterator. This operator only iterates using the\n"
112 " increment operator and is therefore unidirectional.\n"
114 " :arg it: The iterator on the ViewEdges of the ViewMap. It contains\n"
115 " the chaining rule.\n"
116 " :type it: :class:`ViewEdgeIterator`\n"
117 " :arg pred: The predicate on the ViewEdge that expresses the\n"
118 " stopping condition.\n"
119 " :type pred: :class:`UnaryPredicate1D`\n"
120 " :arg modifier: A function that takes a ViewEdge as argument and\n"
121 " that is used to modify the processed ViewEdge state (the\n"
122 " timestamp incrementation is a typical illustration of such a modifier).\n"
123 " If this argument is not given, the time stamp is automatically managed.\n"
124 " :type modifier: :class:`UnaryFunction1DVoid`\n");
128 static const char *kwlist[] = {
"it",
"pred",
"modifier",
nullptr};
129 PyObject *obj1 =
nullptr, *obj2 =
nullptr, *obj3 =
nullptr;
131 if (!PyArg_ParseTupleAndKeywords(args,
144 PyErr_SetString(PyExc_TypeError,
145 "Operators.chain(): 1st argument: invalid ChainingIterator object");
149 PyErr_SetString(PyExc_TypeError,
150 "Operators.chain(): 2nd argument: invalid UnaryPredicate1D object");
156 if (!PyErr_Occurred()) {
157 PyErr_SetString(PyExc_RuntimeError,
"Operators.chain() failed");
164 PyErr_SetString(PyExc_TypeError,
165 "Operators.chain(): 3rd argument: invalid UnaryFunction1DVoid object");
171 if (!PyErr_Occurred()) {
172 PyErr_SetString(PyExc_RuntimeError,
"Operators.chain() failed");
181 ".. staticmethod:: bidirectional_chain(it, pred)\n"
182 " bidirectional_chain(it)\n"
184 " Builds a set of chains from the current set of ViewEdges. Each\n"
185 " ViewEdge of the current list potentially starts a new chain. The\n"
186 " chaining operator then iterates over the ViewEdges of the ViewMap\n"
187 " using the user specified iterator. This operator iterates both using\n"
188 " the increment and decrement operators and is therefore bidirectional.\n"
189 " This operator works with a ChainingIterator which contains the\n"
190 " chaining rules. It is this last one which can be told to chain only\n"
191 " edges that belong to the selection or not to process twice a ViewEdge\n"
192 " during the chaining. Each time a ViewEdge is added to a chain, its\n"
193 " chaining time stamp is incremented. This allows you to keep track of\n"
194 " the number of chains to which a ViewEdge belongs to.\n"
196 " :arg it: The ChainingIterator on the ViewEdges of the ViewMap. It\n"
197 " contains the chaining rule.\n"
198 " :type it: :class:`ChainingIterator`\n"
199 " :arg pred: The predicate on the ViewEdge that expresses the stopping condition.\n"
200 " This parameter is optional, you make not want to pass a stopping criterion\n"
201 " when the stopping criterion is already contained in the iterator definition.\n"
202 " :type pred: :class:`UnaryPredicate1D`\n");
208 static const char *kwlist[] = {
"it",
"pred",
nullptr};
209 PyObject *obj1 =
nullptr, *obj2 =
nullptr;
211 if (!PyArg_ParseTupleAndKeywords(args,
224 "Operators.bidirectional_chain(): 1st argument: invalid ChainingIterator object");
229 if (!PyErr_Occurred()) {
230 PyErr_SetString(PyExc_RuntimeError,
"Operators.bidirectional_chain() failed");
239 "Operators.bidirectional_chain(): 2nd argument: invalid UnaryPredicate1D object");
244 if (!PyErr_Occurred()) {
245 PyErr_SetString(PyExc_RuntimeError,
"Operators.bidirectional_chain() failed");
254 ".. staticmethod:: sequential_split(starting_pred, stopping_pred, sampling=0.0)\n"
255 " sequential_split(pred, sampling=0.0)\n"
257 " Splits each chain of the current set of chains in a sequential way.\n"
258 " The points of each chain are processed (with a specified sampling)\n"
259 " sequentially. The first point of the initial chain is the\n"
260 " first point of one of the resulting chains. The splitting ends when\n"
261 " no more chain can start.\n"
265 " By specifying a starting and stopping predicate allows\n"
266 " the chains to overlap rather than chains partitioning.\n"
268 " :arg starting_pred: The predicate on a point that expresses the\n"
269 " starting condition. Each time this condition is verified, a new chain begins\n"
270 " :type starting_pred: :class:`UnaryPredicate0D`\n"
271 " :arg stopping_pred: The predicate on a point that expresses the\n"
272 " stopping condition. The chain ends as soon as this predicate is verified.\n"
273 " :type stopping_pred: :class:`UnaryPredicate0D`\n"
274 " :arg pred: The predicate on a point that expresses the splitting condition.\n"
275 " Each time the condition is verified, the chain is split into two chains.\n"
276 " The resulting set of chains is a partition of the initial chain\n"
277 " :type pred: :class:`UnaryPredicate0D`\n"
278 " :arg sampling: The resolution used to sample the chain for the\n"
279 " predicates evaluation. (The chain is not actually resampled;\n"
280 " a virtual point only progresses along the curve using this\n"
282 " :type sampling: float\n");
288 static const char *kwlist_1[] = {
"starting_pred",
"stopping_pred",
"sampling",
nullptr};
289 static const char *kwlist_2[] = {
"pred",
"sampling",
nullptr};
290 PyObject *obj1 =
nullptr, *obj2 =
nullptr;
293 if (PyArg_ParseTupleAndKeywords(args,
305 "Operators.sequential_split(): 1st argument: invalid UnaryPredicate0D object");
311 "Operators.sequential_split(): 2nd argument: invalid UnaryPredicate0D object");
317 if (!PyErr_Occurred()) {
318 PyErr_SetString(PyExc_RuntimeError,
"Operators.sequential_split() failed");
323 else if ((
void)PyErr_Clear(),
325 PyArg_ParseTupleAndKeywords(
330 "Operators.sequential_split(): 1st argument: invalid UnaryPredicate0D object");
334 if (!PyErr_Occurred()) {
335 PyErr_SetString(PyExc_RuntimeError,
"Operators.sequential_split() failed");
341 PyErr_SetString(PyExc_TypeError,
"invalid argument(s)");
348 Operators_recursive_split_doc,
349 ".. staticmethod:: recursive_split(func, pred_1d, sampling=0.0)\n"
350 " recursive_split(func, pred_0d, pred_1d, sampling=0.0)\n"
352 " Splits the current set of chains in a recursive way. We process the\n"
353 " points of each chain (with a specified sampling) to find the point\n"
354 " minimizing a specified function. The chain is split in two at this\n"
355 " point and the two new chains are processed in the same way. The\n"
356 " recursivity level is controlled through a predicate 1D that expresses\n"
357 " a stopping condition on the chain that is about to be processed.\n"
359 " The user can also specify a 0D predicate to make a first selection on the points\n"
360 " that can potentially be split. A point that doesn't verify the 0D\n"
361 " predicate won't be candidate in realizing the min.\n"
363 " :arg func: The Unary Function evaluated at each point of the chain.\n"
364 " The splitting point is the point minimizing this function.\n"
365 " :type func: :class:`UnaryFunction0DDouble`\n"
366 " :arg pred_0d: The Unary Predicate 0D used to select the candidate\n"
367 " points where the split can occur. For example, it is very likely\n"
368 " that would rather have your chain splitting around its middle\n"
369 " point than around one of its extremities. A 0D predicate working\n"
370 " on the curvilinear abscissa allows to add this kind of constraints.\n"
371 " :type pred_0d: :class:`UnaryPredicate0D`\n"
372 " :arg pred_1d: The Unary Predicate expressing the recursivity stopping\n"
373 " condition. This predicate is evaluated for each curve before it\n"
374 " actually gets split. If pred_1d(chain) is true, the curve won't be\n"
376 " :type pred_1d: :class:`UnaryPredicate1D`\n"
377 " :arg sampling: The resolution used to sample the chain for the\n"
378 " predicates evaluation. (The chain is not actually resampled; a\n"
379 " virtual point only progresses along the curve using this\n"
381 " :type sampling: float\n");
387 static const char *kwlist_1[] = {
"func",
"pred_1d",
"sampling",
nullptr};
388 static const char *kwlist_2[] = {
"func",
"pred_0d",
"pred_1d",
"sampling",
nullptr};
389 PyObject *obj1 =
nullptr, *obj2 =
nullptr, *obj3 =
nullptr;
392 if (PyArg_ParseTupleAndKeywords(args,
404 "Operators.recursive_split(): 1st argument: invalid UnaryFunction0DDouble object");
410 "Operators.recursive_split(): 2nd argument: invalid UnaryPredicate1D object");
416 if (!PyErr_Occurred()) {
417 PyErr_SetString(PyExc_RuntimeError,
"Operators.recursive_split() failed");
422 else if ((
void)PyErr_Clear(),
424 PyArg_ParseTupleAndKeywords(args,
438 "Operators.recursive_split(): 1st argument: invalid UnaryFunction0DDouble object");
444 "Operators.recursive_split(): 2nd argument: invalid UnaryPredicate0D object");
450 "Operators.recursive_split(): 3rd argument: invalid UnaryPredicate1D object");
457 if (!PyErr_Occurred()) {
458 PyErr_SetString(PyExc_RuntimeError,
"Operators.recursive_split() failed");
464 PyErr_SetString(PyExc_TypeError,
"invalid argument(s)");
471 ".. staticmethod:: sort(pred)\n"
473 " Sorts the current set of chains (or viewedges) according to the\n"
474 " comparison predicate given as argument.\n"
476 " :arg pred: The binary predicate used for the comparison.\n"
477 " :type pred: :class:`BinaryPredicate1D`");
481 static const char *kwlist[] = {
"pred",
nullptr};
482 PyObject *obj =
nullptr;
484 if (!PyArg_ParseTupleAndKeywords(
489 PyErr_SetString(PyExc_TypeError,
490 "Operators.sort(): 1st argument: invalid BinaryPredicate1D object");
494 if (!PyErr_Occurred()) {
495 PyErr_SetString(PyExc_RuntimeError,
"Operators.sort() failed");
503 ".. staticmethod:: create(pred, shaders)\n"
505 " Creates and shades the strokes from the current set of chains. A\n"
506 " predicate can be specified to make a selection pass on the chains.\n"
508 " :arg pred: The predicate that a chain must verify in order to be\n"
509 " transform as a stroke.\n"
510 " :type pred: :class:`UnaryPredicate1D`\n"
511 " :arg shaders: The list of shaders used to shade the strokes.\n"
512 " :type shaders: list of :class:`StrokeShader` objects");
516 static const char *kwlist[] = {
"pred",
"shaders",
nullptr};
517 PyObject *obj1 =
nullptr, *obj2 =
nullptr;
519 if (!PyArg_ParseTupleAndKeywords(args,
530 PyErr_SetString(PyExc_TypeError,
531 "Operators.create(): 1st argument: invalid UnaryPredicate1D object");
534 vector<StrokeShader *>
shaders;
535 shaders.reserve(PyList_Size(obj2));
536 for (
int i = 0; i < PyList_Size(obj2); i++) {
537 PyObject *py_ss = PyList_GET_ITEM(obj2, i);
539 PyErr_SetString(PyExc_TypeError,
540 "Operators.create(): 2nd argument must be a list of StrokeShader objects");
546 ss <<
"Operators.create(): item " << (i + 1)
547 <<
" of the shaders list is invalid likely due to missing call of "
548 "StrokeShader.__init__()";
549 PyErr_SetString(PyExc_TypeError, ss.str().c_str());
555 if (!PyErr_Occurred()) {
556 PyErr_SetString(PyExc_RuntimeError,
"Operators.create() failed");
564 ".. staticmethod:: reset(delete_strokes=True)\n"
566 " Resets the line stylization process to the initial state. The results of\n"
567 " stroke creation are accumulated if **delete_strokes** is set to False.\n"
569 " :arg delete_strokes: Delete the strokes that are currently stored.\n"
570 " :type delete_strokes: bool\n");
574 static const char *kwlist[] = {
"delete_strokes",
nullptr};
575 PyObject *obj1 =
nullptr;
576 if (PyArg_ParseTupleAndKeywords(args, kwds,
"|O!", (
char **)kwlist, &PyBool_Type, &obj1)) {
581 PyErr_SetString(PyExc_RuntimeError,
"Operators.reset() failed");
588 ".. staticmethod:: get_viewedge_from_index(i)\n"
590 " Returns the ViewEdge at the index in the current set of ViewEdges.\n"
592 " :arg i: index (0 <= i < Operators.get_view_edges_size()).\n"
594 " :return: The ViewEdge object.\n"
595 " :rtype: :class:`ViewEdge`");
601 static const char *kwlist[] = {
"i",
nullptr};
604 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"I", (
char **)kwlist, &i)) {
608 PyErr_SetString(PyExc_IndexError,
"index out of range");
615 ".. staticmethod:: get_chain_from_index(i)\n"
617 " Returns the Chain at the index in the current set of Chains.\n"
619 " :arg i: index (0 <= i < Operators.get_chains_size()).\n"
621 " :return: The Chain object.\n"
622 " :rtype: :class:`Chain`");
628 static const char *kwlist[] = {
"i",
nullptr};
631 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"I", (
char **)kwlist, &i)) {
635 PyErr_SetString(PyExc_IndexError,
"index out of range");
642 ".. staticmethod:: get_stroke_from_index(i)\n"
644 " Returns the Stroke at the index in the current set of Strokes.\n"
646 " :arg i: index (0 <= i < Operators.get_strokes_size()).\n"
648 " :return: The Stroke object.\n"
649 " :rtype: :class:`Stroke`");
655 static const char *kwlist[] = {
"i",
nullptr};
658 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"I", (
char **)kwlist, &i)) {
662 PyErr_SetString(PyExc_IndexError,
"index out of range");
669 ".. staticmethod:: get_view_edges_size()\n"
671 " Returns the number of ViewEdges.\n"
673 " :return: The number of ViewEdges.\n"
682 ".. staticmethod:: get_chains_size()\n"
684 " Returns the number of Chains.\n"
686 " :return: The number of Chains.\n"
695 ".. staticmethod:: get_strokes_size()\n"
697 " Returns the number of Strokes.\n"
699 " :return: The number of Strokes.\n"
711 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
712 Operators_select_doc},
715 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
716 Operators_chain_doc},
717 {
"bidirectional_chain",
719 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
720 Operators_bidirectional_chain_doc},
723 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
724 Operators_sequential_split_doc},
727 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
728 Operators_recursive_split_doc},
731 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
735 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
736 Operators_create_doc},
739 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
740 Operators_reset_doc},
741 {
"get_viewedge_from_index",
743 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
744 Operators_get_viewedge_from_index_doc},
745 {
"get_chain_from_index",
747 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
748 Operators_get_chain_from_index_doc},
749 {
"get_stroke_from_index",
751 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
752 Operators_get_stroke_from_index_doc},
753 {
"get_view_edges_size",
755 METH_NOARGS | METH_STATIC,
756 Operators_get_view_edges_size_doc},
759 METH_NOARGS | METH_STATIC,
760 Operators_get_chains_size_doc},
763 METH_NOARGS | METH_STATIC,
764 Operators_get_strokes_size_doc},
765 {
nullptr,
nullptr, 0,
nullptr},
771 PyVarObject_HEAD_INIT(
nullptr, 0)
"Operators",
PyTypeObject BinaryPredicate1D_Type
PyTypeObject ChainingIterator_Type
PyObject * BPy_Chain_from_Chain(Chain &c)
bool bool_from_PyBool(PyObject *b)
PyObject * BPy_Stroke_from_Stroke(Stroke &s)
PyObject * BPy_ViewEdge_from_ViewEdge(ViewEdge &ve)
static PyObject * Operators_get_viewedge_from_index(BPy_Operators *, PyObject *args, PyObject *kwds)
static PyObject * Operators_get_view_edges_size(BPy_Operators *)
static PyMethodDef BPy_Operators_methods[]
int Operators_Init(PyObject *module)
static PyObject * Operators_create(BPy_Operators *, PyObject *args, PyObject *kwds)
static PyObject * Operators_sort(BPy_Operators *, PyObject *args, PyObject *kwds)
static PyObject * Operators_get_chain_from_index(BPy_Operators *, PyObject *args, PyObject *kwds)
PyDoc_STRVAR(Operators_doc, "Class defining the operators used in a style module. There are five\n" "types of operators: Selection, chaining, splitting, sorting and\n" "creation. All these operators are user controlled through functors,\n" "predicates and shaders that are taken as arguments.")
static PyObject * Operators_get_stroke_from_index(BPy_Operators *, PyObject *args, PyObject *kwds)
static PyObject * Operators_get_strokes_size(BPy_Operators *)
static PyObject * Operators_get_chains_size(BPy_Operators *)
static PyObject * Operators_select(BPy_Operators *, PyObject *args, PyObject *kwds)
static PyObject * Operators_reset(BPy_Operators *, PyObject *args, PyObject *kwds)
static PyObject * Operators_recursive_split(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)
static void Operators_dealloc(BPy_Operators *self)
PyTypeObject Operators_Type
static PyObject * Operators_sequential_split(BPy_Operators *, PyObject *args, PyObject *kwds)
#define BPy_StrokeShader_Check(v)
PyTypeObject UnaryFunction0DDouble_Type
PyTypeObject UnaryFunction1DVoid_Type
PyTypeObject UnaryPredicate0D_Type
PyTypeObject UnaryPredicate1D_Type
static struct PyModuleDef module
static int sort(BinaryPredicate1D &pred)
static int select(UnaryPredicate1D &pred)
static int chain(ViewEdgeInternal::ViewEdgeIterator &it, UnaryPredicate1D &pred, UnaryFunction1D_void &modifier)
static void reset(bool removeStrokes=true)
static ViewEdge * getViewEdgeFromIndex(unsigned i)
static int sequentialSplit(UnaryPredicate0D &startingPred, UnaryPredicate0D &stoppingPred, float sampling=0.0f)
static int recursiveSplit(UnaryFunction0D< double > &func, UnaryPredicate1D &pred, float sampling=0)
static unsigned getViewEdgesSize()
static int bidirectionalChain(ChainingIterator &it, UnaryPredicate1D &pred)
static Stroke * getStrokeFromIndex(unsigned i)
static Chain * getChainFromIndex(unsigned i)
static int create(UnaryPredicate1D &pred, vector< StrokeShader * > shaders)
static unsigned getStrokesSize()
static unsigned getChainsSize()
void KERNEL_FUNCTION_FULL_NAME() shader(KernelGlobals *kg, uint4 *input, float4 *output, int type, int filter, int i, int offset, int sample)