Commit 49a3bef897cf60284ade0064acf4fb47ebdcab55
1 parent
2f872421
Exists in
master
calculate_fre working
Showing
2 changed files
with
21 additions
and
29 deletions
Show diff stats
invesalius/data/bases.py
1 | 1 | import numpy as np |
2 | 2 | import invesalius.data.coordinates as dco |
3 | 3 | import invesalius.data.transformations as tr |
4 | - | |
4 | +import invesalius.data.coregistration as dcr | |
5 | 5 | |
6 | 6 | def angle_calculation(ap_axis, coil_axis): |
7 | 7 | """ |
... | ... | @@ -175,37 +175,18 @@ def calculate_fre_m(fiducials): |
175 | 175 | |
176 | 176 | return float(np.sqrt(np.sum(dist ** 2) / 3)) |
177 | 177 | |
178 | -def calculate_fre_matrix(fiducials, m_change): | |
178 | +def calculate_fre(fiducials_raw, fiducials, ref_mode_id, m_change): | |
179 | 179 | |
180 | 180 | dist = np.zeros([3, 1]) |
181 | 181 | |
182 | - p1 = np.hstack((fiducials[3, :], 1)).reshape(4, 1) | |
183 | - p2 = np.hstack((fiducials[4, :], 1)).reshape(4, 1) | |
184 | - p3 = np.hstack((fiducials[5, :], 1)).reshape(4, 1) | |
185 | - | |
186 | - print(p1) | |
187 | - | |
188 | - p1 = flip_x_m([p1[0,0],p1[1,0],p1[2,0]]) | |
189 | - p2 = flip_x_m([p2[0,0],p2[1,0],p2[2,0]]) | |
190 | - p3 = flip_x_m([p3[0,0],p3[1,0],p3[2,0]]) | |
191 | - print(p1) | |
192 | - | |
193 | - p1 = np.hstack([np.identity(3), p1[:3]]) | |
194 | - p2 = np.hstack([np.identity(3), p2[:3]]) | |
195 | - p3 = np.hstack([np.identity(3), p3[:3]]) | |
196 | - | |
197 | - p1 = np.vstack([p1,[0,0,0,1]]) | |
198 | - p2 = np.vstack([p2,[0,0,0,1]]) | |
199 | - p3 = np.vstack([p3,[0,0,0,1]]) | |
200 | - print(p1) | |
201 | - | |
202 | - p1_m = m_change @ p1 | |
203 | - p2_m = m_change @ p2 | |
204 | - p3_m = m_change @ p3 | |
182 | + p1 = np.vstack([fiducials_raw[0, :], fiducials_raw[1, :]]) | |
183 | + p2 = np.vstack([fiducials_raw[2, :], fiducials_raw[3, :]]) | |
184 | + p3 = np.vstack([fiducials_raw[4, :], fiducials_raw[5, :]]) | |
205 | 185 | |
206 | - #p1_m = flip_x_m([p1_m[0,0],p1_m[1,0],p1_m[2,0]]) | |
207 | - #p2_m = flip_x_m([p2_m[0,0],p2_m[1,0],p2_m[2,0]]) | |
208 | - #p3_m = flip_x_m([p3_m[0,0],p3_m[1,0],p3_m[2,0]]) | |
186 | + coreg_data = (m_change, 0) | |
187 | + p1_m, m_img = dcr.corregistrate_dynamic(coreg_data, p1, ref_mode_id, [None, None]) | |
188 | + p2_m, m_img = dcr.corregistrate_dynamic(coreg_data, p2, ref_mode_id, [None, None]) | |
189 | + p3_m, m_img = dcr.corregistrate_dynamic(coreg_data, p3, ref_mode_id, [None, None]) | |
209 | 190 | |
210 | 191 | print(p1_m) |
211 | 192 | print(fiducials[0, :]) | ... | ... |
invesalius/gui/task_navigator.py
... | ... | @@ -299,6 +299,7 @@ class NeuronavigationPanel(wx.Panel): |
299 | 299 | |
300 | 300 | # Initialize global variables |
301 | 301 | self.fiducials = np.full([6, 3], np.nan) |
302 | + self.fiducials_raw = np.zeros((6, 6)) | |
302 | 303 | self.correg = None |
303 | 304 | self.current_coord = 0, 0, 0 |
304 | 305 | self.trk_init = None |
... | ... | @@ -661,6 +662,16 @@ class NeuronavigationPanel(wx.Panel): |
661 | 662 | # Update number controls with tracker coordinates |
662 | 663 | if coord is not None: |
663 | 664 | self.fiducials[btn_id, :] = coord[0:3] |
665 | + if btn_id == 3: | |
666 | + self.fiducials_raw[0, :] = coord_raw[0, :] | |
667 | + self.fiducials_raw[1, :] = coord_raw[1, :] | |
668 | + elif btn_id == 4: | |
669 | + self.fiducials_raw[2, :] = coord_raw[0, :] | |
670 | + self.fiducials_raw[3, :] = coord_raw[1, :] | |
671 | + else: | |
672 | + self.fiducials_raw[4, :] = coord_raw[0, :] | |
673 | + self.fiducials_raw[5, :] = coord_raw[1, :] | |
674 | + | |
664 | 675 | for n in [0, 1, 2]: |
665 | 676 | self.numctrls_coord[btn_id][n].SetValue(float(coord[n])) |
666 | 677 | |
... | ... | @@ -779,7 +790,7 @@ class NeuronavigationPanel(wx.Panel): |
779 | 790 | # fre = db.calculate_fre(self.fiducials, minv, n, q1, q2) |
780 | 791 | fre = db.calculate_fre_m(self.fiducials) |
781 | 792 | self.UpdateFRE(fre) |
782 | - print(db.calculate_fre_matrix(self.fiducials, m_change)) | |
793 | + print(db.calculate_fre(self.fiducials_raw, self.fiducials, self.ref_mode_id, m_change)) | |
783 | 794 | |
784 | 795 | if self.track_obj: |
785 | 796 | # if object tracking is selected | ... | ... |