Skip to content

Commit

Permalink
Simplify how r_stylus is saved to file: move r_stylus to 'navigation'…
Browse files Browse the repository at this point in the history
… object and remove bogus 'navigation-stylus' object
  • Loading branch information
Tolonen Luka committed Jul 22, 2024
1 parent 76defe0 commit 7b212f7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 36 deletions.
34 changes: 15 additions & 19 deletions invesalius/gui/task_navigator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1075,27 +1075,23 @@ def onRecord(self, evt):
marker_visibilities, __, coord_raw = self.tracker.GetTrackerCoordinates(
ref_mode_id=0, n_samples=1
)

if marker_visibilities[0] and marker_visibilities[1]: # if probe and head are visible
if self.navigation.SetStylusOrientation(coord_raw): # if successfully created r_stylus
# Save to config.json file
ses.Session().SetConfig(
"navigation-stylus", {"r_stylus": self.navigation.r_stylus.tolist()}
if self.navigation.SetStylusOrientation(coord_raw) and not self.done:
# if successfully created r_stylus in navigation for the first time: make the illustration green to show success
self.done = True
self.help.Destroy() # show a colored (green) bitmap as opposed to grayscale
self.help = wx.GenericStaticBitmap(
self,
-1,
self.help_img.ConvertToBitmap(),
(10, 5),
(self.help_img.GetWidth(), self.help_img.GetHeight()),
)

if not self.done: # only show green on first record
self.done = True
self.help.Destroy() # show a colored (green) bitmap as opposed to grayscale
self.help = wx.GenericStaticBitmap(
self,
-1,
self.help_img.ConvertToBitmap(),
(10, 5),
(self.help_img.GetWidth(), self.help_img.GetHeight()),
)
self.border.Insert(
2, self.help, 0, wx.EXPAND | wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1
)
self.Layout()
self.border.Insert(
2, self.help, 0, wx.EXPAND | wx.ALL | wx.ALIGN_CENTER_VERTICAL, 1
)
self.Layout()
else:
wx.MessageBox(_("Probe or head not visible to tracker!"), _("InVesalius 3"))

Expand Down
37 changes: 20 additions & 17 deletions invesalius/navigation/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,24 +344,21 @@ def LoadConfig(self):
session = ses.Session()
state = session.GetConfig("navigation")

if state is None:
return

object_fiducials = np.array(state["object_fiducials"])
object_orientations = np.array(state["object_orientations"])
object_reference_mode = state["object_reference_mode"]
object_name = state["object_name"].encode(const.FS_ENCODE)
self.object_registration = (
object_fiducials,
object_orientations,
object_reference_mode,
object_name,
)
if state is not None:
object_fiducials = np.array(state["object_fiducials"])
object_orientations = np.array(state["object_orientations"])
object_reference_mode = state["object_reference_mode"]
object_name = state["object_name"].encode(const.FS_ENCODE)
self.object_registration = (
object_fiducials,
object_orientations,
object_reference_mode,
object_name,
)

# Try to load stylus orientation data
stylus_data = session.GetConfig("navigation-stylus")
if stylus_data is not None:
self.r_stylus = np.array(stylus_data["r_stylus"])
# Try to load stylus orientation data
if "r_stylus" in state:
self.r_stylus = np.array(state["r_stylus"])

def CoilAtTarget(self, state):
self.coil_at_target = state
Expand Down Expand Up @@ -446,6 +443,12 @@ def SetStylusOrientation(self, coord_raw):

# Rotation from tracker to VTK coordinate system
self.r_stylus = up_vtk @ np.linalg.inv(up_trk)

# Save r_stylus to config file
session = ses.Session()
if (nav_config := session.GetConfig("navigation")) is not None:
nav_config["r_stylus"] = self.r_stylus.tolist()
session.SetConfig("navigation", nav_config)
return True
else:
return False
Expand Down

0 comments on commit 7b212f7

Please sign in to comment.