enthought / mayavi

3D visualization of scientific data in Python
http://docs.enthought.com/mayavi/mayavi/
Other
1.32k stars 286 forks source link

offscreen rendering outputs black image unless new renderwindow created #257

Open gnurser opened 9 years ago

gnurser commented 9 years ago

This occurs on OSX 10.9.5 (AMD 6750M graphics card) with mayavi 4.4.2.

A simple test of off screen rendering and image saving, such as:

from mayavi import mlab

mlab.options.offscreen = True
mlab.test_contour3d()
fig = mlab.gcf()
mlab.savefig(figure=fig, filename='example.png')

gives a blank output (i.e. a black image).

However, if a new render window is created and then the figure's renderer is added to this render window, for example (based on tvtk offscreen example code, could undoubtedly be cleaned up):

from mayavi import mlab
from tvtk.api import tvtk
from tvtk.common import configure_input_data

mlab.options.offscreen = True
mlab.test_contour3d()
fig = mlab.gcf()
rw = tvtk.RenderWindow(size=fig.scene._renwin.size, off_screen_rendering=1)
rw.add_renderer(fig.scene._renderer)

w2if = tvtk.WindowToImageFilter()
w2if.magnification = fig.scene.magnification
w2if.input = rw
ex = tvtk.PNGWriter()
ex.file_name = 'example4.png'
configure_input_data(ex, w2if.output)
w2if.update()
ex.write()

the image output is correct.

From a brief inspection it's not clear as to how the new render window differs from the one that is automatically generated.

Regardless of whether the image is saved correctly, the rendering seems to be much slower when mlab.options.offscreen = True than when mlab.options.offscreen = False.

kitchoi commented 8 years ago

Confirmed with Mac OS. I believe this has to do with the use of vtkCocoaRenderWindow available since OS X 10.6 with VTK_USE_COCOA turned ON during VTK build (default). Investigating. Related to PR #317

kitchoi commented 8 years ago

Reopen, as #331 is reverted.