I am curious if it would be possible for have a message box showing a slice widget. I somewhat “hacked” that but I am not happy with it and I would like to know if there is a clean way to do it.
I am asking because prior to doing prostate biopsy our module receives pre-procedural images. The operator has to confirm if an endo-rectal coil was used during pre-procedural acquisition.
The following screenshot displays, what I ‘hacked’ so far.
You need to create nodes in a certain order. I needed this some time ago and remember that Slicer crashed when that strict order was not followed bit otherwise worked. I’m not sure I can find that code, but you should be able to replicate what the layout manager does by inspecting its source code. Let me know if you have trouble finding it.
That’s fine, those are only reported by data probe, as it uses the layout manager to look up slice view node. I’ll fix that today. No need to register anything.
I’ve checked this again and found that the layout manager automatically creates a widget for all slice nodes that are added to the scene. The simplest is to use this widget, as there are no side effects.
# Load some data into the scene
import SampleData
volumeNode = SampleData.SampleDataLogic().downloadMRHead()
# Create slice node (this automatically creates a slice widget)
sliceNode = slicer.mrmlScene.CreateNodeByClass('vtkMRMLSliceNode')
sliceNode.SetName("Black")
sliceNode.SetLayoutName("Black")
sliceNode.SetLayoutLabel("BL")
sliceNode.SetOrientation("Sagittal")
sliceNode = slicer.mrmlScene.AddNode(sliceNode)
# Select background volume
sliceLogic = slicer.app.applicationLogic().GetSliceLogic(sliceNode)
sliceLogic.GetSliceCompositeNode().SetBackgroundVolumeID(volumeNode.GetID())
# Get the automatically created slice widget
lm=slicer.app.layoutManager()
sliceWidget=lm.viewWidget(sliceNode)
# Move slice widget to a different layout
# (it can be added to any other layout)
sliceWidget.setParent(None)
# Show slice widget
sliceNode.SetMappedInLayout(1)
Note: when you switch layouts, the widget gets hidden, so you have to call sliceNode.SetMappedInLayout(1) again.
This is awesome, thanks for sharing!
Is there a way to instead of decoupling the slice widget, have it appear to the left of the current preset layout as part of the currently loaded layout template?
Do I use the sliceWidget.setParent() feature? If so, how do I obtain an instance of the currently used layout?
Ok, but i’m unsure how the syntax would be. Can you please give me an example of Slicer’s preset layout named “Conventional Widescreen” where the slice nodes are grouped on the right and the 3d view on the left. I should be able to play around with that to get what I am looking for. Thanks!