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

Function mesh_to_graph

python/pymesh/meshutils/mesh_to_graph.py:4–30  ·  view source on GitHub ↗

Convert a mesh into a graph :math:`(V, E)`, where :math:`V` represents the mesh vertices, and :math:`E` represent the edges. Args: mesh (:class:`Mesh`): Input mesh. Returns: The graph :math:`(V, E)`.

(mesh)

Source from the content-addressed store, hash-verified

2from ..meshio import form_mesh
3
4def mesh_to_graph(mesh):
5 """
6 Convert a mesh into a graph :math:`(V, E)`, where :math:`V` represents the
7 mesh vertices, and :math:`E` represent the edges.
8
9 Args:
10 mesh (:class:`Mesh`): Input mesh.
11
12 Returns:
13 The graph :math:`(V, E)`.
14 """
15
16 if mesh.num_voxels > 0:
17 # Avoid extracting voxel edges.
18 vertices = mesh.vertices
19 faces = mesh.faces
20 mesh = form_mesh(vertices, faces)
21
22 mesh.enable_connectivity()
23 vertices = mesh.vertices
24 edges = []
25 for vi in range(mesh.num_vertices):
26 adj_vertices = mesh.get_vertex_adjacent_vertices(vi)
27 for vj in adj_vertices:
28 if vj > vi:
29 edges.append((vi, vj))
30 return vertices, np.array(edges, dtype=int)
31
32def mesh_to_dual_graph(mesh):
33 """

Callers

nothing calls this directly

Calls 3

form_meshFunction · 0.85
enable_connectivityMethod · 0.45

Tested by

no test coverage detected