MCPcopy Create free account
hub / github.com/PyMesh/PyMesh / map_boundary_to_sphere

Function map_boundary_to_sphere

scripts/map_to_sphere.py:35–66  ·  view source on GitHub ↗
(mesh, basename)

Source from the content-addressed store, hash-verified

33 return mesh;
34
35def map_boundary_to_sphere(mesh, basename):
36 bd_mesh = pymesh.form_mesh(mesh.vertices, mesh.faces);
37 bd_mesh, info = pymesh.remove_isolated_vertices(bd_mesh);
38 bd_vertices = np.copy(bd_mesh.vertices);
39
40 assembler = pymesh.Assembler(bd_mesh);
41 L = assembler.assemble("graph_laplacian");
42
43 # First, Laplacian smoothing to improve triangle quality.
44 for i in range(100):
45 c = np.mean(bd_vertices, axis=0);
46 bd_vertices = bd_vertices - c;
47 r = np.amax(norm(bd_vertices, axis=1));
48 bd_vertices /= r;
49
50 bd_vertices += L * bd_vertices;
51
52 if i%10 == 0:
53 sphere_mesh = pymesh.form_mesh(bd_vertices, bd_mesh.faces);
54 pymesh.save_mesh("{}_flow_{:03}.msh".format(basename, i), sphere_mesh);
55
56 # Then, run mean curvature flow.
57 sphere_mesh = pymesh.form_mesh(bd_vertices, bd_mesh.faces);
58 sphere_mesh = mean_curvature_flow(sphere_mesh, 100, use_graph_laplacian=True);
59 pymesh.save_mesh("{}_flow_final.msh".format(basename), sphere_mesh);
60 bd_vertices = sphere_mesh.vertices;
61
62 # Lastly, project vertices onto unit sphere.
63 bd_vertex_indices = info["ori_vertex_index"];
64 bd_vertex_positions = np.divide(bd_vertices, norm(bd_vertices,
65 axis=1).reshape((-1,1)));
66 return bd_vertex_indices, bd_vertex_positions;
67
68def init_harmonic_system(L, bd_indices, constraints, is_variable):
69 rhs = -L[:,bd_indices].dot(constraints);

Callers 1

mainFunction · 0.85

Calls 6

assembleMethod · 0.95
mean_curvature_flowFunction · 0.90
form_meshMethod · 0.45
copyMethod · 0.45
save_meshMethod · 0.45

Tested by

no test coverage detected