Off-line visualization

Had a quick look into how much work it might take to enable offscreen rendering, but as it turns out, I think it can already be done :grin:. Skip to the end if you want to find out how.

First off though, just a couple of comments on your previous post:

Well, technically there’s no reason why OpenGL can’t be used for off-screen (headless) rendering: it’s perfectly fine to draw to a framebuffer object, and never actually update the screen. And this will use the graphics hardware if available. And if not, we can always default back to software rendering: mesa provides a high performance driver for that, which would be available on basically any modern GNU/Linux system.

The reason why MRView can’t do it currently is because all of the rendering is tied very closely to the user interface: many of the parameters of the render are taken directly from the various widgets shown to the user. So we’d need to separate the rendering itself from the UI to allow off-screen rendering. As things stand, MRView needs to create an actual window to display all the widgets, so we’d need to bypass all of that, and allow the rendering code to work in an environment where none of the widgets exists, and then find a way to replicate the rendering pipeline so that it renders to an off-screen framebuffer object in headless mode. That strikes me as a lot of work… but not necessarily all that difficult - certainly less work that essentially re-writing everything from scratch, which switching to OSPRay would undoubtedly require.

However: it looks like we won’t have to go this far, because instead we can…

Use Qt5’s offscreen rendering plugin

I’ve just been looking into was whether Qt5 has any options to run in headless mode directly. And lo and behold, it turns out that it does: Qt5 uses platform plugins to manage the various rendering backends that are supported on various OS’s. One of these is the offscreen plugin. It’s very hard to find any documentation about this, but I gave it a shot anyway, and it seems to work:

$ mrview -platform offscreen anat.mif -mode 3 -plane 1 -intensity 0,400 -noannot -capture.grab -exit

produces the expected screenshot0000.png mugshot of yours truly:

So the only issue to sort out at this point is making sure you have an OpenGL 3.3 compliant graphics driver on your target system/server. And that should just be a matter of installing a recent version of mesa, and either using the default hardware driver if it’s good enough, or defaulting to software rendering if the hardware isn’t present or too old. Not sure how to do that last bit, but I’m sure it’ll be documented somewhere on the mesa website…