Skip to content

Commit

Permalink
MOD: ObjectCalibrationDialog fiducial actors color to match buttons
Browse files Browse the repository at this point in the history
OrderedFiducialButtons now colors the fiducial ball and text actors to match the buttons.

Use colorblind-friendly colors for ball and text actors.
  • Loading branch information
Rakhesis committed Jun 27, 2024
1 parent f7dc061 commit dd3fd7b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 15 deletions.
17 changes: 12 additions & 5 deletions invesalius/gui/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3618,6 +3618,16 @@ def ShowObject(self, polydata):
self.ball_actors[1], self.text_actors[1] = self.OnCreateObjectText('Right', (0,-55,0))
self.ball_actors[2], self.text_actors[2] = self.OnCreateObjectText('Anterior', (23,0,0))

# Match actor colors with fiducial buttons
def set_actor_colors(n, color_float):
if n != const.OBJECT_FIDUCIAL_FIXED:
self.ball_actors[n].GetProperty().SetColor(color_float)
self.text_actors[n].GetProperty().SetColor(color_float)
self.Refresh()

self.buttons.set_actor_colors = set_actor_colors
self.buttons.Update()

self.ren.AddActor(obj_actor)
self.ren.ResetCamera()

Expand Down Expand Up @@ -3671,7 +3681,7 @@ def OnCreateObjectText(self, name, coord):
ball_actor = vtkActor()
ball_actor.SetMapper(mapper)
ball_actor.SetPosition(coord)
ball_actor.GetProperty().SetColor(1, 0, 0)
ball_actor.GetProperty().SetColor(const.RED_COLOR_FLOAT)

textSource = vtkVectorText()
textSource.SetText(name)
Expand All @@ -3680,7 +3690,7 @@ def OnCreateObjectText(self, name, coord):
mapper.SetInputConnection(textSource.GetOutputPort())
tactor = vtkFollower()
tactor.SetMapper(mapper)
tactor.GetProperty().SetColor(1.0, 0.0, 0.0)
tactor.GetProperty().SetColor(const.RED_COLOR_FLOAT)
tactor.SetScale(5)
ball_position = ball_actor.GetPosition()
tactor.SetPosition(ball_position[0]+5, ball_position[1]+5, ball_position[2]+10)
Expand Down Expand Up @@ -3750,9 +3760,6 @@ def SetObjectFiducial(self, fiducial_index):
self.buttons.SetFocused()
for i in [0, 1, 2]:
self.txt_coord[fiducial_index][i].SetLabel(str(round(coord[i], 1)))
if self.text_actors[fiducial_index]:
self.text_actors[fiducial_index].GetProperty().SetColor(0.0, 1.0, 0.0)
self.ball_actors[fiducial_index].GetProperty().SetColor(0.0, 1.0, 0.0)
self.Refresh()
else:
ShowNavigationTrackerWarning(0, 'choose')
Expand Down
45 changes: 35 additions & 10 deletions invesalius/gui/widgets/fiducial_buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,37 @@


class OrderedFiducialButtons:
def __init__(self, parent, fiducial_definitions, is_fiducial_set, get_fiducial_coord=None, order=None):
def __init__(self, parent, fiducial_definitions, is_fiducial_set, get_fiducial_coord=None, set_actor_colors=None,
order=None):
"""
Class to initialize fiducials GUI and to keep track of the order to set fiducials.
:param parent: parent for wx elements
:param fiducial_definitions: const.OBJECT_FIDUCIALS or const.TRACKER_FIDUCIALS
:param is_fiducial_set: Function taking fiducial index as parameter, returning True if that
fiducial is set, False otherwise.
:param get_fiducial_coord: Function to retrieve value for NumCtrl. Takes fiducial index and
coordinate index as parameters, returns value.
:param set_actor_colors: Function taking fiducial index and float color as parameter, changing
the color of relevant actors to match the fiducial index.
:param order: list of indices representing default order to record fiducials
"""
count = len(fiducial_definitions)
self.is_fiducial_set = is_fiducial_set
self.get_fiducial_coord = get_fiducial_coord
self.set_actor_colors = set_actor_colors
self.order: list[int] = order or list(range(count))

self.buttons: list[wx.Button] = [] # list of buttons
self.buttons: list[wx.Button] = []
self.numctrls: list[list[NumCtrl]] = []

self.focused_index: int | None = None
self.focused: wx.Button | None = None

self.COLOR_NOT_SET = 0
self.COLOR_FOCUSED = 1
self.COLOR_SET = 2

# Initialize buttons
for n, fiducial in enumerate(fiducial_definitions):
button_id = fiducial['button_id']
Expand Down Expand Up @@ -94,14 +104,30 @@ def focused(self, new_focus):
return
raise ValueError

def _TrySetActorColors(self, n, color_float):
if self.set_actor_colors is not None:
self.set_actor_colors(n, color_float)

def _SetColor(self, n, color):
button = self.buttons[n]
if color == self.COLOR_SET:
button.SetBackgroundColour(const.GREEN_COLOR_RGB)
self._TrySetActorColors(n, const.GREEN_COLOR_FLOAT)
elif color == self.COLOR_FOCUSED:
button.SetBackgroundColour(const.YELLOW_COLOR_RGB)
self._TrySetActorColors(n, const.YELLOW_COLOR_FLOAT)
else:
button.SetBackgroundColour(const.RED_COLOR_RGB)
self._TrySetActorColors(n, const.RED_COLOR_FLOAT)

def _RefreshColors(self):
for n, button in enumerate(self.buttons):
if self.is_fiducial_set(n):
button.SetBackgroundColour(const.GREEN_COLOR_RGB)
self._SetColor(n, self.COLOR_SET)
else:
button.SetBackgroundColour(const.RED_COLOR_RGB)
self._SetColor(n, self.COLOR_NOT_SET)
if self.focused is not None:
self.focused.SetBackgroundColour(const.YELLOW_COLOR_RGB)
self._SetColor(self.focused_index, self.COLOR_FOCUSED)

def _UpdateControls(self):
if self.get_fiducial_coord is None:
Expand Down Expand Up @@ -132,7 +158,7 @@ def FocusNext(self):

def ClearFocus(self):
if self.focused is not None:
self.focused.SetBackgroundColour(const.RED_COLOR_RGB)
self._SetColor(self.focused_index, self.COLOR_NOT_SET)
self.focused = None

def _OnButton(self, evt, n):
Expand All @@ -141,10 +167,10 @@ def _OnButton(self, evt, n):
def Focus(self, n):
self.ClearFocus()
self.focused = self.buttons[n]
self.focused.SetBackgroundColour(const.YELLOW_COLOR_RGB)
self._SetColor(self.focused_index, self.COLOR_FOCUSED)

def SetFocused(self):
self.focused.SetBackgroundColour(const.GREEN_COLOR_RGB)
self._SetColor(self.focused_index, self.COLOR_SET)
self._UpdateControl(self.focused_index)
self.focused = None
self.FocusNext()
Expand All @@ -154,6 +180,5 @@ def Set(self, n):
self.SetFocused()

def Unset(self, n):
button = self.buttons[n]
button.SetBackgroundColour(const.RED_COLOR_RGB)
self._SetColor(n, self.COLOR_NOT_SET)
self.FocusNext()

0 comments on commit dd3fd7b

Please sign in to comment.