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

Function separate_mesh

python/pymesh/meshutils/separate_mesh.py:11–91  ·  view source on GitHub ↗

Split mesh into connected components. Args: mesh (:class:`Mesh`): Input mesh. connectivity_type (:py:class:`str`): possible types are * ``auto``: Same as ``face`` for surface mesh, ``voxel`` for voxel mesh. * ``vertex``: Group component based on vertex

(mesh, connectivity_type="auto")

Source from the content-addressed store, hash-verified

9from .remove_isolated_vertices import remove_isolated_vertices_raw
10
11def separate_mesh(mesh, connectivity_type="auto"):
12 """ Split mesh into connected components.
13
14 Args:
15 mesh (:class:`Mesh`): Input mesh.
16 connectivity_type (:py:class:`str`): possible types are
17
18 * ``auto``: Same as ``face`` for surface mesh, ``voxel`` for voxel mesh.
19 * ``vertex``: Group component based on vertex connectivity.
20 * ``face``: Group component based on face connectivity.
21 * ``voxel``: Group component based on voxel connectivity.
22
23 Returns:
24 A list of meshes, each represent a single connected component. Each
25 output component have the following attributes defined:
26
27 * ``ori_vertex_index``: The input vertex index of each output vertex.
28 * ``ori_elem_index``: The input element index of each output element.
29 """
30 is_voxel_mesh = mesh.num_voxels > 0
31 if connectivity_type == "auto":
32 if is_voxel_mesh:
33 connectivity_type = "voxel"
34 else:
35 connectivity_type = "face"
36
37 if connectivity_type == "vertex":
38 if is_voxel_mesh > 0:
39 separator = MeshSeparator(mesh.voxels)
40 else:
41 separator = MeshSeparator(mesh.faces)
42 separator.set_connectivity_type(MeshSeparator.ConnectivityType.VERTEX)
43 elif connectivity_type == "face":
44 separator = MeshSeparator(mesh.faces)
45 separator.set_connectivity_type(MeshSeparator.ConnectivityType.FACE)
46 elif connectivity_type == "voxel":
47 separator = MeshSeparator(mesh.voxels)
48 separator.set_connectivity_type(MeshSeparator.ConnectivityType.VOXEL)
49 else:
50 raise RuntimeError("Unsupported connectivity type: {}".format(
51 connectivity_type))
52
53 num_comps = separator.separate()
54
55 comp_meshes = []
56 for i in range(num_comps):
57 comp = separator.get_component(i)
58 elem_sources = separator.get_sources(i).ravel()
59 vertices, comp, info = remove_isolated_vertices_raw(
60 mesh.vertices, comp)
61 if is_voxel_mesh:
62 comp_mesh = form_mesh(vertices, np.zeros((0, 3)), comp)
63 else:
64 comp_mesh = form_mesh(vertices, comp)
65 comp_mesh.add_attribute("ori_vertex_index")
66 comp_mesh.set_attribute("ori_vertex_index", info["ori_vertex_index"])
67 comp_mesh.add_attribute("ori_elem_index")
68 comp_mesh.set_attribute("ori_elem_index", elem_sources)

Callers 3

test_simpleMethod · 0.90
mainFunction · 0.90

Calls 11

set_connectivity_typeMethod · 0.95
separateMethod · 0.95
get_componentMethod · 0.95
get_sourcesMethod · 0.95
MeshSeparatorClass · 0.85
RuntimeErrorClass · 0.85
form_meshFunction · 0.85
add_attributeMethod · 0.45
set_attributeMethod · 0.45
get_attributeMethod · 0.45

Tested by 2

test_simpleMethod · 0.72