forked from AcademySoftwareFoundation/MaterialX
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPyTraversal.cpp
More file actions
72 lines (63 loc) · 2.68 KB
/
PyTraversal.cpp
File metadata and controls
72 lines (63 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// TM & (c) 2017 Lucasfilm Entertainment Company Ltd. and Lucasfilm Ltd.
// All rights reserved. See LICENSE.txt for license.
//
#include <PyMaterialX/PyMaterialX.h>
#include <MaterialXCore/Traversal.h>
#include <MaterialXCore/Material.h>
namespace py = pybind11;
namespace mx = MaterialX;
void bindPyTraversal(py::module& mod)
{
py::class_<mx::Edge>(mod, "Edge")
.def("getDownstreamElement", &mx::Edge::getDownstreamElement)
.def("getConnectingElement", &mx::Edge::getConnectingElement)
.def("getUpstreamElement", &mx::Edge::getUpstreamElement)
.def("getName", &mx::Edge::getName);
py::class_<mx::TreeIterator>(mod, "TreeIterator")
.def("getElement", &mx::TreeIterator::getElement)
.def("getElementDepth", &mx::TreeIterator::getElementDepth)
.def("setPruneSubtree", &mx::TreeIterator::setPruneSubtree)
.def("getPruneSubtree", &mx::TreeIterator::getPruneSubtree)
.def("__iter__", [](mx::TreeIterator& it) -> mx::TreeIterator&
{
return it.begin(1);
})
.def("__next__", [](mx::TreeIterator& it)
{
if (++it == it.end())
throw py::stop_iteration();
return *it;
});
py::class_<mx::GraphIterator>(mod, "GraphIterator")
.def("getDownstreamElement", &mx::GraphIterator::getDownstreamElement)
.def("getConnectingElement", &mx::GraphIterator::getConnectingElement)
.def("getUpstreamElement", &mx::GraphIterator::getUpstreamElement)
.def("getUpstreamIndex", &mx::GraphIterator::getUpstreamIndex)
.def("getElementDepth", &mx::GraphIterator::getElementDepth)
.def("getNodeDepth", &mx::GraphIterator::getNodeDepth)
.def("setPruneSubgraph", &mx::GraphIterator::setPruneSubgraph)
.def("getPruneSubgraph", &mx::GraphIterator::getPruneSubgraph)
.def("__iter__", [](mx::GraphIterator& it) -> mx::GraphIterator&
{
return it.begin(1);
})
.def("__next__", [](mx::GraphIterator& it)
{
if (++it == it.end())
throw py::stop_iteration();
return *it;
});
py::class_<mx::InheritanceIterator>(mod, "InheritanceIterator")
.def("__iter__", [](mx::InheritanceIterator& it) -> mx::InheritanceIterator&
{
return it.begin(1);
})
.def("__next__", [](mx::InheritanceIterator& it)
{
if (++it == it.end())
throw py::stop_iteration();
return *it;
});
py::register_exception<mx::ExceptionFoundCycle>(mod, "ExceptionFoundCycle");
}