Skip to content

Add binding for offset_surface() #271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/offset_surface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "default_types.h"
#include <igl/offset_surface.h>
#include <nanobind/nanobind.h>
#include <nanobind/ndarray.h>
#include <nanobind/eigen/dense.h>
#include <nanobind/stl/tuple.h>
#include <nanobind/stl/vector.h>

namespace nb = nanobind;
using namespace nb::literals;

namespace pyigl {
auto offset_surface(const nb::DRef<const Eigen::MatrixXN> &V,
const nb::DRef<const Eigen::MatrixXI> &F,
const Numeric isolevel, const Integer s,
const igl::SignedDistanceType signed_distance_type) {

Eigen::MatrixXN SV;
Eigen::MatrixXI SF;
Eigen::MatrixXN GV;

Eigen::VectorXI side;
Eigen::MatrixXN so;

igl::offset_surface(V, F, isolevel, s, signed_distance_type, SV, SF, GV, side,
so);

return std::make_tuple(SV, SF, GV, side, so);
}
} // namespace pyigl

// Bind the wrapper to the Python module
void bind_offset_surface(nb::module_ &m) {
m.def(
"offset_surface", &pyigl::offset_surface, "V"_a, "F"_a, "isolevel"_a,
"s"_a, "signed_distance_type"_a,
R"(Compute a triangulated offset surface using matching cubes on a grid of signed distance values from the input triangle mesh.

@param[in] V #V by 3 list of mesh vertex positions
@param[in] F #F by 3 list of mesh triangle indices into V
@param[in] isolevel iso level to extract (signed distance: negative inside)
@param[in] s number of grid cells along longest side (controls resolution)
@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

@return Tuple containing:
- SV: #SV by 3 list of output surface mesh vertex positions
- SF: #SF by 3 list of output mesh triangle indices into SV
- GV: #GV=side(0)*side(1)*side(2) by 3 list of grid cell centers
- side: list of number of grid cells in x, y, and z directions
- so: #GV by 3 list of signed distance values _near_ `isolevel` ('far' from `isolevel` these values are incorrect))");
}
4 changes: 4 additions & 0 deletions tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ def test_volume():
F = np.array([[2,1,3]],dtype=np.int64)
NV,NF,I,J = igl.remove_unreferenced(V,F)

def test_offset_surface():
V,F = triangulated_square()
v, f, _, _, _ = igl.offset_surface(V, F, -0.1, 1, igl.SIGNED_DISTANCE_TYPE_DEFAULT)

def test_oriented_facets():
V,F,T = single_tet()
E = igl.oriented_facets(F)
Expand Down
Loading