Add XTK JavaScript library support #2258

Closed
wants to merge 5 commits into
from

Conversation

Projects
None yet
6 participants
Owner

ellisonbg commented Aug 5, 2012

This makes it possible to do 3D visualizations in the Notebook.

IPython/lib/xtkdisplay.py
+
+A simple example would be::
+
+ from xtkdisplay import Mesh
@fperez

fperez Aug 5, 2012

Owner

This should read from IPython.lib.xtkdisplay...

@minrk

minrk Aug 5, 2012

Owner

Why did this get its own file instead of going in lib.display with the YouTubeVideo?

@ellisonbg

ellisonbg Aug 5, 2012

Owner

Done.

On 8/5/12, Fernando Perez
reply@reply.github.com
wrote:

@@ -0,0 +1,88 @@
+"""Display classes for the XTK JavaScript library.
+
+The XTK JavaScript library uses WebGL to render 3D visualizations. It
can
+generate those visualizations based a range of standard 3D data files
types,
+including .vtk and .stl. This module makes it possible to render these
+visualizations in the IPython Notebook.
+
+A simple example would be::
+

  • from xtkdisplay import Mesh

This should read from IPython.lib.xtdksiplay...


Reply to this email directly or view it on GitHub:
https://github.com/ipython/ipython/pull/2258/files#r1308432

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

Owner

minrk commented Aug 5, 2012

This notebook is pretty huge. Do we want to commit it without output?

Owner

ellisonbg commented Aug 5, 2012

This notebook is actually very small, it is the vtk file I put in the
directory that is bigger.

On Sun, Aug 5, 2012 at 11:57 AM, Min RK
reply@reply.github.com
wrote:

This notebook is pretty huge. Do we want to commit it without output?


Reply to this email directly or view it on GitHub:
#2258 (comment)

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

docs/examples/notebooks/xtk_display.ipynb
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "Mesh('files/data/smallsurface.vtk', opacity=0.7, magicmode=True, bgcolor='#FFF')"
@Carreau

Carreau Aug 5, 2012

Owner

why data/? I does not work with data for me.

@ellisonbg

ellisonbg Aug 5, 2012

Owner

Ah crap, I will fix that...

On Sun, Aug 5, 2012 at 12:01 PM, Bussonnier Matthias
reply@reply.github.com
wrote:

  •  }
    
  • ],
    
  • "prompt_number": 2
    
  • },
  • {
  • "cell_type": "markdown",
    
  • "metadata": {},
    
  • "source": [
    
  •  "Or these URLS can be relative to the Notebooks working directory:"
    
  • ]
    
  • },
  • {
  • "cell_type": "code",
    
  • "collapsed": false,
    
  • "input": [
    
  •  "Mesh('files/data/smallsurface.vtk', opacity=0.7, magicmode=True, bgcolor='#FFF')"
    

why data/? I does not work with data for me.


Reply to this email directly or view it on GitHub:
https://github.com/ipython/ipython/pull/2258/files#r1308450

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

@ellisonbg

ellisonbg Aug 5, 2012

Owner

OK, give it a shot again.

On Sun, Aug 5, 2012 at 12:02 PM, Brian Granger ellisonbg@gmail.com wrote:

Ah crap, I will fix that...

On Sun, Aug 5, 2012 at 12:01 PM, Bussonnier Matthias
reply@reply.github.com
wrote:

  •  }
    
  • ],
    
  • "prompt_number": 2
    
  • },
  • {
  • "cell_type": "markdown",
    
  • "metadata": {},
    
  • "source": [
    
  •  "Or these URLS can be relative to the Notebooks working directory:"
    
  • ]
    
  • },
  • {
  • "cell_type": "code",
    
  • "collapsed": false,
    
  • "input": [
    
  •  "Mesh('files/data/smallsurface.vtk', opacity=0.7, magicmode=True, bgcolor='#FFF')"
    

why data/? I does not work with data for me.


Reply to this email directly or view it on GitHub:
https://github.com/ipython/ipython/pull/2258/files#r1308450

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

@Carreau

Carreau Aug 5, 2012

Owner

damned, gihub does not notificate me anymore for some messages !
Annoying !
I'll look at it tomorrow.

Owner

fperez commented Aug 5, 2012

This looks great!! Do you know if it's possible to change the mouse sensitivity? The only problem I see is that right now it seems the default mouse sensitivity is very low, so it takes a lot of clicking and dragging to make things move...

And also, do you know if it can be configured to continue responding to mouse events once they leave the area?

Owner

ellisonbg commented Aug 5, 2012

Yeah, I am not thrilled with the mouse controls right now. I haven't
been able to find any way to configure them, might have to ask the dev
about this.

On Sun, Aug 5, 2012 at 12:04 PM, Fernando Perez
reply@reply.github.com
wrote:

This looks great!! Do you know if it's possible to change the mouse sensitivity? The only problem I see is that right now it seems the default mouse sensitivity is very low, so it takes a lot of clicking and dragging to make things move...

And also, do you know if it can be configured to continue responding to mouse events once they leave the area?


Reply to this email directly or view it on GitHub:
#2258 (comment)

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

Owner

minrk commented Aug 5, 2012

This notebook is actually very small, it is the vtk file I put in the
directory that is bigger.

Gotcha, misread the diff.

Owner

minrk commented Aug 5, 2012

I'm increasingly starting to think our docs/examples really belong as a separate project.

Owner

ellisonbg commented Aug 5, 2012

That might make sense. Either that or examples should be top level
and not a subdir of docs.

On Sun, Aug 5, 2012 at 12:55 PM, Min RK
reply@reply.github.com
wrote:

I'm increasingly starting to think our docs/examples really belong as a separate project.


Reply to this email directly or view it on GitHub:
#2258 (comment)

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

Owner

minrk commented Aug 5, 2012

It's a conversation for another time, but one we should have. Ultimately we are going to want matplotlib gallery-level example notebooks (maybe even autogenerated from the matplotlib gallery!), and it is making an ever decreasing amount of sense for them to live in the IPython source repo.

Any response to why the XTKMesh gets its own file rather than being added to lib.display?

Owner

ellisonbg commented Aug 5, 2012

On Sun, Aug 5, 2012 at 1:39 PM, Min RK
reply@reply.github.com
wrote:

It's a conversation for another time, but one we should have. Ultimately we are going to want matplotlib gallery-level example notebooks (maybe even autogenerated from the matplotlib gallery!), and it makes very little sense for that to live in the IPython source repo.

Any response to the why XTKMesh gets its own file rather than beig added to lib.display?

There are other XTK related display objects we will eventually want to
have and I wanted those objects to be namespace scoped away from other
display classes (rather than prefix "XTK" to all the class names).


Reply to this email directly or view it on GitHub:
#2258 (comment)

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

Owner

minrk commented Aug 5, 2012

There are other XTK related display objects we will eventually want to
have and I wanted those objects to be namespace scoped away from other
display classes (rather than prefix "XTK" to all the class names).

Ah, that makes sense then (not at the moment with just one object, hence the question).

Are there going to be any classes here that are not display-related, in which case it should be lib.xtk instead of lib.xtkdisplay (or lib.displayxtk for completion discovery)?

Owner

ellisonbg commented Aug 5, 2012

On Sun, Aug 5, 2012 at 2:00 PM, Min RK
reply@reply.github.com
wrote:

There are other XTK related display objects we will eventually want to
have and I wanted those objects to be namespace scoped away from other
display classes (rather than prefix "XTK" to all the class names).

Ah, that makes sense then (not at the moment with just one object, hence the question).

Are there going to be any classes here that are not display-related, in which case it should be lib.xtk instead of lib.xtkdisplay (or lib.displayxtk for completion discovery)?

I think they will be display related in some way or another.


Reply to this email directly or view it on GitHub:
#2258 (comment)

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

Owner

minrk commented Aug 5, 2012

I think they will be display related in some way or another.

So there is no reason that we will be adding code to manipulate the XTK structures themselves?

Owner

ellisonbg commented Aug 5, 2012

Not quite sure what you are asking. You might even say that the Mesh class manipulates XTK JS objects. The overall long term vision is that we will probably have a python class for each XTK object (show here under the "Objects" category https://github.com/xtk/X#readme). These objects will know how to generate the appropriate JS code that is returned to the browser. But all of that JS code will be run through the display system.

Owner

minrk commented Aug 5, 2012

Basically just asking whether there would be any manipulation of anything Python-side. If it's all javascript side, then it makes perfect sense (other than possibly reversing it to displayxtk for tab reasons).

Owner

ellisonbg commented Aug 5, 2012

Well, I think the division between python/JS could be a bit blury.
For example, I have thought about making it possible to create 2d/3d
scatter plots from arrays/lists. It is python code, but underneath it
would be generating JS code. So maybe call it just xtk?

On Sun, Aug 5, 2012 at 2:08 PM, Min RK
reply@reply.github.com
wrote:

Basically just asking whether there would be any manipulation of anything Python-side. If it's all javascript side, then it makes perfect sense (other than possibly reversing it to displayxtk for tab reasons).


Reply to this email directly or view it on GitHub:
#2258 (comment)

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

Owner

minrk commented Aug 5, 2012

If lib.xtk makes sense to you, I think that would be my preference.

Basically, if this is 'general utilities for working with xtk', I would call it xtk. If it is only ever going to be 'simple repr-having objects for xtk', then including display in the name makes sense.

I am only being picky because this is a public API, so changing/adding names in the future is costly.

Do you want to add an import to the top-level IPython.display as display.xtk?

Owner

ellisonbg commented Aug 6, 2012

Let's wait to merge this, I am working on some improvements.

Owner

fperez commented Aug 6, 2012

On Sun, Aug 5, 2012 at 1:39 PM, Min RK
reply@reply.github.com
wrote:

It's a conversation for another time, but one we should have. Ultimately we are going to want matplotlib gallery-level example notebooks (maybe even autogenerated from the matplotlib gallery!), and it makes very little sense for that to live in the IPython source repo.

Agreed, not for now, but we'll need to tackle this later on. We
really need to finish up nbconvert soon, so that we can include said
gallery automatically in doc builds, and rethink our documentation
approach. It is tempting to completely separate it, but I also like
ensuring that it's easy to edit the docs in sync with changes to the
code. Anyway, that's a good topic for an open discussion on the dev
list.

Owner

fperez commented Aug 6, 2012

On Sun, Aug 5, 2012 at 3:07 PM, Min RK
reply@reply.github.com
wrote:

If lib.xtk makes sense to you, I think that would be my preference.

Same here.

IPython/lib/xtkdisplay.py
+
+ Parameters
+ ==========
+ url : str
@fperez

fperez Aug 6, 2012

Owner

We should consider this api a bit more carefully, so that we don't assume there has to be a URL for these guys: when clients capture data from remote engines, they will have the data in-memory.

IPython/lib/xtkdisplay.py
+ r.container = id;
+ r.init();
+ var m = new X.mesh();
+ m.file = "%s";
@fperez

fperez Aug 6, 2012

Owner

This shouldn't use plain %s positional arguments, as that makes it extremely brittle. For this kind of more complex template rendering, the new {} syntax that Python allows is both clearer and safer in the long run.

IPython/lib/xtkdisplay.py
+#-----------------------------------------------------------------------------
+
+
+code = """
@fperez

fperez Aug 6, 2012

Owner

This template is mesh-specific, we should probably have a more generic one that we can reuse with the various XTK objects.

Owner

fperez commented Aug 6, 2012

I also noted smallsurface.vtk is executable, it shouldn't.

IPython/lib/xtkdisplay.py
+class Mesh(object):
+ """Display an XTK mesh object using a URL."""
+
+ def __init__(self, url, width=400, height=300, magicmode=False, opacity=1.0, bgcolor='#000'):
@fperez

fperez Aug 7, 2012

Owner

After using it more, I think we should make the default background color be some shade of gray, so that the user has a visual indication of the boundary of the region which is active for mouse event handling. Having it be white is really annoying to use, because it's hard to tell if you've gone off the edge or not. We could use the same color as our boxes or something else, I don't care much. But white is suboptimal here, I think.

Owner

ellisonbg commented Aug 7, 2012

I will fix these things.

On Mon, Aug 6, 2012 at 4:27 AM, Fernando Perez
reply@reply.github.com
wrote:

I also noted smallsurface.vtk is executable, it shouldn't.


Reply to this email directly or view it on GitHub:
#2258 (comment)

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

Owner

ellisonbg commented Aug 9, 2012

This PR should not be merged yet. I am working with XTK devs to fix a bug and I am also refactoring this PR.

Owner

Carreau commented Sep 29, 2012

Hi,
This PR is without activities for 2 month now,
I'm going to close it and open an issue to reference it.
This does not mean than we refuse the code that is here, but that we try to keep the number of opened Pull request as low as possible to have better bird view of active code.

Fell free to reopen this PR whenever you want or contact us if you have any questions.

Thanks for contributing.

How does that sound ? (and if you like it i'll close and open an issue) :-)

Owner

ellisonbg commented Sep 29, 2012

I am fine closing this one and opening an issue, but have one question:

The current version of the PR does work, but in my local branch, I made a
bunch of improvements and expanded the API substantially. BUT, it also
broke things due to a bug in xtk. I asked the author but never really
resolved it:

http://stackoverflow.com/questions/11822195/xtk-could-not-find-the-given-container

Should I merge my local changes into the PR or just leave it as is?

On Sat, Sep 29, 2012 at 12:32 PM, Bussonnier Matthias <
notifications@github.com> wrote:

Hi,
This PR is without activities for 2 month now,
I'm going to close it and open an issue to reference it.
This does not mean than we refuse the code that is here, but that we try
to keep the number of opened Pull request as low as possible to have better
bird view of active code.

Fell free to reopen this PR whenever you want or contact us if you have
any questions.

Thanks for contributing.

How does that sound ? (and if you like it i'll close and open an issue) :-)


Reply to this email directly or view it on GitHubhttps://github.com/ipython/ipython/pull/2258#issuecomment-9007310.

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

Owner

Carreau commented Sep 29, 2012

I would prefere having directly have the full API to avoid people relying on smth that could be changed afterward.

I have a bug that look the same with d3js and timing where things does not work when runned through eval, but does from JS console, even if the dom is updated and the svg contains the right elements, the svg rendering is not. I have not been able to investigate further, but this make me think we might be hitting a issue in the browser itself, or a race condition somewhere with jQuery, maby an issue because we are running stuff through eval. I have to see what append if I push a script with HTML('<script>')

Owner

ellisonbg commented Oct 1, 2012

Oh thanks this information is useful. I will push my changes, but we
should probably close the PR afterwards until we can resolve this. It is
wierd that you have seen something like this as well.

On Sat, Sep 29, 2012 at 2:13 PM, Bussonnier Matthias <
notifications@github.com> wrote:

I would prefere having directly have the full API to avoid people relying
on smth that could be changed afterward.

I have a bug that look the same with d3js and timing where things does not
work when runned through eval, but does from JS console, even if the dom is
updated and the svg contains the right elements, the svg rendering is not.
I have not been able to investigate further, but this make me think we
might be hitting a issue in the browser itself, or a race condition
somewhere with jQuery, maby an issue because we are running stuff through
eval. I have to see what append if I push a script with HTML('&#39#39
;)


Reply to this email directly or view it on GitHubhttps://github.com/ipython/ipython/pull/2258#issuecomment-9008275.

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

Owner

ellisonbg commented Oct 2, 2012

Ok I just pushed all of my changes, you can close this and open an issue for it. Thanks!

Owner

ellisonbg commented Oct 2, 2012

This PR is being closed because of inactivity:

https://github.com/ipython/ipython/wiki/Policy:-Closing-pull-requests

We have opened an issue (#2461) to track the progress. We encourage people to continue work on this. The reason activity stopped is that we ran into a bug, detailed here, with XTK:

http://stackoverflow.com/questions/11822195/xtk-could-not-find-the-given-container

Once this issue has been resolved, this PR can be reopened and proceed.

@ellisonbg ellisonbg closed this Oct 2, 2012

haehn commented Nov 2, 2012

just saw this by random - looks fantastic!! sorry about the bug so :)

haehn commented Nov 2, 2012

I added a possible fix to stackoverflow
http://stackoverflow.com/a/13187938/1183453

Owner

ellisonbg commented Nov 2, 2012

I know what the problem is and will try to post a fix soon.

On Thu, Nov 1, 2012 at 6:09 PM, Daniel Haehn notifications@github.comwrote:

just saw this by random - looks fantastic!! sorry about the bug so :)


Reply to this email directly or view it on GitHubhttps://github.com/ipython/ipython/pull/2258#issuecomment-10001955.

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

haehn commented Nov 2, 2012

Great! Here is also a working example on JSFiddle http://jsfiddle.net/NCKfE/

haehn commented Nov 6, 2012

Just updated the example code - it should all work now!!!

certik commented May 31, 2013

Just giving 👍 to get this into IPython, as I would love to be able to visualize vtk files in the ipython notebook.
@ellisonbg -- do you know what the problem is? What has to be done to get this in?

haehn commented Jun 3, 2013

I am willing to help as well.

Cheers,
Daniel

Owner

Carreau commented Jun 3, 2013

@certik, @haehn IIRC one of the "problem" was fixed, but this got delayed because of a larger issue, which would be the general case of showing data through JS. We hope to be able to design an API to simplify this kind of work and be able to much more simply display for VTK and other format.

It would basically be a js plugin, which given some data can render it.
it would avoid "forging" javascript code by concatenating string in python.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment