How to interact with the 'Paint' effect function of slicer.qMRMLSegmentEditorWidget instance

Happy Children’s Day.
In fact, there are three problems.
At first, my develop environment lists below.
os:ubuntu 16.04.3
slicer:latest stable version 4.8.1
lauguage:python 3.6.4
1.
I met a demand of programming a script to get a roi from someone not familiar with the slicer.
A clear guide for all processes is needed.
I have a segmentation procedure.I got the plan as follows:
step1:
using the Paint effect to get a ROI.
step2:
using the ‘Threshold’ effect to generate the segmentation.
I have tried using the markups while the coordinate is the ‘world’ not the index for array-computing.
It didn’t work well.

I’m not good enough in c++ programming.And when I use python scripts as follows:

    exec_outside = ['python', '/home/cyan/PycharmProjects/adc/compute_model.py', str(flair_path)]
    subprocess_status = check_output(exec_outside, shell=True, env=slicer.util.startupEnvironment())

the slicer become black and won’t wake up anymore.
2mins later ,I use htop command and find the cou is free.slicer is not on working.
the python script can work well using the same command in the bash shell within 5secs.
How could I use the subprocess module?

when I try my own algorithm for computing the adc using dwi data
# adc = np.ones(dwi_200.shape)
# adc[(dwi_200 < noise_threshold) | (dwi_2000 < noise_threshold)] = 0
# effective = adc==1
# ineffective = adc==0
# dwi_2000[ineffective] = 1
# dwi_200[ineffective] = 1
# adc[effective] = np.log(dwi_200[effective] / dwi_2000[effective]) / 1800
the slicer python-interface gives me a runtimeerror said divide 0
while this script can work well in my own python 3.6.4 env within 1 sec.
I’m confused how slicer using the cpu.

And final, I have no idea how to add a model in the right position on a mrml scene.
That to say , when I generate model using out-slicer computation(I can get the spacing,origin and the 3*3 matrix direction params using simpleITK),How can I transform the model in a loaded and mastered slicer mrmlscene?
Sincerely,
waiting for your reply.

Hi -

What you are trying to do sounds very achievable, but not quite trivial so you’ll want to take a step-by-step approach. There shouldn’t be any need to use an external python subprocess.

I would suggest you start by using the Extension Wizard to make a skeleton for your process and then incrementally add functionality confirming your assumptions at each step. You can follow the tutorial linked below to get started. Ideally you should put the code in a github repository with each step as a commit. As you run into specific questions at each step you can send a pointer to the code that worked and a commit that didn’t work as you expected and then we can give specific advice about how to accomplish that step.

https://www.slicer.org/wiki/Documentation/4.8/Training#Developing_and_contributing_extensions_for_3D_Slicer

Hope that helps,
Steve

Thank you for your enthusiastic suggestions.I have tried as you list.And the first barrier is that I can’t programmatically control the interactions to draw a arbitrary shape as segmentaiton-editor’s effect ‘Draw’ does.
I have tried to clean out the other toggles on the editor with ‘Draw’ the only left.But I failed.The widget is written by C++ I can’t access it easily.Can you help me with showing a python-scripts way.

The segment editor widget is highly customizable by Python scripting. To show selected effects only, call setEffectNameOrder with the names of the effects that you would like to show and then set unorderedEffectsVisible to False.