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