After a lot of effort I got the mayavi camera to point in the same direction as a rigid transformation I use to position my camera (different from mayavi camera) in a virtual scene. Then I use mayavi to generate screenshots that I insert in my virtual scene, so I can clearly see when the screenshots and the scene are correctly aligned as the camera moves. As I only need screenshots of the mayavi scene, I made the rendering offscreen to hide the mayavi window by setting:
mlab.options.offscreen = True
before I create the mayavi figure (as explained in here).
At the first glance this seemed to work, but then I realised that the screenshots were slightly different, like if the field of view of the camera had decreased a little bit wrt. not using offscreen rendering. I've queried the view settings and nothing seems to have changed when I'm rendering offscreen.
The only thing I've found online that may remotely be related is this question, where the last answer argues that the border of the window seems to change something in the offscreen rendering. I tried the following:
mlab.options.offscreen = True
self.fig = mlab.figure(bgcolor=(1, 1, 1), fgcolor=(0, 0, 0), size=(w, h))
scene = self.fig.scene
cam = scene.camera
cam.view_angle = self.fov
ren = scene.renderer
win = ren._get_vtk_window()
win.borders = False
to try to switch off these borders, but the screenshots I get while in offscreen rendering are still different from non-offscreen renderings. Any idea what's going on?
I found the problem. It's the toolbar which changes the size of the viewable area and when I do offscreen rendering there is no toolbar (and no window).
If I disable the toolbar like this:
scene = self.fig.scene
scene._tool_bar.setVisible(False)
then I get the same screenshots with offscreen rendering and without.