Skip to content

Commit ebf40a9

Browse files
authored
Merge pull request #271 from ybhvf/offset-surface-bindings
Add binding for offset_surface()
2 parents 1119fd4 + a318659 commit ebf40a9

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

src/offset_surface.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
}

tests/test_all.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ def test_volume():
261261
F = np.array([[2,1,3]],dtype=np.int64)
262262
NV,NF,I,J = igl.remove_unreferenced(V,F)
263263

264+
def test_offset_surface():
265+
V,F = triangulated_square()
266+
v, f, _, _, _ = igl.offset_surface(V, F, -0.1, 1, igl.SIGNED_DISTANCE_TYPE_DEFAULT)
267+
264268
def test_oriented_facets():
265269
V,F,T = single_tet()
266270
E = igl.oriented_facets(F)

0 commit comments

Comments
 (0)