Skip to content

Commit

Permalink
Work with tracker coordinate system where stylus points in x-axis as …
Browse files Browse the repository at this point in the history
…opposed to y-axis
  • Loading branch information
Tolonen Luka committed Jul 25, 2024
1 parent 62ed00e commit a01b6f3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion invesalius/data/coregistration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions invesalius/navigation/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit a01b6f3

Please sign in to comment.