using the colormap of mlab.surf to display a 4th dimension

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

using the colormap of mlab.surf to display a 4th dimension

Didrik Pinte-2
Hi all,

As promised during the Mayavi webinar two weeks ago, here is the post
about making use of the fourth dimension in mlab.surf() calls :
http://dpinte.wordpress.com/2010/03/30/4d-surface-plots-in-mayavi/

Let me know about comments or questions.

-- Didrik
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: using the colormap of mlab.surf to display a 4th dimension

Gael Varoquaux
On Tue, Mar 30, 2010 at 02:06:38PM +0200, Didrik Pinte wrote:
> As promised during the Mayavi webinar two weeks ago, here is the post
> about making use of the fourth dimension in mlab.surf() calls :
> http://dpinte.wordpress.com/2010/03/30/4d-surface-plots-in-mayavi/

Hi Didrik,

I am not certain what the exact purpose of your example is. Some ideas on
how to achieve similar plots more simply. I have taken time to expose
this discussion on my blog (http://gael-varoquaux.info/blog/?p=128), as I
believe it is important, and reflects some features of Mayavi than are
known enough, I am just posting a short summary to the list.

First of all, if what you want is to display a surface and control the
scalar value on this surface independantly from the altitude, you can use
the mesh function:
http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/auto/mlab_helper_functions.html#enthought.mayavi.mlab.mesh

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
from enthought.mayavi import mlab

import numpy as np

x, y = np.mgrid[0:10:100j, 0:10:100j]

z = x**2 + y**2
w = np.arctan(x/y)

mlab.mesh(x, y, .05*z, scalars=w)
mlab.axes()
mlab.outline()
mlab.view(-177, 82, 32)
mlab.show()
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Also, if you want to build your own pipeline, as you do in your blog
post, the right way is to use the mlab.pipeline functions, as documented
in
http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/mlab.html#assembling-pipelines-with-mlab

That way, to replicate a 'surf' inserting a SetActiveAttribute, you can
do:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src = mlab.pipeline.array2d_source(a)
# Snip: add data here, see my blog post on how to do this right.

warp = mlab.pipeline.warp_scalar(src)
normals = mlab.pipeline.poly_data_normals(warp)
active_attr = mlab.pipeline.set_active_attribute(normals)
surf = mlab.pipeline.surface(active_attr)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

That way you don't have to patch Mayavi, which really shouldn't be an
option.

An example of visualizing data with more than one scalar value is given
on
http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/auto/example_atomic_orbital.html#example-atomic-orbital
and can be useful for these purposes, I give working code for purposes
close to your example in my blog post/

I am sorry I wasn't able to attend the webinar to answer such questions
live.

Best,

Gaël
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: using the colormap of mlab.surf to display a 4th dimension

Didrik Pinte-2
Le 5/04/2010 1:36, Gael Varoquaux a écrit :
> On Tue, Mar 30, 2010 at 02:06:38PM +0200, Didrik Pinte wrote:
>    
>> As promised during the Mayavi webinar two weeks ago, here is the post
>> about making use of the fourth dimension in mlab.surf() calls :
>> http://dpinte.wordpress.com/2010/03/30/4d-surface-plots-in-mayavi/
>>      
> Hi Didrik,
>
> I am not certain what the exact purpose of your example is.
I was just trying to share some results I had while playing with the
colormap to make use of a fourth dimension.

The example I have is a bit more complicated because it has live updates
based on the elevation and the colormap that are two functions. As soon
as you change one of the traits inputs, I try to update the pipeline
without creating new objects but just by replacing the arrays at the
right place.

> Some ideas on
> how to achieve similar plots more simply. I have taken time to expose
> this discussion on my blog (http://gael-varoquaux.info/blog/?p=128), as I
> believe it is important, and reflects some features of Mayavi than are
> known enough, I am just posting a short summary to the list.
>    

Your post is great. I'll update some of my post according to that
(particularly the part where I suggest to pach the Surf class ;-) ).

> First of all, if what you want is to display a surface and control the
> scalar value on this surface independantly from the altitude, you can use
> the mesh function:
> http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/auto/mlab_helper_functions.html#enthought.mayavi.mlab.mesh
>
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> from enthought.mayavi import mlab
>
> import numpy as np
>
> x, y = np.mgrid[0:10:100j, 0:10:100j]
>
> z = x**2 + y**2
> w = np.arctan(x/y)
>
> mlab.mesh(x, y, .05*z, scalars=w)
> mlab.axes()
> mlab.outline()
> mlab.view(-177, 82, 32)
> mlab.show()
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>    

Great, I discover some new things with mayavi and vtk every day ;-).
Using the mesh is really cool as the update of the elevation and scalars
part are much easier than with surf (e.g. the scalars update) :

In [8]: w = np.arccos(x/y)
In [9]: mesh = mlab.mesh(x, y, .05*z, scalars=w)
In [10]: w = np.arctan(x/y)
In [11]: mesh.mlab_source.set(scalars=w)

> Also, if you want to build your own pipeline, as you do in your blog
> post, the right way is to use the mlab.pipeline functions, as documented
> in
> http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/mlab.html#assembling-pipelines-with-mlab
>
> That way, to replicate a 'surf' inserting a SetActiveAttribute, you can
> do:
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> src = mlab.pipeline.array2d_source(a)
> # Snip: add data here, see my blog post on how to do this right.
>
> warp = mlab.pipeline.warp_scalar(src)
> normals = mlab.pipeline.poly_data_normals(warp)
> active_attr = mlab.pipeline.set_active_attribute(normals)
> surf = mlab.pipeline.surface(active_attr)
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>    

It is definitely much cleaner than what I did ;-).

Thanks

-- Didrik
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: using the colormap of mlab.surf to display a 4th dimension

Gael Varoquaux
On Mon, Apr 05, 2010 at 02:40:57PM +0200, Didrik Pinte wrote:
> Great, I discover some new things with mayavi and vtk every day ;-).

I find it incredebily hard to make sure that the users get the right
information from the docs. On the one hand, it seems that there is
already too much information as people miss things that are already in
there, on the other hand, there is always information that people are
looking for, and that is not in the docs...

> Using the mesh is really cool as the update of the elevation and scalars
> part are much easier than with surf (e.g. the scalars update) :

> In [8]: w = np.arccos(x/y)
> In [9]: mesh = mlab.mesh(x, y, .05*z, scalars=w)
> In [10]: w = np.arctan(x/y)
> In [11]: mesh.mlab_source.set(scalars=w)

Yes, I thought it might indeed solve your problem thanks to the
mlab_source attribute. In any case, if you need to do more complex stuff,
hopefully the other option is open.

Best,

Gaël
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev