首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >图像平面Widget的数据更新

图像平面Widget的数据更新
EN

Stack Overflow用户
提问于 2015-05-07 09:37:04
回答 1查看 556关注 0票数 0

我正在研究不同向量场的可视化。

为此,我正在使用Python2.7中的Mayavi库(我认为),在可视化打开时创建一个图像平面Widget ( IPW )和一个滑块来更改向量字段的数据,但是我的IPW不会改变。

它的工作,如果我呈现新的IPW每次滑块是改变,但这不是我想要的。

是否有一种方法可以在程序运行时改变IPW的数据,而不每次渲染一个新的平面?

我写了以下代码:

代码语言:javascript
复制
import numpy as np
from mayavi import mlab
from matplotlib.scale import scale_factory
from traits.api import HasTraits, Range, Instance, Array, \
    on_trait_change
from traitsui.api import View, Item, Group
from mayavi.core.pipeline_base import PipelineBase
from mayavi.core.ui.api import MayaviScene, SceneEditor, \
            MlabSceneModel

class Modell(HasTraits):
  p = Array
  n = Range(0, 9, 5)
  #p is a 4 dimensional Array p[10][20][20][20]
  scene = Instance(MlabSceneModel, ())
  plot = Instance(PipelineBase)

  @on_trait_change('n,scene.activated')
  def update_plot(self):
     self.src = mlab.pipeline.scalar_field(self.p[self.n])
     if self.plot is None:                 
        self.plot = self.scene.mlab.pipeline.image_plane_widget(self.src,
                        plane_orientation='z_axes',
                        slice_index=10,
                        vmin=0, vmax=120)
     else:
        '''here should be the update function, i tried using mlab_source.set(self.src=self.src)
        and all variations of expressions in the brackets but nothing worked.
        I also searched for functions in IPW itself but didn't find something that could help me.'''

  #The layout of the dialog created
  view = View(Item('scene', editor=SceneEditor(scene_class=MayaviScene),
                 height=400, width=400, show_label=False),
            Group('_', 'n'),
            resizable=True,
            )

my_model = Modell(p=p)
my_model.configure_traits()

我尝试用self.plot.update_pipeline()和self.plot.update_data()更新管道并更新数据,但这也不起作用。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-11 13:19:03

好的,我找到了解决问题的方法,诀窍是直接通过管道改变数据。因此,在我的代码中,我只需将以下命令设置为segment段:

代码语言:javascript
复制
self.plot.parent.parent.scalar_data = self.p[self.n]
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30097205

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档