forked from PyMesh/PyMesh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhighlight_non_oriented_edges.py
More file actions
executable file
·65 lines (56 loc) · 1.81 KB
/
Copy pathhighlight_non_oriented_edges.py
File metadata and controls
executable file
·65 lines (56 loc) · 1.81 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
#!/usr/bin/env python
"""
Highlight non-oriented edges. A non-oriented edge has inconsistent normals in
its adjacent faces.
"""
import argparse
import numpy as np
import pymesh
def parse_args():
parser = argparse.ArgumentParser(description=__doc__);
parser.add_argument("input_mesh");
parser.add_argument("output_mesh");
return parser.parse_args();
def main():
args = parse_args();
mesh = pymesh.load_mesh(args.input_mesh);
edge_faces = {};
for f in mesh.faces:
edges = [
sorted([f[0], f[1]]),
sorted([f[1], f[2]]),
sorted([f[2], f[0]]),
];
for e in edges:
if tuple(e) in edge_faces:
edge_faces[tuple(e)].append(f);
else:
edge_faces[tuple(e)] = [f];
non_oriented_vertices = np.zeros(mesh.num_vertices);
for e,faces in edge_faces.items():
if e[0] == e[1]:
non_oriented_vertices[e[0]] = 1;
non_oriented_vertices[e[1]] = 1;
continue;
count = 0;
for f in faces:
if e[0] == f[0] and e[1] == f[1]:
count+=1;
if e[0] == f[1] and e[1] == f[2]:
count+=1;
if e[0] == f[2] and e[1] == f[0]:
count+=1;
if e[1] == f[0] and e[0] == f[1]:
count-=1;
if e[1] == f[1] and e[0] == f[2]:
count-=1;
if e[1] == f[2] and e[0] == f[0]:
count-=1;
if count != 0:
non_oriented_vertices[e[0]] = 1;
non_oriented_vertices[e[1]] = 1;
mesh.add_attribute("non_oriented");
mesh.set_attribute("non_oriented", non_oriented_vertices);
pymesh.save_mesh(args.output_mesh, mesh, "non_oriented");
if __name__ == "__main__":
main();