ProbeVolumeWithModel produces wrong output in code

When I use the GUI of the ProbeVolumeWithModel, there is no problem. It does great coloring.


But, when I want to do the same with the following codes, it runs and produces a plane output. Why?

# Inputs
InputModelNode = slicer.mrmlScene.GetFirstNodeByClass("vtkMRMLModelNode")
OutputModelNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLModelNode", "Skull_Thickness")

#Parameters for ProbeVolumeWithModel
parameters = {}
parameters['InputVolume'] = DistanceMapNode.GetID()
parameters['InputModel'] = InputModelNode.GetID()
parameters['OutputModel'] = OutputModelNode.GetID()

probe = slicer.modules.probevolumewithmodel, None, parameters, wait_for_completion=True)


Check in the application log to see what’s different in the command line options when the module runs.

Steve, thanks for reply.
First, I was excited and examined the log file (as below).
I thought I could find the step-by-step python codes of the process done in the log file.
However, the log file unfortunately did not have detailed content.

[DEBUG][Qt] 13.03.2022 21:36:02 [] (unknown:0) - Switch to module:  "ProbeVolumeWithModel"
[DEBUG][Qt] 13.03.2022 21:36:20 [] (unknown:0) - Found CommandLine Module, target is  C:/ProgramData/NA-MIC/Slicer 4.13.0-2022-02-11/bin/../lib/Slicer-4.13/cli-modules/ProbeVolumeWithModel.exe
[DEBUG][Qt] 13.03.2022 21:36:20 [] (unknown:0) - ModuleType: CommandLineModule
[DEBUG][Qt] 13.03.2022 21:36:22 [] (unknown:0) - Probe Volume With Model command line: 

C:/ProgramData/NA-MIC/Slicer 4.13.0-2022-02-11/bin/../lib/Slicer-4.13/cli-modules/ProbeVolumeWithModel.exe --outputArrayName NRRDImage C:/Users/Administrator/AppData/Local/Temp/19/Slicer/BIBHG_vtkMRMLScalarVolumeNodeE.nrrd C:/Users/Administrator/AppData/Local/Temp/19/Slicer/BIBHG_vtkMRMLModelNodeE.vtk C:/Users/Administrator/AppData/Local/Temp/19/Slicer/BIBHG_vtkMRMLModelNodeF.vtk
[DEBUG][Qt] 13.03.2022 21:36:24 [] (unknown:0) - Probe Volume With Model standard output:

Done reading the file C:/Users/Administrator/AppData/Local/Temp/19/Slicer/BIBHG_vtkMRMLScalarVolumeNodeE.nrrd
[DEBUG][Qt] 13.03.2022 21:36:24 [] (unknown:0) - Probe Volume With Model completed without errors

Hi @Muhammed_Fatih_Talu -

Yes, this is expected - the ProbeVolumeWithModel module is a C++ command line module so when you run it from the GUI your widget selections are converted into command line arguments. To call the same module from python you need to make sure your command has all the same arguments of the right types. Both ways of running the module will log the command line in the log.

I solved the problem.
I was not getting the correct ID of InputModelNode.

instead of slicer.mrmlScene.GetFirstNodeByClass(“vtkMRMLModelNode”),
I used slicer.mrmlScene.GetFirstNodeByName(“InputModel”).
It runs perfect :slight_smile:
Thanks every body.

1 Like

Image slices are displayed in 3D views as model nodes, therefore the first 3 model nodes are typically these slice plane nodes.

@pieper what do you think about adding a flag to GetFirstNodeByName method to include/exclude hidden nodes and by default make hidden nodes excluded? This would change the behavior of the method by default, but since this is a high-level convenience function, the expected behavior is probably to not consider hidden nodes.

Yes, those convenience methods (also getNode in python) seem to regularly lead to some confusion; making them behave better could help. Maybe in slicer.util we should provide a pickNode method that pops up a gui node combo box and use that in the script repository instead of teaching people to use the less reliable methods.

This is a very interesting discussion, I’ve started a new topic for it to get some more visibility: