Skip to content

Commit e3a0a76

Browse files
committed
signed distance
1 parent 8bd1bfd commit e3a0a76

File tree

3 files changed

+92
-1
lines changed

3 files changed

+92
-1
lines changed

cmake/PyiglDownloadExternal.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ endfunction()
2727
function(pyigl_download_igl)
2828
pyigl_download_project(libigl
2929
GIT_REPOSITORY https://github.com/skoch9/libigl.git
30-
GIT_TAG 964beea9bfe373f0d398cc78ea3bd044a5c78315
30+
GIT_TAG 9b51e2225e44e3f265f4d3179370e27791392b85
3131
)
3232
endfunction()
3333

src/signed_distance.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#include <common.h>
2+
#include <npe.h>
3+
#include <typedefs.h>
4+
5+
6+
#include <igl/signed_distance.h>
7+
8+
const char *ds_signed_distance = R"igl_Qu8mg5v7(
9+
SIGNED_DISTANCE computes signed distance to a mesh
10+
11+
12+
Parameters
13+
----------
14+
P #P by 3 list of query point positions
15+
V #V by 3 list of vertex positions
16+
F #F by ss list of triangle indices, ss should be 3 unless sign_type
17+
return_normals (Optional, defaults to False) If set to True, will return pseudonormals of
18+
closest points to each query point in P
19+
Returns
20+
-------
21+
S #P list of smallest signed distances
22+
I #P list of facet indices corresponding to smallest distances
23+
C #P by 3 list of closest points
24+
25+
See also
26+
--------
27+
28+
29+
Notes
30+
-----
31+
Known issue: This only computes distances to triangles. So unreferenced
32+
vertices and degenerate triangles are ignored.
33+
34+
Examples
35+
--------
36+
>>> S, I, C = signed_distance(P, V, F, return_normals=False)
37+
38+
)igl_Qu8mg5v7";
39+
40+
npe_function(signed_distance)
41+
npe_doc(ds_signed_distance)
42+
43+
npe_arg(p, dense_float, dense_double)
44+
npe_arg(v, dense_float, dense_double)
45+
npe_arg(f, dense_int, dense_long, dense_longlong)
46+
npe_default_arg(return_normals, bool, false)
47+
48+
npe_begin_code()
49+
assert_cols_equals(p, 3, "p");
50+
assert_nonzero_rows(p, "p");
51+
assert_valid_3d_tri_mesh(v, f, "v", "f");
52+
53+
Eigen::MatrixXd V = v.template cast<double>();
54+
Eigen::MatrixXd P = p.template cast<double>();
55+
Eigen::MatrixXi F = f.template cast<int>();
56+
57+
EigenDenseLike<npe_Matrix_p> S;
58+
EigenDenseLike<npe_Matrix_f> I;
59+
EigenDenseLike<npe_Matrix_v> C;
60+
EigenDenseLike<npe_Matrix_v> N;
61+
62+
if (return_normals) {
63+
igl::signed_distance(P, V, F, igl::SIGNED_DISTANCE_TYPE_PSEUDONORMAL, S, I, C, N);
64+
return pybind11::make_tuple(npe::move(S), npe::move(I), npe::move(C), npe::move(N));
65+
} else {
66+
igl::signed_distance(P, V, F, igl::SIGNED_DISTANCE_TYPE_DEFAULT, S, I, C, N);
67+
return pybind11::make_tuple(npe::move(S), npe::move(I), npe::move(C));
68+
}
69+
70+
npe_end_code()
71+
72+
73+

tests/test_basic.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,24 @@ def test_hessian_energy(self):
946946
self.assertEqual(q.dtype, self.v1.dtype)
947947
self.assertEqual(q.shape, (self.v1.shape[0], self.v1.shape[0]))
948948

949+
def test_signed_distance(self):
950+
min_v = np.min(self.v1, axis=0)
951+
max_v = np.max(self.v1, axis=0)
952+
n = 64
953+
g = np.mgrid[min_v[0]:max_v[0]:complex(n), min_v[1]:max_v[1]:complex(n), min_v[2]:max_v[2]:complex(n)]
954+
p = np.vstack(map(np.ravel, g)).T
955+
s, i, c = igl.signed_distance(p, self.v1, self.f1)
956+
957+
self.assertEqual(s.shape[0], p.shape[0])
958+
self.assertEqual(i.shape[0], p.shape[0])
959+
self.assertEqual(c.shape, p.shape)
960+
961+
s, i, c, n = igl.signed_distance(p, self.v1, self.f1, return_normals=True)
962+
self.assertEqual(s.shape[0], p.shape[0])
963+
self.assertEqual(i.shape[0], p.shape[0])
964+
self.assertEqual(c.shape, p.shape)
965+
self.assertEqual(n.shape, p.shape)
966+
949967
# def test_offset_surface(self):
950968
# sv, sf, gv, side, so = igl.offset_surface(self.v1, self.f1, 1, 10, igl.SIGNED_DISTANCE_TYPE_DEFAULT)
951969
# self.assertEqual(sv.dtype, self.v1.type)

0 commit comments

Comments
 (0)