Blender V5.3
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.hh"
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.\n");
54{
55 Py_TYPE(self)->tp_free((PyObject *)self);
56}
57
59 /* Wrap. */
60 Operators_select_doc,
61 ".. staticmethod:: select(pred)\n"
62 "\n"
63 " Selects the ViewEdges of the ViewMap verifying a specified\n"
64 " condition.\n"
65 "\n"
66 " :param pred: The predicate expressing this condition.\n"
67 " :type pred: :class:`UnaryPredicate1D`\n");
68static PyObject *Operators_select(BPy_Operators * /*self*/, PyObject *args, PyObject *kwds)
69{
70 static const char *kwlist[] = {"pred", nullptr};
71 PyObject *obj = nullptr;
72
73 if (!PyArg_ParseTupleAndKeywords(args,
74 kwds,
75 "O!" /* `pred` */
76 ":select",
77 (char **)kwlist,
79 &obj))
80 {
81 return nullptr;
82 }
83 if (!((BPy_UnaryPredicate1D *)obj)->up1D) {
84 PyErr_SetString(PyExc_TypeError,
85 "Operators.select(): 1st argument: invalid UnaryPredicate1D object");
86 return nullptr;
87 }
88 if (Operators::select(*(((BPy_UnaryPredicate1D *)obj)->up1D)) < 0) {
89 if (!PyErr_Occurred()) {
90 PyErr_SetString(PyExc_RuntimeError, "Operators.select() failed");
91 }
92 return nullptr;
93 }
94 Py_RETURN_NONE;
95}
96
98 /* Wrap. */
99 Operators_chain_doc,
100 ".. staticmethod:: chain(*args)\n"
101 "\n"
102 " Accepted call signatures:\n"
103 "\n"
104 " - ``chain(it, pred, modifier)``\n"
105 " - ``chain(it, pred)``\n"
106 "\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"
112 "\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");
124static PyObject *Operators_chain(BPy_Operators * /*self*/, PyObject *args, PyObject *kwds)
125{
126 static const char *kwlist[] = {"it", "pred", "modifier", nullptr};
127 PyObject *obj1 = nullptr, *obj2 = nullptr, *obj3 = nullptr;
128
129 if (!PyArg_ParseTupleAndKeywords(args,
130 kwds,
131 "O!" /* `it` */
132 "O!" /* `pred` */
133 "|" /* Optional arguments. */
134 "O!" /* `modifier` */
135 ":chain",
136 (char **)kwlist,
138 &obj1,
140 &obj2,
142 &obj3))
143 {
144 return nullptr;
145 }
146 if (!((BPy_ChainingIterator *)obj1)->c_it) {
147 PyErr_SetString(PyExc_TypeError,
148 "Operators.chain(): 1st argument: invalid ChainingIterator object");
149 return nullptr;
150 }
151 if (!((BPy_UnaryPredicate1D *)obj2)->up1D) {
152 PyErr_SetString(PyExc_TypeError,
153 "Operators.chain(): 2nd argument: invalid UnaryPredicate1D object");
154 return nullptr;
155 }
156 if (!obj3) {
157 if (Operators::chain(*(((BPy_ChainingIterator *)obj1)->c_it),
158 *(((BPy_UnaryPredicate1D *)obj2)->up1D)) < 0)
159 {
160 if (!PyErr_Occurred()) {
161 PyErr_SetString(PyExc_RuntimeError, "Operators.chain() failed");
162 }
163 return nullptr;
164 }
165 }
166 else {
167 if (!((BPy_UnaryFunction1DVoid *)obj3)->uf1D_void) {
168 PyErr_SetString(PyExc_TypeError,
169 "Operators.chain(): 3rd argument: invalid UnaryFunction1DVoid object");
170 return nullptr;
171 }
172 if (Operators::chain(*(((BPy_ChainingIterator *)obj1)->c_it),
173 *(((BPy_UnaryPredicate1D *)obj2)->up1D),
174 *(((BPy_UnaryFunction1DVoid *)obj3)->uf1D_void)) < 0)
175 {
176 if (!PyErr_Occurred()) {
177 PyErr_SetString(PyExc_RuntimeError, "Operators.chain() failed");
178 }
179 return nullptr;
180 }
181 }
182 Py_RETURN_NONE;
183}
184
186 /* Wrap. */
187 Operators_bidirectional_chain_doc,
188 ".. staticmethod:: bidirectional_chain(*args)\n"
189 "\n"
190 " Accepted call signatures:\n"
191 "\n"
192 " - ``bidirectional_chain(it, pred)``\n"
193 " - ``bidirectional_chain(it)``\n"
194 "\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"
206 "\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");
215 PyObject *args,
216 PyObject *kwds)
217{
218 static const char *kwlist[] = {"it", "pred", nullptr};
219 PyObject *obj1 = nullptr, *obj2 = nullptr;
220
221 if (!PyArg_ParseTupleAndKeywords(args,
222 kwds,
223 "O!" /* `it` */
224 "|" /* Optional arguments. */
225 "O!" /* `pred` */
226 ":bidirectional_chain",
227 (char **)kwlist,
229 &obj1,
231 &obj2))
232 {
233 return nullptr;
234 }
235 if (!((BPy_ChainingIterator *)obj1)->c_it) {
236 PyErr_SetString(
237 PyExc_TypeError,
238 "Operators.bidirectional_chain(): 1st argument: invalid ChainingIterator object");
239 return nullptr;
240 }
241 if (!obj2) {
242 if (Operators::bidirectionalChain(*(((BPy_ChainingIterator *)obj1)->c_it)) < 0) {
243 if (!PyErr_Occurred()) {
244 PyErr_SetString(PyExc_RuntimeError, "Operators.bidirectional_chain() failed");
245 }
246 return nullptr;
247 }
248 }
249 else {
250 if (!((BPy_UnaryPredicate1D *)obj2)->up1D) {
251 PyErr_SetString(
252 PyExc_TypeError,
253 "Operators.bidirectional_chain(): 2nd argument: invalid UnaryPredicate1D object");
254 return nullptr;
255 }
257 *(((BPy_UnaryPredicate1D *)obj2)->up1D)) < 0)
258 {
259 if (!PyErr_Occurred()) {
260 PyErr_SetString(PyExc_RuntimeError, "Operators.bidirectional_chain() failed");
261 }
262 return nullptr;
263 }
264 }
265 Py_RETURN_NONE;
266}
267
269 /* Wrap. */
270 Operators_sequential_split_doc,
271 ".. staticmethod:: sequential_split(*args, **kwargs)\n"
272 "\n"
273 " Accepted call signatures:\n"
274 "\n"
275 " - ``sequential_split(starting_pred, stopping_pred, sampling=0.0)``\n"
276 " - ``sequential_split(pred, sampling=0.0)``\n"
277 "\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"
283 "\n"
284 " .. tip::\n"
285 "\n"
286 " By specifying a starting and stopping predicate allows\n"
287 " the chains to overlap rather than chains partitioning.\n"
288 "\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"
302 " resolution.)\n"
303 " :type sampling: float\n");
304static PyObject *Operators_sequential_split(BPy_Operators * /*self*/,
305 PyObject *args,
306 PyObject *kwds)
307{
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;
311 float f = 0.0f;
312
313 if (PyArg_ParseTupleAndKeywords(args,
314 kwds,
315 "O!" /* `starting_pred` */
316 "O!" /* `stopping_pred` */
317 "|" /* Optional arguments. */
318 "f" /* `sampling` */
319 ":sequential_split",
320 (char **)kwlist_1,
322 &obj1,
324 &obj2,
325 &f))
326 {
327 if (!((BPy_UnaryPredicate0D *)obj1)->up0D) {
328 PyErr_SetString(
329 PyExc_TypeError,
330 "Operators.sequential_split(): 1st argument: invalid UnaryPredicate0D object");
331 return nullptr;
332 }
333 if (!((BPy_UnaryPredicate0D *)obj2)->up0D) {
334 PyErr_SetString(
335 PyExc_TypeError,
336 "Operators.sequential_split(): 2nd argument: invalid UnaryPredicate0D object");
337 return nullptr;
338 }
340 *(((BPy_UnaryPredicate0D *)obj2)->up0D),
341 f) < 0)
342 {
343 if (!PyErr_Occurred()) {
344 PyErr_SetString(PyExc_RuntimeError, "Operators.sequential_split() failed");
345 }
346 return nullptr;
347 }
348 }
349 else if ((void)PyErr_Clear(),
350 (void)(f = 0.0f),
351 PyArg_ParseTupleAndKeywords(args,
352 kwds,
353 "O!" /* `pred` */
354 "|" /* Optional arguments. */
355 "f" /* `sampling` */
356 ":sequential_split",
357 (char **)kwlist_2,
359 &obj1,
360 &f))
361 {
362 if (!((BPy_UnaryPredicate0D *)obj1)->up0D) {
363 PyErr_SetString(
364 PyExc_TypeError,
365 "Operators.sequential_split(): 1st argument: invalid UnaryPredicate0D object");
366 return nullptr;
367 }
368 if (Operators::sequentialSplit(*(((BPy_UnaryPredicate0D *)obj1)->up0D), f) < 0) {
369 if (!PyErr_Occurred()) {
370 PyErr_SetString(PyExc_RuntimeError, "Operators.sequential_split() failed");
371 }
372 return nullptr;
373 }
374 }
375 else {
376 PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
377 return nullptr;
378 }
379 Py_RETURN_NONE;
380}
381
383 /* Wrap. */
384 Operators_recursive_split_doc,
385 ".. staticmethod:: recursive_split(*args, **kwargs)\n"
386 "\n"
387 " Accepted call signatures:\n"
388 "\n"
389 " - ``recursive_split(func, pred_1d, sampling=0.0)``\n"
390 " - ``recursive_split(func, pred_0d, pred_1d, sampling=0.0)``\n"
391 "\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"
398 "\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"
402 "\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"
415 " split anymore.\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"
420 " resolution.)\n"
421 " :type sampling: float\n");
422static PyObject *Operators_recursive_split(BPy_Operators * /*self*/,
423 PyObject *args,
424 PyObject *kwds)
425{
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;
429 float f = 0.0f;
430
431 if (PyArg_ParseTupleAndKeywords(args,
432 kwds,
433 "O!" /* `func` */
434 "O!" /* `pred_1d` */
435 "|" /* Optional arguments. */
436 "f" /* `sampling` */
437 ":recursive_split",
438 (char **)kwlist_1,
440 &obj1,
442 &obj2,
443 &f))
444 {
445 if (!((BPy_UnaryFunction0DDouble *)obj1)->uf0D_double) {
446 PyErr_SetString(
447 PyExc_TypeError,
448 "Operators.recursive_split(): 1st argument: invalid UnaryFunction0DDouble object");
449 return nullptr;
450 }
451 if (!((BPy_UnaryPredicate1D *)obj2)->up1D) {
452 PyErr_SetString(
453 PyExc_TypeError,
454 "Operators.recursive_split(): 2nd argument: invalid UnaryPredicate1D object");
455 return nullptr;
456 }
457 if (Operators::recursiveSplit(*(((BPy_UnaryFunction0DDouble *)obj1)->uf0D_double),
458 *(((BPy_UnaryPredicate1D *)obj2)->up1D),
459 f) < 0)
460 {
461 if (!PyErr_Occurred()) {
462 PyErr_SetString(PyExc_RuntimeError, "Operators.recursive_split() failed");
463 }
464 return nullptr;
465 }
466 }
467 else if ((void)PyErr_Clear(),
468 (void)(f = 0.0f),
469 PyArg_ParseTupleAndKeywords(args,
470 kwds,
471 "O!" /* `func` */
472 "O!" /* `pred_0d` */
473 "O!" /* `pred_1d` */
474 "|" /* Optional arguments. */
475 "f" /* `sampling` */
476 ":recursive_split",
477 (char **)kwlist_2,
479 &obj1,
481 &obj2,
483 &obj3,
484 &f))
485 {
486 if (!((BPy_UnaryFunction0DDouble *)obj1)->uf0D_double) {
487 PyErr_SetString(
488 PyExc_TypeError,
489 "Operators.recursive_split(): 1st argument: invalid UnaryFunction0DDouble object");
490 return nullptr;
491 }
492 if (!((BPy_UnaryPredicate0D *)obj2)->up0D) {
493 PyErr_SetString(
494 PyExc_TypeError,
495 "Operators.recursive_split(): 2nd argument: invalid UnaryPredicate0D object");
496 return nullptr;
497 }
498 if (!((BPy_UnaryPredicate1D *)obj3)->up1D) {
499 PyErr_SetString(
500 PyExc_TypeError,
501 "Operators.recursive_split(): 3rd argument: invalid UnaryPredicate1D object");
502 return nullptr;
503 }
504 if (Operators::recursiveSplit(*(((BPy_UnaryFunction0DDouble *)obj1)->uf0D_double),
505 *(((BPy_UnaryPredicate0D *)obj2)->up0D),
506 *(((BPy_UnaryPredicate1D *)obj3)->up1D),
507 f) < 0)
508 {
509 if (!PyErr_Occurred()) {
510 PyErr_SetString(PyExc_RuntimeError, "Operators.recursive_split() failed");
511 }
512 return nullptr;
513 }
514 }
515 else {
516 PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
517 return nullptr;
518 }
519 Py_RETURN_NONE;
520}
521
523 /* Wrap. */
524 Operators_sort_doc,
525 ".. staticmethod:: sort(pred)\n"
526 "\n"
527 " Sorts the current set of chains (or viewedges) according to the\n"
528 " comparison predicate given as argument.\n"
529 "\n"
530 " :param pred: The binary predicate used for the comparison.\n"
531 " :type pred: :class:`BinaryPredicate1D`\n");
532static PyObject *Operators_sort(BPy_Operators * /*self*/, PyObject *args, PyObject *kwds)
533{
534 static const char *kwlist[] = {"pred", nullptr};
535 PyObject *obj = nullptr;
536
537 if (!PyArg_ParseTupleAndKeywords(args,
538 kwds,
539 "O!" /* `pred` */
540 ":sort",
541 (char **)kwlist,
543 &obj))
544 {
545 return nullptr;
546 }
547 if (!((BPy_BinaryPredicate1D *)obj)->bp1D) {
548 PyErr_SetString(PyExc_TypeError,
549 "Operators.sort(): 1st argument: invalid BinaryPredicate1D object");
550 return nullptr;
551 }
552 if (Operators::sort(*(((BPy_BinaryPredicate1D *)obj)->bp1D)) < 0) {
553 if (!PyErr_Occurred()) {
554 PyErr_SetString(PyExc_RuntimeError, "Operators.sort() failed");
555 }
556 return nullptr;
557 }
558 Py_RETURN_NONE;
559}
560
562 /* Wrap. */
563 Operators_create_doc,
564 ".. staticmethod:: create(pred, shaders)\n"
565 "\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"
568 "\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");
574static PyObject *Operators_create(BPy_Operators * /*self*/, PyObject *args, PyObject *kwds)
575{
576 static const char *kwlist[] = {"pred", "shaders", nullptr};
577 PyObject *obj1 = nullptr, *obj2 = nullptr;
578
579 if (!PyArg_ParseTupleAndKeywords(args,
580 kwds,
581 "O!" /* `pred` */
582 "O!" /* `shaders` */
583 ":create",
584 (char **)kwlist,
586 &obj1,
587 &PyList_Type,
588 &obj2))
589 {
590 return nullptr;
591 }
592 if (!((BPy_UnaryPredicate1D *)obj1)->up1D) {
593 PyErr_SetString(PyExc_TypeError,
594 "Operators.create(): 1st argument: invalid UnaryPredicate1D object");
595 return nullptr;
596 }
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);
601 if (!BPy_StrokeShader_Check(py_ss)) {
602 PyErr_SetString(PyExc_TypeError,
603 "Operators.create(): 2nd argument must be a list of StrokeShader objects");
604 return nullptr;
605 }
606 StrokeShader *shader = ((BPy_StrokeShader *)py_ss)->ss;
607 if (!shader) {
608 stringstream ss;
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());
613 return nullptr;
614 }
615 shaders.push_back(shader);
616 }
617 if (Operators::create(*(((BPy_UnaryPredicate1D *)obj1)->up1D), shaders) < 0) {
618 if (!PyErr_Occurred()) {
619 PyErr_SetString(PyExc_RuntimeError, "Operators.create() failed");
620 }
621 return nullptr;
622 }
623 Py_RETURN_NONE;
624}
625
627 /* Wrap. */
628 Operators_reset_doc,
629 ".. staticmethod:: reset(delete_strokes=True)\n"
630 "\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"
633 "\n"
634 " :param delete_strokes: Delete the strokes that are currently stored.\n"
635 " :type delete_strokes: bool\n");
636static PyObject *Operators_reset(BPy_Operators * /*self*/, PyObject *args, PyObject *kwds)
637{
638 static const char *kwlist[] = {"delete_strokes", nullptr};
639 PyObject *obj1 = nullptr;
640 if (PyArg_ParseTupleAndKeywords(args,
641 kwds,
642 "|" /* Optional arguments. */
643 "O!" /* `delete_strokes` */
644 ":reset",
645 (char **)kwlist,
646 &PyBool_Type,
647 &obj1))
648 {
649 // true is the default
650 Operators::reset(obj1 ? bool_from_PyBool(obj1) : true);
651 }
652 else {
653 PyErr_SetString(PyExc_RuntimeError, "Operators.reset() failed");
654 return nullptr;
655 }
656 Py_RETURN_NONE;
657}
658
660 /* Wrap. */
661 Operators_get_viewedge_from_index_doc,
662 ".. staticmethod:: get_viewedge_from_index(i)\n"
663 "\n"
664 " Returns the ViewEdge at the index in the current set of ViewEdges.\n"
665 "\n"
666 " :param i: index (0 <= i < Operators.get_view_edges_size()).\n"
667 " :type i: int\n"
668 " :return: The ViewEdge object.\n"
669 " :rtype: :class:`ViewEdge`\n");
671 PyObject *args,
672 PyObject *kwds)
673{
674 static const char *kwlist[] = {"i", nullptr};
675 uint i;
676
677 if (!PyArg_ParseTupleAndKeywords(args,
678 kwds,
679 "I" /* `i` */
680 ":get_viewedge_from_index",
681 (char **)kwlist,
682 &i))
683 {
684 return nullptr;
685 }
686 if (i >= Operators::getViewEdgesSize()) {
687 PyErr_SetString(PyExc_IndexError, "index out of range");
688 return nullptr;
689 }
691}
692
694 /* Wrap. */
695 Operators_get_chain_from_index_doc,
696 ".. staticmethod:: get_chain_from_index(i)\n"
697 "\n"
698 " Returns the Chain at the index in the current set of Chains.\n"
699 "\n"
700 " :param i: index (0 <= i < Operators.get_chains_size()).\n"
701 " :type i: int\n"
702 " :return: The Chain object.\n"
703 " :rtype: :class:`Chain`\n");
705 PyObject *args,
706 PyObject *kwds)
707{
708 static const char *kwlist[] = {"i", nullptr};
709 uint i;
710
711 if (!PyArg_ParseTupleAndKeywords(args,
712 kwds,
713 "I" /* `i` */
714 ":get_chain_from_index",
715 (char **)kwlist,
716 &i))
717 {
718 return nullptr;
719 }
720 if (i >= Operators::getChainsSize()) {
721 PyErr_SetString(PyExc_IndexError, "index out of range");
722 return nullptr;
723 }
725}
726
728 /* Wrap. */
729 Operators_get_stroke_from_index_doc,
730 ".. staticmethod:: get_stroke_from_index(i)\n"
731 "\n"
732 " Returns the Stroke at the index in the current set of Strokes.\n"
733 "\n"
734 " :param i: index (0 <= i < Operators.get_strokes_size()).\n"
735 " :type i: int\n"
736 " :return: The Stroke object.\n"
737 " :rtype: :class:`Stroke`\n");
739 PyObject *args,
740 PyObject *kwds)
741{
742 static const char *kwlist[] = {"i", nullptr};
743 uint i;
744
745 if (!PyArg_ParseTupleAndKeywords(args,
746 kwds,
747 "I" /* `i` */
748 ":get_stroke_from_index",
749 (char **)kwlist,
750 &i))
751 {
752 return nullptr;
753 }
754 if (i >= Operators::getStrokesSize()) {
755 PyErr_SetString(PyExc_IndexError, "index out of range");
756 return nullptr;
757 }
759}
760
762 /* Wrap. */
763 Operators_get_view_edges_size_doc,
764 ".. staticmethod:: get_view_edges_size()\n"
765 "\n"
766 " Returns the number of ViewEdges.\n"
767 "\n"
768 " :return: The number of ViewEdges.\n"
769 " :rtype: int\n");
771{
772 return PyLong_FromLong(Operators::getViewEdgesSize());
773}
774
776 /* Wrap. */
777 Operators_get_chains_size_doc,
778 ".. staticmethod:: get_chains_size()\n"
779 "\n"
780 " Returns the number of Chains.\n"
781 "\n"
782 " :return: The number of Chains.\n"
783 " :rtype: int\n");
784static PyObject *Operators_get_chains_size(BPy_Operators * /*self*/)
785{
786 return PyLong_FromLong(Operators::getChainsSize());
787}
788
790 /* Wrap. */
791 Operators_get_strokes_size_doc,
792 ".. staticmethod:: get_strokes_size()\n"
793 "\n"
794 " Returns the number of Strokes.\n"
795 "\n"
796 " :return: The number of Strokes.\n"
797 " :rtype: int\n");
798static PyObject *Operators_get_strokes_size(BPy_Operators * /*self*/)
799{
800 return PyLong_FromLong(Operators::getStrokesSize());
801}
802
803/*----------------------Operators instance definitions ----------------------------*/
804
805#ifdef __GNUC__
806# ifdef __clang__
807# pragma clang diagnostic push
808# pragma clang diagnostic ignored "-Wcast-function-type"
809# else
810# pragma GCC diagnostic push
811# pragma GCC diagnostic ignored "-Wcast-function-type"
812# endif
813#endif
814
815static PyMethodDef BPy_Operators_methods[] = {
816 {"select",
817 (PyCFunction)Operators_select,
818 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
819 Operators_select_doc},
820 {"chain",
821 (PyCFunction)Operators_chain,
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},
828 {"sequential_split",
829 (PyCFunction)Operators_sequential_split,
830 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
831 Operators_sequential_split_doc},
832 {"recursive_split",
833 (PyCFunction)Operators_recursive_split,
834 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
835 Operators_recursive_split_doc},
836 {"sort",
837 (PyCFunction)Operators_sort,
838 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
839 Operators_sort_doc},
840 {"create",
841 (PyCFunction)Operators_create,
842 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
843 Operators_create_doc},
844 {"reset",
845 (PyCFunction)Operators_reset,
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},
864 {"get_chains_size",
865 (PyCFunction)Operators_get_chains_size,
866 METH_NOARGS | METH_STATIC,
867 Operators_get_chains_size_doc},
868 {"get_strokes_size",
869 (PyCFunction)Operators_get_strokes_size,
870 METH_NOARGS | METH_STATIC,
871 Operators_get_strokes_size_doc},
872 {nullptr, nullptr, 0, nullptr},
873};
874
875#ifdef __GNUC__
876# ifdef __clang__
877# pragma clang diagnostic pop
878# else
879# pragma GCC diagnostic pop
880# endif
881#endif
882
883/*-----------------------BPy_Operators type definition ------------------------------*/
884
885PyTypeObject Operators_Type = {
886 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
887 /*tp_name*/ "Operators",
888 /*tp_basicsize*/ sizeof(BPy_Operators),
889 /*tp_itemsize*/ 0,
890 /*tp_dealloc*/ (destructor)Operators_dealloc,
891 /*tp_vectorcall_offset*/ 0,
892 /*tp_getattr*/ nullptr,
893 /*tp_setattr*/ nullptr,
894 /*tp_as_async*/ nullptr,
895 /*tp_repr*/ nullptr,
896 /*tp_as_number*/ nullptr,
897 /*tp_as_sequence*/ nullptr,
898 /*tp_as_mapping*/ nullptr,
899 /*tp_hash*/ nullptr,
900 /*tp_call*/ nullptr,
901 /*tp_str*/ nullptr,
902 /*tp_getattro*/ nullptr,
903 /*tp_setattro*/ nullptr,
904 /*tp_as_buffer*/ nullptr,
905 /*tp_flags*/ Py_TPFLAGS_DEFAULT,
906 /*tp_doc*/ Operators_doc,
907 /*tp_traverse*/ nullptr,
908 /*tp_clear*/ nullptr,
909 /*tp_richcompare*/ nullptr,
910 /*tp_weaklistoffset*/ 0,
911 /*tp_iter*/ nullptr,
912 /*tp_iternext*/ nullptr,
913 /*tp_methods*/ BPy_Operators_methods,
914 /*tp_members*/ nullptr,
915 /*tp_getset*/ nullptr,
916 /*tp_base*/ nullptr,
917 /*tp_dict*/ nullptr,
918 /*tp_descr_get*/ nullptr,
919 /*tp_descr_set*/ nullptr,
920 /*tp_dictoffset*/ 0,
921 /*tp_init*/ nullptr,
922 /*tp_alloc*/ nullptr,
923 /*tp_new*/ PyType_GenericNew,
924};
925
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)
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