ENH: add a vtk.js backend for MNE's 3D renderer (JupyterLite split 3/5) - #14144
ENH: add a vtk.js backend for MNE's 3D renderer (JupyterLite split 3/5)#14144natinew77-creator wants to merge 10 commits into
Conversation
VTK cannot load in WebAssembly, so the JupyterLite notebooks need a renderer that draws with vtk.js. MNE does its geometry in numpy and only hands the result to a renderer, so replacing that last step leaves the transform maths to MNE.
c20eae7 to
5a823e2
Compare
|
Maybe you have looked and I am coming late to this... have you thought about adding it as a type of AbstractRenderer and using https://github.com/tkoyama010/pyvista-js ? Maybe it's not too much work to use that in place of our PyVista calls... but if you've tried or looked I could be way off! |
Hi Eric, it already uses pyvista-js. On AbstractRenderer, it sits in doc/ as a string the setup cell appends, to keep browser-only code out of mne/. But it already implements 21 of the 22 abstract methods, so converting it is mostly moving and registering it, not a rewrite. Happy to do that here, or land this as is and convert in a follow-up. Which would you prefer? Thanks! |
|
Yeah if there is some way for it to be a plain renderer and then |
The renderer was a 560-line string literal, which no linter or formatter could see. It now lives in _lite_renderer_cell.py as ordinary Python and the cell is read from there, so ruff covers it like any other file. The code itself is unchanged apart from what the formatter did to it.
Done in eb3c814, it's a plain module now and LITE_RENDERER_CELL is read from it, so ruff and the formatter cover it. |
Part 3 of the split of #13925. Parts 1 and 2 are #14128 and #14135.
Adds a drawing backend for MNE's 3D renderer that uses vtk.js, since VTK itself cannot load in WebAssembly. MNE's 3D functions do their geometry and coordinate-frame work in numpy and only hand the result to a renderer, so replacing that last step leaves the transform maths with MNE. That matters here, because a subtly wrong head or device transform still produces a plausible-looking picture.
Supported: meshes, surfaces, spheres, tubes and glyphs, which covers the static figures the docs render. Not supported: the interactive
Braintime viewer, which needs dock widgets, and scalar colormaps, which pyvista-js 0.15 does not have.It is a plain string constant, so nothing in the build touches it yet. The setup cell that appends it is #14150.