Skip to content

Commit

Permalink
Issue #100 implemented luminance changes for last two actors
Browse files Browse the repository at this point in the history
  • Loading branch information
thompson318 committed Jul 12, 2022
1 parent 35d58ee commit be375ca
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 12 deletions.
4 changes: 2 additions & 2 deletions sksurgerybard/interaction/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
36 changes: 28 additions & 8 deletions sksurgerybard/visualisation/bard_visualisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
8 changes: 6 additions & 2 deletions tests/interaction/test_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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])
Expand Down
22 changes: 22 additions & 0 deletions tests/visualisation/test_visualisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit be375ca

Please sign in to comment.