From be375ca6d2fcc4398bfc989e61b25f9ae1bf7199 Mon Sep 17 00:00:00 2001 From: Stephen Thompson Date: Tue, 12 Jul 2022 10:44:51 +0100 Subject: [PATCH] Issue #100 implemented luminance changes for last two actors --- sksurgerybard/interaction/interaction.py | 4 +-- .../visualisation/bard_visualisation.py | 36 ++++++++++++++----- tests/interaction/test_interaction.py | 8 +++-- tests/visualisation/test_visualisation.py | 22 ++++++++++++ 4 files changed, 58 insertions(+), 12 deletions(-) diff --git a/sksurgerybard/interaction/interaction.py b/sksurgerybard/interaction/interaction.py index 9c750b5..92349e6 100644 --- a/sksurgerybard/interaction/interaction.py +++ b/sksurgerybard/interaction/interaction.py @@ -172,7 +172,7 @@ 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(mouse_y) + self._visualisation_control.luminance_change_right(mouse_y) if mouse_x < self.screen_interaction_layout.get('x_left_edge'): - self._visualisation_control.change_opacity(mouse_y) + self._visualisation_control.luminance_change_left(mouse_y) diff --git a/sksurgerybard/visualisation/bard_visualisation.py b/sksurgerybard/visualisation/bard_visualisation.py index 1b6ff8b..b4f8dce 100644 --- a/sksurgerybard/visualisation/bard_visualisation.py +++ b/sksurgerybard/visualisation/bard_visualisation.py @@ -240,16 +240,36 @@ def visibility_toggle(self, y_pos): actor.SetVisibility(True) return - def luminance_change(self, y_pos): + def luminance_change_left(self, y_pos): """ - Changes the luminance of one of the actors + 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 + actor on the green scale """ - print("Got signal to change luminance of actor, ", y_pos) - print("Yellow = ", get_yellow(y_pos)) - print("green = ", get_green(y_pos)) - for actor in self._target_anatomy_actors: - print("Changing luminance for actor ", actor) - + if len(self._target_anatomy_actors) < 2: + return + actor_index = len(self._target_anatomy_actors) - 2 + if actor_index >= 0: + target_colour = get_green(y_pos) + self._target_anatomy_actors[ + actor_index].GetProperty().SetColor(target_colour) + print(f"Changing luminance for actor {actor_index} to ", + f"{target_colour}") + + def luminance_change_right(self, y_pos): + """ + 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 + actor on the yellow scale + """ + if len(self._target_anatomy_actors) < 1: + return + actor_index = len(self._target_anatomy_actors) - 1 + 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"{target_colour}") def next_target(self): """ diff --git a/tests/interaction/test_interaction.py b/tests/interaction/test_interaction.py index 302d222..055826b 100644 --- a/tests/interaction/test_interaction.py +++ b/tests/interaction/test_interaction.py @@ -72,7 +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(self, _): # pylint: disable=no-self-use + def luminance_change_left(self, _): # 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 """Raises an error so we know when it's run""" raise LuminanceChangeEvent @@ -320,7 +324,7 @@ def test_mouse_event(): fake_mouse_event = _FakeMouseEvent([100, 100], [17, 90]) - with pytest.raises(ChangeOpacityEvent): + with pytest.raises(LuminanceChangeEvent): mouse_event(fake_mouse_event, None) fake_mouse_event = _FakeMouseEvent([100, 100], [27, 90]) diff --git a/tests/visualisation/test_visualisation.py b/tests/visualisation/test_visualisation.py index ab8e7a2..d45071a 100644 --- a/tests/visualisation/test_visualisation.py +++ b/tests/visualisation/test_visualisation.py @@ -395,3 +395,25 @@ def test_change_opacity(): _check_state_transition(actors, None, None, None, None, set_opac_state, expected_opac_state, bard_vis.change_opacity, 0.7) + +def test_change_luminance(): + """ + Tests luminance changes + """ + + actors = [] + + for _ in range(8): + actor = vtk.vtkActor() + actors.append(actor) + + model_list = { + 'visible anatomy' : 3, + 'target anatomy' : 2, + 'reference' : 1 + } + + bard_vis = vis.BardVisualisation(actors, model_list) + + bard_vis.luminance_change_left(0.7) + bard_vis.luminance_change_right(0.3)