Datasets:
Download code/robohome/src/engine/tests/test_open_mesh_proxies.py from RoboParty/RoboHome: direct link, hf CLI and curl.
- Browser
- Download file 2.71 kB
-
https://huggingface.co/datasets/RoboParty/RoboHome/resolve/main/code/robohome/src/engine/tests/test_open_mesh_proxies.py
- Command line
-
hf download hf://datasets/RoboParty/RoboHome/code/robohome/src/engine/tests/test_open_mesh_proxies.py
-
curl -L -o test_open_mesh_proxies.py https://huggingface.co/datasets/RoboParty/RoboHome/resolve/main/code/robohome/src/engine/tests/test_open_mesh_proxies.py
2.71 kB
| """Open saved parts get a recorded closed collision proxy instead of staying pending.""" | |
| from pathlib import Path | |
| import sys | |
| import unittest | |
| sys.path.insert(0, str(Path(__file__).resolve().parents[1])) | |
| import numpy as np | |
| import geometry_validation as gv | |
| def box(lo, hi, drop_faces=0): | |
| x0, y0, z0 = lo | |
| x1, y1, z1 = hi | |
| v = [[x0, y0, z0], [x1, y0, z0], [x1, y1, z0], [x0, y1, z0], | |
| [x0, y0, z1], [x1, y0, z1], [x1, y1, z1], [x0, y1, z1]] | |
| t = [[0, 2, 1], [0, 3, 2], [4, 5, 6], [4, 6, 7], [0, 1, 5], [0, 5, 4], | |
| [1, 2, 6], [1, 6, 5], [2, 3, 7], [2, 7, 6], [3, 0, 4], [3, 4, 7]] | |
| return np.asarray(v, dtype=float), np.asarray(t[:len(t) - drop_faces], dtype=np.int64) | |
| def quad(x0, x1): | |
| v = [[x0, 0, 0], [x1, 0, 0], [x1, 1, 0], [x0, 1, 0]] | |
| return np.asarray(v, dtype=float), np.asarray([[0, 1, 2], [0, 2, 3]], dtype=np.int64) | |
| def item(parts): | |
| vertices, triangles, offset = [], [], 0 | |
| for v, t in parts: | |
| vertices.append(v) | |
| triangles.append(t + offset) | |
| offset += len(v) | |
| return dict(name='part', vertices=np.concatenate(vertices), triangles=np.concatenate(triangles)) | |
| class OpenMeshProxyTests(unittest.TestCase): | |
| def setUp(self): | |
| self.backend = gv.solid_backend() | |
| def proxy(self, parts): | |
| return gv._proxy_solid(item(parts), self.backend, np) | |
| def test_open_box_is_capped_to_its_own_volume(self): | |
| solid, kind = self.proxy([box([0, 0, 0], [1, 1, 1], drop_faces=2)]) | |
| self.assertEqual(kind, 'repaired_boundary_caps') | |
| self.assertAlmostEqual(solid.volume(), 1.0, places=6) | |
| def test_separate_flat_pieces_keep_the_gap_free(self): | |
| solid, kind = self.proxy([quad(0, 1), quad(3, 4)]) | |
| self.assertEqual(kind, 'component_convex_hulls') | |
| # Two 1 m2 slabs of 1 mm, not one hull spanning the 2 m gap. | |
| self.assertAlmostEqual(solid.volume(), 2e-3, places=6) | |
| gap = self.backend.Manifold.cube([0.5, 0.5, 0.5]).translate([1.75, 0.25, -0.25]) | |
| self.assertLessEqual((solid ^ gap).volume(), 1e-15) | |
| def test_single_planar_piece_becomes_a_thin_slab(self): | |
| solid, kind = self.proxy([quad(0, 1)]) | |
| self.assertEqual(kind, 'planar_part_convex_hull_1mm') | |
| self.assertAlmostEqual(solid.volume(), 1e-3, places=6) | |
| def test_degenerate_part_has_no_proxy(self): | |
| v = np.asarray([[0, 0, 0], [1, 0, 0], [2, 0, 0]], dtype=float) | |
| solid, kind = gv._proxy_solid(dict(name='line', vertices=v, | |
| triangles=np.asarray([[0, 1, 2]], dtype=np.int64)), self.backend, np) | |
| self.assertIsNone(solid) | |
| self.assertIsNone(kind) | |
| if __name__ == '__main__': | |
| unittest.main(verbosity=2) | |