You made me curious, so I tried offscreen rendering and it basically works, although it sometimes leads to a crash when interacting with the view after rendering. But something like the code below could be added as a feature if someone wants to play with it. It could use more tweaks, but if it’s useful for people we could put it in the script repository for now.
Here’s the full res 5kx5x version:
vtk.vtkGraphicsFactory()
gf = vtk.vtkGraphicsFactory()
gf.SetOffScreenOnlyMode(1)
gf.SetUseMesaClasses(1)
rw = vtk.vtkRenderWindow()
rw.SetOffScreenRendering(1)
ren = vtk.vtkRenderer()
rw.SetSize(5000,5000)
lm = slicer.app.layoutManager()
ren3d = lm.threeDWidget(0).threeDView().renderWindow().GetRenderers().GetItemAsObject(0)
actors = ren3d.GetActors()
for index in range(actors.GetNumberOfItems()):
ren.AddActor(actors.GetItemAsObject(index))
lights = ren3d.GetLights()
for index in range(lights.GetNumberOfItems()):
ren.AddLight(lights.GetItemAsObject(index))
volumes = ren3d.GetVolumes()
for index in range(volumes.GetNumberOfItems()):
ren.AddVolume(volumes.GetItemAsObject(index))
camera = ren3d.GetActiveCamera()
ren.SetActiveCamera(camera)
rw.AddRenderer(ren)
rw.Render()
wti = vtk.vtkWindowToImageFilter()
wti.SetInput(rw)
wti.Update()
writer = vtk.vtkPNGWriter()
writer.SetInputConnection(wti.GetOutputPort())
writer.SetFileName("/tmp/out.png")
writer.Update()
writer.Write()
i = wti.GetOutput()
Here’s an inset of what the full resolution looks like: