wrestling with Mayavi's auto-scaling

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

wrestling with Mayavi's auto-scaling

Robert Stephenson
I'm hoping there is a way to disable Mayavi's auto-scaling.

I'm attempting to combine shapes defined as surface3d with points (point3d) and lines (plot3d) ALL WITHIN THE SAME COORDINATE SYSTEM.  What happen instead is that each command is auto-scaled so that e.g. points that should lie on the surface end up far from it.  Adding identical extents to each command as a keyword was an improvement in the sense that now the various plots are superposed instead of side-by-side, but each item appears centered in the shared extent instead of at its proper location.

I Imagine that I can probably find a work-around by either 1) customizing the extents for each item separately or 2) adding invisible fiduciary points to each plot at the 8 corners of the extents.  But is this really the only way?  Isn't this a common use case that one wants to combine points lines and surfaces in one figure?  Is there no way to disable this wretched auto-scaling when it's not wanted?

If the above is not clear I'll be happy to provide a code sample illustrating my problem.  I'm using the version of Mayavi bundled with the latest EPD 7.3-2 (I'm not sure which Mayavi version that would be).


* * * * * * * * * * * * * * * * * * * * * * *
*  Dr. Robert S. Stephenson
*  E-learning Architect
*  [hidden email]
*  (415) 341-3784
*  http://sun.science.wayne.edu/~rstephe
*
*  Chief Architect and Principal Investigator
*  http://OpenCourse.Org
*  Supporting virtual communities of e-learning developers.
*
*  Founder
*  The Harvey Project
*  Open Course Physiology on the Web
*  http://HarveyProject.org
*
*  Was I helpful?  Let others know:
*  http://rate.affero.net/rstephe
*
*  gpg key fingerprint:
*  4255 FB43 17C8 2B80 8074  7DB6 7DD7 939B F3F6 CB92
* * * * * * * * * * * * * * * * * * * * * * *





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

Re: wrestling with Mayavi's auto-scaling

Gael Varoquaux
On Thu, Oct 25, 2012 at 10:15:41PM -0700, Robert Stephenson wrote:
> I'm attempting to combine shapes defined as surface3d with points
> (point3d) and lines (plot3d) ALL WITHIN THE SAME COORDINATE SYSTEM.
> What happen instead is that each command is auto-scaled so that e.g.
> points that should lie on the surface end up far from it.  Adding
> identical extents to each command as a keyword was an improvement in
> the sense that now the various plots are superposed instead of
> side-by-side, but each item appears centered in the shared extent
> instead of at its proper location.

I don't understand what auto-scaling you are talking about. If I do the
following:

import numpy as np
from mayavi import mlab
x, y, z = np.random.normal(size=(3, 10))
mlab.points3d(x, y, z)

The points that appear on screen are centered at the x, y, z
coordinates.

One thing that might be bothering you, is that Mayavi scales the sizes of
the glyphs. You can disable that with:

mlab.points3d(x, y, z, np.ones_like(x), scale_factor=1)

Hope this helps,

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: wrestling with Mayavi's auto-scaling

Robert Stephenson
Thanks, Gael, for your reply.  Let me try to be clearer.  I have pasted below a simple demo of what I want to do.  Sorry if it seems a bit contrived -- and more appropriate for St. Valentine's Day than Halloween -- but it illustrates my point.  This code below appears to do what I want: e.g. the arrow passes through the point (0,0,0) of the heart's coordinate system.

If you remove the extent keywords in the surface3d command, the arrow appears as a tiny figure on the -x, -y, -z side of the heart.  OTOH, removing the extent from the plot3d command has little effect in this case.  I suspect it is not necessary, but will have to confirm this for other cases.

The application I am developing does ray tracing to test optics designs, so it involves several surface3d commands and a very large number of plot3d commands.  It's obviously essential that the rays be plotted on the correct coordinate system.  That's why I was asking whether there was a way to turn off auto-scaling between different mlab commands.  

So my question now becomes two:
1) is it true that, if the surface3d commands are given appropriate extent keywords, then all subsequent plot3d and point3d commands will use that same coordinate system?

2) if that is not true in some cases, is there a way to turn off the auto-scaling -- i.e. enforce a single coordinate system for all mlab drawing commands?

 

from mayavi import mlab
from numpy import sin, cos, tan, sqrt, ogrid, array

box = [-.75, .75, -.25, .25, -1.01, .3]
N = 50

x, y, z = ogrid[-.8:.8:N*1.0j, -.35:.35:N*.3j, -1.01:.3:N*.7j]
t = 2*(x*x + 9*y*y + z*z)/(1.01 - z/sqrt(z*z + x*x) )
cont = mlab.contour3d( t, contours=[1.0], opacity=1.0, color=(1.0,0.0,0.0), extent=box )

tail = [box[1], box[3], box[5]]
head = [box[0], box[2], -box[5]]
path = array(zip(tail, head))

box2 = box[:]
box2[4] = -box2[5]

mlab.plot3d(path[0], path[1], path[2], color=(0.0, 0.0, 0.0), extent=box2)

On Oct 25, 2012, at 10:54 PM, Gael Varoquaux wrote:

On Thu, Oct 25, 2012 at 10:15:41PM -0700, Robert Stephenson wrote:
I'm attempting to combine shapes defined as surface3d with points
(point3d) and lines (plot3d) ALL WITHIN THE SAME COORDINATE SYSTEM.
What happen instead is that each command is auto-scaled so that e.g.
points that should lie on the surface end up far from it.  Adding
identical extents to each command as a keyword was an improvement in
the sense that now the various plots are superposed instead of
side-by-side, but each item appears centered in the shared extent
instead of at its proper location.

I don't understand what auto-scaling you are talking about. If I do the
following:

import numpy as np
from mayavi import mlab
x, y, z = np.random.normal(size=(3, 10))
mlab.points3d(x, y, z)

The points that appear on screen are centered at the x, y, z
coordinates.

One thing that might be bothering you, is that Mayavi scales the sizes of
the glyphs. You can disable that with:

mlab.points3d(x, y, z, np.ones_like(x), scale_factor=1)

Hope this helps,

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: wrestling with Mayavi's auto-scaling

Gael Varoquaux
Hey Robert,

I am quite surprised that you expected this to work. If you don't give
any extra information to 'contour3d', it cannot know what x, y, z
dimensions that data is supposed to have. Thus, by default, it supposes
that data points have a spacing of 1. This is not an auto scaling, it is
just that it doesn't have information to do any better.

As indicated in the docstring of the mlab.contour3d function, the right
way to specify the position of the points on the grid is to give the data
points as x, y, z arguments to the mlab.contour3d. One caveat is then
that the x, y, z arrays need to be 3D arrays, and thus you need to
replace the 'ogrid' call by an 'mgrid' call.

Then you can simply do:

cont = mlab.contour3d(x, y, z, t, contours=[1.0], opacity=1.0,
                      color=(1.0,0.0,0.0))

Hope this helps,

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