|
10 | 10 |
|
11 | 11 | #include <pybind11/pybind11.h> |
12 | 12 | #include <pybind11/stl.h> |
| 13 | +#include <pybind11/functional.h> |
13 | 14 | #ifdef PY_OPENVDB_USE_NUMPY |
14 | 15 | #include <pybind11/numpy.h> |
15 | 16 | #include <openvdb/tools/MeshToVolume.h> |
@@ -942,30 +943,20 @@ struct TreeCombineOp |
942 | 943 | using TreeT = typename GridType::TreeType; |
943 | 944 | using ValueT = typename GridType::ValueType; |
944 | 945 |
|
945 | | - TreeCombineOp(py::function _op): op(_op) {} |
| 946 | + TreeCombineOp(const std::function<typename GridType::ValueType(typename GridType::ValueType, typename GridType::ValueType)>& _op): op(_op) {} |
946 | 947 | void operator()(const ValueT& a, const ValueT& b, ValueT& result) |
947 | 948 | { |
948 | | - py::object resultObj = op(a, b); |
949 | | - |
950 | | - if (!py::isinstance<py::float_>(resultObj)) { |
951 | | - std::ostringstream os; |
952 | | - os << "expected callable argument to " << pyutil::GridTraits<GridType>::name(); |
953 | | - os << ".combine() to return " << openvdb::typeNameAsString<ValueT>(); |
954 | | - os << ", found " << pyutil::className(resultObj); |
955 | | - throw py::type_error(os.str()); |
956 | | - } |
957 | | - |
958 | | - result = py::cast<ValueT>(resultObj); |
| 949 | + result = op(a, b); |
959 | 950 | } |
960 | | - py::function op; |
| 951 | + const std::function<typename GridType::ValueType(typename GridType::ValueType, typename GridType::ValueType)>& op; |
961 | 952 | }; |
962 | 953 |
|
963 | 954 |
|
964 | 955 | template<typename GridType> |
965 | 956 | inline void |
966 | | -combine(GridType& grid, GridType& otherGrid, py::function funcObj) |
| 957 | +combine(GridType& grid, GridType& otherGrid, const std::function<typename GridType::ValueType(typename GridType::ValueType, typename GridType::ValueType)>& func) |
967 | 958 | { |
968 | | - TreeCombineOp<GridType> op(funcObj); |
| 959 | + TreeCombineOp<GridType> op(func); |
969 | 960 | grid.tree().combine(otherGrid.tree(), op, /*prune=*/true); |
970 | 961 | } |
971 | 962 |
|
@@ -1346,7 +1337,7 @@ class IterWrap |
1346 | 1337 | .def("__getitem__", &IterValueProxyT::getItem, |
1347 | 1338 | "__getitem__(key) -> value\n\n" |
1348 | 1339 | "Return the value of the item with the given key.") |
1349 | | - .def("__setitem__", &IterValueProxyT::getItem, |
| 1340 | + .def("__setitem__", &IterValueProxyT::setItem, |
1350 | 1341 | "__setitem__(key, value)\n\n" |
1351 | 1342 | "Set the value of the item with the given key."); |
1352 | 1343 | } |
|
0 commit comments