Blender  V2.93
BPy_ViewVertex.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 
21 #include "BPy_ViewVertex.h"
22 
23 #include "../BPy_Convert.h"
24 #include "../BPy_Nature.h"
25 #include "../Interface1D/BPy_ViewEdge.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 using namespace Freestyle;
32 
34 
35 /*----------------------ViewVertex methods----------------------------*/
36 
37 PyDoc_STRVAR(ViewVertex_doc,
38  "Class hierarchy: :class:`Interface0D` > :class:`ViewVertex`\n"
39  "\n"
40  "Class to define a view vertex. A view vertex is a feature vertex\n"
41  "corresponding to a point of the image graph, where the characteristics\n"
42  "of an edge (e.g., nature and visibility) might change. A\n"
43  ":class:`ViewVertex` can be of two kinds: A :class:`TVertex` when it\n"
44  "corresponds to the intersection between two ViewEdges or a\n"
45  ":class:`NonTVertex` when it corresponds to a vertex of the initial\n"
46  "input mesh (it is the case for vertices such as corners for example).\n"
47  "Thus, this class can be specialized into two classes, the\n"
48  ":class:`TVertex` class and the :class:`NonTVertex` class.");
49 
50 static int ViewVertex_init(BPy_ViewVertex * /*self*/, PyObject * /*args*/, PyObject * /*kwds*/)
51 {
52  PyErr_SetString(PyExc_TypeError, "cannot instantiate abstract class");
53  return -1;
54 }
55 
56 PyDoc_STRVAR(ViewVertex_edges_begin_doc,
57  ".. method:: edges_begin()\n"
58  "\n"
59  " Returns an iterator over the ViewEdges that goes to or comes from\n"
60  " this ViewVertex pointing to the first ViewEdge of the list. The\n"
61  " orientedViewEdgeIterator allows to iterate in CCW order over these\n"
62  " ViewEdges and to get the orientation for each ViewEdge\n"
63  " (incoming/outgoing).\n"
64  "\n"
65  " :return: An orientedViewEdgeIterator pointing to the first ViewEdge.\n"
66  " :rtype: :class:`orientedViewEdgeIterator`");
67 
68 static PyObject *ViewVertex_edges_begin(BPy_ViewVertex *self)
69 {
70  ViewVertexInternal::orientedViewEdgeIterator ove_it(self->vv->edgesBegin());
72 }
73 
74 PyDoc_STRVAR(ViewVertex_edges_end_doc,
75  ".. method:: edges_end()\n"
76  "\n"
77  " Returns an orientedViewEdgeIterator over the ViewEdges around this\n"
78  " ViewVertex, pointing after the last ViewEdge.\n"
79  "\n"
80  " :return: An orientedViewEdgeIterator pointing after the last ViewEdge.\n"
81  " :rtype: :class:`orientedViewEdgeIterator`");
82 
83 static PyObject *ViewVertex_edges_end(BPy_ViewVertex * /*self*/)
84 {
85 #if 0
86  ViewVertexInternal::orientedViewEdgeIterator ove_it(self->vv->edgesEnd());
88 #else
89  PyErr_SetString(PyExc_NotImplementedError, "edges_end method currently disabled");
90  return nullptr;
91 #endif
92 }
93 
94 PyDoc_STRVAR(ViewVertex_edges_iterator_doc,
95  ".. method:: edges_iterator(edge)\n"
96  "\n"
97  " Returns an orientedViewEdgeIterator pointing to the ViewEdge given\n"
98  " as argument.\n"
99  "\n"
100  " :arg edge: A ViewEdge object.\n"
101  " :type edge: :class:`ViewEdge`\n"
102  " :return: An orientedViewEdgeIterator pointing to the given ViewEdge.\n"
103  " :rtype: :class:`orientedViewEdgeIterator`");
104 
105 static PyObject *ViewVertex_edges_iterator(BPy_ViewVertex *self, PyObject *args, PyObject *kwds)
106 {
107  static const char *kwlist[] = {"edge", nullptr};
108  PyObject *py_ve;
109 
110  if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &ViewEdge_Type, &py_ve)) {
111  return nullptr;
112  }
113  ViewEdge *ve = ((BPy_ViewEdge *)py_ve)->ve;
114  ViewVertexInternal::orientedViewEdgeIterator ove_it(self->vv->edgesIterator(ve));
116 }
117 
118 static PyMethodDef BPy_ViewVertex_methods[] = {
119  {"edges_begin", (PyCFunction)ViewVertex_edges_begin, METH_NOARGS, ViewVertex_edges_begin_doc},
120  {"edges_end", (PyCFunction)ViewVertex_edges_end, METH_NOARGS, ViewVertex_edges_end_doc},
121  {"edges_iterator",
122  (PyCFunction)ViewVertex_edges_iterator,
123  METH_VARARGS | METH_KEYWORDS,
124  ViewVertex_edges_iterator_doc},
125  {nullptr, nullptr, 0, nullptr},
126 };
127 
128 /*----------------------ViewVertex get/setters ----------------------------*/
129 
130 PyDoc_STRVAR(ViewVertex_nature_doc,
131  "The nature of this ViewVertex.\n"
132  "\n"
133  ":type: :class:`Nature`");
134 
135 static PyObject *ViewVertex_nature_get(BPy_ViewVertex *self, void *UNUSED(closure))
136 {
137  Nature::VertexNature nature = self->vv->getNature();
138  if (PyErr_Occurred()) {
139  return nullptr;
140  }
141  return BPy_Nature_from_Nature(nature); // return a copy
142 }
143 
144 static int ViewVertex_nature_set(BPy_ViewVertex *self, PyObject *value, void *UNUSED(closure))
145 {
146  if (!BPy_Nature_Check(value)) {
147  PyErr_SetString(PyExc_TypeError, "value must be a Nature");
148  return -1;
149  }
150  self->vv->setNature(PyLong_AsLong((PyObject *)&((BPy_Nature *)value)->i));
151  return 0;
152 }
153 
154 static PyGetSetDef BPy_ViewVertex_getseters[] = {
155  {"nature",
156  (getter)ViewVertex_nature_get,
157  (setter)ViewVertex_nature_set,
158  ViewVertex_nature_doc,
159  nullptr},
160  {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
161 };
162 
163 /*-----------------------BPy_ViewVertex type definition ------------------------------*/
164 PyTypeObject ViewVertex_Type = {
165  PyVarObject_HEAD_INIT(nullptr, 0) "ViewVertex", /* tp_name */
166  sizeof(BPy_ViewVertex), /* tp_basicsize */
167  0, /* tp_itemsize */
168  nullptr, /* tp_dealloc */
169  0, /* tp_vectorcall_offset */
170  nullptr, /* tp_getattr */
171  nullptr, /* tp_setattr */
172  nullptr, /* tp_reserved */
173  nullptr, /* tp_repr */
174  nullptr, /* tp_as_number */
175  nullptr, /* tp_as_sequence */
176  nullptr, /* tp_as_mapping */
177  nullptr, /* tp_hash */
178  nullptr, /* tp_call */
179  nullptr, /* tp_str */
180  nullptr, /* tp_getattro */
181  nullptr, /* tp_setattro */
182  nullptr, /* tp_as_buffer */
183  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
184  ViewVertex_doc, /* tp_doc */
185  nullptr, /* tp_traverse */
186  nullptr, /* tp_clear */
187  nullptr, /* tp_richcompare */
188  0, /* tp_weaklistoffset */
189  nullptr, /* tp_iter */
190  nullptr, /* tp_iternext */
191  BPy_ViewVertex_methods, /* tp_methods */
192  nullptr, /* tp_members */
193  BPy_ViewVertex_getseters, /* tp_getset */
194  &Interface0D_Type, /* tp_base */
195  nullptr, /* tp_dict */
196  nullptr, /* tp_descr_get */
197  nullptr, /* tp_descr_set */
198  0, /* tp_dictoffset */
199  (initproc)ViewVertex_init, /* tp_init */
200  nullptr, /* tp_alloc */
201  nullptr, /* tp_new */
202 };
203 
205 
206 #ifdef __cplusplus
207 }
208 #endif
#define UNUSED(x)
PyObject * BPy_orientedViewEdgeIterator_from_orientedViewEdgeIterator(ViewVertexInternal::orientedViewEdgeIterator &ove_it, bool reversed)
PyObject * BPy_Nature_from_Nature(unsigned short n)
PyTypeObject Interface0D_Type
#define BPy_Nature_Check(v)
Definition: BPy_Nature.h:37
PyTypeObject ViewEdge_Type
static PyMethodDef BPy_ViewVertex_methods[]
PyDoc_STRVAR(ViewVertex_doc, "Class hierarchy: :class:`Interface0D` > :class:`ViewVertex`\n" "\n" "Class to define a view vertex. A view vertex is a feature vertex\n" "corresponding to a point of the image graph, where the characteristics\n" "of an edge (e.g., nature and visibility) might change. A\n" ":class:`ViewVertex` can be of two kinds: A :class:`TVertex` when it\n" "corresponds to the intersection between two ViewEdges or a\n" ":class:`NonTVertex` when it corresponds to a vertex of the initial\n" "input mesh (it is the case for vertices such as corners for example).\n" "Thus, this class can be specialized into two classes, the\n" ":class:`TVertex` class and the :class:`NonTVertex` class.")
static int ViewVertex_init(BPy_ViewVertex *, PyObject *, PyObject *)
static PyObject * ViewVertex_nature_get(BPy_ViewVertex *self, void *UNUSED(closure))
PyTypeObject ViewVertex_Type
static int ViewVertex_nature_set(BPy_ViewVertex *self, PyObject *value, void *UNUSED(closure))
static PyObject * ViewVertex_edges_begin(BPy_ViewVertex *self)
static PyGetSetDef BPy_ViewVertex_getseters[]
static PyObject * ViewVertex_edges_end(BPy_ViewVertex *)
static PyObject * ViewVertex_edges_iterator(BPy_ViewVertex *self, PyObject *args, PyObject *kwds)
PyObject * self
Definition: bpy_driver.c:185
unsigned short VertexNature
Definition: Nature.h:32
inherits from class Rep
Definition: AppCanvas.cpp:32