How to export position parameters like slice center and the normal vector for the slice plane?

Hi!

I wanted to know how can we export position parameters like slice center and the normal vector for the slice plane we are viewing such that I can visualize that slice of the 3D data in lets say python? Thanks for the help

You can get the slice transformation matrix using the slice Id (here for the default red slice). This returns the 4x4 transform matrix, from which you can retrieve the slice origin and the normal vector.

sliceNode = slicer.util.getNode('vtkMRMLSliceNodeRed')
sliceToRas = sliceNode..GetSliceToRAS()
origin = np.array([sliceToRas.GetElement(i, 3) for i in range(3)])
normal = np.array([sliceToRas.GetElement(0, 2), sliceToRas.GetElement(1, 2), sliceToRas.GetElement(2, 2)])
2 Likes

Hi! Thank you so much! I tried this but it does seem to be updating the slice we are seeing on the Red, Green and Yellow panels. The 4x4 transform matrix remains the same, is there something else I need to do for getting the transform matrix for the slice I see on the screen after interacting with it?

sliceNode.GetSliceToRAS() will give you the updated 4x4 matrix after interaction. The sliceToRas matrix in the code above is just a stored copy of that information at the point when that code is run, and will not be dynamically updated as the slice location is changed.

1 Like