How can I display text in pop-up 3D views?
Steps I follow:
- I create and show a right and left view with the following code:
layoutName = "LeftEyeView"
layoutLabel = "Left Eye"
layoutColor = [1.0, 1.0, 0.0]
viewOwnerNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLScriptedModuleNode")
# Create MRML node
viewLogic = slicer.vtkMRMLViewLogic()
viewLogic.SetMRMLScene(slicer.mrmlScene)
# Left node
viewNodeLeft = viewLogic.AddViewNode(layoutName)
viewNodeLeft.SetLayoutLabel(layoutLabel)
viewNodeLeft.SetLayoutColor(layoutColor)
viewNodeLeft.SetAndObserveParentLayoutNodeID(viewOwnerNode.GetID())
viewNodeLeft.SetStereoType(3)# Quadbuffer Stereo layout 1 is left eye (dont know why)
# Create widget
self.viewWidgetLeft = slicer.qMRMLThreeDWidget()
self.viewWidgetLeft.setMRMLScene(slicer.mrmlScene)
self.viewWidgetLeft.setMRMLViewNode(viewNodeLeft)
print("Left widget created")
self.viewWidgetLeft.show()
- I display some text on the 3D view from the Slicer UI
# Get the 3D view renderer
self.layoutManager = slicer.app.layoutManager()
self.threeDView = self.layoutManager.threeDWidget(0).threeDView()
self.renderer = self.threeDView.renderWindow().GetRenderers().GetFirstRenderer()
# Create a text actor to display the text
self.textActor = vtk.vtkTextActor()
# Position the text actor in the corner
self.textActor.GetPositionCoordinate().SetCoordinateSystemToNormalizedViewport()
self.textActor.SetPosition(0.8, 0.9)
# Add the text actor to the renderer
self.renderer.AddActor2D(self.textActor )
- In order to add the text in the created left and right views, I need to access those views. Using “layoutManager.threeDWidget(–viewNumber–).threeDView()” does not let me display any text in those views.
The view nodes I actually have are:
View1 (from the UI): vtkMRMLViewNode1
View (left eye): vtkMRMLViewNodeLeftEyeView
View_1 (right eye): vtkMRMLViewNodeRightEyeView
How can I access the render windows of those views in order to be able to display text in those?