Using Volume Reslice Driver Programatically

Hello community,

I am having trouble using the volume reslice driver module programmatically. For many loadble scripted modules, I am used to accessing their logic and widget classes by importing them e.g import MyModule or accessing them through slicer.modules.module_name.widgetRepresentation() typically help(...) is then sufficient to figure out how to use it.

For volume reslice driver, I have found the class slicer.vtkSlicerVolumeResliceDriverLogic. However, when I try to use some of its methods, slicer crashes. for example:

>>> logic = slicer.vtkSlicerVolumeResliceDriverLogic()
>>> red = slicer.mrmlScene.GetNodeByID('vtkMRMLSliceNodeRed')
>>> volume = getNode('BMode_5')
>>> logic.SetDriverForSlice(volume.GetID(), red)

Causes slicer to immediately close.

My goal is to programatically do what the volume reslice driver module widget does.

Thanks in advance,

Paul

I tried also visting here: https://github.com/openigtlink/VolumeResliceDriver/blob/master/Logic/vtkSlicerVolumeResliceDriverLogic.h but the header file does not give me too many clues how to use the class…

Typically the easiest is to create MRML nodes and set its properties. You can save the scene and look at the .mrml file to see what nodes are created and what properties are set.

Module logic classes observe all the nodes that are added to the scene, so you rarely have to call any logic functions (except sometimes there are some convenience functions in logic classes that can be useful). It should never be necessary to call module widget methods directly (the module widgets are meant to respond to scene changes and user actions on the GUI).

I’ve compared your code with a working example, and the only difference I found was in the way you get an instance of the volume reslice driver logic. You don’t have “.modules” par of this line: https://github.com/SlicerIGT/LumpNav/blob/13511fccbee82553de91f0e495ba89eed82bbe4b/LumpNav2/LumpNav2.py#L1682

Hi Andras and Tamas,

Thanks for your responses. Tamas, the code you shared appears to do exactly what I need to do, so I should be able to implement that no problem!

Paul