Have sequence of steps executed when adding data

Operating system: Windows 10
Slicer version: 4.11.20210226
Expected behavior: Reformatting views in .sliccerrc file remains active when adding a volume
Actual behavior: Views reset to Axial, Sagittal, Coronal when adding data

Hi there,

In previous slicer versions I had some reformatting of the slicer views triggered upon opening slicer with .sliccerrc.py file that persisted when adding data. Now I notice that the views are still reformatted when I open slicer but when I add a new volume the views are reset (axial, sagittal, coronal). Is there a way to make the reformatting persist when loading data or alternatively have some python code run everytime a new volume is added?

Many thanks!

  • Jon

See an example for this in the script repository.

In Slicer Preview Releases you probably don’t need to use manual reformatting. You can enable “Reset field of view on show” and “Reset view orientation on show” options in to automatically align slice views whenever a volume gets shown.

Hi Andras,

Thank you, that works well, however it seems like the view will reset every time I apply a filter, attempt to compare volumes etc.

Fundamentally, I have a volume where IJK (X,Y,Z) is aligned with the RAS axes but the typically way to show the slice views in my industry is R(X) pointing to the right and A(Y) pointing downwards on the Axial slice, S(Z) pointing to the right and R(X) pointing upwards on the Sagital slice and S(Z) pointing right and A(Y) pointing down for the Coronal slice:

I can do this with the following code at the beginning of my .slicerrc.py file using the reformatting widget, however, a way to do this which takes effect all of the time would be preferred. Is there a way to save the data differently or by default change the way the slice views are oriented? If I could get this working it would greatly simplify my life! I want to use Slicer for all of my nondestructive testing scan analysis but having these views constantly change into something unfamiliar makes it hard for me to present things to my colleagues.

viewNodes = slicer.util.getNodesByClass('vtkMRMLSliceCompositeNode')
for viewNode in viewNodes:
displayNode = slicer.mrmlScene.CreateNodeByClass('vtkMRMLScalarVolumeDisplayNode')
NDTColor = slicer.util.getFirstNodeByName('NDT')
# displayNode.SetAndObserveColorNodeID('vtkMRMLColorTableNodeNDT')
# Select Red slice
widget = slicer.modules.reformat.widgetRepresentation()
sliceNodeSelector = slicer.util.findChildren(widget, "SliceNodeSelector")[0]
isslider = slicer.util.findChildren(widget, "ISSlider")[0]
isslider.value = 180
isslider = slicer.util.findChildren(widget, "ISSlider")[0]
isslider.value = -90
isslider = slicer.util.findChildren(widget, "ISSlider")[0]
isslider.value = 0
isslider = slicer.util.findChildren(widget, "LRSlider")[0]
isslider.value = 180

This is a feature not a bug, because you can turn it off. If you run the CLI from Python then specify update_display=False (see details here).

Names and directions of slice view axes are completely customizable. See this example.

Hi Andras,

Thank you for the tip! This seems to be exactly what I need, however, I am having trouble determining how to set the elements so that the views are as I would like. What do the entries in the matrices correspond to? Is there some documentation on this. It is somewhat difficult to get a general idea of what is happening from the script example, although that is still quite useful!

Any further assistance would be greatly appreciated!

  • Jon

SliceToRAS transform is homogeneous linear transformation from Slice coordinate system to RAS coordinate system. You can look up homogeneous coordinate transforms on Wikipedia for details, but in short, the first column of the matrix specifies the direction of the x axis of the Slice coordinate system in the RAS coordinate system (y is the second column, z is the third column), and the fourth column specifies the Slice coordinate system origin in the RAS coordinate system.

Slice coordinate system origin is in the center and x direction = screen right, y direction = screen up, z = orthogonal to the screen (can point towards or away from the viewer, depending what is the preferred scrolling direction).

RAS coordinate system axis directions are x = patient right, y = patient anterior, s = patient superior.

You can find more examples and explanation in SlicerIGT tutorials and PerkLab Bootcamp training materials. These are all standard computer graphics concepts, so you should be able to find many other tutorials about it on the web (homogeneous coordinate systems and transforms).

Hi Andras,

I finally have the slice views configured properly for my application. Thank you so much!

  • Jon
1 Like