However, I didn’t find a way on the wiki or other posts to toggle the volume node show/hidden button under Data/Subject Hierachy/Node. I tried:
volumeNode.GetDisplayNode().SetVisibility(True)
But it didn’t work, and I have to toggle the show/hidden manually in slicer UI under Data/Subject Hierachy/Node. Is there any python command to do this? Thanks!
Sorry I have one follow-up question… I found it is not quite the same thing as toggling the show/hide button. For example, I was trying to load a 2D ultrasound image (volume size=[1,480,640]) and apply transformation on the image. After initial loading, I did
usImgTransformNode = slicer.mrmlScene.AddNewNodeByClass(“vtkMRMLTransformNode”, “TrackedUSImagePose”)
usImgNode.SetAndObserveTransformNodeID(usImgTransformNode.GetID())
and do slicer.util.resetSliceViews() I got:
Then I fill in the transformation node with actual matrix by usImgTransformNode.SetMatrixTransformToParent(transformMatrix) and do slicer.util.resetSliceViews(), I got:
which is the display I’d like to have. I wonder is there a mechanism behind the show/hide button that I can do with script to enable this kind of behavior? I essentially would like to change the transformation matrice multiple times and show the US image moving in 3D as well as showing the image in one of the slice view.
Thanks!
I am not really sure what is going on there as my slicer program does not have that same behaviour although I am using an older version (4.11.20200930)
Usually the red, yellow and green slice views just look along the primary axes, e.g. the red slice always looks normal to the Sup/Inf axis. It looks like when you pressed the show hide button that the yellow view has become reformatted to look at the rotated volume. As I said my slicer does not reformat the slice views by toggling the show hide button so I am not sure why yours does this?
Anyway if you want some code which is equivalent to pressing the " Rotate to volume plane" button which reformats the slice views to look at the rotated volume try this:
This just rotates the red slice to the volume. Just replace the ‘Red’ with ‘Yellow’ or ‘Green’ if you want to rotate the other slices. If you want to rotate all 3 then you will need to loop through them:
layoutManager = slicer.app.layoutManager()
for sliceViewName in layoutManager.sliceViewNames():
sliceWidget = layoutManager.sliceWidget(sliceViewName)
controller = sliceWidget.sliceController()
controller.rotateSliceToBackground()
slicer.util.resetSliceViews()
Thanks! I am using the latest stable version (4.11.20210226, revision 29738, built 2021-03-01), and I found that currently there is an attribute error when doing
controller.rotateSliceToBackground()
AttributeError: qMRMLSliceControllerWidget has no attribute named ‘rotateSliceToBackground’
I think now it has been updated to controller.rotateSliceToLowestVolumeAxes() which works great.