Transform Widget

Hello.

I would like to display transformation fields and manipulate some visualization features of the fields such as spacing, scale factor. I tried writing a program to do that based on this document but it does not work.

Below is my code:
#get a field node
field = getNode(“Transform_field”)

get the transforms widget

displacement_widget = slicer.qMRMLTransformDisplayNodeWidget()
displacement_widget.setMRMLTransformNode(field)
displacement_widget.setVisibility(True)
displacement_widget.setVisibility2d(True)
#set spacing and scale factors
displacement_widget.setGlyphSpacingMm(3)
displacement_widget.setGlyphScalePercent(250)

I realized that when I check and uncheck the “visible” or “visible in slice view” checkbox inside visualization section, my program works. It would be great if you could correct my code.

Thank you.

You created a GUI widget that you can use to edit properties of a transform display node. The widget is useful if you want to allow users to modify transform display properties in your module’s GUI. It probably does not work if you don’t set the MRML scene in the widget and/or the widget is not displayed.

If you just want to modify a transform’s appearance then you can edit the transform display node properties directly:

transformNode = getNode('LinearTransform_3')
transformNode.CreateDefaultDisplayNodes()
transformDisplayNode = transformNode.GetDisplayNode()
transformDisplayNode.SetVisibility(True)
transformDisplayNode.SetVisibility2D(True)
transformDisplayNode.SetAndObserveRegionNode(getNode('MRHead'))
1 Like

Thank you so much! It works perfectly

1 Like