On Mon, Nov 30, 2009 at 11:00:14AM -0800, M Trumpis wrote:
> I'm finding some weird behavior with Mayavi when I go to update
> scalars in a scalar_field source. With ImagePlaneWidgets, after using
> the set() or reset() methods on the source, if I say
> src.update_image_data = True, then I get a bunch of errors from the
> VTK subsystem (copied below) and the planes won't update without
> interaction. My initial tactic was to simply skip that step, and
> everything appeared fine with respect to the ImagePlaneWidgets. When I
> put an additional threshold and surface into that source's pipeline,
> then I discovered the reverse problem is true. Those objects won't
> update automatically unless I include the src.update_image_data = True
> step. How do I update the data correctly?

There is always black magic involved when there is some VTK around the
corner. That's why we have Mayavi (Mayavi means magician in Sanskrit).

So, here is the way I would do it:

################################################################################
from enthought.mayavi import mlab

import numpy as np

x, y, z = np.ogrid[-3:3:31j, -3:3:31j, -3:3:31j]

r = np.sqrt(x**2 + y**2 + z**2)
   
mlab.clf()
sf = mlab.pipeline.scalar_field(r)
    
ipw = mlab.pipeline.image_plane_widget(sf)
sf.mlab_source.scalars = np.sin(r)

mlab.show()
################################################################################

See
http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/mlab.html#animating-the-data

Now, I understand that it may not suit your needs, as you may not be
creating your objects with mlab, and thus they may not have an
'mlab_source' attribute (although, I must admit that even in my
application code, I use mlab). So, all you have to do is to read the code
that does the right magic. You'll find it in
enthought/mayavi/tools/sources.py, in particular in the MArraySource: in
the '_scalars_changed' callback.

But, if you can afford using mlab, the above code is quite readable,
IMHO.

HTH,

Gaƫl

------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing. 
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
MayaVi-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mayavi-users

Reply via email to