Add texture coordinates to triangular_mesh

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

Add texture coordinates to triangular_mesh

Dat Chu
I have three numpy arrays:
Nx3 vertex coordinates
Nx2 texture coordinates
Mx3 triangle indexing

Using mlab.triangular_mesh(vertex[:,0], vertex[:,1], vertex[:,2], triangles) I can create my mesh. But now I want to texture this mesh. I search around and it seems that I need to set the t_coords.

s = mlab.triangular_mesh(vertex[:,0], vertex[:,1], vertex[:,2], triangles)
s.point_data.t_coords = texture

I then get an error
AttributeError: 'Surface' object has no attribute 'point_data'

How do I texture my triangular mesh?

With warm regards,

Dat Chu

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

Re: Add texture coordinates to triangular_mesh

Gael Varoquaux
On Wed, Apr 28, 2010 at 11:52:01AM -0500, Dat Chu wrote:

>    I have three numpy arrays:
>    Nx3 vertex coordinates
>    Nx2 texture coordinates
>    Mx3 triangle indexing
>    Using mlab.triangular_mesh(vertex[:,0], vertex[:,1], vertex[:,2],
>    triangles) I can create my mesh. But now I want to texture this mesh. I
>    search around and it seems that I need to set the t_coords.
>    s = mlab.triangular_mesh(vertex[:,0], vertex[:,1], vertex[:,2],
>    triangles)
>    s.point_data.t_coords = texture

Use:

    s.mlab_source.dataset.point_data.t_coords

In general, for an object created by mlab, obj.mlab_source.dataset gives
access to the underlying VTK dataset object.

HTH,

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: Add texture coordinates to triangular_mesh

Dat Chu
Great, my triangular mesh now has textures. Now I want to change the positions of the points by applying a projection_matrix to it. How can I do this directly on VTK array?

Should I instead perform the projection and then create another triangular_mesh for visualization?

On Wed, Apr 28, 2010 at 1:37 PM, Gael Varoquaux <[hidden email]> wrote:
On Wed, Apr 28, 2010 at 11:52:01AM -0500, Dat Chu wrote:
>    I have three numpy arrays:
>    Nx3 vertex coordinates
>    Nx2 texture coordinates
>    Mx3 triangle indexing
>    Using mlab.triangular_mesh(vertex[:,0], vertex[:,1], vertex[:,2],
>    triangles) I can create my mesh. But now I want to texture this mesh. I
>    search around and it seems that I need to set the t_coords.
>    s = mlab.triangular_mesh(vertex[:,0], vertex[:,1], vertex[:,2],
>    triangles)
>    s.point_data.t_coords = texture

Use:

   s.mlab_source.dataset.point_data.t_coords

In general, for an object created by mlab, obj.mlab_source.dataset gives
access to the underlying VTK dataset object.

HTH,

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


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

Re: Add texture coordinates to triangular_mesh

Gael Varoquaux
On Wed, Apr 28, 2010 at 04:59:36PM -0500, Dat Chu wrote:
>    Great, my triangular mesh now has textures. Now I want to change the
>    positions of the points by applying a projection_matrix to it. How can I
>    do this directly on VTK array?
>    Should I instead perform the projection and then create another
>    triangular_mesh for visualization?

It think the easiest way would be to do:

    s.mlab_source.set(x=new_x, y=new_y, z=new_z)

This is detailed in:
http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/mlab.html#animating-the-data

HTH,

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: Add texture coordinates to triangular_mesh

Dat Chu
Thanks Gael. You hit the nail right on the head. Mayavi2 is indeed an awesome piece of work. It should replace python-binding for VTK.

Dat Chu

On Wed, Apr 28, 2010 at 5:02 PM, Gael Varoquaux <[hidden email]> wrote:
On Wed, Apr 28, 2010 at 04:59:36PM -0500, Dat Chu wrote:
>    Great, my triangular mesh now has textures. Now I want to change the
>    positions of the points by applying a projection_matrix to it. How can I
>    do this directly on VTK array?
>    Should I instead perform the projection and then create another
>    triangular_mesh for visualization?

It think the easiest way would be to do:

   s.mlab_source.set(x=new_x, y=new_y, z=new_z)

This is detailed in:
http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/mlab.html#animating-the-data

HTH,

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


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

Re: Add texture coordinates to triangular_mesh

Gael Varoquaux
On Wed, Apr 28, 2010 at 05:43:09PM -0500, Dat Chu wrote:
>    Thanks Gael. You hit the nail right on the head. Mayavi2 is indeed an
>    awesome piece of work. It should replace python-binding for VTK.

Thank you. I am not always happy with the current state of the software,
and I don't manage to find the time to improve it. Support really helps
keeping motivated!

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: Add texture coordinates to triangular_mesh

Jonathan Guyer

On Apr 29, 2010, at 1:50 AM, Gael Varoquaux wrote:

> On Wed, Apr 28, 2010 at 05:43:09PM -0500, Dat Chu wrote:
>>   Thanks Gael. You hit the nail right on the head. Mayavi2 is indeed an
>>   awesome piece of work. It should replace python-binding for VTK.
>
> Thank you. I am not always happy with the current state of the software,
> and I don't manage to find the time to improve it. Support really helps
> keeping motivated!

Rest assured that your efforts are greatly appreciated [not that I'm suggesting that you shouldn't do more! 8^) ]

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

Re: Add texture coordinates to triangular_mesh

fred-2
Le 29/04/2010 16:26, Jonathan Guyer a écrit :

> Rest assured that your efforts are greatly appreciated [not that I'm suggesting that you shouldn't do more! 8^) ]
+1e999

Cheers,

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