3d display: x3d?

222 views
Skip to first unread message

Prabhu Ramachandran

unread,
Mar 8, 2009, 7:36:29 AM3/8/09
to sage-...@googlegroups.com
Dear Sage developers,

Is it possible to view an x3d file from a sage worksheet (assuming my
browser has the necessary plugin or java support for example)? I saw
numerous mentions of x3d support in the source code in plot/plot3d. For
example if one generates a 'foo.png', the image is immediately and very
conveniently rendered. This doesn't work if I save an x3d file.

The reason I ask is really simple. mayavi2 can produce x3d files via
mlab.savefig('foo.x3d') for example (thanks to VTK) and freewrl is able
to view these pretty well. I was wondering if there were a mechanism to
support this seamlessly on a notebook. This would allow for very nice
integrated 3D display. Alternatively, does jmol support display via x3d
files? Ondrej has integrated mayavi2 with the notebook but it only
produces static images and I'd like to find an easy way to also provide
3D interactivity. Here are a few simple examples from Ondrej's site
that I made from some mlab examples:

http://nb.hpfem.org/home/pub/16

Another option would be to produce output suitable for use with jmol.
Would this require a pmesh exporter?

I'd appreciate any ideas on this. Thanks.

cheers,
prabhu

William Stein

unread,
Mar 8, 2009, 9:49:37 AM3/8/09
to sage-...@googlegroups.com
On Sun, Mar 8, 2009 at 4:36 AM, Prabhu Ramachandran
<pra...@aero.iitb.ac.in> wrote:
>
> Dear Sage developers,
>
> Is it possible to view an x3d file from a sage worksheet (assuming my
> browser has the necessary plugin or java support for example)?

No, but as you've basically observed below such support would likely
be easy to add to sage. I don't have time to try right now.

> I saw
> numerous mentions of x3d support in the source code in plot/plot3d.  For
> example if one generates a 'foo.png', the image is immediately and very
> conveniently rendered.  This doesn't work if I save an x3d file.
>
> The reason I ask is really simple.  mayavi2 can produce x3d files via
> mlab.savefig('foo.x3d') for example (thanks to VTK) and freewrl is able
> to view these pretty well.  I was wondering if there were a mechanism to
> support this seamlessly on a notebook.  This would allow for very nice
> integrated 3D display.  Alternatively, does jmol support display via x3d
> files?  Ondrej has integrated mayavi2 with the notebook but it only
> produces static images and I'd like to find an easy way to also provide
> 3D interactivity.  Here are a few simple examples from Ondrej's site
> that I made from some mlab examples:
>
>  http://nb.hpfem.org/home/pub/16

Awesome!!

>
> Another option would be to produce output suitable for use with jmol.
> Would this require a pmesh exporter?
>
> I'd appreciate any ideas on this.  Thanks.

Robert Bradshaw will likely have something useful to say tomorrow (=Monday) too.

William

Carl Witty

unread,
Mar 8, 2009, 1:01:12 PM3/8/09
to sage-...@googlegroups.com
On Sun, Mar 8, 2009 at 3:36 AM, Prabhu Ramachandran
<pra...@aero.iitb.ac.in> wrote:
>
> Dear Sage developers,
>
> Is it possible to view an x3d file from a sage worksheet (assuming my
> browser has the necessary plugin or java support for example)? I saw
> numerous mentions of x3d support in the source code in plot/plot3d.  For
> example if one generates a 'foo.png', the image is immediately and very
> conveniently rendered.  This doesn't work if I save an x3d file.

If you want to add such support, the place to look is
sage/server/notebook/cell.py, in the function files_html. This
function takes a list of all the files that were produced by
evaluating the cell, and produces HTML with display or download links
for those files. For example, the case of *.svg files is handled like
this:

elif F.endswith('.svg'):
images.append('<embed src="%s" type="image/svg+xml"
name="emap">'%url)

So if you know what to put into HTML to display an x3d model, it would
be trivial to add another case in files_html.

Carl

Prabhu Ramachandran

unread,
Mar 8, 2009, 2:03:08 PM3/8/09
to sage-...@googlegroups.com, Ondrej Certik, enthou...@mail.enthought.com
Hi Carl,

On 03/08/09 22:31, Carl Witty wrote:
> If you want to add such support, the place to look is
> sage/server/notebook/cell.py, in the function files_html. This
> function takes a list of all the files that were produced by
> evaluating the cell, and produces HTML with display or download links
> for those files. For example, the case of *.svg files is handled like
> this:
>
> elif F.endswith('.svg'):
> images.append('<embed src="%s" type="image/svg+xml"
> name="emap">'%url)
>
> So if you know what to put into HTML to display an x3d model, it would
> be trivial to add another case in files_html.

Aha! Thanks. I haven't touched cell.py yet but as a proof of concept
look here again:

http://nb.hpfem.org/home/pub/16/

At the bottom you should (if all goes well and you have an x3d reader
setup for use on your browser) see a blue triangle like the one here:

http://nb.hpfem.org/home/pub/12/

except that on this one you can actually interact over the web. This is
really cool although the x3d files can get pretty big. We'd probably
want to throw in some compression in as well but I'm not sure that would
work with all plugins (or would the browser take care of that?). Anyway,
in the above I simply edited the worksheet and added something like:

<embed width='400' height='300' src="./cell/14/a.x3d">

and it seems to work with my setup. I am using freewrl
http://freewrl.sourceforge.net/ on Ubuntu 8.04.

cheers,
prabhu

p.s. apologies for cross posting.

Prabhu Ramachandran

unread,
Mar 8, 2009, 2:14:17 PM3/8/09
to sage-...@googlegroups.com
On 03/08/09 19:19, William Stein wrote:
>> 3D interactivity. Here are a few simple examples from Ondrej's site
>> that I made from some mlab examples:
>>
>> http://nb.hpfem.org/home/pub/16
>
> Awesome!!

Thanks, yes, the sage notebook is awesome!

>> Another option would be to produce output suitable for use with jmol.
>> Would this require a pmesh exporter?
>>
>> I'd appreciate any ideas on this. Thanks.
>
> Robert Bradshaw will likely have something useful to say tomorrow (=Monday) too.

Cool, will wait for his response. But it looks like simple x3d support
should work with a trivial patch to cell.py as Carl pointed out. I'm
swamped myself but if its a trivial patch I can have a go.

cheers,
prabhu

Ondrej Certik

unread,
Mar 8, 2009, 5:31:57 PM3/8/09
to sage-...@googlegroups.com, enthou...@mail.enthought.com

I just tried that too and it works for me as well:

http://nb.hpfem.org/home/pub/15/

and clearly I could now create some nice 3d results of our code and it
would work. Nice job!

jmol doesn't work for me in Debian/Ubuntu if I am using the opensource
java. If I used the proprietary version, then it works, but I really
prefer to use opensource tools. With freewrl, all I did was to add:

deb http://kheb.homelinux.org/debian unstable main

to may sources.list and "apt-get install freewrl" and it just works in firefox.

Ondrej

Prabhu Ramachandran

unread,
Mar 9, 2009, 12:05:01 AM3/9/09
to sage-...@googlegroups.com, enthou...@mail.enthought.com
On 03/09/09 03:01, Ondrej Certik wrote:
>> <embed width='400' height='300' src="./cell/14/a.x3d">
>>
>> and it seems to work with my setup. I am using freewrl
>> http://freewrl.sourceforge.net/ on Ubuntu 8.04.
>
> I just tried that too and it works for me as well:
>
> http://nb.hpfem.org/home/pub/15/
>
> and clearly I could now create some nice 3d results of our code and it
> would work. Nice job!

Thanks.

> to may sources.list and "apt-get install freewrl" and it just works in firefox.

Yes, I have more complex visualizations on my local machine that work
really well (for example the Lorenz attractor example renders
surprisingly nicely). It works well with texture maps too so things
like the image plane widget render pretty well. No 2D actors though but
thats not a big deal.

While looking at cell.py I find that sage supports visualizing ".obj"
files via sage_3d. So I tried that (yes mayavi2 exports wavefront obj
as well) and despite having java enabled and doing this locally I ended
up crashing my firefox even for the simplest .obj file (the little
triangle). It seems that freewrl OTOH is light, fast and works well.
VTK also has a POV exporter which mayavi2 exposes. There is also
eps/pdf output (files are huge though) via gl2ps. Regardless, there are
clearly a large number of viable options now given the variety of usable
outputs mayavi2 and sage support.

Anyway, attached below is a little patch for cell.py that may help. The
approach is clunky and the hardcoded width and height is poor. Perhaps
more sophisticated rendering can be done with some nice javascript I
found here:

http://cic.nist.gov/vrml/vbdetect.html

In particular, the vb_VRMLDetect.js could be reused but I've already
blown a little too much time on this and other work including a pile of
grading beckons.

cheers,
prabhu

cell.diff

Robert Bradshaw

unread,
Mar 9, 2009, 1:41:31 PM3/9/09
to sage-...@googlegroups.com
On Mar 8, 2009, at 11:14 AM, Prabhu Ramachandran wrote:

>
> On 03/08/09 19:19, William Stein wrote:
>>> 3D interactivity. Here are a few simple examples from Ondrej's site
>>> that I made from some mlab examples:
>>>
>>> http://nb.hpfem.org/home/pub/16
>>
>> Awesome!!
>
> Thanks, yes, the sage notebook is awesome!
>
>>> Another option would be to produce output suitable for use with
>>> jmol.
>>> Would this require a pmesh exporter?
>>>
>>> I'd appreciate any ideas on this. Thanks.
>>
>> Robert Bradshaw will likely have something useful to say tomorrow
>> (=Monday) too.
>
> Cool, will wait for his response.

Way back when I started working on the 3d stuff, this is what I
imagined people would do. Unfortunately, x3d viewers aren't common
(meaning not commonly installed, they are easy to get) and using an
applet to install and/or view them was unwieldily (both in terms of
the download size, and there were weird rendering issues). Jmol was
the first solution that worked well, out of the box, just about
anywhere.

I'm not sure how well the x3d functions have been maintained, but it
looks like you got them working which is a good sign. (No need to do
jmol -> x3d, much easier to export it directly--in fact the internals
of the 3d plotting in Sage is conceptually much closer to x3d than to
jmol.)

> But it looks like simple x3d support
> should work with a trivial patch to cell.py as Carl pointed out. I'm
> swamped myself but if its a trivial patch I can have a go.

I bet it will be an easy patch.

- Robert

Ondrej Certik

unread,
Mar 9, 2009, 1:52:46 PM3/9/09
to sage-...@googlegroups.com
On Mon, Mar 9, 2009 at 10:41 AM, Robert Bradshaw
<robe...@math.washington.edu> wrote:
>
> On Mar 8, 2009, at 11:14 AM, Prabhu Ramachandran wrote:
>
>>
>> On 03/08/09 19:19, William Stein wrote:
>>>> 3D interactivity.  Here are a few simple examples from Ondrej's site
>>>> that I made from some mlab examples:
>>>>
>>>>  http://nb.hpfem.org/home/pub/16
>>>
>>> Awesome!!
>>
>> Thanks, yes, the sage notebook is awesome!
>>
>>>> Another option would be to produce output suitable for use with
>>>> jmol.
>>>> Would this require a pmesh exporter?
>>>>
>>>> I'd appreciate any ideas on this.  Thanks.
>>>
>>> Robert Bradshaw will likely have something useful to say tomorrow
>>> (=Monday) too.
>>
>> Cool, will wait for his response.
>
> Way back when I started working on the 3d stuff, this is what I
> imagined people would do. Unfortunately, x3d viewers aren't common
> (meaning not commonly installed, they are easy to get) and using an
> applet to install and/or view them was unwieldily (both in terms of
> the download size, and there were weird rendering issues). Jmol was
> the first solution that worked well, out of the box, just about
> anywhere.

I think I am the minority here, but in fact jmol doesn't work out of
the box for me at all, unless I install some proprietary java on my
debian/ubuntu. If I install the opensource java, it just doesn't work
-- I discussed this on the jmol list and even reported a bug against
the java package in Debian, but I just don't have time to push this
forward and get it fixed.

x3d on the other hand does work out of the box, after I installed one package.

Ondrej

Robert Bradshaw

unread,
Mar 9, 2009, 2:11:41 PM3/9/09
to sage-...@googlegroups.com

It isn't just "some" proprietary Java, it's the original and official
Java from Sun. But yes, it's not completely free and open yet...

> If I install the opensource java, it just doesn't work
> -- I discussed this on the jmol list and even reported a bug against
> the java package in Debian, but I just don't have time to push this
> forward and get it fixed.

Yes, this is clearly a bug in Debian's java--hopefully they fix it
someday. (I don't have the time to work on it either.) Fixing either
jmol and/or the open source Java to actually work together would be a
great GSoC project.

> x3d on the other hand does work out of the box, after I installed
> one package.

OK, I could lower the bar to "works out of the box over 50% of the
time on at least 50% of the systems" and still jmol is the only thing
we tried that actually passes this criteria. If the average user goes
to sagenb.org, the 3d plots are likely to work.

That being said, I'd really like for x3d to be fully supported, and
it would be nice to have a notebook option to choose between tachyon/
jmol/x3d as being the default way to show 3d data.

- Robert

Ondrej Certik

unread,
Mar 9, 2009, 2:24:47 PM3/9/09
to sage-...@googlegroups.com
On Mon, Mar 9, 2009 at 11:11 AM, Robert Bradshaw

Yes, that's what I mean, I don't want to install original and official
non free programs on my machine. :) I mean I don't mind using some
nonfree programs as a user, but I don't want to depend on them as a
developer.

>
>> If I install the opensource java, it just doesn't work
>> -- I discussed this on the jmol list and even reported a bug against
>> the java package in Debian, but I just don't have time to push this
>> forward and get it fixed.
>
> Yes, this is clearly a bug in Debian's java--hopefully they fix it
> someday. (I don't have the time to work on it either.) Fixing either
> jmol and/or the open source Java to actually work together would be a
> great GSoC project.

Yep, for the record if anyone wants to give it a shot, here is my
email from the jmol list:

http://www.mail-archive.com/jmol-...@lists.sourceforge.net/msg11605.html

and here is my bug report in Debian:

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=505726

So basically the Debian maintainer says the applet is wrong and jmol
developers say the java in Debian is wrong, so both parties wash their
hands and as the result jmol doesn't work in Debian. So to get this
fixed, one needs to first determine where exactly the problem is and
then push it.

>
>> x3d on the other hand does work out of the box, after I installed
>> one package.
>
> OK, I could lower the bar to "works out of the box over 50% of the
> time on at least 50% of the systems" and still jmol is the only thing
> we tried that actually passes this criteria. If the average user goes
> to sagenb.org, the 3d plots are likely to work.

Yep, jmol is a good choice for Sage.

>
> That being said, I'd really like for x3d to be fully supported, and
> it would be nice to have a notebook option to choose between tachyon/
> jmol/x3d as being the default way to show 3d data.

+1

Ondrej

Prabhu Ramachandran

unread,
Mar 9, 2009, 2:37:48 PM3/9/09
to sage-...@googlegroups.com
On 03/09/09 23:11, Robert Bradshaw wrote:
> Way back when I started working on the 3d stuff, this is what I
> imagined people would do. Unfortunately, x3d viewers aren't common
> (meaning not commonly installed, they are easy to get) and using an
> applet to install and/or view them was unwieldily (both in terms of
> the download size, and there were weird rendering issues). Jmol was
> the first solution that worked well, out of the box, just about
> anywhere.

Jmol is very nice. Just FYI, the freewrl deb file is about 0.5 MB. On
the mac the installer is about 8 MB and seems to work great, although
the plugin works under Safari and I didn't bother to figure out what to
do to get it to work under FF.

> I'm not sure how well the x3d functions have been maintained, but it
> looks like you got them working which is a good sign. (No need to do

Sorry to disappoint you but I haven't used any of the existing x3d code
in sage. mayavi2 generates x3d natively via VTK.

> jmol -> x3d, much easier to export it directly--in fact the internals
> of the 3d plotting in Sage is conceptually much closer to x3d than to
> jmol.)
>
>> But it looks like simple x3d support
>> should work with a trivial patch to cell.py as Carl pointed out. I'm
>> swamped myself but if its a trivial patch I can have a go.
>
> I bet it will be an easy patch.

It was and I sent it to the list but doing more fancy things like
detecting x3d support and prompting the user appropriately if it is not
installed or presenting a png image in such a case hasn't been done.

cheers,
prabhu

Jason Grout

unread,
Mar 10, 2009, 7:11:26 AM3/10/09
to sage-...@googlegroups.com
Prabhu Ramachandran wrote:
> Dear Sage developers,
>
> Is it possible to view an x3d file from a sage worksheet (assuming my
> browser has the necessary plugin or java support for example)? I saw
> numerous mentions of x3d support in the source code in plot/plot3d. For
> example if one generates a 'foo.png', the image is immediately and very
> conveniently rendered. This doesn't work if I save an x3d file.
>
> The reason I ask is really simple. mayavi2 can produce x3d files via
> mlab.savefig('foo.x3d') for example (thanks to VTK) and freewrl is able
> to view these pretty well. I was wondering if there were a mechanism to
> support this seamlessly on a notebook. This would allow for very nice
> integrated 3D display. Alternatively, does jmol support display via x3d
> files? Ondrej has integrated mayavi2 with the notebook but it only
> produces static images and I'd like to find an easy way to also provide
> 3D interactivity. Here are a few simple examples from Ondrej's site
> that I made from some mlab examples:
>
> http://nb.hpfem.org/home/pub/16


I just installed FreeWRL and looked at this. Awesome! It looks like
this might be the best way to get good opengl graphics (and mayavi!) in
the sage notebook while we still wait on the possibility of an html
canvas3d tag.

I noticed that, at least with Freewrl, there didn't seem to be an easy
way of rotating the object in the above demo. Instead, all the methods
focused on navigating the camera. Does anyone know a way to rotate the
whole scene around some point, similar to grabbing and dragging an
object in jmol or mayavi? This could be accomplished by moving the
camera around a sphere, always pointing at the same spot in space.

Thanks,

Jason

Ronan Paixão

unread,
Mar 10, 2009, 8:39:13 PM3/10/09
to sage-...@googlegroups.com

Actually in my Ubuntu even the official proprietary Java doesn't work
with Jmol... The applet loads fine, including menus, but the model
doesn't appear, just the black background.


>
> > If I install the opensource java, it just doesn't work
> > -- I discussed this on the jmol list and even reported a bug against
> > the java package in Debian, but I just don't have time to push this
> > forward and get it fixed.
>
> Yes, this is clearly a bug in Debian's java--hopefully they fix it
> someday. (I don't have the time to work on it either.) Fixing either
> jmol and/or the open source Java to actually work together would be a
> great GSoC project.
>
> > x3d on the other hand does work out of the box, after I installed
> > one package.
>
> OK, I could lower the bar to "works out of the box over 50% of the
> time on at least 50% of the systems" and still jmol is the only thing
> we tried that actually passes this criteria. If the average user goes
> to sagenb.org, the 3d plots are likely to work.

Even in sagenb.org it doesn't work for me :(


>
> That being said, I'd really like for x3d to be fully supported, and
> it would be nice to have a notebook option to choose between tachyon/
> jmol/x3d as being the default way to show 3d data.
>
> - Robert

Ronan

Ondrej Certik

unread,
Mar 10, 2009, 10:06:51 PM3/10/09
to sage-...@googlegroups.com

Exactly, that's my experience too. Could you please try the x3d if it
works for you?


Ondrej

Prabhu Ramachandran

unread,
Mar 10, 2009, 1:40:59 PM3/10/09
to sage-...@googlegroups.com
On 03/10/09 16:41, Jason Grout wrote:
>> http://nb.hpfem.org/home/pub/16
>
> I just installed FreeWRL and looked at this. Awesome! It looks like
> this might be the best way to get good opengl graphics (and mayavi!) in
> the sage notebook while we still wait on the possibility of an html
> canvas3d tag.

Thanks for the kind words. It would be nice if someone would
incorporate the little patch to cell.py to support this directly. It
would be cool if the build process for this were easier so others could
also have a mayavi enabled sage. I am not sure what the status of that
was, I believe Jaap and Ondrej were working that out.

> I noticed that, at least with Freewrl, there didn't seem to be an easy
> way of rotating the object in the above demo. Instead, all the methods
> focused on navigating the camera. Does anyone know a way to rotate the
> whole scene around some point, similar to grabbing and dragging an
> object in jmol or mayavi? This could be accomplished by moving the
> camera around a sphere, always pointing at the same spot in space.

Left-click and drag rotates the camera and right click drag zooms. I
couldn't find something for panning the camera. The trouble with the
rotation is that the center of the rotation always seems to be at
(0,0,0) which causes the funny interactionr. I wrote to John Stewart
regarding fixing this a day or so ago and haven't heard back.

cheers,
prabhu

Reply all
Reply to author
Forward
0 new messages