Achieve "Click to jump Slices -> centered" programmatically

Hi all,
I would like to achieve the fiducial feature “Click to Jump Slices” programmatically. I know how to achieve this for the Red/Green/Yellow offsets, but I would like the slice views to get centered on the fiducial location as well. Here’s how I set the offset:

lm = slicer.app.layoutManager()
# for a point with coordinates x/y/z (floats in mm)
for slice, loc in zip(['Yellow','Green','Red'], [x,y,z]):
    sliceNode = lm.sliceWidget(slice) # can be Red/Yellow
    sliceLogic = sliceNode.sliceLogic()
    sliceLogic.SetSliceOffset(loc)

Unfortunately, I cannot see sth like “SetSliceCenter” in sliceLogic.
Thx for your help in advance!

You can search the source code for vtkMRMLSliceNode::JumpSliceByCentering

1 Like

Thank you Steve, that helped a lot. I realized that the sliceNode that I retrieved above was not a sliceNode at all, but actually a widget of class qMRMLSliceWidget. The function JumpSliceByCentering is a method of class vtkMRMLSliceNode though. If somebody else stumbles across this, the code above should be modified. It should not make the slice jump through the widget’s sliceLogic, instead it should read:

lm = slicer.app.layoutManager()
# for a point with coordinates x/y/z (floats in mm)
# (better denoted as r/a/s, as in Slicer source code)
for slice in ['Yellow','Green','Red']:
    sliceNode = lm.sliceWidget(slice).mrmlSliceNode()
    sliceNode.JumpSliceByCentering(x,y,z) # or r,a,s

    # NOTE: in case you only want to offset, not center:
    # sliceNode.JumpSliceByOffsetting(x,y,z) # or r,a,s
2 Likes