Repository navigation
Expand file tree
/
Copy pathselfintersection.py
More file actions
68 lines (54 loc) · 2.27 KB
/
Copy pathselfintersection.py
File metadata and controls
68 lines (54 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import PySelfIntersection
from .meshio import form_mesh
def resolve_self_intersection(mesh, engine="auto"):
""" Resolve all self-intersections.
Args:
mesh (:py:class:`Mesh`): The input mesh. Only triangular mesh is
supported.
engine (``string``): (optional) Self-intersection engine. Valid engines
include:
* ``auto``: the default engine (default is ``igl``).
* ``igl``: `libigl's self-intersection engine
<https://github.com/libigl/libigl>`_
Returns:
``Mesh``: A triangular mesh with all self-intersection meshed. The
following per-face scalar field is defined:
* ``face_sources``: For each output face, this field specifies the index
of the corresponding "source face" in the input mesh.
"""
if engine == "auto":
engine = "igl";
if mesh.dim != 3:
raise NotImplementedError(
"Resolving self-intersection only support 3D meshes");
if mesh.vertex_per_face != 3:
raise NotImplementedError(
"Resolving self-intersection only support triangle meshes");
resolver = PySelfIntersection.SelfIntersectionResolver.create(engine);
resolver.set_mesh(mesh.vertices, mesh.faces);
resolver.run();
vertices = resolver.get_vertices();
faces = resolver.get_faces();
output_mesh = form_mesh(vertices, faces);
face_sources = resolver.get_face_sources();
output_mesh.add_attribute("face_sources");
output_mesh.set_attribute("face_sources", face_sources);
return output_mesh;
def detect_self_intersection(mesh):
""" Detect all self-intersections.
Args:
mesh (:class:`Mesh`): The input mesh.
Returns:
:py:class:`numpy.ndarray`: A n by 2 array of face indices. Each
row contains the indices of two intersecting faces. :math:`n` is
the number of intersecting face pairs.
"""
try:
import PyCGAL
except ImportError:
raise NotImplementedError(
"Self intersection detection is not supported");
detector = PyCGAL.SelfIntersection(mesh.vertices, mesh.faces);
detector.detect_self_intersection();
intersecting_faces = detector.get_self_intersecting_pairs();
return intersecting_faces;