diff --git a/invesalius/control.py b/invesalius/control.py index cc856ba35..ddb668200 100644 --- a/invesalius/control.py +++ b/invesalius/control.py @@ -646,6 +646,7 @@ def LoadProject(self): Publisher.sendMessage('Enable Go-to-Coord', status=False) Publisher.sendMessage('End busy cursor') + Publisher.sendMessage('Project loaded successfully') def CreateDicomProject(self, dicom, matrix, matrix_filename): name_to_const = {"AXIAL":const.AXIAL, diff --git a/invesalius/data/visualization/coil_visualizer.py b/invesalius/data/visualization/coil_visualizer.py index 6eb3dfc5a..c0b1a6368 100644 --- a/invesalius/data/visualization/coil_visualizer.py +++ b/invesalius/data/visualization/coil_visualizer.py @@ -8,6 +8,7 @@ import invesalius.data.polydata_utils as pu from invesalius.pubsub import pub as Publisher +from invesalius.navigation.tracker import Tracker import invesalius.session as ses @@ -24,6 +25,10 @@ class CoilVisualizer: def __init__(self, renderer, interactor, actor_factory, vector_field_visualizer): self.renderer = renderer self.interactor = interactor + self.tracker = Tracker() + + # Keeps track of whether tracker fiducials have been set. + self.tracker_fiducials_set = self.tracker.AreTrackerFiducialsSet() # The actor factory is used to create actors for the coil and coil center. self.actor_factory = actor_factory @@ -52,7 +57,18 @@ def __init__(self, renderer, interactor, actor_factory, vector_field_visualizer) self.coil_path = None self.coil_polydata = None - self.show_coil = False + # Show coil button status + self.show_coil_pressed = False + + # Track object button status + self.track_object_pressed = False + + # Is this the first time show coil button has been pressed + self.initial_button_press = True + + # Is this the initial project that was loaded + self.initial_project = True + self.is_navigating = False self.LoadConfig() @@ -67,6 +83,9 @@ def __bind_events(self): Publisher.subscribe(self.ConfigureCoil, 'Configure coil') Publisher.subscribe(self.UpdateCoilPose, 'Update coil pose') Publisher.subscribe(self.UpdateVectorField, 'Update vector field') + Publisher.subscribe(self.OnSetTrackerFiducials, 'Tracker fiducials set') + Publisher.subscribe(self.OnResetTrackerFiducials, 'Reset tracker fiducials') + Publisher.subscribe(self.OnLoadProject, 'Project loaded successfully') def SaveConfig(self): coil_path = self.coil_path.decode(const.FS_ENCODE) if self.coil_path is not None else None @@ -84,6 +103,34 @@ def LoadConfig(self): self.coil_path = coil_path_unencoded.encode(const.FS_ENCODE) self.coil_polydata = pu.LoadPolydata(path=coil_path_unencoded) + def OnSetTrackerFiducials(self): + self.tracker_fiducials_set = True + + # If the track coil button is not pressed, press it after tracker fiducials have been set + if not self.track_object_pressed: + Publisher.sendMessage('Press track object button', pressed=True) + + elif not self.show_coil_pressed: + Publisher.sendMessage('Press show-coil button', pressed=True) + else: + self.ShowCoil(self.show_coil_pressed) + + def OnResetTrackerFiducials(self): + self.tracker_fiducials_set = False + + # If the show coil button is pressed, press it again to hide the coil + if self.show_coil_pressed: + Publisher.sendMessage('Press show-coil button', pressed=False) + + def OnLoadProject(self): + + # When loading some other than the initially loaded project, reset some instance variables + if self.initial_project: + self.initial_project = False + else: + self.tracker_fiducials_set = False + #self.initial_button_press = True + def UpdateVectorField(self): """ Update the vector field assembly to reflect the current vector field. @@ -131,10 +178,12 @@ def ConfigureCoil(self, coil_path=None, polydata=None): def OnNavigationStatus(self, nav_status, vis_status): self.is_navigating = nav_status if self.is_navigating and self.coil_actor is not None: - self.coil_actor.SetVisibility(self.show_coil) + self.coil_actor.SetVisibility(self.show_coil_pressed) - # Called when 'track object' button is pressed in the user interface. + # Called when 'track object' button is pressed in the user interface or in code. def TrackObject(self, enabled): + self.track_object_pressed = enabled + if self.coil_path is None: return @@ -146,15 +195,28 @@ def TrackObject(self, enabled): if enabled: self.AddCoilActor(self.coil_path) - # Called when 'show coil' button is pressed in the user interface. + # Called when 'show coil' button is pressed in the user interface or in code. def ShowCoil(self, state): - self.show_coil = state + self.show_coil_pressed = state + + # Initially, if the tracker fiducials are not set but the show coil button is pressed, + # press it again to hide the coil + if not self.tracker_fiducials_set and self.show_coil_pressed and self.initial_button_press: + + self.initial_button_press = False + + # Press the show coil button to turn it off + Publisher.sendMessage('Press show-coil button', pressed=False) + return if self.target_coil_actor is not None: - self.target_coil_actor.SetVisibility(state) + self.target_coil_actor.SetVisibility(self.show_coil_pressed) + + if self.coil_center_actor is not None: + self.coil_center_actor.SetVisibility(self.show_coil_pressed) if self.coil_actor: - self.coil_actor.SetVisibility(state) + self.coil_actor.SetVisibility(self.show_coil_pressed) if not self.is_navigating: self.interactor.Render() @@ -199,7 +261,7 @@ def AddTargetCoil(self, m_target): self.target_coil_actor.GetProperty().SetSpecular(0.5) self.target_coil_actor.GetProperty().SetSpecularPower(10) self.target_coil_actor.GetProperty().SetOpacity(.3) - self.target_coil_actor.SetVisibility(self.show_coil) + self.target_coil_actor.SetVisibility(self.show_coil_pressed) self.target_coil_actor.SetUserMatrix(m_target) self.renderer.AddActor(self.target_coil_actor)