|
| 1 | +#include "default_types.h" |
| 2 | +#include <igl/offset_surface.h> |
| 3 | +#include <nanobind/nanobind.h> |
| 4 | +#include <nanobind/ndarray.h> |
| 5 | +#include <nanobind/eigen/dense.h> |
| 6 | +#include <nanobind/stl/tuple.h> |
| 7 | +#include <nanobind/stl/vector.h> |
| 8 | + |
| 9 | +namespace nb = nanobind; |
| 10 | +using namespace nb::literals; |
| 11 | + |
| 12 | +namespace pyigl { |
| 13 | +auto offset_surface(const nb::DRef<const Eigen::MatrixXN> &V, |
| 14 | + const nb::DRef<const Eigen::MatrixXI> &F, |
| 15 | + const Numeric isolevel, const Integer s, |
| 16 | + const igl::SignedDistanceType signed_distance_type) { |
| 17 | + |
| 18 | + Eigen::MatrixXN SV; |
| 19 | + Eigen::MatrixXI SF; |
| 20 | + Eigen::MatrixXN GV; |
| 21 | + |
| 22 | + Eigen::VectorXI side; |
| 23 | + Eigen::MatrixXN so; |
| 24 | + |
| 25 | + igl::offset_surface(V, F, isolevel, s, signed_distance_type, SV, SF, GV, side, |
| 26 | + so); |
| 27 | + |
| 28 | + return std::make_tuple(SV, SF, GV, side, so); |
| 29 | +} |
| 30 | +} // namespace pyigl |
| 31 | + |
| 32 | +// Bind the wrapper to the Python module |
| 33 | +void bind_offset_surface(nb::module_ &m) { |
| 34 | + m.def( |
| 35 | + "offset_surface", &pyigl::offset_surface, "V"_a, "F"_a, "isolevel"_a, |
| 36 | + "s"_a, "signed_distance_type"_a, |
| 37 | + R"(Compute a triangulated offset surface using matching cubes on a grid of signed distance values from the input triangle mesh. |
| 38 | +
|
| 39 | +@param[in] V #V by 3 list of mesh vertex positions |
| 40 | +@param[in] F #F by 3 list of mesh triangle indices into V |
| 41 | +@param[in] isolevel iso level to extract (signed distance: negative inside) |
| 42 | +@param[in] s number of grid cells along longest side (controls resolution) |
| 43 | +@param[in] signed_distance_type type of signing to use one of SIGNED_DISTANCE_TYPE_PSEUDONORMAL, SIGNED_DISTANCE_TYPE_WINDING_NUMBER, SIGNED_DISTANCE_TYPE_DEFAULT, SIGNED_DISTANCE_TYPE_UNSIGNED, SIGNED_DISTANCE_TYPE_FAST_WINDING_NUMBER |
| 44 | +
|
| 45 | +@return Tuple containing: |
| 46 | + - SV: #SV by 3 list of output surface mesh vertex positions |
| 47 | + - SF: #SF by 3 list of output mesh triangle indices into SV |
| 48 | + - GV: #GV=side(0)*side(1)*side(2) by 3 list of grid cell centers |
| 49 | + - side: list of number of grid cells in x, y, and z directions |
| 50 | + - so: #GV by 3 list of signed distance values _near_ `isolevel` ('far' from `isolevel` these values are incorrect))"); |
| 51 | +} |
0 commit comments