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

Function extract_submesh_surface

python/pymesh/submesh.py:12–48  ·  view source on GitHub ↗
(mesh, face_indices, n_ring)

Source from the content-addressed store, hash-verified

10 return selected_elements
11
12def extract_submesh_surface(mesh, face_indices, n_ring):
13 vertices = mesh.vertices
14
15 selected_faces = np.zeros(mesh.num_faces, dtype=bool)
16 selected_faces[face_indices] = True
17 ring_index = np.zeros(mesh.num_faces, dtype=int)
18 ring_index[selected_faces] += 1
19 for i in range(n_ring):
20 selected_faces = expand_by_one_ring(
21 mesh.vertices, mesh.faces, selected_faces)
22 ring_index[selected_faces] += 1
23 selected_face_indices = np.arange(mesh.num_faces)[selected_faces]
24 faces = mesh.faces[selected_faces]
25 ring_index = (ring_index[selected_faces] - n_ring - 1) * (-1)
26
27 vertices, faces, info = remove_isolated_vertices_raw(vertices, faces)
28 out_mesh = form_mesh(vertices, faces)
29 out_mesh.add_attribute("ori_face_index")
30 out_mesh.set_attribute("ori_face_index", selected_face_indices)
31 out_mesh.add_attribute("ring")
32 out_mesh.set_attribute("ring", ring_index)
33
34 # Transport attributes to output mesh.
35 for name in mesh.attribute_names:
36 attr = mesh.get_attribute(name)
37 if len(attr) % mesh.num_vertices == 0:
38 attr = attr.reshape((mesh.num_vertices, -1), order="C")
39 attr = attr[info["ori_vertex_index"]]
40 out_mesh.add_attribute(name)
41 out_mesh.set_attribute(name, attr)
42 elif len(attr) % mesh.num_faces == 0:
43 attr = attr.reshape((mesh.num_faces, -1), order="C")
44 attr = attr[selected_faces]
45 out_mesh.add_attribute(name)
46 out_mesh.set_attribute(name, attr)
47
48 return out_mesh
49
50def extract_submesh_volume(mesh, tet_indices, n_ring):
51 vertices = mesh.vertices

Callers 1

submeshFunction · 0.85

Calls 6

expand_by_one_ringFunction · 0.85
form_meshFunction · 0.85
add_attributeMethod · 0.45
set_attributeMethod · 0.45
get_attributeMethod · 0.45

Tested by

no test coverage detected