|
36 | 36 |
|
37 | 37 | // depthai/
|
38 | 38 | #include "depthai/properties/GlobalProperties.hpp"
|
| 39 | +#include <memory> |
39 | 40 |
|
40 | 41 | std::shared_ptr<dai::Node> createNode(dai::Pipeline& p, py::object class_){
|
41 | 42 | auto nodeCreateMap = NodeBindings::getNodeCreateMap();
|
@@ -87,7 +88,8 @@ void PipelineBindings::bind(pybind11::module& m, void* pCallstack){
|
87 | 88 | pipeline
|
88 | 89 | .def(py::init<>(), DOC(dai, Pipeline, Pipeline))
|
89 | 90 | //.def(py::init<const Pipeline&>())
|
90 |
| - .def("getGlobalProperties", &Pipeline::getGlobalProperties, DOC(dai, Pipeline, getGlobalProperties)) |
| 91 | + .def("getGlobalProperties", &Pipeline::getGlobalProperties, |
| 92 | + DOC(dai, Pipeline, getGlobalProperties)) |
91 | 93 | //.def("create", &Pipeline::create<node::XLinkIn>)
|
92 | 94 | .def("remove", &Pipeline::remove, py::arg("node"), DOC(dai, Pipeline, remove))
|
93 | 95 | .def("getAllNodes", static_cast<std::vector<std::shared_ptr<Node>> (Pipeline::*)() const>(&Pipeline::getAllNodes), DOC(dai, Pipeline, getAllNodes))
|
@@ -116,27 +118,47 @@ void PipelineBindings::bind(pybind11::module& m, void* pCallstack){
|
116 | 118 | .def("setBoardConfig", &Pipeline::setBoardConfig, DOC(dai, Pipeline, setBoardConfig))
|
117 | 119 | .def("getBoardConfig", &Pipeline::getBoardConfig, DOC(dai, Pipeline, getBoardConfig))
|
118 | 120 | // 'Template' create function
|
119 |
| - .def("create", [](dai::Pipeline& p, py::object class_) { |
120 |
| - if (py::cast<std::string>(class_.attr("__base__").attr("__name__")) == "HostNode") { |
121 |
| -#if 0 |
122 |
| - py::cast<std::shared_ptr<HostNode>>(class_())->run(); |
123 |
| -#else |
124 |
| - auto host_node = py::cast<std::shared_ptr<HostNode>>(class_()); |
125 |
| - //std::shared_ptr<HostNode> host_node = py::cast<std::shared_ptr<HostNode>>(class_()); |
126 |
| - //std::shared_ptr<HostNode> host_node = class_().cast<std::shared_ptr<HostNode>>(); |
127 |
| - host_node->run(); |
128 |
| -#endif |
129 |
| - |
130 |
| - //p.add(host_node); |
131 |
| - //return (std::shared_ptr<Node>) host_node; |
132 |
| - return (std::shared_ptr<Node>) nullptr; |
133 |
| - } |
134 |
| - auto node = createNode(p, class_); |
135 |
| - if(node == nullptr){ |
136 |
| - throw std::invalid_argument(std::string(py::str(class_)) + " is not a subclass of depthai.node"); |
137 |
| - } |
138 |
| - return node; |
139 |
| - }) |
| 121 | + .def("add", |
| 122 | + [](Pipeline &p, std::shared_ptr<Node> hostNode) { |
| 123 | + p.add(hostNode); |
| 124 | + // TODO(Morato) TMP TMP only a test |
| 125 | + if (std::dynamic_pointer_cast<HostNode>(hostNode) != nullptr) { |
| 126 | + std::dynamic_pointer_cast<HostNode>(hostNode)->run(); |
| 127 | + } |
| 128 | + }) |
| 129 | + // 'Template' create function |
| 130 | + .def("create", |
| 131 | + [](dai::Pipeline &p, py::object class_) { |
| 132 | + // TODO(zimen) re-introduce create function for custom host nodes |
| 133 | + // if |
| 134 | + // (py::cast<std::string>(class_.attr("__base__").attr("__name__")) |
| 135 | + // == "HostNode") { Call the constructor of the class auto |
| 136 | + // host_node = |
| 137 | + // py::cast<std::shared_ptr<Node>>(class_.attr("__new__")(class_)); |
| 138 | + // std::cout << py::str(class_.attr("a")) << std::endl; |
| 139 | + // class_().attr("run")(); |
| 140 | + // auto host_node = py::cast<std::shared_ptr<Node>>(class_()); |
| 141 | + // std::shared_ptr<HostNode> host_node = |
| 142 | + // py::cast<std::shared_ptr<HostNode>>(class_()); |
| 143 | + // std::shared_ptr<HostNode> host_node = |
| 144 | + // class_().cast<std::shared_ptr<HostNode>>(); |
| 145 | + // host_node->run(); |
| 146 | + // return class_(); |
| 147 | + |
| 148 | + // p.add(host_node); |
| 149 | + // return (std::shared_ptr<Node>) host_node; |
| 150 | + // return (std::shared_ptr<Node>) nullptr; |
| 151 | + // } |
| 152 | + auto node = createNode(p, class_); |
| 153 | + if (node == nullptr) { |
| 154 | + throw std::invalid_argument( |
| 155 | + std::string(py::str(class_)) + |
| 156 | + " is not a subclass of depthai.node"); |
| 157 | + } |
| 158 | + // Cast the node to a py::object |
| 159 | + py::object obj = py::cast(node); |
| 160 | + return obj; |
| 161 | + }) |
140 | 162 | // TODO(themarpe) DEPRECATE, use pipeline.create([class name])
|
141 | 163 | // templated create<NODE> function
|
142 | 164 | .def("createXLinkIn", &Pipeline::create<node::XLinkIn>)
|
@@ -166,8 +188,11 @@ void PipelineBindings::bind(pybind11::module& m, void* pCallstack){
|
166 | 188 | // .def("createCamera", &Pipeline::create<node::Camera>)
|
167 | 189 | // .def("createWarp", &Pipeline::create<node::Warp>)
|
168 | 190 | .def("start", &Pipeline::start)
|
169 |
| - .def("wait", &Pipeline::wait) |
170 |
| - ; |
| 191 | + .def("wait", [](Pipeline &p) { |
| 192 | + py::gil_scoped_release release; |
| 193 | + p.wait(); |
| 194 | + }); |
| 195 | + ; |
171 | 196 |
|
172 | 197 |
|
173 | 198 | }
|
0 commit comments