def test_fill(self): from trimesh.voxel.morphology import fillers hollow = Sphere().voxelized(pitch=0.1).hollow() for key in fillers: filled = hollow.copy().fill(key) self.assertLess(hollow.filled_count, filled.filled_count)
def test_hollow(self): if not g.has_binvox: g.log.warning('no binvox to test!') return filled = Sphere().voxelized(pitch=0.1, method='binvox', exact=True) hollow = filled.copy().hollow() self.assertLess(hollow.filled_count, filled.filled_count) self.assertGreater(hollow.filled_count, 0)
def test_strip(self): if not g.has_binvox: g.log.warning('no binvox to test!') return octant = Sphere().voxelized(pitch=0.1, method='binvox', exact=True) dense = octant.encoding.dense.copy() nx, ny, nz = octant.shape dense[:nx // 2] = 0 dense[:, :ny // 2] = 0 dense[:, :, nz // 2:] = 0 octant.encoding = dense stripped = octant.copy().strip() self.assertEqual(octant.filled_count, stripped.filled_count) self.assertEqual(octant.volume, stripped.volume) np.testing.assert_allclose(octant.points, stripped.points) self.assertGreater(octant.encoding.size, stripped.encoding.size)
def test_binvox_with_dimension(self): if not g.has_binvox: g.log.warning('no binvox to test!') return dim = 10 octant = Sphere().voxelized(pitch=None, dimension=dim, method='binvox', exact=True) self.assertEqual(octant.shape, (dim, ) * 3)
from trimesh.scene import Scene from trimesh.primitives import Sphere from trimesh.voxel.morphology import fillers mesh = Sphere() def show(surface, filled, label): print(label) scene = Scene() scene.add_geometry(surface.as_boxes(colors=(1, 0, 0, 0.3))) scene.add_geometry(filled.as_boxes(colors=(0, 0, 1, 0.5))) scene.show() # remove_internal produced unexpected results when boundary pixels are occupied # not useful very often, but handy to demonstrate filling algorithms. surface = mesh.voxelized(pitch=0.2, method='binvox', remove_internal=True) for impl in fillers: show(surface, surface.copy().fill(method=impl), impl) filled = mesh.voxelized(pitch=0.05, method='binvox', exact=True).fill(method='holes') hollow = filled.copy().hollow() print('filled volume, hollow_volume') print(filled.volume, hollow.volume) print('hollow voxel (zoom in to see hollowness)') hollow.show()