From dc41305480f8b75c953dca866bcec4b9400e7c44 Mon Sep 17 00:00:00 2001 From: rmatsuda Date: Tue, 15 Oct 2024 10:11:58 +0300 Subject: [PATCH 1/2] ADD: robot warning text in viewer volume --- invesalius/data/viewer_volume.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/invesalius/data/viewer_volume.py b/invesalius/data/viewer_volume.py index a705441d5..f67f2808a 100644 --- a/invesalius/data/viewer_volume.py +++ b/invesalius/data/viewer_volume.py @@ -255,6 +255,7 @@ def __init__(self, parent): self.pTarget = [0.0, 0.0, 0.0] self.distance_text = None + self.robot_warnings_text = None # self.obj_axes = None self.mark_actor = None @@ -468,6 +469,7 @@ def __bind_events(self): Publisher.subscribe(self.OnUnsetTarget, "Unset target") Publisher.subscribe(self.OnUpdateAngleThreshold, "Update angle threshold") Publisher.subscribe(self.OnUpdateDistanceThreshold, "Update distance threshold") + Publisher.subscribe(self.OnUpdateRobotWarning, "Robot to Neuronavigation: Update robot warning") Publisher.subscribe(self.OnUpdateTracts, "Update tracts") Publisher.subscribe(self.OnUpdateEfieldvis, "Update efield vis") Publisher.subscribe(self.InitializeColorArray, "Initialize color array") @@ -859,6 +861,10 @@ def OnUpdateDistanceThreshold(self, dist_threshold): print("updated to ", dist_threshold) self.distance_threshold = dist_threshold + def OnUpdateRobotWarning(self, robot_warning): + if self.robot_warnings_text is not None: + self.robot_warnings_text.SetValue(robot_warning) + def IsTargetMode(self): return self.target_mode @@ -984,6 +990,17 @@ def EnableTargetMode(self): # Store the object for 'distance' text so it can be modified when distance changes. self.distance_text = distance_text + # Remove the previous actor for 'distance' text + if self.robot_warnings_text is not None: + self.ren.RemoveActor(self.robot_warnings_text.actor) + + # Create new actor for 'distance' text + robot_warnings_text = self.CreateRobotWarningsText() + self.ren.AddActor(robot_warnings_text.actor) + + # Store the object for 'distance' text so it can be modified when distance changes. + self.robot_warnings_text = robot_warnings_text + self.CreateTargetGuide() self.ren.ResetCamera() @@ -1019,6 +1036,10 @@ def DisableTargetMode(self): if self.distance_text is not None: self.ren.RemoveActor(self.distance_text.actor) + # Remove the actor for 'distance' text. + if self.robot_warnings_text is not None: + self.ren.RemoveActor(self.robot_warnings_text.actor) + self.camera_show_object = None if self.actor_peel: if self.object_orientation_torus_actor: @@ -1246,6 +1267,17 @@ def CreateVTKObjectMatrix(self, direction, orientation): return m_img_vtk + def CreateRobotWarningsText(self): + robot_warnings_text = vtku.Text() + + robot_warnings_text.SetSize(const.TEXT_SIZE_DISTANCE_DURING_NAVIGATION) + robot_warnings_text.SetPosition((const.X, 1.02 - const.YZ)) + robot_warnings_text.SetVerticalJustificationToBottom() + robot_warnings_text.SetColour((1, 1, 0)) + robot_warnings_text.BoldOn() + + return robot_warnings_text + def CreateDistanceText(self): distance_text = vtku.Text() From f5faf9b3543938a80cf7f8bdc60209ebd5b394aa Mon Sep 17 00:00:00 2001 From: rmatsuda Date: Tue, 15 Oct 2024 10:12:10 +0300 Subject: [PATCH 2/2] RUFF --- invesalius/data/viewer_volume.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/invesalius/data/viewer_volume.py b/invesalius/data/viewer_volume.py index f67f2808a..df1ff14c6 100644 --- a/invesalius/data/viewer_volume.py +++ b/invesalius/data/viewer_volume.py @@ -469,7 +469,9 @@ def __bind_events(self): Publisher.subscribe(self.OnUnsetTarget, "Unset target") Publisher.subscribe(self.OnUpdateAngleThreshold, "Update angle threshold") Publisher.subscribe(self.OnUpdateDistanceThreshold, "Update distance threshold") - Publisher.subscribe(self.OnUpdateRobotWarning, "Robot to Neuronavigation: Update robot warning") + Publisher.subscribe( + self.OnUpdateRobotWarning, "Robot to Neuronavigation: Update robot warning" + ) Publisher.subscribe(self.OnUpdateTracts, "Update tracts") Publisher.subscribe(self.OnUpdateEfieldvis, "Update efield vis") Publisher.subscribe(self.InitializeColorArray, "Initialize color array")