enthought / enthought/mayavi

Mayavi off screen rendering not working for VTK 7.1.0

Open
#477 21 comments 6 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1.4k
Forks
316
Avg merge
7h 44m
Merged PRs (30d)
5

Description

I use vtk with the MesaOS driver as I want to run the rendering as part of a jupyter notebook in headless mode, some more details to the package configuration can be found here:
https://github.com/conda-forge/vtk-feedstock/issues/20

When I use the VTK off screen example it is working fine:
```
#! ./local/bin/python

from vtk import (vtkSphereSource, vtkPolyDataMapper, vtkActor, vtkRenderer,
vtkRenderWindow, vtkWindowToImageFilter, vtkPNGWriter)

sphereSource = vtkSphereSource()
mapper = vtkPolyDataMapper()
mapper.SetInputConnection(sphereSource.GetOutputPort())

actor = vtkActor()
actor.SetMapper(mapper)

renderer = vtkRenderer()
renderWindow = vtkRenderWindow()
renderWindow.SetOffScreenRendering(1)
renderWindow.AddRenderer(renderer)

renderer.AddActor(actor)
renderer.SetBackground(1, 1, 1)

renderWindow.Render()

windowToImageFilter = vtkWindowToImageFilter()
windowToImageFilter.SetInput(renderWindow)
windowToImageFilter.Update()

writer = vtkPNGWriter()
writer.SetFileName("sphere.png")
writer.SetInputConnection(windowToImageFilter.GetOutputPort())
writer.Write()
```

But when I test the mayavi off screen example, it is not working:
```
# Author: Prabhu Ramachandran
# Copyright (c) 2007, Enthought, Inc.
# License: BSD Style.

from os.path import join, abspath, dirname

# The offscreen Engine.
from mayavi.api import OffScreenEngine

# Usual MayaVi imports
from mayavi.scripts.util import get_data_dir
from mayavi.sources.api import VTKXMLFileReader
from mayavi.modules.api import Outline, ScalarCutPlane, Streamline

def main():
# Create the MayaVi offscreen engine and start it.
e = OffScreenEngine()
# Starting the engine registers the engine with the registry and
# notifies others that the engine is ready.
e.start()

# Create a new scene.
win = e.new_scene()

# Now setup a normal MayaVi pipeline.
src = VTKXMLFileReader()
src.initialize(join(get_data_dir(dirname(abspath(__file__))),
'fire_ug.vtu'))
e.add_source(src)
e.add_module(Outline())
e.add_module(ScalarCutPlane())
e.add_module(Streamline())
win.scene.isometric_view()
# Change the size argument to anything you want.
win.scene.save('offscreen.png', size=(800, 800))

if __name__ == '__main__':
main()
```

The error message I get is:
```
ERROR: In ../Rendering/OpenGL2/vtkXOpenGLRenderWindow.cxx, line 301
vtkXOpenGLRenderWindow (0x30ced20): bad X server connection. DISPLAY=Aborted
```

So to me it seems like the off screen initialisation is not correctly forwarded to VTK. Unfortunately I was unable to locate the initialisation of VTK inside mayavi myself. To me it seems to be happening in `tvtk_access.py`, still I do not see an option to force offscreen rendering directly.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.