Skip to content

Commit dd1bb7e

Browse files
committed
test(repair): add unit tests for find non-manifold edges
1 parent d9d9d6d commit dd1bb7e

4 files changed

Lines changed: 161 additions & 18 deletions

File tree

edge_mender/data_factory.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -228,19 +228,6 @@ def hole() -> NDArray:
228228

229229
return data
230230

231-
@staticmethod
232-
def test_case_1() -> NDArray:
233-
"""`faces_to_flip=[16, 17, 44, 45, 54, 55, 58, 59]`"""
234-
data = np.array(
235-
[
236-
[[0, 0, 1], [0, 1, 1], [0, 1, 1]],
237-
[[0, 1, 1], [1, 0, 1], [1, 1, 1]],
238-
[[0, 1, 0], [0, 1, 0], [1, 1, 1]],
239-
],
240-
dtype=np.uint8,
241-
)
242-
return np.pad(data, pad_width=1, mode="constant", constant_values=0)
243-
244231
@staticmethod
245232
def random(*, size: int = 16, seed: int | None = None) -> NDArray:
246233
rng = np.random.default_rng(seed)

edge_mender/tests/test_edge_mender.py

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Test major functions in the EdgeMender class."""
22

3+
import numpy as np
34
import pytest
45
import trimesh
56
from numpy.typing import NDArray
@@ -21,6 +22,7 @@
2122
DataFactory.double_tower_ceiling(),
2223
DataFactory.hanging_points(),
2324
DataFactory.checkerboard(),
25+
DataFactory.hole(),
2426
],
2527
)
2628
def test_validate(data: NDArray, spacing: tuple[float, float, float]) -> None:
@@ -57,3 +59,121 @@ def test_validate_fail_areas() -> None:
5759
mender = EdgeMender(mesh)
5860
with pytest.raises(ValueError, match="non-uniform face areas"):
5961
mender.validate(spacing=(1, 1, 1))
62+
63+
64+
@pytest.mark.parametrize(
65+
("data", "expected_faces", "expected_vertices", "expected_edges"),
66+
[
67+
(
68+
np.array(
69+
[
70+
[[0, 0, 0], [0, 0, 0], [0, 0, 0]],
71+
[[0, 0, 0], [0, 1, 0], [0, 0, 0]],
72+
[[0, 0, 0], [0, 0, 0], [0, 0, 0]],
73+
],
74+
),
75+
np.empty((0, 4)),
76+
np.empty((0, 2)),
77+
[],
78+
),
79+
(
80+
DataFactory.simple_extrusion(),
81+
[[25, 41, 18, 22]],
82+
[[12, 15]],
83+
[37],
84+
),
85+
(
86+
DataFactory.double_extrusion(),
87+
[[51, 20, 22, 25], [35, 32, 57, 28]],
88+
[[14, 17], [17, 20]],
89+
[42, 52],
90+
),
91+
(
92+
DataFactory.triple_extrusion(),
93+
[[27, 61, 24, 22], [35, 67, 32, 30], [73, 38, 45, 42]],
94+
[[16, 19], [19, 22], [22, 25]],
95+
[46, 57, 67],
96+
),
97+
(
98+
DataFactory.stairs(),
99+
[[28, 30, 65, 33]],
100+
[[19, 22]],
101+
[55],
102+
),
103+
(
104+
DataFactory.ceiling(),
105+
[[24, 27, 55, 22]],
106+
[[16, 19]],
107+
[46],
108+
),
109+
(
110+
DataFactory.double_tower_ceiling(),
111+
[[26, 61, 29, 24], [37, 32, 34, 69]],
112+
[[18, 21], [21, 24]],
113+
[50, 61],
114+
),
115+
(
116+
DataFactory.hanging_points(),
117+
[[38, 45, 40, 59]],
118+
[[10, 25]],
119+
[68],
120+
),
121+
(
122+
DataFactory.checkerboard(),
123+
[
124+
[26, 28, 33, 39],
125+
[24, 67, 31, 28],
126+
[65, 35, 24, 26],
127+
[41, 32, 30, 71],
128+
[79, 38, 41, 34],
129+
[66, 71, 64, 79],
130+
],
131+
[[7, 22], [19, 22], [21, 22], [22, 23], [22, 25], [22, 37]],
132+
[49, 52, 54, 58, 65, 105],
133+
),
134+
(
135+
DataFactory.hole(),
136+
[
137+
[18, 51, 21, 16],
138+
[20, 57, 27, 24],
139+
[20, 22, 35, 55],
140+
[36, 34, 71, 43],
141+
[55, 67, 50, 48],
142+
[50, 46, 53, 95],
143+
[54, 56, 61, 73],
144+
[99, 52, 59, 56],
145+
[52, 69, 97, 54],
146+
[64, 79, 66, 71],
147+
[85, 70, 75, 72],
148+
[70, 113, 81, 68],
149+
],
150+
[
151+
[13, 17],
152+
[14, 18],
153+
[17, 18],
154+
[21, 22],
155+
[17, 31],
156+
[27, 31],
157+
[18, 32],
158+
[28, 32],
159+
[31, 32],
160+
[21, 35],
161+
[22, 36],
162+
[35, 36],
163+
],
164+
[40, 44, 46, 62, 83, 86, 89, 92, 94, 102, 108, 112],
165+
),
166+
],
167+
)
168+
def test_find_non_manifold_edges(
169+
data: NDArray,
170+
expected_faces: NDArray | list[list[int]],
171+
expected_vertices: NDArray | list[list[int]],
172+
expected_edges: NDArray | list[int],
173+
) -> None:
174+
"""Test that the validate function works for valid meshes."""
175+
mesh = MeshGenerator.to_mesh_surface_nets(data)
176+
faces, vertices, edges = EdgeMender(mesh).find_non_manifold_edges()
177+
np.testing.assert_array_equal(faces, expected_faces)
178+
np.testing.assert_array_equal(vertices, expected_vertices)
179+
np.testing.assert_array_equal(edges, expected_edges)

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ dependencies = ["numpy>=2.3.4", "trimesh>=4.9.0"]
1818
test = [
1919
"connected-components-3d>=3.26.0",
2020
"fill-voids>=2.1.1",
21-
"pyvista>=0.46.3",
21+
"pyvista>=0.46.4",
2222
"nibabel>=5.3.2",
2323
"scipy>=1.16.3",
2424
"panda3d>=1.10.15",
25+
"manifold3d>=3.3.2",
2526
]
2627
dev = [
2728
"pytest>=8.4.2",

uv.lock

Lines changed: 39 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)