绘制两个不同的场景

时间:2015-05-29 09:49:18

标签: python vtk mayavi

我试图在mayavi中的两个不同场景中同时绘制两个图像平面小部件。但是这两架飞机都显示在第一个场景中。有人知道如何解决这个问题吗?

以下是我的代码示例:

import numpy as np
from mayavi import mlab
from mayavi.mlab import axes, outline
from traitsui.api import View, Item, Group, HGroup
from mayavi.core.pipeline_base import PipelineBase
from mayavi.core.ui.api import MayaviScene, SceneEditor, MlabSceneModel

class myclass():
  p='somedata[20][20][20]' #I can't give you the data here because it's too big
  scene = Instance(MlabSceneModel, ())        
  sx = Instance(MlabSceneModel, ())
  plot = Instance(PipelineBase)

  def function(self):
    self.src = mlab.pipeline.scalar_field(self.p)
    self.plot2 = self.scene.mlab.pipeline.image_plane_widget(self.src,         
                            plane_orientation='x_axes',             
                            slice_index=0,
                            #vmin=0, vmax=140,
                            colormap='hot')

    self.sx.scene.parallel_projection = True
    side_src = self.plot.ipw._get_reslice_output() #gets the data for the 2d planes
    self.ipw = self.sx.mlab.pipeline.image_plane_widget(     #creates the 2d views
                            side_src,
                            plane_orientation='z_axes',
                            #vmin=self.data.min(),
                            #vmax=self.data.max(),
                            #figure=self.sx.mayavi_scene,
                            name='Cut view X',
                            colormap='hot',
                            )

    mlab.colorbar(title='Wert', orientation='vertical', nb_labels=5, label_fmt='%.3f')            #adds a colorbar at the left side of the screen
    mlab.view(azimuth=50,elevation=50,distance=80,focalpoint=(10,15,10))      #defines the starting view of the camera
    mlab.roll(110)
    self.scene.scene_editor.background = (0, 0, 0)
    view = View(HGroup(Item('scene', editor=SceneEditor(scene_class=MayaviScene),
                                  height=400, width=500, show_label=False),
                       Item('sx',editor=SceneEditor(scene_class=MayaviScene),
                                  height=400, width=500, show_label=False),),
                resizable=True,
                )

myclass()

我无法在网络上找到解决方案,有多个场景的示例,但我无法弄清楚为什么它在那里工作而不是在我的代码中。任何帮助都会很好。

当我尝试使用figure中的image_plane_widget kwarg时,就像这样

self.plot = mlab.pipeline.image_plane_widget(self.src,         
                            plane_orientation='x_axes',             
                            slice_index=0,
                            #vmin=0, vmax=140,
                            figure=self.sx,
                            colormap='hot')

它返回以下错误:

  

TraitError:'数字' ImagePlaneWidgetFactory实例的特征   必须是场景或无,但值为     被指定了。

1 个答案:

答案 0 :(得分:0)

要指定管道中定向的场景,请调用@Bean kwarg和类似内容,例如RequestMappingHandlerMapping。否则,如果未指定figure,则管道调用将转到mlab.pipeline.image_plane_widget(*args, figure=self.scene),这通常是最后创建的数字。

相关问题