MCPcopy Create free account
hub / github.com/InternRobotics/G2VLM / triangulate

Function triangulate

eval_code/recons/models/moge/utils3d/numpy/mesh.py:21–62  ·  view source on GitHub ↗

Triangulate a polygonal mesh. Args: faces (np.ndarray): [L, P] polygonal faces vertices (np.ndarray, optional): [N, 3] 3-dimensional vertices. If given, the triangulation is performed according to the distance between vertices. Defaults to None.

(
    faces: np.ndarray,
    vertices: np.ndarray = None,
    backslash: np.ndarray = None
)

Source from the content-addressed store, hash-verified

19
20
21def triangulate(
22 faces: np.ndarray,
23 vertices: np.ndarray = None,
24 backslash: np.ndarray = None
25) -> np.ndarray:
26 """
27 Triangulate a polygonal mesh.
28
29 Args:
30 faces (np.ndarray): [L, P] polygonal faces
31 vertices (np.ndarray, optional): [N, 3] 3-dimensional vertices.
32 If given, the triangulation is performed according to the distance
33 between vertices. Defaults to None.
34 backslash (np.ndarray, optional): [L] boolean array indicating
35 how to triangulate the quad faces. Defaults to None.
36
37 Returns:
38 (np.ndarray): [L * (P - 2), 3] triangular faces
39 """
40 if faces.shape[-1] == 3:
41 return faces
42 P = faces.shape[-1]
43 if vertices is not None:
44 assert faces.shape[-1] == 4, "now only support quad mesh"
45 if backslash is None:
46 backslash = np.linalg.norm(vertices[faces[:, 0]] - vertices[faces[:, 2]], axis=-1) < \
47 np.linalg.norm(vertices[faces[:, 1]] - vertices[faces[:, 3]], axis=-1)
48 if backslash is None:
49 loop_indice = np.stack([
50 np.zeros(P - 2, dtype=int),
51 np.arange(1, P - 1, 1, dtype=int),
52 np.arange(2, P, 1, dtype=int)
53 ], axis=1)
54 return faces[:, loop_indice].reshape((-1, 3))
55 else:
56 assert faces.shape[-1] == 4, "now only support quad mesh"
57 faces = np.where(
58 backslash[:, None],
59 faces[:, [0, 1, 2, 0, 2, 3]],
60 faces[:, [0, 1, 3, 3, 1, 2]]
61 ).reshape((-1, 3))
62 return faces
63
64
65@batched(2, None)

Callers

nothing calls this directly

Calls 1

normMethod · 0.80

Tested by

no test coverage detected