Get SliceWidget / SliceNode Coordinate From RAS or IJK

Hello,

I am trying to find the relationship between the coordinates used in the SliceWidgets / SliceNodes (Red, Yellow, Green) and the RAS or Voxel coordinates of a volumeNode.

Everytime I load a 3D image into Slicer, I apply “rotate to volume node” (see top of attached image) so that my slices in the Red Widget (x-y) plane are those of the DICOMS for my axial acquisitions. I have created various annotation modules where I have a button that jumps to the slices (Red, Yellow, Green) of the center of a segmentation/bounding box/markupLine etc. When I have a volumeNode that doesn’t have any off diagonal elements in the direction matrix, the RAS coordinates match perfectly with the coordinates of the SliceWidgets/Slice Nodes (Red, Yellow, Green) and I can use this to jump to a certain slice. However, when I do have an acquisition with off-diagonal elements in the direction matrix and apply “rotate to volume node”, the Slice Widget coordinates do not match the RAS coordinates anymore (see Red and Orange boxes in attached image), so I cannot use the RAS coordinates of the center of my object to choose the Red,Yellow,Green slice coordinate. Is there a way to know what would be the SlicerWidget coordinates used for a specific RAS or Voxel coordinate after applying “rotate to volume plane”? (I know how to find the IJKtoRAS correspondance, but I’m unsure how to relate that to the SliceWidget coordinate).

I have tried a bit of my own custom matrices and also tried sliceNode.GetXYToSlice or sliceNode.GetXYtoRAS but nothing seems to be giving me the right answer.

Perhaps there is already a function in Slicer that figures this out? Any help is much appreciated.

Best,
Eric

You can use vtkMRMLSliceNode’s JumpSlice/JumpSliceByCentering/JumpSliceByOffsetting methods to show any RAS position in a slice. If you want to reimplement this method in your own module (I would not recommend it though) then you can take the implementation here:

Hi @lassoan,

Before, I was using sliceWidgetLogic.SetSliceOffset(c) to achieve this, but now with the following code, I can get it to work exactly how I want:

cYellow, cGreen, cRed = c #RAS coordinate
sliceWidgetColors = ['Yellow','Green','Red']

layoutManager = slicer.app.layoutManager()
for color in sliceWidgetColors:
  sliceWidget = layoutManager.sliceWidget(color)
  sliceWidgetLogic = sliceWidget.sliceLogic()
  sliceNode = sliceWidgetLogic.GetSliceNode()
  sliceNode.JumpSlice(cYellow,cGreen,cRed)

Thanks for the code too.

Best,
Eric

1 Like