[SciPy-User] [SciPy-user] set difference on meshes
Gael Varoquaux
gael.varoquaux at normalesup.org
Tue Aug 18 01:56:24 EDT 2009
On Mon, Aug 17, 2009 at 08:03:10PM -0700, Martin van Leeuwen wrote:
> http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/mlab.html
> , under: "From data points to surfaces." But I don't see how
> delaunay2d() needs to be implemented to return the trianges that
> triangular_mesh() needs.
It doesn't. It returns a data structure on which you can apply the
surface module, amongst other things, with:
mlab.pipeline.surface(obj)
where obj is returned by mlab.pipeline.delaunay2d.
You can also get the data as arrays as in the following:
In [1]: from enthought.mayavi import mlab
In [2]: import numpy as np
In [3]: x, y, z, s = np.random.random((4, 10))
In [4]: src = mlab.pipeline.scalar_scatter(x, y, z, s)
In [5]: mesh = mlab.pipeline.delaunay2d(src)
In [6]: surf = mlab.pipeline.surface(mesh)
In [7]: mesh.outputs[0].polys.to_array()
Out[7]:
array([3, 9, 4, 3, 3, 5, 3, 2, 3, 8, 7, 0, 3, 6, 3, 1, 3, 4, 2, 3, 3, 5, 1,
3, 3, 6, 1, 0, 3, 7, 3, 6, 3, 7, 6, 0, 3, 9, 3, 8, 3, 8, 3, 7, 3, 9,
2, 4])
In [8]: mesh.outputs[0].points.to_array()
Out[8]:
array([[ 0.94464944, 0.47644135, 0.72179666],
[ 0.74063624, 0.09717904, 0.81146878],
[ 0.17031379, 0.73111888, 0.62790633],
[ 0.50215195, 0.54242855, 0.20974343],
[ 0.27069343, 0.83886682, 0.38808641],
[ 0.15944449, 0.21834495, 0.39882205],
[ 0.78877187, 0.34613708, 0.79911974],
[ 0.86809041, 0.48792871, 0.65521137],
[ 0.85557844, 0.57255716, 0.6484326 ],
[ 0.30144246, 0.96996277, 0.15670321]])
In [9]: mesh.outputs[0].point_data.scalars.to_array()
Out[9]:
array([ 0.18869998, 0.87639289, 0.51392855, 0.30845021, 0.57186958,
0.74023876, 0.41477073, 0.50683163, 0.4276263 , 0.80960671])
HTH,
Gaël
More information about the SciPy-User
mailing list