(mesh, tet_indices, n_ring)
| 48 | return out_mesh |
| 49 | |
| 50 | def extract_submesh_volume(mesh, tet_indices, n_ring): |
| 51 | vertices = mesh.vertices |
| 52 | |
| 53 | selected_voxels = np.zeros(mesh.num_voxels, dtype=bool) |
| 54 | selected_voxels[tet_indices] = True |
| 55 | ring_index = np.zeros(mesh.num_voxels, dtype=int) |
| 56 | ring_index[selected_voxels] += 1 |
| 57 | for i in range(n_ring): |
| 58 | selected_voxels = expand_by_one_ring( |
| 59 | mesh.vertices, mesh.voxels, selected_voxels) |
| 60 | ring_index[selected_voxels] += 1 |
| 61 | selected_voxel_indices = np.arange(mesh.num_voxels)[selected_voxels] |
| 62 | voxels = mesh.voxels[selected_voxels] |
| 63 | ring_index = (ring_index[selected_voxels] - n_ring - 1) * (-1) |
| 64 | |
| 65 | vertices, voxels, info = remove_isolated_vertices_raw(vertices, voxels) |
| 66 | out_mesh = form_mesh(vertices, np.array([]), voxels) |
| 67 | out_mesh.add_attribute("ori_voxel_index") |
| 68 | out_mesh.set_attribute("ori_voxel_index", selected_voxel_indices) |
| 69 | out_mesh.add_attribute("ring") |
| 70 | out_mesh.set_attribute("ring", ring_index) |
| 71 | |
| 72 | # Transport attributes to output mesh. |
| 73 | for name in mesh.attribute_names: |
| 74 | attr = mesh.get_attribute(name) |
| 75 | if len(attr) % mesh.num_vertices == 0: |
| 76 | attr = attr.reshape((mesh.num_vertices, -1), order="C") |
| 77 | attr = attr[info["ori_vertex_index"]] |
| 78 | out_mesh.add_attribute(name) |
| 79 | out_mesh.set_attribute(name, attr) |
| 80 | elif len(attr) % mesh.num_voxels == 0: |
| 81 | attr = attr.reshape((mesh.num_voxels, -1), order="C") |
| 82 | attr = attr[selected_voxels] |
| 83 | out_mesh.add_attribute(name) |
| 84 | out_mesh.set_attribute(name, attr) |
| 85 | |
| 86 | return out_mesh |
| 87 | |
| 88 | def submesh(mesh, element_indices, num_rings): |
| 89 | """ Extract a subset of the mesh elements and forming a new mesh. |
no test coverage detected