Skip to content

Commit

Permalink
Add check to prevent delayed rendering of coil/probe when navigating.…
Browse files Browse the repository at this point in the history
… Remove obj_id=0 choice in multicoil mode. Automatically select a coil for navigation when it's created.
  • Loading branch information
Tolonen Luka committed Sep 10, 2024
1 parent ff5c1be commit 95374e8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
3 changes: 2 additions & 1 deletion invesalius/data/visualization/coil_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,9 @@ def RemoveCoil(self, coil_name=None):
self.renderer.RemoveActor(coil["center_actor"])
self.coils = {}

self.interactor.Render()
# self.vector_field_assembly.SetVisibility(0)
if not self.is_navigating:
self.interactor.Render()

def ResetCoilVisualizer(self, n_coils):
self.RemoveCoil() # Remove all coils
Expand Down
7 changes: 6 additions & 1 deletion invesalius/data/visualization/probe_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ def __init__(self, renderer, interactor):
def __bind_events(self):
Publisher.subscribe(self.ShowProbe, "Show probe in viewer volume")
Publisher.subscribe(self.UpdateProbePose, "Update probe pose")
Publisher.subscribe(self.OnNavigationStatus, "Navigation status")

def OnNavigationStatus(self, nav_status, vis_status):
self.is_navigating = nav_status

def ShowProbe(self, state):
self.show_probe = state

if self.probe_actor:
self.probe_actor.SetVisibility(self.show_probe)
self.interactor.Render()
if not self.is_navigating:
self.interactor.Render()

def AddProbeActor(self, probe_path):
vtk_colors = vtk.vtkNamedColors()
Expand Down
32 changes: 17 additions & 15 deletions invesalius/gui/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3856,8 +3856,10 @@ def __init__(
self.pedal_connector = pedal_connector

self.tracker_id = tracker.GetTrackerId()
self.show_sensor_options: bool = self.tracker_id in const.TRACKERS_WITH_SENSOR_OPTIONS
self.obj_id = 2 # the index of the object in coord_raw
self.show_sensor_options: bool = (
self.tracker_id in const.TRACKERS_WITH_SENSOR_OPTIONS and self.obj_id == 0
)
self.coil_path = None
self.polydata = None

Expand Down Expand Up @@ -3895,17 +3897,22 @@ def _init_gui(self) -> None:
tooltip = _(
"Choose the coil index in coord_raw. Choose 0 for static mode, 2 for dynamic mode and 3 onwards for multiple coils."
)

# Static mode obj_id=0 (case where stylus is attached to coil) is only feasible for single coil-mode, so hide it in multicoil mode
choices = ["0"] if self.n_coils == 1 else []
choices += [str(i) for i in range(2, max_obj_id)]

choice_obj_id = wx.ComboBox(
self,
-1,
"",
size=wx.Size(90, 23),
choices=["0"] + [str(i) for i in range(2, max_obj_id)],
choices=choices,
style=wx.CB_DROPDOWN | wx.CB_READONLY,
)
choice_obj_id.SetToolTip(tooltip)
choice_obj_id.Bind(wx.EVT_COMBOBOX, self.OnChooseObjID)
choice_obj_id.SetSelection(1)
choice_obj_id.SetStringSelection("2")
choice_obj_id.Enable(True)

if self.tracker_id == const.PATRIOT or self.tracker_id == const.ISOTRAKII:
Expand Down Expand Up @@ -4227,21 +4234,16 @@ def OnReset(self, evt: wx.CommandEvent) -> None:
self.ResetObjectFiducials()

def OnChooseObjID(self, evt: wx.CommandEvent) -> None:
# When ref mode is changed the tracker coordinates are set to nan
# This is for Polhemus FASTRAK wrapper, where the sensor attached to the object can be the stylus (Static
# reference - Selection 0 - index 0 for coordinates) or can be a 3rd sensor (Dynamic reference - Selection 1 -
# index 2 for coordinates)
self.obj_id = int(evt.GetEventObject().GetStringSelection())

if evt.GetSelection() == 0:
self.obj_id = 0
self.choice_sensor.Show(False)
else:
self.obj_id = evt.GetSelection() + 1
self.choice_sensor.Show(self.tracker_id in const.TRACKERS_WITH_SENSOR_OPTIONS)
# choice_sensor is only shown for relevant trackers like Polhemus FASTRAK
# If obj_id=0, (ie. the stylus is attached to the coil), the sensor is not used, so hide this
self.choice_sensor.Show(
self.obj_id == 0 and self.tracker_id in const.TRACKERS_WITH_SENSOR_OPTIONS
)

# When obj_id is changed the object fiducials are reset
self.ResetObjectFiducials()

# Used to update choice sensor controls
self.Layout()

def OnChoiceFTSensor(self, evt: wx.CommandEvent) -> None:
Expand Down
16 changes: 9 additions & 7 deletions invesalius/gui/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,9 @@ def OnSelectCoil(self, event=None, name=None, select=False):
),
_("InVesalius 3"),
)
event.GetEventObject().SetValue(False) # Unpress the coil-button
self.coil_btns[name][0].SetValue(
False
) # Unpress the coil-button since its selection just failed
return

# Check that the tracker used to configure the coil matches the currently used tracker
Expand All @@ -791,7 +793,7 @@ def OnSelectCoil(self, event=None, name=None, select=False):
),
_("InVesalius 3"),
)
event.GetEventObject().SetValue(False) # Unpress the button
self.coil_btns[name][0].SetValue(False) # Unpress the button
return

# Press the coil button here in case selection was done via code without pressing button
Expand Down Expand Up @@ -902,11 +904,11 @@ def OnCreateNewCoil(self, event=None):
coil_btn.SetValue(False)
self.OnSelectCoil(name=coil_name, select=False)

if self.navigation.n_coils == 1:
# Select the coil that was created for navigation
self.OnSelectCoil(name=coil_name, select=True)
# Hide the coil-button
coil_btn.Show(False)
# Select the coil that was just created
self.OnSelectCoil(name=coil_name, select=True)

# Show button only in multicoil mode
coil_btn.Show(self.navigation.n_coils > 1)

self.Layout()

Expand Down

0 comments on commit 95374e8

Please sign in to comment.