Flickering when using segmentation effects

While the use of segmentation effects in python scripts in slicer works really well, it creates flickering in the Slicer GUI when using full screen mode in mac. Using windowed mode makes no flickering, only full screen mode is the problematic.

It sounds interesting, but I don’t see anything on this “video”. Could you please upload a higher-quality screen capture video,upload it somewhere (dropbox, onedrive, youtube, …), and post the link?

It is difficult to make the video because the “bug” only happens in full screen mode in MAC.

Maybe a quick phone video? Flickering artifacts can be hard to capture on the device they’re happening on.

I just recorded it with quickTime, then reprocess it to gif with ffmpeg. It was nasty but it worked out of the box.

Still very bad quality recording. I don’t see any flickering, but just that the image quality of the recording is very bad. Maybe recording with your phone would be better. Replay of animated gifs is also very bad, as it is not easy to navigate the timeline (at least in the viewers that I have). It would also help if you did more things in different modules, just to see if the issue is specific to a particular module or mode.

May you recommend me any other module that uses segment editor in python script. The video just shows that the Slicer starts creating things on the fly and then returns to original state. That does not happen in windowed mode.

I’m not sure what you mean but Segment Editor module is a typical example of using segment editor widget in a scripted module.

Just wander around Slicer and use other modules (that behave normally) so that I can see what is normal (and just image compression artifact or bad image quality) and what is something else (a problem that you can only see in a specific module).

Here is my code anyways, Ill try to upload a better video
https://gitlab.com/opendose/opendose4d/-/blob/calibration/Dosimetry4D/Calibration.py#L317

here it is https://drive.google.com/open?id=1uOnVNJFSrp0JG0W2HSpjV_CjrEgRxXm2

By “flickering” you mean that a window is shown for a second at 0:05, 0:15, and 0:30? I would comment out things first in the Python module then in the segment editor widget to see what exact step causes this.

I have bisected the code and the specific line that causes the flickering is this one

segmentEditorWidget = slicer.qMRMLSegmentEditorWidget()

OK, this is useful information. You need to continue commenting out code parts within the segment editor widget. It is more tedious, but it should lead us to the call that triggers this and then we should be able to fix it.

I have created this routine
image
Thats everything I need to replicate the flickering. Again in windowed mode the bug does not show.

OK. Now you need to continue commenting out code parts within the segment editor widget (in C++) to see what exactly triggers the behavior.

OK, that call just do this

qMRMLSegmentEditorWidget::qMRMLSegmentEditorWidget(QWidget* _parent)
  : qMRMLWidget(_parent)
  , d_ptr(new qMRMLSegmentEditorWidgetPrivate(*this))
{
  Q_D(qMRMLSegmentEditorWidget);
  d->init();
}

and the init call do this

void qMRMLSegmentEditorWidgetPrivate::init()
{
  Q_Q(qMRMLSegmentEditorWidget);
  this->setupUi(q);
..........

So the UI is always generated even in the case we don’t need it at all. My nose tells me this is the thing but I can’t confirm without a build. I have left c++ because of this, I hate to build!

Instantiating a couple of widgets in setupUi() should be no problem.

We were debating when we designed segment editor if we should separate GUI and logic. Since an “editor” is inherently an interactive component, instantiating GUI classes has practically zero cost, segment editor effect classes are usually very small, and splitting classes would have resulted in many more classes, we chose not to split. That is why you always instantiate GUI widgets, even if you don’t need it.

Let us know what you find. You might even get some information without rebuilding, buy XCode Instrument, but probably you cannot avoid building Slicer if you want to experiment.