co_registration.py
2.09 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
65
import threading
import serial
import wx
from wx.lib.pubsub import pub as Publisher
from numpy import *
from math import sqrt
from time import sleep
class Corregister(threading.Thread):
def __init__(self, bases, flag):
threading.Thread.__init__(self)
self.Minv = bases[0]
self.N = bases[1]
self.q1 = bases[2]
self.q2 = bases[3]
self.flag = flag
self._pause_ = 0
self.start()
def stop(self):
# Stop neuronavigation
self._pause_ = 1
def Coordinates(self):
#Get Polhemus points for neuronavigation
ser = serial.Serial(0)
ser.write("Y")
ser.write("P")
str = ser.readline()
ser.write("Y")
str = str.replace("\r\n","")
str = str.replace("-"," -")
aostr = [s for s in str.split()]
#aoflt -> 0:letter 1:x 2:y 3:z
aoflt = [float(aostr[1]), float(aostr[2]), float(aostr[3]),
float(aostr[4]), float(aostr[5]), float(aostr[6])]
ser.close()
#Unit change: inches to millimeters
x = 25.4
y = 25.4
z = -25.4
coord = (aoflt[0]*x, aoflt[1]*y, aoflt[2]*z)
return coord
def run(self):
while self.flag == True:
#Neuronavigation with Polhemus
trck = self.Coordinates()
tracker = matrix([[trck[0]], [trck[1]], [trck[2]]])
img = self.q1 + (self.Minv*self.N)*(tracker - self.q2)
coord = [float(img[0]), float(img[1]), float(img[2])]
coord_cam = float(img[0]), float(img[1]), float(img[2])
Publisher.sendMessage('Set ball reference position based on bound', coord_cam)
Publisher.sendMessage('Set camera in volume', coord_cam)
wx.CallAfter(Publisher.sendMessage, 'Render volume viewer')
wx.CallAfter(Publisher.sendMessage, 'Co-registered Points', coord)
sleep(0.005)
if self._pause_:
return