当交互不更新情节时的Mayavi

时间:2019-06-13 01:55:23

标签: python mayavi

update_plot函数中,我添加了print语句以检查与场景交互后是否获取了正确的数据,可以看到我获取了正确的值,但图本身未更新。我不在哪里,我做错了。当我将数据传递回scaler_field

时,我认为我做错了
from traits.api import HasTraits, Range, Instance, \
                    on_trait_change
from traitsui.api import View, Item, HGroup
from tvtk.pyface.scene_editor import SceneEditor
from mayavi.tools.mlab_scene_model import \
                    MlabSceneModel
from mayavi.core.ui.mayavi_scene import MayaviScene
from mayavi import mlab

class Visualization(HasTraits):
    mySlice = Range(0, 400, 100) # slice number
    scene = Instance(MlabSceneModel, ())

    def __init__(self):
        HasTraits.__init__(self)
        data = InlinemySlice(self.mySlice) # call new data
        self.x_source = self.scene.mlab.pipeline.scalar_field(data)
        self.plot = self.scene.mlab.pipeline.image_plane_widget(self.x_source, plane_orientation='x_axes',  colormap='Greys', vmin=-0.020505040884017944 ,vmax=0.020505040884017944)

    @on_trait_change('mySlice')
    def update_plot(self):
        x = InlinemySlice(self.mySlice)
        print(x)
        y_source = mlab.pipeline.scalar_field(x)
        self.plot.mlab_source.trait_set(y_source)

    # the layout of the dialog created
    view = View(Item('scene', editor=SceneEditor(scene_class=MayaviScene),
                    height=500, width=600, show_label=False),
                HGroup( 'mySlice' ),
                )

visualization = Visualization()
visualization.configure_traits()

0 个答案:

没有答案