def countcube2 delon tri v0 tri v1 tri v2 tri if tri and tri return tr

  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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
def countcube2(delon, tri, p):
v0 = tri[0]
v1 = tri[1]
v2 = tri[2]
if ((p[0] == tri[0][0]) and (p[1] == tri[0][1])):
return tri[0][2]
if ((p[0] == tri[1][0]) and (p[1] == tri[1][1])):
return tri[1][2]
if ((p[0] == tri[2][0]) and (p[1] == tri[2][1])):
return tri[2][2]
#find triangle for each vertex
#print "search tris for tri ",tri
#print "delon ",delon
#v0
fl0 = False
v3 = tri[0]
v4 = tri[0]
for k in delon:
if eq(k[0], v0) and (not eq(k[1], v1)) and (not eq(k[2], v2)):
fl0 = True
v3 = k[1]
v4 = k[2]
break
if eq(k[1], v0) and (not eq(k[0], v1)) and (not eq(k[2], v2)):
fl0 = True
v3 = k[0]
v4 = k[2]
break
if eq(k[2], v0) and (not eq(k[0], v1)) and (not eq(k[1], v2)):
fl0 = True
v3 = k[0]
v4 = k[1]
break
#v1
fl1 = False
v5 = tri[0]
v6 = tri[0]
for k in delon:
if eq(k[0], v1) and (not eq(k[1], v0)) and (not eq(k[2], v2)):
fl1 = True
v5 = k[1]
v6 = k[2]
break
if eq(k[1], v1) and (not eq(k[0], v0)) and (not eq(k[2], v2)):
fl1 = True
v5 = k[0]
v6 = k[2]
break
if eq(k[2], v1) and (not eq(k[0], v0)) and (not eq(k[1], v2)):
fl1 = True
v5 = k[0]
v6 = k[1]
break
#v2
fl2 = False
v7 = tri[0]
v8 = tri[0]
for k in delon:
if eq(k[0], v2) and (not eq(k[1], v0)) and (not eq(k[2], v1)):
fl2 = True
v7 = k[1]
v8 = k[2]
break
if eq(k[1], v2) and (not eq(k[0], v0)) and (not eq(k[2], v1)):
fl2 = True
v7 = k[0]
v8 = k[2]
break
if eq(k[2], v0) and (not eq(k[0], v0)) and (not eq(k[1], v1)):
fl2 = True
v7 = k[0]
v8 = k[1]
break
#print "flags ", fl01, fl12, fl02
vertex = np.array([np.array(v0), np.array(v1), np.array(v2)])
#print "vertex cube1 before ",vertex
if fl0:
vertex = np.insert(vertex, len(vertex), [v3], axis=0)
vertex = np.insert(vertex, len(vertex), [v4], axis=0)
if fl1:
vertex = np.insert(vertex, len(vertex), [v5], axis=0)
vertex = np.insert(vertex, len(vertex), [v6], axis=0)
if fl2:
vertex = np.insert(vertex, len(vertex), [v7], axis=0)
vertex = np.insert(vertex, len(vertex), [v8], axis=0)
print "vertex cube2 after ",vertex
#print "vertex in cube1: ",len(vertex)
A = np.zeros((len(vertex), len(vertex)))
for i in range(0, len(vertex)):
for j in range(0, len(vertex)):
A[i][j] = phi(dist(vertex[i][0] - vertex[j][0], vertex[i][1] - vertex[j][1]))
A = np.matrix(A)
V = np.zeros((3, len(vertex)))
#print V
for i in range(0, len(vertex)):
V[0][i] = 1
V[1][i] = vertex[i][0]
V[2][i] = vertex[i][1]
V = np.matrix(V)
Vt = V.getT()
M = np.zeros((len(vertex) + 3, len(vertex) + 3))
M = np.matrix(M)
M[0:len(vertex), 0:len(vertex)] = A
M[len(vertex):len(vertex) + 3, 0:len(vertex)] = V
M[0:len(vertex), len(vertex):len(vertex) + 3] = Vt
b = np.zeros((len(vertex) + 3, 1))
for i in range(0, len(vertex)):
b[i][0] = vertex[i][2]
b = np.matrix(b)
print "cube2 tri ", tri, "p ", p, "vertex ", vertex
wv = M.getI() * b
#print "wv:", wv
sum = 0.0
for i in range(0, len(vertex)):
sum += wv[i][0] * phi(dist(p[0] - vertex[i][0], p[1] - vertex[i][1]))
sum += wv[len(vertex)][0] + wv[len(vertex) + 1][0] * p[0] + wv[len(vertex) + 2][0] * p[1]
#print "res cube1 ",sum
if (sum > 1000):
print "cube2 tri ", tri, "p ", p, "vertex ", vertex, "sum", sum, "wv:", wv
return sum