# Slicer 4.11 Slice view widget interactions, intersections issue in slicelet

**URL:** <https://discourse.slicer.org/t/slicer-4-11-slice-view-widget-interactions-intersections-issue-in-slicelet/7383>\
**Category:** Development\
**Created:** [July 2, 2019, 5:28pm UTC](https://discourse.slicer.org/t/slicer-4-11-slice-view-widget-interactions-intersections-issue-in-slicelet/7383 "2019-07-02T17:28:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![RMR54](https://avatars.discourse-cdn.com/v4/letter/r/90ced4/32.png) [@RMR54](https://discourse.slicer.org/u/RMR54)\
**Post date:** [July 2, 2019, 5:28pm UTC](https://discourse.slicer.org/t/slicer-4-11-slice-view-widget-interactions-intersections-issue-in-slicelet/7383/1 "2019-07-02T17:28:12Z")

</div>

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](https://www.slicer.org/wiki/Documentation/Nightly/Developers/Slicelets), (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](https://github.com/Slicer/Slicer/commit/9b8bc06cd53ab31753fcac456993595b70d73e56) 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)`

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 3, 2019, 1:49pm UTC](https://discourse.slicer.org/t/slicer-4-11-slice-view-widget-interactions-intersections-issue-in-slicelet/7383/2 "2019-07-03T13:49:10Z")

</div>

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](https://github.com/Slicer/Slicer/commit/21dc780a216f077bdd080fdc64073ccf6b5356e0) 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: [SlicerSimpleWorkflows/QuickSegment at master · lassoan/SlicerSimpleWorkflows · GitHub](https://github.com/lassoan/SlicerSimpleWorkflows/tree/master/QuickSegment)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/0/604780bb54a8f8f337d5d598985690dbd0cbd52e.jpeg)

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

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/b/2b83011f0c3e754c21f700309456a18564a7cb0c.png)

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [July 3, 2019, 2:35pm UTC](https://discourse.slicer.org/t/slicer-4-11-slice-view-widget-interactions-intersections-issue-in-slicelet/7383/3 "2019-07-03T14:35:42Z")

</div>

+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.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 3, 2019, 4:02pm UTC](https://discourse.slicer.org/t/slicer-4-11-slice-view-widget-interactions-intersections-issue-in-slicelet/7383/4 "2019-07-03T16:02:59Z")

</div>

I’ve updated [Slicelets wiki page for latest Slicer version](https://www.slicer.org/wiki/Documentation/Nightly/Developers/Slicelets) to reflect the changes in infrastructure and the new way of approaching slicelets and custom applications.

> [@pieper](#):
>
> +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.

@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).

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [July 3, 2019, 9:55pm UTC](https://discourse.slicer.org/t/slicer-4-11-slice-view-widget-interactions-intersections-issue-in-slicelet/7383/5 "2019-07-03T21:55:44Z")

</div>

> [@RMR54](#):
>
> 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.

To follow up on this, the “problem” was that the layout manager is associated with the `qSlicerApplication` in `qSlicerMainWindowPrivate::setupUi` (see [here](https://github.com/Slicer/Slicer/blob/21dc780a216f077bdd080fdc64073ccf6b5356e0/Base/QTApp/qSlicerMainWindow.cxx#L311)). By using `--no-main-window`, this call was skipped and logics were not associated with the `vtkMRMLSliceIntersectionWidget` object recently introduced.

To address this, replace:

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

```

with

```python
# 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](https://www.slicer.org/w/index.php?title=Documentation%2F4.10%2FDevelopers%2FSlicelets&type=revision&diff=61282&oldid=61278).

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 3, 2019, 10:53pm UTC](https://discourse.slicer.org/t/slicer-4-11-slice-view-widget-interactions-intersections-issue-in-slicelet/7383/6 "2019-07-03T22:53:51Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![RMR54](https://avatars.discourse-cdn.com/v4/letter/r/90ced4/32.png) [@RMR54](https://discourse.slicer.org/u/RMR54)\
**Post date:** [July 8, 2019, 12:57pm UTC](https://discourse.slicer.org/t/slicer-4-11-slice-view-widget-interactions-intersections-issue-in-slicelet/7383/7 "2019-07-08T12:57:29Z")

</div>

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.
