Looking for recommended way to saving frames without opening windows in 7.1.0. Current solution seems unstable.
I am currently using vtkGraphicsFactory and vtkWindowToImageFilter.
width, height = size
if offscreen:
graphics_factory = vtk.vtkGraphicsFactory()
graphics_factory.SetOffScreenOnlyMode(1)
# TODO check if the line below helps in something
# graphics_factory.SetUseMesaClasses(1)
render_window = vtk.vtkRenderWindow()
if offscreen:
render_window.SetOffScreenRendering(1)
render_window.AddRenderer(ren)
render_window.SetSize(width, height)
render_window.Render()
window_to_image_filter = vtk.vtkWindowToImageFilter()
window_to_image_filter.SetInput(render_window)
window_to_image_filter.Update()
vtk_image = window_to_image_filter.GetOutput()
h, w, _ = vtk_image.GetDimensions()
vtk_array = vtk_image.GetPointData().GetScalars()
components = vtk_array.GetNumberOfComponents()
arr = vtk_to_numpy(vtk_array).reshape(h, w, components)
I saw that there is some development on headless and offscreen rendering.
The code above is what I am currently using and it does work in my machine (Anaconda with vtk 7.1.0 and GL2 backend) but has problems with Travis and xvbf. The behavior is irregular and difficult to debug.
I am open to suggestions. So, first is there a better API for directly rendering on a file or memory?