Data is not in center of slicer views after JumpSlicesToLocation process

Hi all
I use the JumpSlicesToLocation to change data in slicer view when mouse position changed, but images in slicer view will not be in view center, how can I solve the problm, this is my code

def jumpToCursor(self):
    ras = [0, 0, 0]
    slicer.mrmlScene.GetFirstNodeByClass('vtkMRMLCrosshairNode').GetCursorPositionRAS(ras)
    slicer.modules.markups.logic().JumpSlicesToLocation(ras[0], ras[1], ras[2], slicer.vtkMRMLCrosshairNode.JumpSlice)
    print(ras[1])
shortcut = qt.QShortcut(slicer.util.mainWindow())
shortcut.setKey(qt.QKeySequence("Ctrl+B"))
shortcut.connect('activated()', jumpToCursor)


here is the screenshot after the code excuted

You can choose to you can use CenteredJumpSlice option if you want the chosen position be centered.

I try this, but it seems not to work, I want to get a similiar function like ‘Shift + mouse’ in slicer, and rewrite it. Could you tell me where to rewrite ‘Shift + mouse’ in Python or realize similar function like it?

CenteredJumpSlice options works. You can also use this static method of vtkMRMLSliceNode:

slicer.vtkMRMLSliceNode.JumpAllSlices(slicer.mrmlScene, 2.3, 4.5, 6.7, slicer.vtkMRMLSliceNode.CenteredJumpSlice)

If you also want to move the crosshair position then you can call:

crosshairNode = slicer.vtkMRMLCrosshairDisplayableManager.FindCrosshairNode(slicer.mrmlScene)
crosshairNode.SetCrosshairRAS([2.3, 4.5, 6.7])
1 Like