mayavi: scaling data

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

mayavi: scaling data

Arnd Baecker
Hi,

the question of displaying data in 3D which have
strongly different scale for the axes has come up a couple
of times.

The script below works fine
- as long as one does not change from points to spheres.
Because of the applied scaling the spheres turn into long
cigars. I would like them to stay spheres.
Is there some parameter which allows to compensate
for the applied scaling?

Any pointers are welcome! Best, Arnd

##############################################################################
"""Scaling data in mayavi."""

import numpy as np
import mayavi.mlab as mlab

def main():
     # --- data
     data = np.random.random((1000, 3))
     fac_data = 0.01
     data[:,2] =  data[:,2] * fac_data
     data = data + np.array([1, 2, 4])       # change origin

     FAC_MAG_FOR_VISU = 50                   # scaling factor for the data

     x0,x1 = min(data[:,0]), max(data[:,0])
     y0,y1 = min(data[:,1]), max(data[:,1])
     z0,z1 = min(data[:,2]), max(data[:,2])

     clipping_extent = [x0, x1-0.5, y0, y1, z0, z1]    # some clipping region

     # --- visualization pipeline
     pts = mlab.pipeline.scalar_scatter(data[:,0], data[:,1], data[:,2])

     # clipping:
     geometry_filter = mlab.pipeline.user_defined(pts, filter='GeometryFilter')
     geometry_filter.filter.extent_clipping = True
     geometry_filter.filter.extent = clipping_extent
     clip = mlab.pipeline.user_defined(geometry_filter, filter='CleanPolyData')

     # define extent so that the magnification works fine:
     mag_extent = [x0, x1, y0, y1, z0*FAC_MAG_FOR_VISU, z1*FAC_MAG_FOR_VISU]
     spheres = mlab.pipeline.glyph(clip, mode="point", color=(0.5, 0.5, 0.5),
                                   reset_zoom=False, extent=mag_extent)
     spheres.actor.property.point_size = 3.0

     # ---- show:
     engine = mlab.get_engine()
     scene = engine.current_scene

     scene.scene.background = (1,1,1)
     scene.scene.foreground = (0,0,0)

     mlab.axes(xlabel="x", ylabel="y",  zlabel="z",
               extent=mag_extent,                    # For the data
               ranges=clipping_extent                # For the labels
               )
     mlab.outline(extent=mag_extent)
     scene.scene.isometric_view()
     mlab.show()

if __name__ == '__main__':
     main()
##############################################################################




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

Re: mayavi: scaling data

Gael Varoquaux
On Thu, Apr 26, 2012 at 12:29:44PM +0200, Arnd Baecker wrote:
> the question of displaying data in 3D which have
> strongly different scale for the axes has come up a couple
> of times.

> - as long as one does not change from points to spheres.
> Because of the applied scaling the spheres turn into long
> cigars. I would like them to stay spheres.
> Is there some parameter which allows to compensate
> for the applied scaling?

Not that I know. VTK is a bit annoying when it comes to scaling the axes:
it doesn't allow it, and you have to hack around. The only thing that
comes to my mind is to apply the scaling to you data.

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: mayavi: scaling data

Arnd Baecker
Hi,

On Thu, 26 Apr 2012, Gael Varoquaux wrote:

> On Thu, Apr 26, 2012 at 12:29:44PM +0200, Arnd Baecker wrote:
>> the question of displaying data in 3D which have
>> strongly different scale for the axes has come up a couple
>> of times.
>
>> - as long as one does not change from points to spheres.
>> Because of the applied scaling the spheres turn into long
>> cigars. I would like them to stay spheres.
>> Is there some parameter which allows to compensate
>> for the applied scaling?
>
> Not that I know. VTK is a bit annoying when it comes to scaling the axes:
> it doesn't allow it, and you have to hack around. The only thing that
> comes to my mind is to apply the scaling to you data.

In the meantime I also tried this approach, but
I am not really happy, as it means that I have to change
all the different data sets in my visualization
whenever the user needs a different scaling (our use-case is: zooming into
data by clipping of a box). Also I am not sure
whether one has to rescale any other objects
(like cut-planes etc.), which we want to add in the future.

Do you think that better support for scaling could be added on
the level of Mayavi?
For example, if the sphere source could be supplied
with a scale factor, which is a triple corresponding
to each coordinate direction, this could be used.
Alternatively, I tried to find an Ellipsoid Source in the VTK docs,
but only found
http://www.vtk.org/doc/nightly/html/classvtkParametricEllipsoid.html
Could one maybe make use of that?

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