Skip to content

Commit

Permalink
Issue #100 set up configurable but identical colours
Browse files Browse the repository at this point in the history
  • Loading branch information
thompson318 committed Jul 12, 2022
1 parent cc0d074 commit 0bf787d
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 13 deletions.
5 changes: 3 additions & 2 deletions config/little_liver_interaction.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@
},

"models": {
"models_dir": "data/models",
"models_dir": "/home/thompson/data/bard_data/Depth_Perception",
"reference_to_model": "data/reference_to_model.txt",
"visible_anatomy": 1
},
"interaction": {
"keyboard": true,
"footswitch": true,
"maximum delay": 2.0,
"mouse": true
"mouse": true,
"green": true
},
"pointer": {
"pointer_tag_to_tip": "data/pointer_tip.txt"
Expand Down
4 changes: 3 additions & 1 deletion sksurgerybard/algorithms/bard_config_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,7 @@ def configure_interaction(interaction_config, vtk_window, pointer_writer,
BardFootSwitchEvent(max_delay, bard_visualisation))

if interaction_config.get('mouse', False):
green = interaction_config.get('green', True)
vtk_window.AddObserver("LeftButtonPressEvent",
BardMouseEvent(bard_visualisation))
BardMouseEvent(bard_visualisation),
green)
12 changes: 9 additions & 3 deletions sksurgerybard/interaction/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,18 @@ def __del__(self):
class BardMouseEvent:
"""
Handles mouse events for BARD.
:param: a visualisation control object
:param: if green is true we use green colours for luminance,
otherwise we use yellow.
"""
def __init__(self, visualisation_control):
def __init__(self, visualisation_control, green=True):
self.screen_interaction_layout = {
'x_right_edge' : 0.80,
'x_left_edge' : 0.20
}

self._visualisation_control = visualisation_control
self._green = green

def __call__(self, event, _event_type_not_used):
mouse_x, mouse_y = event.GetEventPosition()
Expand All @@ -172,7 +176,9 @@ def __call__(self, event, _event_type_not_used):
mouse_y /= window_y

if mouse_x > self.screen_interaction_layout.get('x_right_edge'):
self._visualisation_control.luminance_change_right(mouse_y)
self._visualisation_control.luminance_change_right(mouse_y,
self._green)

if mouse_x < self.screen_interaction_layout.get('x_left_edge'):
self._visualisation_control.luminance_change_left(mouse_y)
self._visualisation_control.luminance_change_left(mouse_y,
self._green)
10 changes: 7 additions & 3 deletions sksurgerybard/visualisation/bard_visualisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def visibility_toggle(self, y_pos):
actor.SetVisibility(True)
return

def luminance_change_left(self, y_pos):
def luminance_change_left(self, y_pos, green):
"""
Changes the luminance of either of the last two actors of the actors
At the moment it's hard coded to change the second to last last anatomy
Expand All @@ -251,12 +251,14 @@ def luminance_change_left(self, y_pos):
actor_index = len(self._target_anatomy_actors) - 2
if actor_index >= 0:
luminance, target_colour = get_green(y_pos)
if not green:
luminance, target_colour = get_yellow(y_pos)
self._target_anatomy_actors[
actor_index].GetProperty().SetColor(target_colour)
print(f"Changing luminance for actor {actor_index} to ",
f"{luminance}, RGB={target_colour}", flush=True)

def luminance_change_right(self, y_pos):
def luminance_change_right(self, y_pos, green):
"""
Changes the luminance of either of the last two actors of the actors
At the moment it's hard coded to change the last last anatomy
Expand All @@ -265,7 +267,9 @@ def luminance_change_right(self, y_pos):
if len(self._target_anatomy_actors) < 1:
return
actor_index = len(self._target_anatomy_actors) - 1
luminance, target_colour = get_yellow(y_pos)
luminance, target_colour = get_green(y_pos)
if not green:
luminance, target_colour = get_yellow(y_pos)
self._target_anatomy_actors[
actor_index].GetProperty().SetColor(target_colour)
print(f"Changing luminance for actor {actor_index} to ",
Expand Down
4 changes: 2 additions & 2 deletions tests/interaction/test_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ def turn_on_all_targets(self): # pylint: disable=no-self-use
"""Raises an error so we know when it's run"""
raise TurnOnAllEvent

def luminance_change_left(self, _): # pylint: disable=no-self-use
def luminance_change_left(self, _y_pos, _green): # pylint: disable=no-self-use
"""Raises an error so we know when it's run"""
raise LuminanceChangeEvent

def luminance_change_right(self, _): # pylint: disable=no-self-use
def luminance_change_right(self, _y_pos, _green): # pylint: disable=no-self-use
"""Raises an error so we know when it's run"""
raise LuminanceChangeEvent

Expand Down
4 changes: 2 additions & 2 deletions tests/visualisation/test_visualisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,5 +415,5 @@ def test_change_luminance():

bard_vis = vis.BardVisualisation(actors, model_list)

bard_vis.luminance_change_left(0.7)
bard_vis.luminance_change_right(0.3)
bard_vis.luminance_change_left(0.7, True)
bard_vis.luminance_change_right(0.3, False)

0 comments on commit 0bf787d

Please sign in to comment.