-
Notifications
You must be signed in to change notification settings - Fork 0
/
output.py
61 lines (56 loc) · 1.98 KB
/
output.py
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
def output(filename,e,vertices, bounding_box, type_f):
output_edges = {}
output_triangles = []
def printtriangle(edge):
if edge in output_edges:
return
v1 = edge.origin
edge = edge.rNext()
if edge in output_edges:
return
v2 = edge.origin
edge = edge.rNext()
if edge in output_edges:
return
v3 = edge.origin
if v1 in bounding_box or v2 in bounding_box or v3 in bounding_box:
return
output_triangles.append(((v1.x, v1.y),(v2.x, v2.y),(v3.x, v3.y)))
def bfs(edge):
stack = []
stack.append(edge)
while len(stack):
edge = stack.pop()
if edge.next_edge not in output_edges:
stack.append(edge.next_edge)
if edge.sym().next_edge not in output_edges:
stack.append(edge.sym().next_edge)
printtriangle(edge)
printtriangle(edge.sym())
output_edges[edge] = True
output_edges[edge.sym()] = True
if type_f == "ele":
bfs(e)
o = open(filename[:-5] + ".ele", 'w')
o.write(str(len(output_triangles)) + " 3 0\n")
counter = 0
for triangle in output_triangles:
counter += 1
o.write(str(counter) + " " + vertices[triangle[0]] \
+ " " + vertices[triangle[1]] + " "\
+ vertices[triangle[2]] + "\n")
o.close()
if type_f == "edge":
o = open(filename[:-5] + ".edge", 'w')
counter = 0
l = []
for edge in e:
edge = edge.edges[0]
if edge.origin in bounding_box or edge.destination in bounding_box:
continue
counter += 1
l.append(str(counter) + " " + vertices[(edge.origin.x, edge.origin.y)] + " " + vertices[(edge.destination.x, edge.destination.y)] + "\n")
o.write(str(len(l)) + " 0\n")
for i in l:
o.write(i)
o.close()