Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

link slider events #413

Merged
merged 9 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
16 changes: 16 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,20 @@ 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()
print(f"SliderEvent : {sliceno}")
paskino marked this conversation as resolved.
Show resolved Hide resolved
paskino marked this conversation as resolved.
Show resolved Hide resolved
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
Loading