Skip to content

Commit

Permalink
link slider events (#413)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: DanicaSTFC <138598662+DanicaSTFC@users.noreply.github.com>
  • Loading branch information
3 people authored Jun 6, 2024
1 parent 894fc7b commit 608f9d9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

New functionality:
- Add method to edit axes label text & tests, hide one label on 2D viewer #389 #408
- Add slider widget #365 and option to not install it #386
- Add slider widget #365 and option to not install it #386. Link slider events #413

Bugfixes:
- Fix failing unit test #394
Expand Down
2 changes: 1 addition & 1 deletion Wrappers/Python/ccpi/viewer/CILViewer2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@ def installSliceSliderWidgetPipeline(self):
cb = SliderCallback(self, sw)

# Add interaction observers
# propagate events from the slider to the viewer
# to propagate events from the slider to the viewer
sw.AddObserver(vtk.vtkCommand.InteractionEvent, cb)

# propagate events from the viewer to the slider
Expand Down
15 changes: 15 additions & 0 deletions Wrappers/Python/ccpi/viewer/viewerLinker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from ccpi.viewer.CILViewer import CILInteractorStyle as CIL3DInteractorStyle
from ccpi.viewer.CILViewer2D import CILInteractorStyle as CIL2DInteractorStyle

from ccpi.viewer.widgets.slider import SLIDER_EVENT


class Linked3DInteractorStyle(CIL3DInteractorStyle):
"""
Expand Down Expand Up @@ -311,6 +313,19 @@ def __call__(self, interactor, event):
if (self.sourceVtkViewer.getSliceOrientation() != self.targetVtkViewer.getSliceOrientation()):
shouldPassEvent = False

# Slice from the slider
if event == "NoEvent" and self.linkSlice:
# Although I invoked a SLIDER_EVENT in widgets/slider.py, I noticed that a
# NoEvent is actually emitted/received. Therefore, we will link the slice in case of a
# NoEvent and self.linkSlice=True
if (not self.linkSlice):
shouldPassEvent = False
else:
# Set current slice
sliceno = self.sourceViewer.getActiveSlice()
self.targetInteractor.GetInteractorStyle().SetActiveSlice(sliceno)
self.targetInteractor.GetInteractorStyle().UpdatePipeline(True)

# KeyPress and orientation
if (event == "KeyPressEvent" or state == 1026):
orientation_link_event = self.linkOrientation and (interactor.GetKeyCode() == "x"
Expand Down
3 changes: 3 additions & 0 deletions Wrappers/Python/ccpi/viewer/widgets/slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import logging

logger = logging.getLogger(__name__)
# Define a new event type
SLIDER_EVENT = vtk.vtkCommand.UserEvent + 1


class SliceSliderRepresentation(vtk.vtkSliderRepresentation2D):
Expand Down Expand Up @@ -95,6 +97,7 @@ def __call__(self, caller, ev):
value = slider_widget.GetRepresentation().GetValue()
self.viewer.displaySlice(int(value))
self.update_label(value)
self.viewer.getInteractor().InvokeEvent(SLIDER_EVENT)

def update_label(self, value):
'''Update the text label on the slider. This is called by update_from_viewer
Expand Down

0 comments on commit 608f9d9

Please sign in to comment.