From c036972625b028c16c2b5b4d382d1c7c9c59bf61 Mon Sep 17 00:00:00 2001 From: Tolonen Luka Date: Thu, 25 Jul 2024 12:47:15 +0300 Subject: [PATCH] Now works with tracker coordinate system where stylus points in x-axis as opposed to y-axis. Also, removed unnecessary disabling of 'Track coil' button before navigation. --- invesalius/data/coregistration.py | 5 ++++- invesalius/gui/task_navigator.py | 2 -- invesalius/navigation/navigation.py | 7 +++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/invesalius/data/coregistration.py b/invesalius/data/coregistration.py index 3d7fe6e50..73e08b91f 100644 --- a/invesalius/data/coregistration.py +++ b/invesalius/data/coregistration.py @@ -190,8 +190,11 @@ def corregistrate_probe(m_change, r_stylus, coord_raw, ref_mode_id, icp=[None, N m_img = m_change @ m_probe_ref m_img = apply_icp(m_img, icp) + # Rotate from trk system where stylus points in x-axis to vtk-system where stylus points in y-axis + R = tr.euler_matrix(*np.radians([0, 0, -90]), axes="rxyz")[:3, :3] + # rotate m_probe_ref from tracker to image space - r_img = r_stylus @ m_probe_ref[:3, :3] + r_img = r_stylus @ R @ m_probe_ref[:3, :3] @ np.linalg.inv(R) m_img[:3, :3] = r_img[:3, :3] # compute rotation angles diff --git a/invesalius/gui/task_navigator.py b/invesalius/gui/task_navigator.py index 00a699450..1d8d50dda 100644 --- a/invesalius/gui/task_navigator.py +++ b/invesalius/gui/task_navigator.py @@ -1304,8 +1304,6 @@ def __init__(self, parent, nav_hub): track_object_button.SetBackgroundColour(GREY_COLOR) track_object_button.SetBitmap(BMP_TRACK) track_object_button.SetValue(False) - if not self.track_obj: - track_object_button.Enable(False) track_object_button.SetToolTip(tooltip) track_object_button.Bind( wx.EVT_TOGGLEBUTTON, partial(self.OnTrackObjectButton, ctrl=track_object_button) diff --git a/invesalius/navigation/navigation.py b/invesalius/navigation/navigation.py index 2c3308a75..ca08e51f2 100644 --- a/invesalius/navigation/navigation.py +++ b/invesalius/navigation/navigation.py @@ -441,9 +441,12 @@ def SetStylusOrientation(self, coord_raw): # up_vtk: orientation 'stylus pointing up along head' in vtk space up_vtk = tr.euler_matrix(*np.radians([90.0, 0.0, 0.0]), axes="rxyz")[:3, :3] - # Rotation from tracker to VTK coordinate system - self.r_stylus = up_vtk @ np.linalg.inv(up_trk) + # Rotate 90 degrees around z-axis from trk system where stylus points in x-axis + # to vtk-system where stylus points in y-axis + R = tr.euler_matrix(*np.radians([0, 0, -90]), axes="rxyz")[:3, :3] + # Rotation from tracker to VTK coordinate system + self.r_stylus = up_vtk @ np.linalg.inv(R @ up_trk @ np.linalg.inv(R)) # Save r_stylus to config file session = ses.Session() if (nav_config := session.GetConfig("navigation")) is not None: