-
Notifications
You must be signed in to change notification settings - Fork 0
/
_delaunay.py
103 lines (91 loc) · 2.25 KB
/
_delaunay.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import numpy as np
import itertools as it
import struct
import itertools
import math
import numpy
import scipy.spatial
from time import time
now = time()
file = open(r"hits.data","rb")
cnt = 0
verts = []
print("load")
while True:
# file.read(12)
packed = file.read(12)
if not packed:
break
if len(packed) != 12:
break
if cnt > 1000:
break
cnt += 1
unpacked = struct.unpack("<3f", packed)
verts.append(unpacked)
#tri.AddPoint(de.Point(*unpacked))
print("loaded")
array = numpy.array(verts)
tri = scipy.spatial.Delaunay(array, qhull_options="Qt Qbb Qc Qz Qx")
tetras = tri.simplices
def distance(a,b):
s = 0
for x,y in zip(a,b):
s+= (x-y)*(x-y)
return math.sqrt(s)
def take_triangles(tetras,max_dist):
tris = set()
for tetra in tetras:
#tetra = [verts[i] for i in tetra]
bad_edges = []
flag = False
for a,b in itertools.combinations( tetra, 2): #iterating by 3 verts
if distance(verts[a],verts[b]) > max_dist:
#bad_edges.append((a,b))
flag = True
break
if flag:
#continue
pass
'''
for a, b, c in itertools.combinations(tetra, 3):
if (a,b) in bad_edges:
continue
if (a,c) in bad_edges:
continue
if (b,c) in bad_edges:
continue
'''
for x, y, z in itertools.combinations(tetra, 3):
if x > y:
t = x
x = y
y = t
if y > z:
t = y
y = z
z = t
if x > y:
t = x
x = y
y = t
tris.add((x,y,z))
'''
flag = True
for x,y,z in itertools.permutations([a,b,c],3):
if (x,y,z) in tris:
flag = False
break
if flag:
tris.extend((a,b,c))
'''
return tris
print("before")
tris = take_triangles(tetras,20*2)
print("after")
file = open(r"faces.data","wb")
for tri in tris:
file.write(struct.pack('<3i', *tri))
file.close()
print("done")
print(time() - now)