def test_smoothing_hexagon(self): """ Try 'smoothing' a simple 2D hexagon, which is an easy case to understand. """ # This map is correctly labeled with the vertex indices _ = -1 hexagon = [[[_, _, _, _, _, _, _], [_, _, 0, _, 1, _, _], [_, _, _, _, _, _, _], [_, 2, _, 3, _, 4, _], [_, _, _, _, _, _, _], [_, _, 5, _, 6, _, _], [_, _, _, _, _, _, _]]] hexagon = 1 + np.array(hexagon) original_vertices_zyx = np.transpose(hexagon.nonzero()) faces = [[3, 1, 4], [3, 4, 6], [3, 6, 5], [3, 5, 2], [3, 2, 0], [3, 0, 1]] mesh = Mesh(original_vertices_zyx, faces) #mesh.serialize('/tmp/hexagon.obj') mesh.laplacian_smooth(1) #mesh.serialize('/tmp/hexagon-smoothed.obj') # Since vertex 3 is exactly centered between the rest, # it's location never changes. assert (mesh.vertices_zyx[3] == original_vertices_zyx[3]).all()
def test_empty_mesh(self): """ What happens when we call functions on an empty mesh? """ mesh = Mesh(np.zeros((0, 3), np.float32), np.zeros((0, 3), int)) mesh.simplify(1.0) assert len(mesh.vertices_zyx) == len(mesh.normals_zyx) == len( mesh.faces) == 0 mesh.simplify(0.1) assert len(mesh.vertices_zyx) == len(mesh.normals_zyx) == len( mesh.faces) == 0 mesh.laplacian_smooth(0) assert len(mesh.vertices_zyx) == len(mesh.normals_zyx) == len( mesh.faces) == 0 mesh.laplacian_smooth(2) assert len(mesh.vertices_zyx) == len(mesh.normals_zyx) == len( mesh.faces) == 0 mesh.stitch_adjacent_faces() assert len(mesh.vertices_zyx) == len(mesh.normals_zyx) == len( mesh.faces) == 0 mesh.serialize(fmt='obj') assert len(mesh.vertices_zyx) == len(mesh.normals_zyx) == len( mesh.faces) == 0 mesh.serialize(fmt='drc') assert len(mesh.vertices_zyx) == len(mesh.normals_zyx) == len( mesh.faces) == 0 mesh.compress() concatenate_meshes((mesh, mesh)) assert len(mesh.vertices_zyx) == len(mesh.normals_zyx) == len( mesh.faces) == 0
def test_smoothing_trivial(self): vertices_zyx = np.array([[0.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0, 0.0, 2.0]]) # This "face" is actually straight line, # which makes it easy to see what's going on faces = np.array([[0, 1, 2]]) mesh = Mesh(vertices_zyx, faces) average_vertex = vertices_zyx.sum(axis=0) / 3 mesh.laplacian_smooth(1) assert (mesh.vertices_zyx == average_vertex).all()