Change mlab quiver3d & surf data sources without clearing figure in traits script

久未见 提交于 2019-12-11 05:28:14

问题


I have a Traits and Mayavi script that presents an mlab scene and several traits editors. The editors affect what data is shown in a surface, quiver3d and legend (Scalar LUT Manager) by calling my drawing method. Each change triggers a clear figure and re-draw.

Learning from the Mlab interactive dialog example the plot3d* uses mlab_source.set to change the data without clearing the figure and re-drawing. In update_plot():

if self.plot is None:
    self.plot = self.scene.mlab.plot3d(x, y, z, t, tube_radius=0.025, colormap='Spectral')
else:
    self.plot.mlab_source.set(x=x, y=y, z=z, scalars=t)

What my surface and quiver3d calls return are mayavi.modules.surface.Surface and mayavi.modules.vectors.Vectors objects respectively. Surface and LUTManager report no mlab_source: AttributeError: 'Surface'/'LUTManager' object has no attribute 'mlab_source'. Quiver3d reports an mayavi.tools.sources.MGlyphSource

1) How can I change the data/source in my surface and scalar LUTManager?

2) How do I correctly change the quiver’s data/source?

When I attempt to change the values of the quiver I get a TraitError: Cannot set the undefined 'u' attribute of a 'Vectors' object. This puzzles me because I used the six-value initializer.

if self.quiver is None:
    self.quiver = self.scene.mlab.quiver3d(xyz[:,0], xyz[:,1], xyz[:,2],
        velocity[:,0], velocity[:,1], velocity[:,2], 
        figure=self.scene.mayavi_scene, scale_factor = self.scale)
else:
    self.quiver.mlab_source.set(x = xyz[:,0], y = xyz[:,1], z = xyz[:,2],
            u = velocity[:,0], v = velocity[:,1], w = velocity[:,2])

In the example the plot3d returns a mayavi.modules.surface.Surface and its mlab_source object is a mayavi.tools.sources.MLineSource. Searching the docs for MLineSource is fruitless but externally yields Enthought Tool Suite 3.2 results. Are the Tool Suite docs current?

*self.plot, self.surface and self.quiver are declared as variable = Instance(PipelineBase). PipelineBase is imported from mayavi.core.api.


回答1:


Based on your comments:

The reason there is no reference to an mlab source in surface is because there is no mlab source. Your module just consists of a raw vtk source, which mayavi is perfectly happy to render unadulterated. However you retain a reference to the PolyData and so you could edit the scalars from that. (You could also use mlab.triangular_mesh which very likely does what you want while introducing an intervening TriangularMeshSource to control the vtk PolyData).

You can get to the LUT with surface.module_manager.scalar_lut_manager.

And you should also be able to get to the mlab level source for the vectors as in the comments, I don't know what is the problem with that if there still is one. The use of traitsui should not have an effect -- the problem is probably a conflict between mayavi and your object model. Try setting the trait type of your mayavi objects to be Any.



来源:https://stackoverflow.com/questions/24022204/change-mlab-quiver3d-surf-data-sources-without-clearing-figure-in-traits-scrip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!