Exporting plots from Slicer


(Murat Maga) #1

Beyond screen capture, what is the option to export a plot from Slicer. If possible in SVG format or at least some bitmap?


(Andras Lasso) #2

VTK should be able to export plots as postscript file (see https://vtk.org/doc/nightly/html/classvtkGL2PSExporter.html). You may also experiment with anti-aliasing options and view size to get high-quality output suitable for printing.


(Murat Maga) #3

Thanks @lassoan. Will take a careful look. Cursory examination suggests it is dependent on a library called gl2ps (http://www.geuz.org/gl2ps/), is this available with the VTK distributed with Slicer, or would it require custom build?


(Steve Pieper) #4

I didn’t try with a plot, but the class does work in Slicer as shown below. Looks like we just need to add an accessor to get the renderWindow from a chart view.

>>> e = vtk.vtkGL2PSExporter()
>>> e.SetFileFormatToSVG()
>>> lm = slicer.app.layoutManager()
>>> e.SetRenderWindow(lm.sliceWidget('Red').sliceView().renderWindow())
>>> e.SetFilePrefix('/tmp/red')
>>> e.Update()


(Murat Maga) #5

@pieper my specific concerns is the Plots. Slice view is straightforward with available Snapshot tool.
SVG is more relevant for plots, as the user can modify the colors/symbols etc…


(Steve Pieper) #6

Of course I know that!

This was just a demo to show you that the gl2ps code is bundled with Slicer. The plots should work the same if one used their render window instead of the slice view render window.


(Steve Pieper) #7

I added a hook to export plots svg, which is available via python for now. I’m thinking it would make sense to add a Save As button to the qMRMLPlotViewControllerWidget for this.


(Steve Pieper) #8

I went ahead and added a Save button to the plot controller popup. I also confirmed the SVG output is in vector form, not raster, so it should look good in print or at least it won’t have rasterization effects).