3d shaded polygons

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

3d shaded polygons

julien.delafontaine
Hi,

I have to plot a 3D molecule, on which I'd like to add shaded  
rectangles/hexagons that represent some site (bases of the DNA).
I've been trying hard to find a way to fill my polygons.

How can I fill them, given coordinates of the corners?
(Am I using the wrong tool?)

Please help!

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

Re: 3d shaded polygons

Stephan Gerhard
Hi,

Have you consulted already the Mayavi docs?
http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/index.html

In particular, you can create your rectangles with two triangles, as
described here:
http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/auto/example_polydata.html#example-polydata

Stephan

Am Freitag, den 26.03.2010, 17:26 +0100 schrieb
[hidden email]:

> Hi,
>
> I have to plot a 3D molecule, on which I'd like to add shaded  
> rectangles/hexagons that represent some site (bases of the DNA).
> I've been trying hard to find a way to fill my polygons.
>
> How can I fill them, given coordinates of the corners?
> (Am I using the wrong tool?)
>
> Please help!
>
> Julien D.
> _______________________________________________
> 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: 3d shaded polygons

julien.delafontaine
Thank you for your answer!

Of course I read the doc a thousand times, but it is very incomplete.  
I found this example, but there is a problem.

I copied the code, with all the imports. Alone it works, but all the  
"mayavi.something" are underlined in red (in Eclipse), and it says  
"NameError: global name 'mayavi' is not defined". Same for "PolyData".
It compiles even though.

Then my rectangles appears in the visualizer, when all my others  
points3d() and plot3d() appear in another more simple window. Actually  
only one or none of the rectangles appear, because I don't know how to  
put my "meshes" (PolyData) together.

Also I don't understand what it means to write
s = Surface()
mayavi.add_module(s)
, since I cannot find documentation on mayavi modules of functions.
Nor can I guess what the mayavi2.standalone() function does. It  
doesn't work without it. Where can I find such information?

But I have hope now, please help one more time. I copied the  
interesting part of my code below.

Julien D.


@mayavi2.standalone
def view():
         mayavi.new_scene()
         src = VTKDataSource(data = mesh)
         mayavi.add_source(src)
         s = Surface()
         mayavi.add_module(s)

for a in range(18):       #plots the rectangles
         rect = my_points(a)
         mlab.plot3d(rect[0], rect[1], rect[2], tube_radius=0.05) #border lines
         points = my_points(a).T
         triangles = array([[0,1,2], [0,2,3]])
         mesh = tvtk.PolyData(points=points, polys=triangles)

#how to put my meshes together??
#the border lines and the rectangles don't appear in the same window
view()


Stephan Gerhard <[hidden email]> a écrit :

> Hi,
>
> Have you consulted already the Mayavi docs?
> http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/index.html
>
> In particular, you can create your rectangles with two triangles, as
> described here:
> http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/auto/example_polydata.html#example-polydata
>
> Stephan
>
> Am Freitag, den 26.03.2010, 17:26 +0100 schrieb
> [hidden email]:
>> Hi,
>>
>> I have to plot a 3D molecule, on which I'd like to add shaded
>> rectangles/hexagons that represent some site (bases of the DNA).
>> I've been trying hard to find a way to fill my polygons.
>>
>> How can I fill them, given coordinates of the corners?
>> (Am I using the wrong tool?)
>>
>> Please help!
>>
>> Julien D.
>> _______________________________________________
>> 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
>

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

Re: 3d shaded polygons

julien.delafontaine
In reply to this post by Stephan Gerhard
Actually I could put the meshes together. But it's still not working :(

def view(mesh):
     ...
for a in range(nbbases):
     points = vstack((points,my_points(a).T))
triangles = array([[0,1,2], [0,2,3]])
mesh = tvtk.PolyData(points=points, polys=triangles)
view(mesh)


Stephan Gerhard <[hidden email]> a écrit :

> Hi,
>
> Have you consulted already the Mayavi docs?
> http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/index.html
>
> In particular, you can create your rectangles with two triangles, as
> described here:
> http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/auto/example_polydata.html#example-polydata
>
> Stephan
>
> Am Freitag, den 26.03.2010, 17:26 +0100 schrieb
> [hidden email]:
>> Hi,
>>
>> I have to plot a 3D molecule, on which I'd like to add shaded
>> rectangles/hexagons that represent some site (bases of the DNA).
>> I've been trying hard to find a way to fill my polygons.
>>
>> How can I fill them, given coordinates of the corners?
>> (Am I using the wrong tool?)
>>
>> Please help!
>>
>> Julien D.
>> _______________________________________________
>> 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
>

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

Re: 3d shaded polygons

Stephan Gerhard
I think you should use mlab:
http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/mlab_pipeline.html#controlling-the-pipeline-with-mlab-scripts

It is very convenient.

In particular:
http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/auto/mlab_pipeline_sources.html#enthought.mayavi.tools.pipeline.triangular_mesh_source



Am Freitag, den 26.03.2010, 21:56 +0100 schrieb
[hidden email]:

> Actually I could put the meshes together. But it's still not working :(
>
> def view(mesh):
>      ...
> for a in range(nbbases):
>      points = vstack((points,my_points(a).T))
> triangles = array([[0,1,2], [0,2,3]])
> mesh = tvtk.PolyData(points=points, polys=triangles)
> view(mesh)
>
>
> Stephan Gerhard <[hidden email]> a écrit :
>
> > Hi,
> >
> > Have you consulted already the Mayavi docs?
> > http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/index.html
> >
> > In particular, you can create your rectangles with two triangles, as
> > described here:
> > http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/auto/example_polydata.html#example-polydata
> >
> > Stephan
> >
> > Am Freitag, den 26.03.2010, 17:26 +0100 schrieb
> > [hidden email]:
> >> Hi,
> >>
> >> I have to plot a 3D molecule, on which I'd like to add shaded
> >> rectangles/hexagons that represent some site (bases of the DNA).
> >> I've been trying hard to find a way to fill my polygons.
> >>
> >> How can I fill them, given coordinates of the corners?
> >> (Am I using the wrong tool?)
> >>
> >> Please help!
> >>
> >> Julien D.
> >> _______________________________________________
> >> 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
> >
>
> _______________________________________________
> 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: 3d shaded polygons

julien.delafontaine
It took me a long time but I did it :)
Thank you!

I thought that mlab was a part of mayavi or something like that. Well,  
I still don't understand but it works. The doc is still very bad.
Here is my piece of code in case someone has the same problem and reads it.

Cheers
Julien D.

-------------------------------------------------
from enthought.mayavi import mlab
from enthought.mayavi.tools.pipeline import triangular_mesh_source
from enthought.mayavi.tools.pipeline import surface

def pot3d(my_data):
     for a in range(18):
         rect = my_data(a)
         #mlab.plot3d(rect[0],rect[1],rect[2],tube_radius=0.05)
         points[4*a:4*a+4] = rect.T
         tri1 = array((4*a,4*a+1,4*a+2))
         tri2 = array((4*a,4*a+2,4*a+3))
         triangles = vstack((triangles,tri1,tri2))
     mesh = triangular_mesh_source
            (points[:,0],points[:,1],points[:,2],triangles,colormap=(1,1,1))
            #maybe it was transposed twice
     surface(mesh, color=(0,0.5,0.5))
     mlab.show()
plot3d(data)
-------------------------------------------------


Stephan Gerhard <[hidden email]> a écrit :

> I think you should use mlab:
> http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/mlab_pipeline.html#controlling-the-pipeline-with-mlab-scripts
>
> It is very convenient.
>
> In particular:
> http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/auto/mlab_pipeline_sources.html#enthought.mayavi.tools.pipeline.triangular_mesh_source
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: 3d shaded polygons

Gael Varoquaux
On Sat, Mar 27, 2010 at 02:03:13AM +0100, [hidden email] wrote:
> It took me a long time but I did it :)

> I thought that mlab was a part of mayavi or something like that.

It is. Mayavi can be used in many different ways. A synthetic paragraph
explaining the links between the different options in the documentation
remains to be written.

Such a summary has been written in a paper that is still in review. I am
more than happy to provide a copy of the paper to whoever feels like
using it to improve the documentation.

> Well,  I still don't understand but it works. The doc is still very
> bad.

Patches to improve the docs are most welcomed. Documentating something of
the size and versatility of Mayavi while keeping the documentation clear
is challenging, especially for people who do this on their free time. As
you say, the documentation is incomplete, but also, you found it hard to
find what you were looking for. We will happily take any patch improving
it.

> -------------------------------------------------
> from enthought.mayavi import mlab
> from enthought.mayavi.tools.pipeline import triangular_mesh_source
> from enthought.mayavi.tools.pipeline import surface

> def pot3d(my_data):
>      for a in range(18):
>          rect = my_data(a)
>          #mlab.plot3d(rect[0],rect[1],rect[2],tube_radius=0.05)
>          points[4*a:4*a+4] = rect.T
>          tri1 = array((4*a,4*a+1,4*a+2))
>          tri2 = array((4*a,4*a+2,4*a+3))
>          triangles = vstack((triangles,tri1,tri2))
>      mesh = triangular_mesh_source
>             (points[:,0],points[:,1],points[:,2],triangles,colormap=(1,1,1))
>             #maybe it was transposed twice
>      surface(mesh, color=(0,0.5,0.5))
>      mlab.show()
> plot3d(data)
> -------------------------------------------------

Looks good. You could also simply do:

mlab.triangular_mesh(points[:, 0], points[:, 1], points[:, 2], triangles,
                     color=(0, 0.5, 0.5))

See
http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/mlab.html#d-plotting-functions-for-numpy-arrays
and the link to the triangular_mesh function.

This will do exactly the same thing than what you are doing but with a
little less typing.

HTH,

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