Blender  V2.93
BPy_ChainPredicateIterator.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
22 
23 #include "../BPy_BinaryPredicate1D.h"
24 #include "../BPy_Convert.h"
25 #include "../BPy_UnaryPredicate1D.h"
26 #include "../Interface1D/BPy_ViewEdge.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 using namespace Freestyle;
33 
35 
36 //------------------------INSTANCE METHODS ----------------------------------
37 
39  ChainPredicateIterator_doc,
40 
41  "Class hierarchy: :class:`freestyle.types.Iterator` >\n"
42  ":class:`freestyle.types.ViewEdgeIterator` >\n"
43  ":class:`freestyle.types.ChainingIterator` >\n"
44  ":class:`ChainPredicateIterator`\n"
45  "\n"
46  "A \"generic\" user-controlled ViewEdge iterator. This iterator is in\n"
47  "particular built from a unary predicate and a binary predicate.\n"
48  "First, the unary predicate is evaluated for all potential next\n"
49  "ViewEdges in order to only keep the ones respecting a certain\n"
50  "constraint. Then, the binary predicate is evaluated on the current\n"
51  "ViewEdge together with each ViewEdge of the previous selection. The\n"
52  "first ViewEdge respecting both the unary predicate and the binary\n"
53  "predicate is kept as the next one. If none of the potential next\n"
54  "ViewEdge respects these two predicates, None is returned.\n"
55  "\n"
56  ".. method:: __init__(upred, bpred, restrict_to_selection=True, "
57  " restrict_to_unvisited=True, begin=None, "
58  " orientation=True)\n"
59  " __init__(brother)\n"
60  "\n"
61  " Builds a ChainPredicateIterator from a unary predicate, a binary\n"
62  " predicate, a starting ViewEdge and its orientation or using the copy constructor.\n"
63  "\n"
64  " :arg upred: The unary predicate that the next ViewEdge must satisfy.\n"
65  " :type upred: :class:`freestyle.types.UnaryPredicate1D`\n"
66  " :arg bpred: The binary predicate that the next ViewEdge must\n"
67  " satisfy together with the actual pointed ViewEdge.\n"
68  " :type bpred: :class:`freestyle.types.BinaryPredicate1D`\n"
69  " :arg restrict_to_selection: Indicates whether to force the chaining\n"
70  " to stay within the set of selected ViewEdges or not.\n"
71  " :type restrict_to_selection: bool\n"
72  " :arg restrict_to_unvisited: Indicates whether a ViewEdge that has\n"
73  " already been chained must be ignored ot not.\n"
74  " :type restrict_to_unvisited: bool\n"
75  " :arg begin: The ViewEdge from where to start the iteration.\n"
76  " :type begin: :class:`freestyle.types.ViewEdge` or None\n"
77  " :arg orientation: If true, we'll look for the next ViewEdge among\n"
78  " the ViewEdges that surround the ending ViewVertex of begin. If\n"
79  " false, we'll search over the ViewEdges surrounding the ending\n"
80  " ViewVertex of begin.\n"
81  " :type orientation: bool\n"
82  " :arg brother: A ChainPredicateIterator object.\n"
83  " :type brother: :class:`ChainPredicateIterator`");
84 
85 static int check_begin(PyObject *obj, void *v)
86 {
87  if (obj != nullptr && obj != Py_None && !BPy_ViewEdge_Check(obj)) {
88  return 0;
89  }
90  *((PyObject **)v) = obj;
91  return 1;
92 }
93 
95  PyObject *args,
96  PyObject *kwds)
97 {
98  static const char *kwlist_1[] = {"brother", nullptr};
99  static const char *kwlist_2[] = {"upred",
100  "bpred",
101  "restrict_to_selection",
102  "restrict_to_unvisited",
103  "begin",
104  "orientation",
105  nullptr};
106  PyObject *obj1 = nullptr, *obj2 = nullptr, *obj3 = nullptr, *obj4 = nullptr, *obj5 = nullptr,
107  *obj6 = nullptr;
108 
109  if (PyArg_ParseTupleAndKeywords(
110  args, kwds, "O!", (char **)kwlist_1, &ChainPredicateIterator_Type, &obj1)) {
111  self->cp_it = new ChainPredicateIterator(*(((BPy_ChainPredicateIterator *)obj1)->cp_it));
112  self->upred = ((BPy_ChainPredicateIterator *)obj1)->upred;
113  self->bpred = ((BPy_ChainPredicateIterator *)obj1)->bpred;
114  Py_INCREF(self->upred);
115  Py_INCREF(self->bpred);
116  }
117  else if ((void)PyErr_Clear(),
118  (void)(obj3 = obj4 = obj5 = obj6 = nullptr),
119  PyArg_ParseTupleAndKeywords(args,
120  kwds,
121  "O!O!|O!O!O&O!",
122  (char **)kwlist_2,
124  &obj1,
126  &obj2,
127  &PyBool_Type,
128  &obj3,
129  &PyBool_Type,
130  &obj4,
131  check_begin,
132  &obj5,
133  &PyBool_Type,
134  &obj6)) {
135  UnaryPredicate1D *up1D = ((BPy_UnaryPredicate1D *)obj1)->up1D;
136  BinaryPredicate1D *bp1D = ((BPy_BinaryPredicate1D *)obj2)->bp1D;
137  bool restrict_to_selection = (!obj3) ? true : bool_from_PyBool(obj3);
138  bool restrict_to_unvisited = (!obj4) ? true : bool_from_PyBool(obj4);
139  ViewEdge *begin = (!obj5 || obj5 == Py_None) ? nullptr : ((BPy_ViewEdge *)obj5)->ve;
140  bool orientation = (!obj6) ? true : bool_from_PyBool(obj6);
141  self->cp_it = new ChainPredicateIterator(
142  *up1D, *bp1D, restrict_to_selection, restrict_to_unvisited, begin, orientation);
143  self->upred = obj1;
144  self->bpred = obj2;
145  Py_INCREF(self->upred);
146  Py_INCREF(self->bpred);
147  }
148  else {
149  PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
150  return -1;
151  }
152  self->py_c_it.c_it = self->cp_it;
153  self->py_c_it.py_ve_it.ve_it = self->cp_it;
154  self->py_c_it.py_ve_it.py_it.it = self->cp_it;
155  return 0;
156 }
157 
159 {
160  Py_XDECREF(self->upred);
161  Py_XDECREF(self->bpred);
162  ChainingIterator_Type.tp_dealloc((PyObject *)self);
163 }
164 
165 /*-----------------------BPy_ChainPredicateIterator type definition ----------------------------*/
166 
168  PyVarObject_HEAD_INIT(nullptr, 0) "ChainPredicateIterator", /* tp_name */
169  sizeof(BPy_ChainPredicateIterator), /* tp_basicsize */
170  0, /* tp_itemsize */
171  (destructor)ChainPredicateIterator_dealloc, /* tp_dealloc */
172  0, /* tp_vectorcall_offset */
173  nullptr, /* tp_getattr */
174  nullptr, /* tp_setattr */
175  nullptr, /* tp_reserved */
176  nullptr, /* tp_repr */
177  nullptr, /* tp_as_number */
178  nullptr, /* tp_as_sequence */
179  nullptr, /* tp_as_mapping */
180  nullptr, /* tp_hash */
181  nullptr, /* tp_call */
182  nullptr, /* tp_str */
183  nullptr, /* tp_getattro */
184  nullptr, /* tp_setattro */
185  nullptr, /* tp_as_buffer */
186  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
187  ChainPredicateIterator_doc, /* tp_doc */
188  nullptr, /* tp_traverse */
189  nullptr, /* tp_clear */
190  nullptr, /* tp_richcompare */
191  0, /* tp_weaklistoffset */
192  nullptr, /* tp_iter */
193  nullptr, /* tp_iternext */
194  nullptr, /* tp_methods */
195  nullptr, /* tp_members */
196  nullptr, /* tp_getset */
197  &ChainingIterator_Type, /* tp_base */
198  nullptr, /* tp_dict */
199  nullptr, /* tp_descr_get */
200  nullptr, /* tp_descr_set */
201  0, /* tp_dictoffset */
202  (initproc)ChainPredicateIterator_init, /* tp_init */
203  nullptr, /* tp_alloc */
204  nullptr, /* tp_new */
205 };
206 
208 
209 #ifdef __cplusplus
210 }
211 #endif
PyTypeObject BinaryPredicate1D_Type
static int check_begin(PyObject *obj, void *v)
PyTypeObject ChainPredicateIterator_Type
static int ChainPredicateIterator_init(BPy_ChainPredicateIterator *self, PyObject *args, PyObject *kwds)
PyDoc_STRVAR(ChainPredicateIterator_doc, "Class hierarchy: :class:`freestyle.types.Iterator` >\n" ":class:`freestyle.types.ViewEdgeIterator` >\n" ":class:`freestyle.types.ChainingIterator` >\n" ":class:`ChainPredicateIterator`\n" "\n" "A \"generic\" user-controlled ViewEdge iterator. This iterator is in\n" "particular built from a unary predicate and a binary predicate.\n" "First, the unary predicate is evaluated for all potential next\n" "ViewEdges in order to only keep the ones respecting a certain\n" "constraint. Then, the binary predicate is evaluated on the current\n" "ViewEdge together with each ViewEdge of the previous selection. The\n" "first ViewEdge respecting both the unary predicate and the binary\n" "predicate is kept as the next one. If none of the potential next\n" "ViewEdge respects these two predicates, None is returned.\n" "\n" ".. method:: __init__(upred, bpred, restrict_to_selection=True, " " restrict_to_unvisited=True, begin=None, " " orientation=True)\n" " __init__(brother)\n" "\n" " Builds a ChainPredicateIterator from a unary predicate, a binary\n" " predicate, a starting ViewEdge and its orientation or using the copy constructor.\n" "\n" " :arg upred: The unary predicate that the next ViewEdge must satisfy.\n" " :type upred: :class:`freestyle.types.UnaryPredicate1D`\n" " :arg bpred: The binary predicate that the next ViewEdge must\n" " satisfy together with the actual pointed ViewEdge.\n" " :type bpred: :class:`freestyle.types.BinaryPredicate1D`\n" " :arg restrict_to_selection: Indicates whether to force the chaining\n" " to stay within the set of selected ViewEdges or not.\n" " :type restrict_to_selection: bool\n" " :arg restrict_to_unvisited: Indicates whether a ViewEdge that has\n" " already been chained must be ignored ot not.\n" " :type restrict_to_unvisited: bool\n" " :arg begin: The ViewEdge from where to start the iteration.\n" " :type begin: :class:`freestyle.types.ViewEdge` or None\n" " :arg orientation: If true, we'll look for the next ViewEdge among\n" " the ViewEdges that surround the ending ViewVertex of begin. If\n" " false, we'll search over the ViewEdges surrounding the ending\n" " ViewVertex of begin.\n" " :type orientation: bool\n" " :arg brother: A ChainPredicateIterator object.\n" " :type brother: :class:`ChainPredicateIterator`")
static void ChainPredicateIterator_dealloc(BPy_ChainPredicateIterator *self)
PyTypeObject ChainingIterator_Type
bool bool_from_PyBool(PyObject *b)
PyTypeObject UnaryPredicate1D_Type
#define BPy_ViewEdge_Check(v)
Definition: BPy_ViewEdge.h:35
ATTR_WARN_UNUSED_RESULT const BMVert * v
PyObject * self
Definition: bpy_driver.c:185
inherits from class Rep
Definition: AppCanvas.cpp:32