Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add show robots warnings in viewer volume #859

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions invesalius/data/viewer_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -468,6 +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.OnUpdateTracts, "Update tracts")
Publisher.subscribe(self.OnUpdateEfieldvis, "Update efield vis")
Publisher.subscribe(self.InitializeColorArray, "Initialize color array")
Expand Down Expand Up @@ -859,6 +863,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

Expand Down Expand Up @@ -984,6 +992,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()
Expand Down Expand Up @@ -1019,6 +1038,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:
Expand Down Expand Up @@ -1246,6 +1269,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()

Expand Down
Loading