Odd behavior when i run my Scriptable Module and when i run same code in Python interactor.
i’m using threshold first to mask the segment and then applying seed grow for making segment, when i run it in python interactor it looks its working as expected , but same code in scripted module is not working as expected and i’m not seeing any difference with and without masking code
The most likely cause is that the GUI gets updated each time you hit return in the python interactor, but it’s blocked when executing a script. So you might need to call slicer.app.processEvents()
in your script or otherwise make it event driven.
Segment Editor only use asynchronous event processing for display, so if you see difference in processing results then there may be some other trivial mistake (e.g., you have multiple segment editor parameter nodes and you change the wrong one). You can typically find such errors very easily by using a Python debugger.
@pieper
i tried to put slicer.app.processEvents()
this before applying threshold and after effect.self().onUseForPaint()
then the seedgrow Code from the example script referred by @lassoan
and i’m sure that i’ve created Segment editor node once and using that for both the segments (masking and seedgrow )
this is the effect when i call my scripted module.
and
and this is when i use same code in python interactor
threshold masking is used and seeds grown in that limited area.
If you show the editor widget, do you see that “Editable intensity range” is enabled?
Put a breakpoint in AbstractScriptedSegmentEditorAutoCompleteEffect.py in preview(self)
method. What value intensityBasedMasking
is set to?
I have 2 scenarios ,
- when i’m ruining my script in python interarctor , i can able to add breakpoints and i’m getting this value as True, and threshold masking works perfectly as expected .
- when i call my script through batch file , i cant set the breakpoints and i cant see the “Editable intensity range” enable when slicer window pop up. , threshold masking doesn’t seems to be applied here.
so the thing is happening here as per my observation is, when i call the script module using batch file it goes in one shot and before the onUseForPaint() finishes the work, seedgrow code already gets executed and it doesn’t get that masking intensity.
i tried to put this code in thread , which doesn’t work , and i cant use the async/await call as i’m getting error for import asyncio.
Do you attempt to run the script without a main window?
You should be able to set breakpoints the same way. To make sure your code runs after the debugger is attached, start you processing with a timer (e.g., after 5-10 seconds the application has started).
I don’t think multithreading is relevant here.
its helped me to debug my code.
and finally i found the cause , its the slicer version.
i have Slicer 4.11.0-2018-11-13 nightly version which was set for batch file process, and i was testing in stable 4.10 editor which was working fine.
so in this nightly build i believe that the masking plus seedgrow has some issue or may be solved in next nightly release.
i’m really thankful to @lassoan for all the support .
one last thing
i was using window mode .
now everything is working in window mode but i just tried no-window mode and after crash this is the log i’m seeing
[CRITICAL][Qt] 30.05.2019 16:10:39 [] (unknown:0) - void __cdecl qMRMLSegmentEditorWidget::onSegmentSelectionChanged(const class QItemSelection &,const class QItemSelection &) : Invalid segment editor parameter set node
[CRITICAL][Qt] 30.05.2019 16:10:39 [] (unknown:0) - void __cdecl qMRMLSegmentEditorWidget::onSegmentationNodeChanged(class vtkMRMLNode *) : Invalid segment editor parameter set node
[CRITICAL][Qt] 30.05.2019 16:10:39 [] (unknown:0) - void __cdecl qMRMLSegmentEditorWidget::onSegmentSelectionChanged(const class QItemSelection &,const class QItemSelection &) : Invalid segment editor parameter set node
[CRITICAL][Qt] 30.05.2019 16:10:39 [] (unknown:0) - void __cdecl qMRMLSegmentEditorWidget::onSegmentationNodeChanged(class vtkMRMLNode *) : Invalid segment editor parameter set node
[CRITICAL][Qt] 30.05.2019 16:10:39 [] (unknown:0) - void __cdecl qMRMLSegmentEditorWidget::onMasterVolumeNodeChanged(class vtkMRMLNode *) : Invalid segment editor parameter set node
[CRITICAL][Qt] 30.05.2019 16:10:39 [] (unknown:0) - void __cdecl qMRMLSegmentEditorWidget::onMasterVolumeNodeChanged(class vtkMRMLNode *) : Invalid segment editor parameter set node
[CRITICAL][Qt] 30.05.2019 16:10:39 [] (unknown:0) - void __cdecl qMRMLSegmentEditorWidget::onMasterVolumeNodeChanged(class vtkMRMLNode *) : Invalid segment editor parameter set node
[WARNING][Qt] 30.05.2019 16:10:39 [] (unknown:0) - QObject::connect: Cannot connect (null)::layoutChanged(int) to qMRMLSegmentEditorWidget::onLayoutChanged(int)
[CRITICAL][Qt] 30.05.2019 16:10:39 [] (unknown:0) - void __cdecl qMRMLSegmentEditorWidget::updateWidgetFromMRML(void) : Invalid segment editor parameter set node
Masking in “Grow from Seeds” effect is available since latest stable (Slicer-4.10.2) and recent preview releases.
I think Segment Editor currently requires a main application window (it may be possible to remove the dependency but we don’t plan to work on that right now).
strange! , cause same script when i was using for seedgrow only (without masking code) , it was running fine with --no-window mode.