Commit d19662c85f107838c17e5a9920a2ff2fc6d8c641
1 parent
f55f4241
Exists in
master
and in
6 other branches
It'was missing two files, data/co_registration.py and data/bases.py
Showing
3 changed files
with
170 additions
and
0 deletions
Show diff stats
.gitattributes
... | ... | @@ -151,6 +151,8 @@ icons/volume_raycasting.png -text |
151 | 151 | icons/volume_raycasting_original.png -text |
152 | 152 | icons/zh_TW.bmp -text |
153 | 153 | invesalius/.svnignore -text |
154 | +invesalius/data/bases.py -text | |
155 | +invesalius/data/co_registration.py -text | |
154 | 156 | locale/de/LC_MESSAGES/invesalius.mo -text |
155 | 157 | locale/el/LC_MESSAGES/invesalius.mo -text |
156 | 158 | locale/en/LC_MESSAGES/invesalius.mo -text | ... | ... |
... | ... | @@ -0,0 +1,85 @@ |
1 | +from numpy import * | |
2 | +from math import sqrt | |
3 | + | |
4 | +class Bases: | |
5 | + | |
6 | + def __init__(self, p1, p2, p3): | |
7 | + | |
8 | + self.p1 = array([p1[0], p1[1], p1[2]]) | |
9 | + self.p2 = array([p2[0], p2[1], p2[2]]) | |
10 | + self.p3 = array([p3[0], p3[1], p3[2]]) | |
11 | + | |
12 | + print "p1: ", self.p1 | |
13 | + print "p2: ", self.p2 | |
14 | + print "p3: ", self.p3 | |
15 | + | |
16 | + self.sub1 = self.p2 - self.p1 | |
17 | + self.sub2 = self.p3 - self.p1 | |
18 | + | |
19 | + def Basecreation(self): | |
20 | + #g1 | |
21 | + g1 = self.sub1 | |
22 | + | |
23 | + #g2 | |
24 | + lamb1 = g1[0]*self.sub2[0] + g1[1]*self.sub2[1] + g1[2]*self.sub2[2] | |
25 | + lamb2 = dot(g1, g1) | |
26 | + lamb = lamb1/lamb2 | |
27 | + | |
28 | + #Ponto q | |
29 | + q = self.p1 + lamb*self.sub1 | |
30 | + | |
31 | + #g1 e g2 com origem em q | |
32 | + g1 = self.p1 - q | |
33 | + g2 = self.p3 - q | |
34 | + | |
35 | + #testa se o g1 nao eh um vetor nulo | |
36 | + if g1.any() == False: | |
37 | + g1 = self.p2 - q | |
38 | + | |
39 | + #g3 - Produto vetorial NumPy | |
40 | + g3 = cross(g2, g1) | |
41 | + | |
42 | + #normalizacao dos vetores | |
43 | + g1 = g1/sqrt(lamb2) | |
44 | + g2 = g2/sqrt(dot(g2, g2)) | |
45 | + g3 = g3/sqrt(dot(g3, g3)) | |
46 | + | |
47 | + M = matrix([[g1[0],g1[1],g1[2]], [g2[0],g2[1],g2[2]], [g3[0],g3[1],g3[2]]]) | |
48 | + q.shape = (3, 1) | |
49 | + q = matrix(q.copy()) | |
50 | + print"M: ", M | |
51 | ||
52 | + print"q: ", q | |
53 | ||
54 | + Minv = M.I | |
55 | + | |
56 | + return M, q, Minv | |
57 | + | |
58 | +def FlipX(point): | |
59 | + | |
60 | + point = matrix(point + (0,)) | |
61 | + | |
62 | + #inverter o eixo z | |
63 | + ## possivel explicacaoo -- origem do eixo do imagedata esta no canto | |
64 | + ## superior esquerdo e origem da superfice eh no canto inferior esquerdo | |
65 | + ## ou a ordem de empilhamento das fatias | |
66 | + | |
67 | + point[0, 2] = -point[0, 2] | |
68 | + | |
69 | + #Flip em y | |
70 | + Mrot = matrix([[1.0, 0.0, 0.0, 0.0], | |
71 | + [0.0, -1.0, 0.0, 0.0], | |
72 | + [0.0, 0.0, -1.0, 0.0], | |
73 | + [0.0, 0.0, 0.0, 1.0]]) | |
74 | + Mtrans = matrix([[1.0, 0, 0, -point[0, 0]], | |
75 | + [0.0, 1.0, 0, -point[0, 1]], | |
76 | + [0.0, 0.0, 1.0, -point[0, 2]], | |
77 | + [0.0, 0.0, 0.0, 1.0]]) | |
78 | + Mtrans_return = matrix([[1.0, 0, 0, point[0, 0]], | |
79 | + [0.0, 1.0, 0, point[0, 1]], | |
80 | + [0.0, 0.0, 1.0, point[0, 2]], | |
81 | + [0.0, 0.0, 0.0, 1.0]]) | |
82 | + | |
83 | + point_rot = point*Mtrans*Mrot*Mtrans_return | |
84 | + x, y, z = point_rot.tolist()[0][:3] | |
85 | + return x, y, z | ... | ... |
... | ... | @@ -0,0 +1,83 @@ |
1 | +import threading | |
2 | +import serial | |
3 | +import wx.lib.pubsub as ps | |
4 | +from numpy import * | |
5 | +from math import sqrt | |
6 | +from time import sleep | |
7 | +import project | |
8 | + | |
9 | +class Corregister(threading.Thread): | |
10 | + | |
11 | + def __init__(self, bases, flag): | |
12 | + | |
13 | + threading.Thread.__init__(self) | |
14 | + self.M = bases[0] | |
15 | + self.Minv = bases[1] | |
16 | + self.N = bases[2] | |
17 | + self.Ninv = bases[3] | |
18 | + self.q1 = bases[4] | |
19 | + self.q2 = bases[5] | |
20 | + self.flag = flag | |
21 | + self._pause_ = 0 | |
22 | + self.start() | |
23 | + | |
24 | + def stop(self): | |
25 | + # Stop neuronavigation | |
26 | + self._pause_ = 1 | |
27 | + | |
28 | + def Coordinates(self): | |
29 | + #Get Polhemus points for neuronavigation | |
30 | + ser = serial.Serial(0) | |
31 | + ser.write("Y") | |
32 | + ser.write("P") | |
33 | + str = ser.readline() | |
34 | + ser.write("Y") | |
35 | + str = str.replace("\r\n","") | |
36 | + str = str.replace("-"," -") | |
37 | + aostr = [s for s in str.split()] | |
38 | + #aoflt -> 0:letter 1:x 2:y 3:z | |
39 | + aoflt = [float(aostr[1]), float(aostr[2]), float(aostr[3]), | |
40 | + float(aostr[4]), float(aostr[5]), float(aostr[6])] | |
41 | + ser.close() | |
42 | + | |
43 | + #Unit change: inches to millimeters | |
44 | + x = 25.4 | |
45 | + y = 25.4 | |
46 | + z = -25.4 | |
47 | + | |
48 | + coord = (aoflt[0]*x, aoflt[1]*y, aoflt[2]*z) | |
49 | + return coord | |
50 | + | |
51 | + def run(self): | |
52 | + #Image limits to use in simulation | |
53 | + #bounds = array(project.Project().imagedata.GetBounds()) | |
54 | + #im_simu = bounds | |
55 | + #im_simu[0] = bounds[0] - 10.0 | |
56 | + #im_simu[2] = bounds[2] - 10.0 | |
57 | + #im_simu[4] = bounds[4] - 10.0 | |
58 | + | |
59 | + while self.flag == True: | |
60 | + #Neuronavigation with Polhemus | |
61 | + trck = self.Coordinates() | |
62 | + tracker = matrix([[trck[0]], [trck[1]], [trck[2]]]) | |
63 | + img = self.q1 + (self.Minv*self.N)*(tracker - self.q2) | |
64 | + coord = [float(img[0]), float(img[1]), float(img[2])] | |
65 | + ps.Publisher().sendMessage('Co-registered Points', coord) | |
66 | + | |
67 | + if self._pause_: | |
68 | + return | |
69 | + | |
70 | + #Loop for simulate Polhemus movement and Neuronavigation | |
71 | + #for i in range(0, 5, 2): | |
72 | + # while im_simu[i] < (bounds[i+1]+10.0): | |
73 | + # im_init = matrix([[im_simu[0]], [im_simu[2]], [im_simu[4]]]) | |
74 | + # #mudanca coordenada img2plh | |
75 | + # tr_simu = self.q2 + (self.Ninv*self.M)*(im_init - self.q1) | |
76 | + # #mudanca coordenada plh2img | |
77 | + # img_final = self.q1 + (self.Minv*self.N)*(tr_simu - self.q2) | |
78 | + # #publica as alteracoes que devem ser feitas nas fatias | |
79 | + # coord = [float(img_final[0]), float(img_final[1]), float(img_final[2])] | |
80 | + # ps.Publisher().sendMessage('Co-registered Points', coord) | |
81 | + # im_simu[i] = im_simu[i] + 4.0 | |
82 | + # if self._pause_: | |
83 | + # return | ... | ... |