forked from mikedh/trimesh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_voxel.py
48 lines (34 loc) · 1.54 KB
/
test_voxel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import generic as g
class VoxelTest(g.unittest.TestCase):
def test_voxel(self):
'''
Test that voxels work at all
'''
for m in [g.get_mesh('featuretype.STL'),
g.trimesh.primitives.Box(),
g.trimesh.primitives.Sphere()]:
for pitch in [.1, .1 - g.tol.merge]:
v = m.voxelized(pitch)
self.assertTrue(len(v.raw.shape) == 3)
self.assertTrue(v.shape == v.raw.shape)
self.assertTrue(v.volume > 0.0)
self.assertTrue(v.origin.shape == (3,))
self.assertTrue(isinstance(v.pitch, float))
self.assertTrue(g.np.isfinite(v.pitch))
self.assertTrue(g.np.issubdtype(v.filled_count, int))
self.assertTrue(v.filled_count > 0)
self.assertTrue(isinstance(v.mesh, g.trimesh.Trimesh))
self.assertTrue(abs(v.mesh.volume - v.volume) < g.tol.merge)
self.assertTrue(g.trimesh.util.is_shape(v.points, (-1, 3)))
for p in v.points:
self.assertTrue(v.is_filled(p))
outside = m.bounds[1] + m.scale
self.assertFalse(v.is_filled(outside))
cubes = v.marching_cubes
self.assertTrue(cubes.is_watertight)
g.log.info('Mesh volume was %f, voxelized volume was %f',
m.volume,
v.volume)
if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()