Skip to content

Commit

Permalink
Merge branch 'main' of github.com:libigl/libigl-python-bindings into …
Browse files Browse the repository at this point in the history
…alecjacobson/numpyeigen-fork
  • Loading branch information
alecjacobson committed Sep 4, 2023
2 parents e47ad98 + 8b7757f commit ba020a0
Showing 1 changed file with 35 additions and 21 deletions.
56 changes: 35 additions & 21 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import platform

import igl
print("Using igl found at: ",igl.__file__)
import igl.triangle
import igl.copyleft.cgal
import numpy as np
Expand Down Expand Up @@ -38,10 +39,22 @@ def setUp(self):
self.v2, self.f2 = igl.read_triangle_mesh(
os.path.join(self.test_data_path, "fertility.off"))

self.v = np.random.rand(10, 3).astype(self.v1.dtype)
self.t = np.random.rand(10, 4)
self.f = np.random.randint(0, 10, size=(20, 3), dtype=self.f1.dtype)
self.g = np.random.randint(0, 10, size=(20, 4), dtype="int32")
## Alec: I don't understand why it makes sense to use junk random data
## for the tests. Especially for f and t. These will almost never be
## non-degenerate meshes.
#self.v = np.random.rand(10, 3).astype(self.v1.dtype)
#self.t = np.random.rand(10, 4)
#self.f = np.random.randint(0, 10, size=(20, 3), dtype=self.f1.dtype)
#self.g = np.random.randint(0, 10, size=(20, 4), dtype="int32")
# This model is a quad mesh that's been trivially triangulated
self.v3, self.f3 = igl.read_triangle_mesh(os.path.join(self.test_data_path, "face.obj"))
self.v4, self.t4, self.f4 = igl.read_mesh(os.path.join(self.test_data_path, "decimated-knight.mesh"))
self.q3 = np.concatenate((self.f3[0::2,0:3], self.f3[1::2,2:3]), axis=1)
# Use the bunny rather than random junk. Ideally we'd loop over meshes
# by category like the libigl tests.
self.v = self.v1
self.f = self.f1


self.default_int = np.array(range(2)).dtype
self.default_float = np.zeros((2,2)).dtype
Expand Down Expand Up @@ -443,9 +456,9 @@ def test_circumradius(self):
self.assertTrue(r.flags.c_contiguous)

def test_quad_planarity(self):
p = igl.quad_planarity(self.v, self.g)
self.assertTrue(p.dtype == self.v.dtype)
self.assertEqual(p.shape[0], self.g.shape[0])
p = igl.quad_planarity(self.v3, self.q3)
self.assertTrue(p.dtype == self.v3.dtype)
self.assertEqual(p.shape[0], self.q3.shape[0])
self.assertTrue(p.flags.c_contiguous)

def test_collapse_small_triangles(self):
Expand Down Expand Up @@ -604,7 +617,7 @@ def test_boundary_loop(self):
self.assertTrue(l.flags.c_contiguous)

def test_all_boundary_loop(self):
l = igl.all_boundary_loop(self.f)
l = igl.all_boundary_loop(self.f3)
self.assertEqual(type(l), type([]))
self.assertTrue(len(l) > 0)

Expand Down Expand Up @@ -706,12 +719,11 @@ def test_decimate(self):
self.assertTrue(i.flags.c_contiguous)

def test_dihedral_angles(self):
t = np.random.randint(0, 10, size=(10, 4))
theta, cos_theta = igl.dihedral_angles(self.v, t)
self.assertEqual(theta.dtype, self.v.dtype)
self.assertEqual(cos_theta.dtype, self.v.dtype)
theta, cos_theta = igl.dihedral_angles(self.v4, self.t4)
self.assertEqual(theta.dtype, self.v4.dtype)
self.assertEqual(cos_theta.dtype, self.v4.dtype)
self.assertTrue(
theta.shape == cos_theta.shape and cos_theta.shape == (self.t.shape[0], 6))
theta.shape == cos_theta.shape and cos_theta.shape == (self.t4.shape[0], 6))
self.assertTrue(theta.flags.c_contiguous)
self.assertTrue(cos_theta.flags.c_contiguous)

Expand Down Expand Up @@ -1789,14 +1801,15 @@ def test_normal_derivative(self):
self.assertTrue(type(d) == csc.csc_matrix)

def test_orient_outward(self):
c, _ = igl.orientable_patches(self.f)
ff, i = igl.orient_outward(self.v, self.f, c)
v,f = igl.read_triangle_mesh(os.path.join(self.test_data_path, "truck.obj"))
c, _ = igl.orientable_patches(f)
ff, i = igl.orient_outward(v, f, c)

self.assertTrue(ff.flags.c_contiguous)
self.assertTrue(i.flags.c_contiguous)
self.assertTrue(ff.dtype == self.f.dtype)
self.assertTrue(i.dtype == self.f.dtype)
self.assertTrue(ff.shape[0] == self.f.shape[0])
self.assertTrue(ff.dtype == f.dtype)
self.assertTrue(i.dtype == f.dtype)
self.assertTrue(ff.shape[0] == f.shape[0])
self.assertTrue(ff.shape[1] == 3)
self.assertTrue(len(i.shape) == 1)
self.assertTrue(i.shape[0] == np.max(c)+1)
Expand Down Expand Up @@ -2160,7 +2173,7 @@ def test_two_axis_valuator_fixed_up(self):
def test_triangle_fan(self):
_, f = igl.read_triangle_mesh(
os.path.join(self.test_data_path, "camelhead.off"))
e = igl.exterior_edges(self.f)
e = igl.exterior_edges(f)
cap = igl.triangle_fan(e)

self.assertTrue(cap.flags.c_contiguous)
Expand Down Expand Up @@ -2293,7 +2306,8 @@ def test_intrinsic_delaunay_cotmatrix(self):
self.assertTrue(type(l) == csc.csc_matrix)

def test_cut_to_disk(self):
cuts = igl.cut_to_disk(self.f)
cuts = igl.cut_to_disk(self.f2)
# This test assumes fertility.off
self.assertTrue(len(cuts) == 9)

def test_iterative_closest_point(self):
Expand Down Expand Up @@ -2536,7 +2550,7 @@ def test__version(self):

def test_blue_noise(self):
r = igl.avg_edge_length(self.v, self.f)
b,fi,p = igl.blue_noise(self.v, self.f, r*0.1)
b,fi,p = igl.blue_noise(self.v, self.f, r)
self.assertTrue(b.shape[0] == fi.shape[0])
self.assertTrue(b.shape[0] == p.shape[0])
self.assertTrue(self.v.shape[1] == p.shape[1])
Expand Down

0 comments on commit ba020a0

Please sign in to comment.