Blender V4.5
BPy_Operators.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2004-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BPy_Operators.h"
10
12#include "BPy_Convert.h"
13#include "BPy_StrokeShader.h"
20
21#include "BLI_sys_types.h"
22
23#include <sstream>
24
25using namespace Freestyle;
26
28
29//-------------------MODULE INITIALIZATION--------------------------------
30int Operators_Init(PyObject *module)
31{
32 if (module == nullptr) {
33 return -1;
34 }
35
36 if (PyType_Ready(&Operators_Type) < 0) {
37 return -1;
38 }
39 PyModule_AddObjectRef(module, "Operators", (PyObject *)&Operators_Type);
40
41 return 0;
42}
43
44//------------------------INSTANCE METHODS ----------------------------------
45
47 /* Wrap. */
48 Operators_doc,
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.");
53
55{
56 Py_TYPE(self)->tp_free((PyObject *)self);
57}
58
60 /* Wrap. */
61 Operators_select_doc,
62 ".. staticmethod:: select(pred)\n"
63 "\n"
64 " Selects the ViewEdges of the ViewMap verifying a specified\n"
65 " condition.\n"
66 "\n"
67 " :arg pred: The predicate expressing this condition.\n"
68 " :type pred: :class:`UnaryPredicate1D`");
69
70static PyObject *Operators_select(BPy_Operators * /*self*/, PyObject *args, PyObject *kwds)
71{
72 static const char *kwlist[] = {"pred", nullptr};
73 PyObject *obj = nullptr;
74
75 if (!PyArg_ParseTupleAndKeywords(
76 args, kwds, "O!", (char **)kwlist, &UnaryPredicate1D_Type, &obj))
77 {
78 return nullptr;
79 }
80 if (!((BPy_UnaryPredicate1D *)obj)->up1D) {
81 PyErr_SetString(PyExc_TypeError,
82 "Operators.select(): 1st argument: invalid UnaryPredicate1D object");
83 return nullptr;
84 }
85 if (Operators::select(*(((BPy_UnaryPredicate1D *)obj)->up1D)) < 0) {
86 if (!PyErr_Occurred()) {
87 PyErr_SetString(PyExc_RuntimeError, "Operators.select() failed");
88 }
89 return nullptr;
90 }
91 Py_RETURN_NONE;
92}
93
95 /* Wrap. */
96 Operators_chain_doc,
97 ".. staticmethod:: chain(it, pred, modifier)\n"
98 " chain(it, pred)\n"
99 "\n"
100 " Builds a set of chains from the current set of ViewEdges. Each\n"
101 " ViewEdge of the current list starts a new chain. The chaining\n"
102 " operator then iterates over the ViewEdges of the ViewMap using the\n"
103 " user specified iterator. This operator only iterates using the\n"
104 " increment operator and is therefore unidirectional.\n"
105 "\n"
106 " :arg it: The iterator on the ViewEdges of the ViewMap. It contains\n"
107 " the chaining rule.\n"
108 " :type it: :class:`ViewEdgeIterator`\n"
109 " :arg pred: The predicate on the ViewEdge that expresses the\n"
110 " stopping condition.\n"
111 " :type pred: :class:`UnaryPredicate1D`\n"
112 " :arg modifier: A function that takes a ViewEdge as argument and\n"
113 " that is used to modify the processed ViewEdge state (the\n"
114 " timestamp incrementation is a typical illustration of such a modifier).\n"
115 " If this argument is not given, the time stamp is automatically managed.\n"
116 " :type modifier: :class:`UnaryFunction1DVoid`\n");
117
118static PyObject *Operators_chain(BPy_Operators * /*self*/, PyObject *args, PyObject *kwds)
119{
120 static const char *kwlist[] = {"it", "pred", "modifier", nullptr};
121 PyObject *obj1 = nullptr, *obj2 = nullptr, *obj3 = nullptr;
122
123 if (!PyArg_ParseTupleAndKeywords(args,
124 kwds,
125 "O!O!|O!",
126 (char **)kwlist,
128 &obj1,
130 &obj2,
132 &obj3))
133 {
134 return nullptr;
135 }
136 if (!((BPy_ChainingIterator *)obj1)->c_it) {
137 PyErr_SetString(PyExc_TypeError,
138 "Operators.chain(): 1st argument: invalid ChainingIterator object");
139 return nullptr;
140 }
141 if (!((BPy_UnaryPredicate1D *)obj2)->up1D) {
142 PyErr_SetString(PyExc_TypeError,
143 "Operators.chain(): 2nd argument: invalid UnaryPredicate1D object");
144 return nullptr;
145 }
146 if (!obj3) {
147 if (Operators::chain(*(((BPy_ChainingIterator *)obj1)->c_it),
148 *(((BPy_UnaryPredicate1D *)obj2)->up1D)) < 0)
149 {
150 if (!PyErr_Occurred()) {
151 PyErr_SetString(PyExc_RuntimeError, "Operators.chain() failed");
152 }
153 return nullptr;
154 }
155 }
156 else {
157 if (!((BPy_UnaryFunction1DVoid *)obj3)->uf1D_void) {
158 PyErr_SetString(PyExc_TypeError,
159 "Operators.chain(): 3rd argument: invalid UnaryFunction1DVoid object");
160 return nullptr;
161 }
162 if (Operators::chain(*(((BPy_ChainingIterator *)obj1)->c_it),
163 *(((BPy_UnaryPredicate1D *)obj2)->up1D),
164 *(((BPy_UnaryFunction1DVoid *)obj3)->uf1D_void)) < 0)
165 {
166 if (!PyErr_Occurred()) {
167 PyErr_SetString(PyExc_RuntimeError, "Operators.chain() failed");
168 }
169 return nullptr;
170 }
171 }
172 Py_RETURN_NONE;
173}
174
176 /* Wrap. */
177 Operators_bidirectional_chain_doc,
178 ".. staticmethod:: bidirectional_chain(it, pred)\n"
179 " bidirectional_chain(it)\n"
180 "\n"
181 " Builds a set of chains from the current set of ViewEdges. Each\n"
182 " ViewEdge of the current list potentially starts a new chain. The\n"
183 " chaining operator then iterates over the ViewEdges of the ViewMap\n"
184 " using the user specified iterator. This operator iterates both using\n"
185 " the increment and decrement operators and is therefore bidirectional.\n"
186 " This operator works with a ChainingIterator which contains the\n"
187 " chaining rules. It is this last one which can be told to chain only\n"
188 " edges that belong to the selection or not to process twice a ViewEdge\n"
189 " during the chaining. Each time a ViewEdge is added to a chain, its\n"
190 " chaining time stamp is incremented. This allows you to keep track of\n"
191 " the number of chains to which a ViewEdge belongs to.\n"
192 "\n"
193 " :arg it: The ChainingIterator on the ViewEdges of the ViewMap. It\n"
194 " contains the chaining rule.\n"
195 " :type it: :class:`ChainingIterator`\n"
196 " :arg pred: The predicate on the ViewEdge that expresses the stopping condition.\n"
197 " This parameter is optional, you make not want to pass a stopping criterion\n"
198 " when the stopping criterion is already contained in the iterator definition.\n"
199 " :type pred: :class:`UnaryPredicate1D`\n");
200
202 PyObject *args,
203 PyObject *kwds)
204{
205 static const char *kwlist[] = {"it", "pred", nullptr};
206 PyObject *obj1 = nullptr, *obj2 = nullptr;
207
208 if (!PyArg_ParseTupleAndKeywords(args,
209 kwds,
210 "O!|O!",
211 (char **)kwlist,
213 &obj1,
215 &obj2))
216 {
217 return nullptr;
218 }
219 if (!((BPy_ChainingIterator *)obj1)->c_it) {
220 PyErr_SetString(
221 PyExc_TypeError,
222 "Operators.bidirectional_chain(): 1st argument: invalid ChainingIterator object");
223 return nullptr;
224 }
225 if (!obj2) {
226 if (Operators::bidirectionalChain(*(((BPy_ChainingIterator *)obj1)->c_it)) < 0) {
227 if (!PyErr_Occurred()) {
228 PyErr_SetString(PyExc_RuntimeError, "Operators.bidirectional_chain() failed");
229 }
230 return nullptr;
231 }
232 }
233 else {
234 if (!((BPy_UnaryPredicate1D *)obj2)->up1D) {
235 PyErr_SetString(
236 PyExc_TypeError,
237 "Operators.bidirectional_chain(): 2nd argument: invalid UnaryPredicate1D object");
238 return nullptr;
239 }
241 *(((BPy_UnaryPredicate1D *)obj2)->up1D)) < 0)
242 {
243 if (!PyErr_Occurred()) {
244 PyErr_SetString(PyExc_RuntimeError, "Operators.bidirectional_chain() failed");
245 }
246 return nullptr;
247 }
248 }
249 Py_RETURN_NONE;
250}
251
253 /* Wrap. */
254 Operators_sequential_split_doc,
255 ".. staticmethod:: sequential_split(starting_pred, stopping_pred, sampling=0.0)\n"
256 " sequential_split(pred, sampling=0.0)\n"
257 "\n"
258 " Splits each chain of the current set of chains in a sequential way.\n"
259 " The points of each chain are processed (with a specified sampling)\n"
260 " sequentially. The first point of the initial chain is the\n"
261 " first point of one of the resulting chains. The splitting ends when\n"
262 " no more chain can start.\n"
263 "\n"
264 " .. tip::\n"
265 "\n"
266 " By specifying a starting and stopping predicate allows\n"
267 " the chains to overlap rather than chains partitioning.\n"
268 "\n"
269 " :arg starting_pred: The predicate on a point that expresses the\n"
270 " starting condition. Each time this condition is verified, a new chain begins\n"
271 " :type starting_pred: :class:`UnaryPredicate0D`\n"
272 " :arg stopping_pred: The predicate on a point that expresses the\n"
273 " stopping condition. The chain ends as soon as this predicate is verified.\n"
274 " :type stopping_pred: :class:`UnaryPredicate0D`\n"
275 " :arg pred: The predicate on a point that expresses the splitting condition.\n"
276 " Each time the condition is verified, the chain is split into two chains.\n"
277 " The resulting set of chains is a partition of the initial chain\n"
278 " :type pred: :class:`UnaryPredicate0D`\n"
279 " :arg sampling: The resolution used to sample the chain for the\n"
280 " predicates evaluation. (The chain is not actually resampled;\n"
281 " a virtual point only progresses along the curve using this\n"
282 " resolution.)\n"
283 " :type sampling: float\n");
284
285static PyObject *Operators_sequential_split(BPy_Operators * /*self*/,
286 PyObject *args,
287 PyObject *kwds)
288{
289 static const char *kwlist_1[] = {"starting_pred", "stopping_pred", "sampling", nullptr};
290 static const char *kwlist_2[] = {"pred", "sampling", nullptr};
291 PyObject *obj1 = nullptr, *obj2 = nullptr;
292 float f = 0.0f;
293
294 if (PyArg_ParseTupleAndKeywords(args,
295 kwds,
296 "O!O!|f",
297 (char **)kwlist_1,
299 &obj1,
301 &obj2,
302 &f))
303 {
304 if (!((BPy_UnaryPredicate0D *)obj1)->up0D) {
305 PyErr_SetString(
306 PyExc_TypeError,
307 "Operators.sequential_split(): 1st argument: invalid UnaryPredicate0D object");
308 return nullptr;
309 }
310 if (!((BPy_UnaryPredicate0D *)obj2)->up0D) {
311 PyErr_SetString(
312 PyExc_TypeError,
313 "Operators.sequential_split(): 2nd argument: invalid UnaryPredicate0D object");
314 return nullptr;
315 }
317 *(((BPy_UnaryPredicate0D *)obj2)->up0D),
318 f) < 0)
319 {
320 if (!PyErr_Occurred()) {
321 PyErr_SetString(PyExc_RuntimeError, "Operators.sequential_split() failed");
322 }
323 return nullptr;
324 }
325 }
326 else if ((void)PyErr_Clear(),
327 (void)(f = 0.0f),
328 PyArg_ParseTupleAndKeywords(
329 args, kwds, "O!|f", (char **)kwlist_2, &UnaryPredicate0D_Type, &obj1, &f))
330 {
331 if (!((BPy_UnaryPredicate0D *)obj1)->up0D) {
332 PyErr_SetString(
333 PyExc_TypeError,
334 "Operators.sequential_split(): 1st argument: invalid UnaryPredicate0D object");
335 return nullptr;
336 }
337 if (Operators::sequentialSplit(*(((BPy_UnaryPredicate0D *)obj1)->up0D), f) < 0) {
338 if (!PyErr_Occurred()) {
339 PyErr_SetString(PyExc_RuntimeError, "Operators.sequential_split() failed");
340 }
341 return nullptr;
342 }
343 }
344 else {
345 PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
346 return nullptr;
347 }
348 Py_RETURN_NONE;
349}
350
352 /* Wrap. */
353 Operators_recursive_split_doc,
354 ".. staticmethod:: recursive_split(func, pred_1d, sampling=0.0)\n"
355 " recursive_split(func, pred_0d, pred_1d, sampling=0.0)\n"
356 "\n"
357 " Splits the current set of chains in a recursive way. We process the\n"
358 " points of each chain (with a specified sampling) to find the point\n"
359 " minimizing a specified function. The chain is split in two at this\n"
360 " point and the two new chains are processed in the same way. The\n"
361 " recursivity level is controlled through a predicate 1D that expresses\n"
362 " a stopping condition on the chain that is about to be processed.\n"
363 "\n"
364 " The user can also specify a 0D predicate to make a first selection on the points\n"
365 " that can potentially be split. A point that doesn't verify the 0D\n"
366 " predicate won't be candidate in realizing the min.\n"
367 "\n"
368 " :arg func: The Unary Function evaluated at each point of the chain.\n"
369 " The splitting point is the point minimizing this function.\n"
370 " :type func: :class:`UnaryFunction0DDouble`\n"
371 " :arg pred_0d: The Unary Predicate 0D used to select the candidate\n"
372 " points where the split can occur. For example, it is very likely\n"
373 " that would rather have your chain splitting around its middle\n"
374 " point than around one of its extremities. A 0D predicate working\n"
375 " on the curvilinear abscissa allows to add this kind of constraints.\n"
376 " :type pred_0d: :class:`UnaryPredicate0D`\n"
377 " :arg pred_1d: The Unary Predicate expressing the recursivity stopping\n"
378 " condition. This predicate is evaluated for each curve before it\n"
379 " actually gets split. If pred_1d(chain) is true, the curve won't be\n"
380 " split anymore.\n"
381 " :type pred_1d: :class:`UnaryPredicate1D`\n"
382 " :arg sampling: The resolution used to sample the chain for the\n"
383 " predicates evaluation. (The chain is not actually resampled; a\n"
384 " virtual point only progresses along the curve using this\n"
385 " resolution.)\n"
386 " :type sampling: float\n");
387
388static PyObject *Operators_recursive_split(BPy_Operators * /*self*/,
389 PyObject *args,
390 PyObject *kwds)
391{
392 static const char *kwlist_1[] = {"func", "pred_1d", "sampling", nullptr};
393 static const char *kwlist_2[] = {"func", "pred_0d", "pred_1d", "sampling", nullptr};
394 PyObject *obj1 = nullptr, *obj2 = nullptr, *obj3 = nullptr;
395 float f = 0.0f;
396
397 if (PyArg_ParseTupleAndKeywords(args,
398 kwds,
399 "O!O!|f",
400 (char **)kwlist_1,
402 &obj1,
404 &obj2,
405 &f))
406 {
407 if (!((BPy_UnaryFunction0DDouble *)obj1)->uf0D_double) {
408 PyErr_SetString(
409 PyExc_TypeError,
410 "Operators.recursive_split(): 1st argument: invalid UnaryFunction0DDouble object");
411 return nullptr;
412 }
413 if (!((BPy_UnaryPredicate1D *)obj2)->up1D) {
414 PyErr_SetString(
415 PyExc_TypeError,
416 "Operators.recursive_split(): 2nd argument: invalid UnaryPredicate1D object");
417 return nullptr;
418 }
419 if (Operators::recursiveSplit(*(((BPy_UnaryFunction0DDouble *)obj1)->uf0D_double),
420 *(((BPy_UnaryPredicate1D *)obj2)->up1D),
421 f) < 0)
422 {
423 if (!PyErr_Occurred()) {
424 PyErr_SetString(PyExc_RuntimeError, "Operators.recursive_split() failed");
425 }
426 return nullptr;
427 }
428 }
429 else if ((void)PyErr_Clear(),
430 (void)(f = 0.0f),
431 PyArg_ParseTupleAndKeywords(args,
432 kwds,
433 "O!O!O!|f",
434 (char **)kwlist_2,
436 &obj1,
438 &obj2,
440 &obj3,
441 &f))
442 {
443 if (!((BPy_UnaryFunction0DDouble *)obj1)->uf0D_double) {
444 PyErr_SetString(
445 PyExc_TypeError,
446 "Operators.recursive_split(): 1st argument: invalid UnaryFunction0DDouble object");
447 return nullptr;
448 }
449 if (!((BPy_UnaryPredicate0D *)obj2)->up0D) {
450 PyErr_SetString(
451 PyExc_TypeError,
452 "Operators.recursive_split(): 2nd argument: invalid UnaryPredicate0D object");
453 return nullptr;
454 }
455 if (!((BPy_UnaryPredicate1D *)obj3)->up1D) {
456 PyErr_SetString(
457 PyExc_TypeError,
458 "Operators.recursive_split(): 3rd argument: invalid UnaryPredicate1D object");
459 return nullptr;
460 }
461 if (Operators::recursiveSplit(*(((BPy_UnaryFunction0DDouble *)obj1)->uf0D_double),
462 *(((BPy_UnaryPredicate0D *)obj2)->up0D),
463 *(((BPy_UnaryPredicate1D *)obj3)->up1D),
464 f) < 0)
465 {
466 if (!PyErr_Occurred()) {
467 PyErr_SetString(PyExc_RuntimeError, "Operators.recursive_split() failed");
468 }
469 return nullptr;
470 }
471 }
472 else {
473 PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
474 return nullptr;
475 }
476 Py_RETURN_NONE;
477}
478
480 /* Wrap. */
481 Operators_sort_doc,
482 ".. staticmethod:: sort(pred)\n"
483 "\n"
484 " Sorts the current set of chains (or viewedges) according to the\n"
485 " comparison predicate given as argument.\n"
486 "\n"
487 " :arg pred: The binary predicate used for the comparison.\n"
488 " :type pred: :class:`BinaryPredicate1D`");
489
490static PyObject *Operators_sort(BPy_Operators * /*self*/, PyObject *args, PyObject *kwds)
491{
492 static const char *kwlist[] = {"pred", nullptr};
493 PyObject *obj = nullptr;
494
495 if (!PyArg_ParseTupleAndKeywords(
496 args, kwds, "O!", (char **)kwlist, &BinaryPredicate1D_Type, &obj))
497 {
498 return nullptr;
499 }
500 if (!((BPy_BinaryPredicate1D *)obj)->bp1D) {
501 PyErr_SetString(PyExc_TypeError,
502 "Operators.sort(): 1st argument: invalid BinaryPredicate1D object");
503 return nullptr;
504 }
505 if (Operators::sort(*(((BPy_BinaryPredicate1D *)obj)->bp1D)) < 0) {
506 if (!PyErr_Occurred()) {
507 PyErr_SetString(PyExc_RuntimeError, "Operators.sort() failed");
508 }
509 return nullptr;
510 }
511 Py_RETURN_NONE;
512}
513
515 /* Wrap. */
516 Operators_create_doc,
517 ".. staticmethod:: create(pred, shaders)\n"
518 "\n"
519 " Creates and shades the strokes from the current set of chains. A\n"
520 " predicate can be specified to make a selection pass on the chains.\n"
521 "\n"
522 " :arg pred: The predicate that a chain must verify in order to be\n"
523 " transform as a stroke.\n"
524 " :type pred: :class:`UnaryPredicate1D`\n"
525 " :arg shaders: The list of shaders used to shade the strokes.\n"
526 " :type shaders: list[:class:`StrokeShader`]");
527
528static PyObject *Operators_create(BPy_Operators * /*self*/, PyObject *args, PyObject *kwds)
529{
530 static const char *kwlist[] = {"pred", "shaders", nullptr};
531 PyObject *obj1 = nullptr, *obj2 = nullptr;
532
533 if (!PyArg_ParseTupleAndKeywords(
534 args, kwds, "O!O!", (char **)kwlist, &UnaryPredicate1D_Type, &obj1, &PyList_Type, &obj2))
535 {
536 return nullptr;
537 }
538 if (!((BPy_UnaryPredicate1D *)obj1)->up1D) {
539 PyErr_SetString(PyExc_TypeError,
540 "Operators.create(): 1st argument: invalid UnaryPredicate1D object");
541 return nullptr;
542 }
544 shaders.reserve(PyList_Size(obj2));
545 for (int i = 0; i < PyList_Size(obj2); i++) {
546 PyObject *py_ss = PyList_GET_ITEM(obj2, i);
547 if (!BPy_StrokeShader_Check(py_ss)) {
548 PyErr_SetString(PyExc_TypeError,
549 "Operators.create(): 2nd argument must be a list of StrokeShader objects");
550 return nullptr;
551 }
552 StrokeShader *shader = ((BPy_StrokeShader *)py_ss)->ss;
553 if (!shader) {
554 stringstream ss;
555 ss << "Operators.create(): item " << (i + 1)
556 << " of the shaders list is invalid likely due to missing call of "
557 "StrokeShader.__init__()";
558 PyErr_SetString(PyExc_TypeError, ss.str().c_str());
559 return nullptr;
560 }
561 shaders.push_back(shader);
562 }
563 if (Operators::create(*(((BPy_UnaryPredicate1D *)obj1)->up1D), shaders) < 0) {
564 if (!PyErr_Occurred()) {
565 PyErr_SetString(PyExc_RuntimeError, "Operators.create() failed");
566 }
567 return nullptr;
568 }
569 Py_RETURN_NONE;
570}
571
573 /* Wrap. */
574 Operators_reset_doc,
575 ".. staticmethod:: reset(delete_strokes=True)\n"
576 "\n"
577 " Resets the line stylization process to the initial state. The results of\n"
578 " stroke creation are accumulated if **delete_strokes** is set to False.\n"
579 "\n"
580 " :arg delete_strokes: Delete the strokes that are currently stored.\n"
581 " :type delete_strokes: bool\n");
582
583static PyObject *Operators_reset(BPy_Operators * /*self*/, PyObject *args, PyObject *kwds)
584{
585 static const char *kwlist[] = {"delete_strokes", nullptr};
586 PyObject *obj1 = nullptr;
587 if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &PyBool_Type, &obj1)) {
588 // true is the default
589 Operators::reset(obj1 ? bool_from_PyBool(obj1) : true);
590 }
591 else {
592 PyErr_SetString(PyExc_RuntimeError, "Operators.reset() failed");
593 return nullptr;
594 }
595 Py_RETURN_NONE;
596}
597
599 /* Wrap. */
600 Operators_get_viewedge_from_index_doc,
601 ".. staticmethod:: get_viewedge_from_index(i)\n"
602 "\n"
603 " Returns the ViewEdge at the index in the current set of ViewEdges.\n"
604 "\n"
605 " :arg i: index (0 <= i < Operators.get_view_edges_size()).\n"
606 " :type i: int\n"
607 " :return: The ViewEdge object.\n"
608 " :rtype: :class:`ViewEdge`");
609
611 PyObject *args,
612 PyObject *kwds)
613{
614 static const char *kwlist[] = {"i", nullptr};
615 uint i;
616
617 if (!PyArg_ParseTupleAndKeywords(args, kwds, "I", (char **)kwlist, &i)) {
618 return nullptr;
619 }
621 PyErr_SetString(PyExc_IndexError, "index out of range");
622 return nullptr;
623 }
625}
626
628 /* Wrap. */
629 Operators_get_chain_from_index_doc,
630 ".. staticmethod:: get_chain_from_index(i)\n"
631 "\n"
632 " Returns the Chain at the index in the current set of Chains.\n"
633 "\n"
634 " :arg i: index (0 <= i < Operators.get_chains_size()).\n"
635 " :type i: int\n"
636 " :return: The Chain object.\n"
637 " :rtype: :class:`Chain`");
638
640 PyObject *args,
641 PyObject *kwds)
642{
643 static const char *kwlist[] = {"i", nullptr};
644 uint i;
645
646 if (!PyArg_ParseTupleAndKeywords(args, kwds, "I", (char **)kwlist, &i)) {
647 return nullptr;
648 }
649 if (i >= Operators::getChainsSize()) {
650 PyErr_SetString(PyExc_IndexError, "index out of range");
651 return nullptr;
652 }
654}
655
657 /* Wrap. */
658 Operators_get_stroke_from_index_doc,
659 ".. staticmethod:: get_stroke_from_index(i)\n"
660 "\n"
661 " Returns the Stroke at the index in the current set of Strokes.\n"
662 "\n"
663 " :arg i: index (0 <= i < Operators.get_strokes_size()).\n"
664 " :type i: int\n"
665 " :return: The Stroke object.\n"
666 " :rtype: :class:`Stroke`");
667
669 PyObject *args,
670 PyObject *kwds)
671{
672 static const char *kwlist[] = {"i", nullptr};
673 uint i;
674
675 if (!PyArg_ParseTupleAndKeywords(args, kwds, "I", (char **)kwlist, &i)) {
676 return nullptr;
677 }
678 if (i >= Operators::getStrokesSize()) {
679 PyErr_SetString(PyExc_IndexError, "index out of range");
680 return nullptr;
681 }
683}
684
686 /* Wrap. */
687 Operators_get_view_edges_size_doc,
688 ".. staticmethod:: get_view_edges_size()\n"
689 "\n"
690 " Returns the number of ViewEdges.\n"
691 "\n"
692 " :return: The number of ViewEdges.\n"
693 " :rtype: int");
694
696{
697 return PyLong_FromLong(Operators::getViewEdgesSize());
698}
699
701 /* Wrap. */
702 Operators_get_chains_size_doc,
703 ".. staticmethod:: get_chains_size()\n"
704 "\n"
705 " Returns the number of Chains.\n"
706 "\n"
707 " :return: The number of Chains.\n"
708 " :rtype: int");
709
710static PyObject *Operators_get_chains_size(BPy_Operators * /*self*/)
711{
712 return PyLong_FromLong(Operators::getChainsSize());
713}
714
716 /* Wrap. */
717 Operators_get_strokes_size_doc,
718 ".. staticmethod:: get_strokes_size()\n"
719 "\n"
720 " Returns the number of Strokes.\n"
721 "\n"
722 " :return: The number of Strokes.\n"
723 " :rtype: int");
724
725static PyObject *Operators_get_strokes_size(BPy_Operators * /*self*/)
726{
727 return PyLong_FromLong(Operators::getStrokesSize());
728}
729
730/*----------------------Operators instance definitions ----------------------------*/
731
732#ifdef __GNUC__
733# ifdef __clang__
734# pragma clang diagnostic push
735# pragma clang diagnostic ignored "-Wcast-function-type"
736# else
737# pragma GCC diagnostic push
738# pragma GCC diagnostic ignored "-Wcast-function-type"
739# endif
740#endif
741
742static PyMethodDef BPy_Operators_methods[] = {
743 {"select",
744 (PyCFunction)Operators_select,
745 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
746 Operators_select_doc},
747 {"chain",
748 (PyCFunction)Operators_chain,
749 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
750 Operators_chain_doc},
751 {"bidirectional_chain",
753 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
754 Operators_bidirectional_chain_doc},
755 {"sequential_split",
756 (PyCFunction)Operators_sequential_split,
757 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
758 Operators_sequential_split_doc},
759 {"recursive_split",
760 (PyCFunction)Operators_recursive_split,
761 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
762 Operators_recursive_split_doc},
763 {"sort",
764 (PyCFunction)Operators_sort,
765 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
766 Operators_sort_doc},
767 {"create",
768 (PyCFunction)Operators_create,
769 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
770 Operators_create_doc},
771 {"reset",
772 (PyCFunction)Operators_reset,
773 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
774 Operators_reset_doc},
775 {"get_viewedge_from_index",
777 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
778 Operators_get_viewedge_from_index_doc},
779 {"get_chain_from_index",
781 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
782 Operators_get_chain_from_index_doc},
783 {"get_stroke_from_index",
785 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
786 Operators_get_stroke_from_index_doc},
787 {"get_view_edges_size",
789 METH_NOARGS | METH_STATIC,
790 Operators_get_view_edges_size_doc},
791 {"get_chains_size",
792 (PyCFunction)Operators_get_chains_size,
793 METH_NOARGS | METH_STATIC,
794 Operators_get_chains_size_doc},
795 {"get_strokes_size",
796 (PyCFunction)Operators_get_strokes_size,
797 METH_NOARGS | METH_STATIC,
798 Operators_get_strokes_size_doc},
799 {nullptr, nullptr, 0, nullptr},
800};
801
802#ifdef __GNUC__
803# ifdef __clang__
804# pragma clang diagnostic pop
805# else
806# pragma GCC diagnostic pop
807# endif
808#endif
809
810/*-----------------------BPy_Operators type definition ------------------------------*/
811
812PyTypeObject Operators_Type = {
813 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
814 /*tp_name*/ "Operators",
815 /*tp_basicsize*/ sizeof(BPy_Operators),
816 /*tp_itemsize*/ 0,
817 /*tp_dealloc*/ (destructor)Operators_dealloc,
818 /*tp_vectorcall_offset*/ 0,
819 /*tp_getattr*/ nullptr,
820 /*tp_setattr*/ nullptr,
821 /*tp_as_async*/ nullptr,
822 /*tp_repr*/ nullptr,
823 /*tp_as_number*/ nullptr,
824 /*tp_as_sequence*/ nullptr,
825 /*tp_as_mapping*/ nullptr,
826 /*tp_hash*/ nullptr,
827 /*tp_call*/ nullptr,
828 /*tp_str*/ nullptr,
829 /*tp_getattro*/ nullptr,
830 /*tp_setattro*/ nullptr,
831 /*tp_as_buffer*/ nullptr,
832 /*tp_flags*/ Py_TPFLAGS_DEFAULT,
833 /*tp_doc*/ Operators_doc,
834 /*tp_traverse*/ nullptr,
835 /*tp_clear*/ nullptr,
836 /*tp_richcompare*/ nullptr,
837 /*tp_weaklistoffset*/ 0,
838 /*tp_iter*/ nullptr,
839 /*tp_iternext*/ nullptr,
840 /*tp_methods*/ BPy_Operators_methods,
841 /*tp_members*/ nullptr,
842 /*tp_getset*/ nullptr,
843 /*tp_base*/ nullptr,
844 /*tp_dict*/ nullptr,
845 /*tp_descr_get*/ nullptr,
846 /*tp_descr_set*/ nullptr,
847 /*tp_dictoffset*/ 0,
848 /*tp_init*/ nullptr,
849 /*tp_alloc*/ nullptr,
850 /*tp_new*/ PyType_GenericNew,
851};
852
unsigned int uint
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)
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)
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_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
PyObject * self
static int sort(BinaryPredicate1D &pred)
static ViewEdge * getViewEdgeFromIndex(uint i)
Definition Operators.h:220
static int select(UnaryPredicate1D &pred)
Definition Operators.cpp:30
static int chain(ViewEdgeInternal::ViewEdgeIterator &it, UnaryPredicate1D &pred, UnaryFunction1D_void &modifier)
Definition Operators.cpp:72
static void reset(bool removeStrokes=true)
static uint getChainsSize()
Definition Operators.h:240
static uint getViewEdgesSize()
Definition Operators.h:235
static uint getStrokesSize()
Definition Operators.h:245
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)
Definition Operators.h:230
static int create(UnaryPredicate1D &pred, vector< StrokeShader * > shaders)
static Chain * getChainFromIndex(uint i)
Definition Operators.h:225
inherits from class Rep
Definition AppCanvas.cpp:20
static struct PyModuleDef module
Definition python.cpp:796
i
Definition text_draw.cc:230