Commit e2f228d400ee5f53e893678e82155f42def18136
1 parent
121e33b4
Exists in
master
Fixed for obj correg
Showing
3 changed files
with
17 additions
and
8 deletions
Show diff stats
invesalius/data/coregistration.py
@@ -105,7 +105,7 @@ def tracker_to_image(m_change, m_probe_ref, r_obj_img, m_obj_raw, s0_dyn): | @@ -105,7 +105,7 @@ def tracker_to_image(m_change, m_probe_ref, r_obj_img, m_obj_raw, s0_dyn): | ||
105 | return m_img | 105 | return m_img |
106 | 106 | ||
107 | 107 | ||
108 | -def corregistrate_object_dynamic(inp, coord_raw, ref_mode_id): | 108 | +def corregistrate_object_dynamic(inp, coord_raw, ref_mode_id, icp): |
109 | 109 | ||
110 | m_change, obj_ref_mode, t_obj_raw, s0_raw, r_s0_raw, s0_dyn, m_obj_raw, r_obj_img = inp | 110 | m_change, obj_ref_mode, t_obj_raw, s0_raw, r_s0_raw, s0_dyn, m_obj_raw, r_obj_img = inp |
111 | 111 | ||
@@ -120,6 +120,8 @@ def corregistrate_object_dynamic(inp, coord_raw, ref_mode_id): | @@ -120,6 +120,8 @@ def corregistrate_object_dynamic(inp, coord_raw, ref_mode_id): | ||
120 | m_probe_ref[2, -1] = -m_probe_ref[2, -1] | 120 | m_probe_ref[2, -1] = -m_probe_ref[2, -1] |
121 | # corregistrate from tracker to image space | 121 | # corregistrate from tracker to image space |
122 | m_img = tracker_to_image(m_change, m_probe_ref, r_obj_img, m_obj_raw, s0_dyn) | 122 | m_img = tracker_to_image(m_change, m_probe_ref, r_obj_img, m_obj_raw, s0_dyn) |
123 | + if icp[0]: | ||
124 | + m_img = bases.transform_icp(m_img, icp[1]) | ||
123 | # compute rotation angles | 125 | # compute rotation angles |
124 | _, _, angles, _, _ = tr.decompose_matrix(m_img) | 126 | _, _, angles, _, _ = tr.decompose_matrix(m_img) |
125 | # create output coordiante list | 127 | # create output coordiante list |
@@ -169,7 +171,7 @@ def corregistrate_dynamic(inp, coord_raw, ref_mode_id, icp): | @@ -169,7 +171,7 @@ def corregistrate_dynamic(inp, coord_raw, ref_mode_id, icp): | ||
169 | 171 | ||
170 | 172 | ||
171 | class CoordinateCorregistrate(threading.Thread): | 173 | class CoordinateCorregistrate(threading.Thread): |
172 | - def __init__(self, ref_mode_id, trck_info, coreg_data, coord_queue, view_tracts, coord_tracts_queue, event, sle): | 174 | + def __init__(self, ref_mode_id, trck_info, coreg_data, coord_queue, view_tracts, coord_tracts_queue, event, sle, icp_queue): |
173 | threading.Thread.__init__(self, name='CoordCoregObject') | 175 | threading.Thread.__init__(self, name='CoordCoregObject') |
174 | self.ref_mode_id = ref_mode_id | 176 | self.ref_mode_id = ref_mode_id |
175 | self.trck_info = trck_info | 177 | self.trck_info = trck_info |
@@ -179,8 +181,9 @@ class CoordinateCorregistrate(threading.Thread): | @@ -179,8 +181,9 @@ class CoordinateCorregistrate(threading.Thread): | ||
179 | self.coord_tracts_queue = coord_tracts_queue | 181 | self.coord_tracts_queue = coord_tracts_queue |
180 | self.event = event | 182 | self.event = event |
181 | self.sle = sle | 183 | self.sle = sle |
184 | + self.icp_queue = icp_queue | ||
185 | + self.icp = None | ||
182 | self.m_icp = None | 186 | self.m_icp = None |
183 | - self.icp = False | ||
184 | 187 | ||
185 | def run(self): | 188 | def run(self): |
186 | trck_info = self.trck_info | 189 | trck_info = self.trck_info |
@@ -191,9 +194,13 @@ class CoordinateCorregistrate(threading.Thread): | @@ -191,9 +194,13 @@ class CoordinateCorregistrate(threading.Thread): | ||
191 | # print('CoordCoreg: event {}'.format(self.event.is_set())) | 194 | # print('CoordCoreg: event {}'.format(self.event.is_set())) |
192 | while not self.event.is_set(): | 195 | while not self.event.is_set(): |
193 | try: | 196 | try: |
197 | + if self.icp_queue.empty(): | ||
198 | + None | ||
199 | + else: | ||
200 | + self.icp, self.m_icp = self.icp_queue.get_nowait() | ||
194 | # print(f"Set the coordinate") | 201 | # print(f"Set the coordinate") |
195 | coord_raw = dco.GetCoordinates(trck_init, trck_id, trck_mode) | 202 | coord_raw = dco.GetCoordinates(trck_init, trck_id, trck_mode) |
196 | - coord, m_img = corregistrate_object_dynamic(coreg_data, coord_raw, self.ref_mode_id) | 203 | + coord, m_img = corregistrate_object_dynamic(coreg_data, coord_raw, self.ref_mode_id, [self.icp, self.m_icp]) |
197 | m_img_flip = m_img.copy() | 204 | m_img_flip = m_img.copy() |
198 | m_img_flip[1, -1] = -m_img_flip[1, -1] | 205 | m_img_flip[1, -1] = -m_img_flip[1, -1] |
199 | # self.pipeline.set_message(m_img_flip) | 206 | # self.pipeline.set_message(m_img_flip) |
@@ -209,6 +216,9 @@ class CoordinateCorregistrate(threading.Thread): | @@ -209,6 +216,9 @@ class CoordinateCorregistrate(threading.Thread): | ||
209 | if self.view_tracts: | 216 | if self.view_tracts: |
210 | self.coord_tracts_queue.put_nowait(m_img_flip) | 217 | self.coord_tracts_queue.put_nowait(m_img_flip) |
211 | 218 | ||
219 | + if not self.icp_queue.empty(): | ||
220 | + self.icp_queue.task_done() | ||
221 | + | ||
212 | # The sleep has to be in both threads | 222 | # The sleep has to be in both threads |
213 | sleep(self.sle) | 223 | sleep(self.sle) |
214 | except queue.Full: | 224 | except queue.Full: |
@@ -244,14 +254,13 @@ class CoordinateCorregistrateNoObject(threading.Thread): | @@ -244,14 +254,13 @@ class CoordinateCorregistrateNoObject(threading.Thread): | ||
244 | else: | 254 | else: |
245 | self.icp, self.m_icp = self.icp_queue.get_nowait() | 255 | self.icp, self.m_icp = self.icp_queue.get_nowait() |
246 | # print(f"Set the coordinate") | 256 | # print(f"Set the coordinate") |
247 | - print(self.icp, self.m_icp) | 257 | + #print(self.icp, self.m_icp) |
248 | coord_raw = dco.GetCoordinates(trck_init, trck_id, trck_mode) | 258 | coord_raw = dco.GetCoordinates(trck_init, trck_id, trck_mode) |
249 | coord, m_img = corregistrate_dynamic(coreg_data, coord_raw, self.ref_mode_id, [self.icp, self.m_icp]) | 259 | coord, m_img = corregistrate_dynamic(coreg_data, coord_raw, self.ref_mode_id, [self.icp, self.m_icp]) |
250 | # print("Coord: ", coord) | 260 | # print("Coord: ", coord) |
251 | m_img_flip = m_img.copy() | 261 | m_img_flip = m_img.copy() |
252 | m_img_flip[1, -1] = -m_img_flip[1, -1] | 262 | m_img_flip[1, -1] = -m_img_flip[1, -1] |
253 | 263 | ||
254 | - #print(icp) | ||
255 | if self.icp: | 264 | if self.icp: |
256 | m_img = bases.transform_icp(m_img, self.m_icp) | 265 | m_img = bases.transform_icp(m_img, self.m_icp) |
257 | 266 |
invesalius/gui/dialogs.py
@@ -850,7 +850,7 @@ def ShowNavigationTrackerWarning(trck_id, lib_mode): | @@ -850,7 +850,7 @@ def ShowNavigationTrackerWarning(trck_id, lib_mode): | ||
850 | dlg.Destroy() | 850 | dlg.Destroy() |
851 | 851 | ||
852 | def ICPcorregistration(fre): | 852 | def ICPcorregistration(fre): |
853 | - msg = _("The fiducial registration error is: ") + str(round(fre, 2)) + '\n' + \ | 853 | + msg = _("The fiducial registration error is: ") + str(round(fre, 2)) + '\n\n' + \ |
854 | _("Would you like to improve accuracy?") | 854 | _("Would you like to improve accuracy?") |
855 | if sys.platform == 'darwin': | 855 | if sys.platform == 'darwin': |
856 | dlg = wx.MessageDialog(None, "", msg, | 856 | dlg = wx.MessageDialog(None, "", msg, |
invesalius/gui/task_navigator.py
@@ -809,7 +809,7 @@ class NeuronavigationPanel(wx.Panel): | @@ -809,7 +809,7 @@ class NeuronavigationPanel(wx.Panel): | ||
809 | 809 | ||
810 | jobs_list.append(dcr.CoordinateCorregistrate(self.ref_mode_id, tracker_mode, coreg_data, self.coord_queue, | 810 | jobs_list.append(dcr.CoordinateCorregistrate(self.ref_mode_id, tracker_mode, coreg_data, self.coord_queue, |
811 | self.view_tracts, self.coord_tracts_queue, | 811 | self.view_tracts, self.coord_tracts_queue, |
812 | - self.event, self.sleep_nav)) | 812 | + self.event, self.sleep_nav, self.icp_queue)) |
813 | 813 | ||
814 | else: | 814 | else: |
815 | coreg_data = (m_change, 0) | 815 | coreg_data = (m_change, 0) |