|
1 | 1 | """Test major functions in the EdgeMender class.""" |
2 | 2 |
|
| 3 | +import numpy as np |
3 | 4 | import pytest |
4 | 5 | import trimesh |
5 | 6 | from numpy.typing import NDArray |
|
21 | 22 | DataFactory.double_tower_ceiling(), |
22 | 23 | DataFactory.hanging_points(), |
23 | 24 | DataFactory.checkerboard(), |
| 25 | + DataFactory.hole(), |
24 | 26 | ], |
25 | 27 | ) |
26 | 28 | def test_validate(data: NDArray, spacing: tuple[float, float, float]) -> None: |
@@ -57,3 +59,121 @@ def test_validate_fail_areas() -> None: |
57 | 59 | mender = EdgeMender(mesh) |
58 | 60 | with pytest.raises(ValueError, match="non-uniform face areas"): |
59 | 61 | 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) |
0 commit comments