Monday, March 9, 2009

Sage notebook, Mayavi2 and 3D interaction on the web

Thanks to a cool open source x3d viewer along with its browser plugin -- freewrl, I can now use mayavi2 in a sage notebook and also get 3d interactivity! To see this in action see here. You should see something that looks like this:

The view on the bottom supports full 3d interactivity, which is really quite cool. This works seamlessly with the debian package on the freewrl site. I just installed the packge on my Ubuntu 8.04 machine and it works really nicely. The only trouble is that for more complex visualizations, the x3d file exported can be quite large but this can be partially alleviated by perhaps using mod_deflate and similar options on the server.

Now the x3d embedding above is a hack currently since I manually embedded the necessary HTML tag into the sage worksheet but as can be gleaned from this thread, this should be trivial to add to Sage proper. This opens up an exciting new possibility for mayavi2 on the web.

Saturday, March 7, 2009

Mayavi2 in a Sage notebook on the web!

I've been pretty hopeless at blogging (or even responding to comments on my blog) but this was too good to not blog about. Ondrej Certik has setup a Sage notebook on the web with support for Mayavi2. This lets you generate pictures using mayavi2 offline, from anywhere on the web and see them as static images. No interactivity yet but that is technically possible and may happen sometime.

Ondrej blogged about this very briefly and mentioned his struggle on getting mayavi2 working in sage. Here is a link to his first attempt demonstrating a mayavi plot on the hpfem notebook:

I made a little worksheet with a few of the standard mayavi test cases here:

If your browser shows you a text rendering of the above, download the Force HTML bookmarklet from here and click on that, you should see the page nicely.

Quite a bit of work went into this before we got this far. I spent several hours figuring out how to get VTK built reliably so it can work for this. There was a minor bug in mlab that was fixed by Gael and me. Ondrej then figured out (after much pain) how to get mayavi2 and sage working nicely together. Jaap Spies' very cool mayavi2 packages for sage were also a big help I believe. Ondrej then ran into trouble with memory issues with the virtual machine he hosts this on. Once that was resolved this became possible.

Needless to say, this opens up some very interesting possibilities and is very cool.