Slicer 4.11 Slice view widget interactions, intersections issue in slicelet

This has been observed with Slicer 4.11 nightly. When a slicelet is launched such that the mainWindow is hidden, (the .bat includes --no-main-window argument). I load in a 3D volume, and the red, yellow, and green slice views in the slicelet display this volume node. I can use the slider to go through each slice, but it if I try mouse events, as in moving the mouse wheel, clicking on volume to translate, or zoom in and out, I don’t see any response from the slice widget. Similarly when I try to view slice intersections (SetSliceIntersectionVisiblity(1) ), I don’t observe the slice intersections in any of the slice widgets. Interestingly, I observe the intersections, if I launch the script with the mainWindow displayed as well. Also, if I utilize sliceViewInteractorStyle to setActionEnabled(interactor_style.BrowseSlice, True), I’m able to observe the response to mouse wheel events. Again if I launch the slicelet with --no-main-window, then the same commands, to set BrowseSlice action enabled, don’t evoke a response on mouse wheel events.

I don’t observe this issue in stable release.

A simple way to recreate would be to set up a slicelet using the code provided here, (with layout set as slicer.vtkMRMLLayoutNode.SlicerLayoutFourUpView instead). I ran the slicelet using a .bat with the following lines:
@echo off
"C:\Program Files\Slicer 4.11.0\Slicer.exe" --python-code "import MainWidget;" --no-splash --no-main-window --show-python-interactor
pause
Upon display of slicelet, I then load in volume using “Load Data” button click. I loaded in .MHA 3D volume, and then tried to evoke response using mouse events in red/yellow/green slice view, but couldn’t get any response. Also at one point, I think I saw these events working, but then as soon as I displayed the volume in red slice onto 3D view, I didn’t get see any response.

I noticed there was a recent commit regarding using widgets for showing slice intersections. Do any updates have to be made for slice widget/layouts in slicelets, in order to view slice intersections and maintain mouse event response?


MainWidget.py contained the same code except for the following differences:

Top of file prior to def onModuleSelected(modulename): contains the following lines:

import qt
import main
from main import qt, slicer

mainWidget = qt.QWidget()
mainWidget.objectName = “qSlicerAppMainWindow”
vlayout = qt.QVBoxLayout()
mainWidget.setLayout(vlayout)

def onModuleSelected(modulename):

And this line was modified from layoutManager.setLayout(slicer.vtkMRMLLayoutNode.SlicerLayoutOneUp3DView) to
layoutManager.setLayout(slicer.vtkMRMLLayoutNode.SlicerLayoutFourUpView)

Slicer has evolved a lot since the concepts of no-main-window-slicelets. Initialization of the main window has become more complicated (due to hi-DPI screens, OpenGL context initialization overrides, interaction widgets, etc.) and it is expected to get even more complex in the future (with multi-monitor support, multi-touch, pen, and Mac trackpad support, etc.). It should be still possible to mimic initialization steps of the Slicer main window in a generic widget in a Python script, but it would be significant effort to maintain consistency.

Instead, I would recommend to use Slicer’s main window but customize it (hide all those parts that you don’t need). This has the advantage that you can flip between “slicelet” and “full Slicer” experience very easily, which helps a lot in development and support.

I’ve added a number of helper functions to show/hide user interface elements that you can use to show a single module and a view layout, with any additional user interface elements you need (these functions will be included in Preview releases you download tomorrow or later). You can add these functions in the module widget setup method and then launch Slicer using Slicer.exe --python-code "slicer.util.selectModule('MyModuleName')". It would not be too difficult to generate application shortcut with an icon (at least on Windows), which would make it very easy for users to start Slicer with the simple GUI.

Here is an example module (not functional yet, but maybe we’ll make it work, if there is enough interest) that uses the newly added functions: https://github.com/lassoan/SlicerSimpleWorkflows/tree/master/QuickSegment

By hitting Ctrl+Shift+b you can switch to the full Slicer GUI:

1 Like

+1 for QuickSegment. I think there’s a user base out there who use tools like Seg3D and ITKSnap because they don’t have all the complexity of Slicer, so having a more focused on-ramp could be very useful.

I’ve updated Slicelets wiki page for latest Slicer version to reflect the changes in infrastructure and the new way of approaching slicelets and custom applications.

@Sunderlandkyl We can try to improve this QuickSegment module to implement simplified neuro segmentation workflow (at least start with this, then we may fork it if we start to add neuroanatomy specific segmentation features).

1 Like

To follow up on this, the “problem” was that the layout manager is associated with the qSlicerApplication in qSlicerMainWindowPrivate::setupUi (see here). By using --no-main-window, this call was skipped and logics were not associated with the vtkMRMLSliceIntersectionWidget object recently introduced.

To address this, replace:

# layout
layoutManager = slicer.qMRMLLayoutWidget()
layoutManager.setMRMLScene(slicer.mrmlScene)
layoutManager.setLayout(slicer.vtkMRMLLayoutNode.SlicerLayoutFourUpView)
splitter.addWidget(layoutManager)

with

# layout manager
layoutManager = slicer.qSlicerLayoutManager()
slicer.app.setLayoutManager(layoutManager)
layoutManager.setMRMLScene(slicer.mrmlScene)
layoutManager.setLayout(slicer.vtkMRMLLayoutNode.SlicerLayoutFourUpView)

# layout widget
layoutWidget = slicer.qMRMLLayoutWidget()
splitter.addWidget(layoutWidget)
layoutWidget.setLayoutManager(layoutManager)

I also updated the older slicelet example found on the wiki.

I’ve tried to do something similar and slice view navigation did not work. Anyway, customizing the existing main window from factory-built Slicer is a more robust and flexible solution. The only shortcoming is that the full Slicer GUI flashes for a moment (but this can be solved by using a custom executable name and storing custom the screen layout and startup module in the ini file).

Thanks @jcfr, the updated code fixed the issues with slice intersections and interactions! @lassoan, Thanks for your insight regarding the new approach to slicelets. @jcfr’s solution is a good solution for our short-term needs, but implementing new approach would be next in backlog queue, to take advantage of recent updates for customization and support.