Mayavi: interpolate face colors in triangular_mesh

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

Mayavi: interpolate face colors in triangular_mesh

Dimagiba, Lorenzo
Hi,

I have not been able to try your code, however based off of what I'm reading, you might possibly want to try turning on scalar interpolation for a smoother look.

For your code I believe you should be able to add the following line after creating your surface:

mesh2.actor.mapper.interpolate_scalars_before_mapping = True

Hopefully this is what you are looking for.

Lorenzo

This e-mail may contain confidential and/or privileged information for the sole use of the intended recipient.
Any review or distribution by anyone other than the person for whom it was originally intended is strictly prohibited.
If you have received this e-mail in error, please contact the sender and delete all copies.
Opinions, conclusions or other information contained in this e-mail may not be that of the organization.

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

Re: Mayavi: interpolate face colors in triangular_mesh

Nikolaus Rath
(quoting recovered)

"Dimagiba, Lorenzo" <[hidden email]>
writes:

>> # Plot it
>> mesh = mlab.triangular_mesh(x, y, z, triangles,
>>                             representation='wireframe',
>>                             opacity=0)
>> cell_data = mesh.mlab_source.dataset.cell_data
>> cell_data.scalars = f
>> cell_data.scalars.name = 'Cell data'
>> cell_data.update()
>>
>> mesh2 = mlab.pipeline.set_active_attribute(mesh,
>>         cell_scalars='Cell data')
>> mlab.pipeline.surface(mesh2)
>>
>> mlab.show()
>> --snip--
>>
>>
>> This works reasonably well. However, instead of having every triangle
>> with a uniform color and sharp transitions between the triangles, I'd
>> much rather have a smooth interpolation over the entire surface.
>>
>> Is there a way to do that?
>>
> Hi,
>
> I have not been able to try your code, however based off of what I'm
> reading, you might possibly want to try turning on scalar
> interpolation for a smoother look.
>
> For your code I believe you should be able to add the following line
> after creating your surface:
>
> mesh2.actor.mapper.interpolate_scalars_before_mapping = True
>
> Hopefully this is what you are looking for.

Hmm. Not quite. The mesh2 object doesn't have an 'actor' attribute, only
a 'actors' list (but that is also empty). Any suggestions where else I
can find this setting?



Best,

   -Nikolaus

--
 »Time flies like an arrow, fruit flies like a Banana.«

  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Mayavi: interpolate face colors in triangular_mesh

Gael Varoquaux
On Thu, Feb 21, 2013 at 05:10:40PM -0800, Nikolaus Rath wrote:

> "Dimagiba, Lorenzo" <[hidden email]>
> writes:
> >> # Plot it
> >> mesh = mlab.triangular_mesh(x, y, z, triangles,
> >>                             representation='wireframe',
> >>                             opacity=0)
> >> cell_data = mesh.mlab_source.dataset.cell_data
> >> cell_data.scalars = f
> >> cell_data.scalars.name = 'Cell data'
> >> cell_data.update()

> >> mesh2 = mlab.pipeline.set_active_attribute(mesh,
> >>         cell_scalars='Cell data')
> >> mlab.pipeline.surface(mesh2)

> >> mlab.show()
> >> --snip--


> > For your code I believe you should be able to add the following line
> > after creating your surface:

> > mesh2.actor.mapper.interpolate_scalars_before_mapping = True

> > Hopefully this is what you are looking for.

> Hmm. Not quite. The mesh2 object doesn't have an 'actor' attribute, only
> a 'actors' list (but that is also empty). Any suggestions where else I
> can find this setting?

I beliebe that you want to apply Lorenzo's suggestion to the object
returned by the call to mlab.pipeline.surface.

HTH,

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

Re: Mayavi: interpolate face colors in triangular_mesh

Dimagiba, Lorenzo
In reply to this post by Dimagiba, Lorenzo
Hello Nikolaus,

A lot of what I know about MayaVI has come from me going through a lot of trial and error, so forgive me if my suggestions don't work properly.

Perhaps try and give a handle when you perform the surface function, so try:

my_surface = mlab.pipeline.surface(mesh2)

then try:

my_surface.actor.mapper.interpolate_scalars_before_mapping = True

I hope this is what you are looking for.

Regards,

Lorenzo

This e-mail may contain confidential and/or privileged information for the sole use of the intended recipient.
Any review or distribution by anyone other than the person for whom it was originally intended is strictly prohibited.
If you have received this e-mail in error, please contact the sender and delete all copies.
Opinions, conclusions or other information contained in this e-mail may not be that of the organization.

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

Re: Mayavi: interpolate face colors in triangular_mesh

Nikolaus Rath
In reply to this post by Gael Varoquaux
Gael Varoquaux <[hidden email]> writes:

> On Thu, Feb 21, 2013 at 05:10:40PM -0800, Nikolaus Rath wrote:
>> "Dimagiba, Lorenzo" <[hidden email]>
>> writes:
>> >> # Plot it
>> >> mesh = mlab.triangular_mesh(x, y, z, triangles,
>> >>                             representation='wireframe',
>> >>                             opacity=0)
>> >> cell_data = mesh.mlab_source.dataset.cell_data
>> >> cell_data.scalars = f
>> >> cell_data.scalars.name = 'Cell data'
>> >> cell_data.update()
>
>> >> mesh2 = mlab.pipeline.set_active_attribute(mesh,
>> >>         cell_scalars='Cell data')
>> >> mlab.pipeline.surface(mesh2)
>
>> >> mlab.show()
>> >> --snip--
>
>
>> > For your code I believe you should be able to add the following line
>> > after creating your surface:
>
>> > mesh2.actor.mapper.interpolate_scalars_before_mapping = True
>
>> > Hopefully this is what you are looking for.
>
>> Hmm. Not quite. The mesh2 object doesn't have an 'actor' attribute, only
>> a 'actors' list (but that is also empty). Any suggestions where else I
>> can find this setting?
>
> I beliebe that you want to apply Lorenzo's suggestion to the object
> returned by the call to mlab.pipeline.surface.

That doesn't produce errors any more, but unfortunately it doesn't
change the rendering either. :-/

Best,

   -Nikolaus

--
 »Time flies like an arrow, fruit flies like a Banana.«

  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Mayavi: interpolate face colors in triangular_mesh

Dimagiba, Lorenzo
In reply to this post by Dimagiba, Lorenzo
Perhaps try and post a picture of what you currently have, and then describe what it is you are trying to obtain. I'm not entirely sure at this point what you are looking for.

Lorenzo

This e-mail may contain confidential and/or privileged information for the sole use of the intended recipient.
Any review or distribution by anyone other than the person for whom it was originally intended is strictly prohibited.
If you have received this e-mail in error, please contact the sender and delete all copies.
Opinions, conclusions or other information contained in this e-mail may not be that of the organization.

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

Re: Mayavi: interpolate face colors in triangular_mesh

Rich Signell
How about posting this on stackoverflow.com, tagged with "python" and
"enthought"?

You can post a picture there, there is code highlighting, and the rest
of the community can benefit (and add to) the discussion.

-Rich

On Mon, Feb 25, 2013 at 9:17 AM, Dimagiba, Lorenzo
<[hidden email]> wrote:

> Perhaps try and post a picture of what you currently have, and then describe what it is you are trying to obtain. I'm not entirely sure at this point what you are looking for.
>
> Lorenzo
>
> This e-mail may contain confidential and/or privileged information for the sole use of the intended recipient.
> Any review or distribution by anyone other than the person for whom it was originally intended is strictly prohibited.
> If you have received this e-mail in error, please contact the sender and delete all copies.
> Opinions, conclusions or other information contained in this e-mail may not be that of the organization.
>
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev



--
Dr. Richard P. Signell   (508) 457-2229
USGS, 384 Woods Hole Rd.
Woods Hole, MA 02543-1598
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Mayavi: interpolate face colors in triangular_mesh

Nikolaus Rath
In reply to this post by Dimagiba, Lorenzo
"Dimagiba, Lorenzo" <[hidden email]> writes:
> Perhaps try and post a picture of what you currently have, and then
> describe what it is you are trying to obtain. I'm not entirely sure at
> this point what you are looking for.

The following script generates a smooth, interpolated plot using
mlab.mesh and a "ragged" plot using mlab.triangular_mesh. What I want is
the smooth plot, but without having to use mlab.mesh (because the
surface that I actually want to plot has explicit connectivity).

---snip---
#! /usr/bin/env python
import numpy as np
from mayavi import mlab

(ys, xs) = np.mgrid[-10:10:20j, -10:10:20j]
zs = np.cos(xs/2) + 0.5 * np.cos(ys/4)

alpha = np.arctan2(ys, xs)
u = np.sin(alpha)
v = -np.cos(alpha)
w = -u * np.sin(xs/2)/2 - v * np.sin(ys/4)/4

mlab.figure()
mlab.mesh(xs, ys, zs, scalars=w)

indices = np.arange(xs.size)
indices.shape = xs.shape
rectangles = np.empty((xs.shape[0]-1, xs.shape[1]-1, 4),
                      dtype=np.int)
rectangles[:, :, 0] = indices[:-1,:-1]
rectangles[:, :, 1] = indices[:-1,1:]
rectangles[:, :, 2] = indices[1:,1:]
rectangles[:, :, 3] = indices[1:,:-1]

rectangles = rectangles.reshape((-1, 4))
triangles = np.empty((2*len(rectangles), 3), dtype=np.int)
triangles[:len(rectangles)] = rectangles[:,:3]
triangles[len(rectangles):] = rectangles[:,:3]
triangles[len(rectangles):,1] = rectangles[:,3]

xs_1d = xs.reshape(-1)
ys_1d = ys.reshape(-1)
zs_1d = zs.reshape(-1)

mlab.figure()
mesh = mlab.triangular_mesh(xs_1d, ys_1d, zs_1d, triangles)

cell_data = mesh.mlab_source.dataset.cell_data
w_1d = w[:-1,:-1].reshape(-1)
cell_data.scalars = np.r_[w_1d, w_1d]
cell_data.scalars.name = 'Cell data'
cell_data.update()

mesh2 = mlab.pipeline.set_active_attribute(mesh,
        cell_scalars='Cell data')
thingy = mlab.pipeline.surface(mesh2)

thingy.actor.mapper.interpolate_scalars_before_mapping = True

mlab.show()
---snip---


Thanks for your help!

   -Nikolaus

--
 »Time flies like an arrow, fruit flies like a Banana.«

  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev