Skip to content

Commit adc84c1

Browse files
committed
expose copies of LinearAccess data vectors to python
1 parent f7e00fc commit adc84c1

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

pyapr/data_containers/src/BindAPR.hpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@ namespace py = pybind11;
1616

1717
PYBIND11_MAKE_OPAQUE(std::vector<APR*>)
1818

19+
20+
auto _get_y_vec = [](APR& apr) -> py::array {
21+
return py::array_t<uint16>(apr.linearAccess.y_vec.size(), apr.linearAccess.y_vec.begin());
22+
};
23+
24+
auto _get_xz_end_vec = [](APR& apr) -> py::array {
25+
return py::array_t<uint64>(apr.linearAccess.xz_end_vec.size(), apr.linearAccess.xz_end_vec.begin());
26+
};
27+
28+
auto _get_level_xz_vec = [](APR& apr) -> py::array {
29+
return py::array_t<uint64>(apr.linearAccess.level_xz_vec.size(), apr.linearAccess.level_xz_vec.begin());
30+
};
31+
32+
33+
1934
void AddAPR(pybind11::module &m, const std::string &modulename) {
2035

2136
using namespace py::literals;
@@ -38,7 +53,10 @@ void AddAPR(pybind11::module &m, const std::string &modulename) {
3853
.def("org_dims", &APR::org_dims, "returns the original image size in a specified dimension (y, x, z)" , "dim"_a)
3954
.def("shape", [](APR& self){return py::make_tuple(self.org_dims(2), self.org_dims(1), self.org_dims(0));}, "returns the original pixel image dimensions as a tuple (z, x, y)")
4055
.def("get_parameters", &APR::get_apr_parameters, "return the parameters used to create the APR")
41-
.def("computational_ratio", &APR::computational_ratio, "return the computational ratio (number of pixels in original image / number of particles in the APR)");
56+
.def("computational_ratio", &APR::computational_ratio, "return the computational ratio (number of pixels in original image / number of particles in the APR)")
57+
.def("get_y_vec", _get_y_vec, "return linearAccess y_vec as a numpy array")
58+
.def("get_xz_end_vec", _get_xz_end_vec, "return linearAccess xz_end_vec as a numpy array")
59+
.def("get_level_xz_vec", _get_level_xz_vec, "return linearAccess level_xz_vec as a numpy array");
4260

4361
py::bind_vector<std::vector<APR*>>(m, "APRPtrVector", py::module_local(false));
4462
}

0 commit comments

Comments
 (0)