Progamatically get slice view bounding box in RAS

Hi, I’d like to write a python script that gets the bounding box of a slice view.
For example, with the attached images, I’d like to have 2 points: (-2.1, 133.1, -199.7) and (-2.1, -120.3, 178.3).

Using vtkMRMLSliceNode::GetXYZOrigin and applying the XYToRAS matrix gives me the bottom left corner. But I don’t see how to get the top right corner.
I played around with the field of view, but didn’t get the right results when switching between axial/coronal/sagittal presets.

How can I accomplish that?

1 Like

Get the RAS coordinates of the bottom left corner:

xytoras = sliceNode.GetXYToRAS()
xytoras.MultiplyPoint((0, 0 , 0, 1))

Get the coordinate of the top right corner:

dims = sliceNode.GetDimensions()
xytoras.MultiplyPoint((dims[0], dims[1] , 0, 1))
1 Like