Skip to content

Commit 71310c0

Browse files
committed
More Python binding cleanup
Signed-off-by: Matthew Cong <mcong@nvidia.com>
1 parent 28453c1 commit 71310c0

File tree

2 files changed

+7
-20
lines changed

2 files changed

+7
-20
lines changed

openvdb/openvdb/python/pyGrid.h

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <pybind11/pybind11.h>
1212
#include <pybind11/stl.h>
13+
#include <pybind11/functional.h>
1314
#ifdef PY_OPENVDB_USE_NUMPY
1415
#include <pybind11/numpy.h>
1516
#include <openvdb/tools/MeshToVolume.h>
@@ -942,30 +943,20 @@ struct TreeCombineOp
942943
using TreeT = typename GridType::TreeType;
943944
using ValueT = typename GridType::ValueType;
944945

945-
TreeCombineOp(py::function _op): op(_op) {}
946+
TreeCombineOp(const std::function<typename GridType::ValueType(typename GridType::ValueType, typename GridType::ValueType)>& _op): op(_op) {}
946947
void operator()(const ValueT& a, const ValueT& b, ValueT& result)
947948
{
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);
959950
}
960-
py::function op;
951+
const std::function<typename GridType::ValueType(typename GridType::ValueType, typename GridType::ValueType)>& op;
961952
};
962953

963954

964955
template<typename GridType>
965956
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)
967958
{
968-
TreeCombineOp<GridType> op(funcObj);
959+
TreeCombineOp<GridType> op(func);
969960
grid.tree().combine(otherGrid.tree(), op, /*prune=*/true);
970961
}
971962

@@ -1346,7 +1337,7 @@ class IterWrap
13461337
.def("__getitem__", &IterValueProxyT::getItem,
13471338
"__getitem__(key) -> value\n\n"
13481339
"Return the value of the item with the given key.")
1349-
.def("__setitem__", &IterValueProxyT::getItem,
1340+
.def("__setitem__", &IterValueProxyT::setItem,
13501341
"__setitem__(key, value)\n\n"
13511342
"Set the value of the item with the given key.");
13521343
}

openvdb/openvdb/python/pyOpenVDBModule.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,6 @@ PYBIND11_MODULE(PY_OPENVDB_MODULE_NAME, m)
371371

372372
#undef PYOPENVDB_TRANSLATE_EXCEPTION
373373

374-
py::class_<openvdb::PointDataIndex32>(m, "PointDataIndex32")
375-
.def(py::init<openvdb::Index32>(), py::arg("i") = openvdb::Index32(0));
376-
377-
378374
// Export the python bindings.
379375
exportTransform(m);
380376
exportMetadata(m);

0 commit comments

Comments
 (0)