我正在遵循官方 mayaVI 站点上给出的脚本(多个 mlab 场景模型示例),并希望使用该sync_camera
命令在 qt GUI 中将两个图形同步在一起(如图所示),这样任何旋转/缩放,一个图中的等以完全相同的方式同时自动旋转/缩放,等等。
该sync_camera
命令在另一个官方 mayaVI 页面Figure processing functions 上简要介绍过,但我还没有找到太多关于它在类层次结构中成功使用的正确用法。
有没有人对此程序或建议有任何经验?
import numpy as np
from traits.api import HasTraits, Instance, Button, \
on_trait_change
from traitsui.api import View, Item, HSplit, Group
from mayavi import mlab
from mayavi.core.ui.api import MlabSceneModel, SceneEditor
class MyDialog(HasTraits):
scene1 = Instance(MlabSceneModel, ())
scene2 = Instance(MlabSceneModel, ())
button1 = Button('Redraw')
button2 = Button('Redraw')
@on_trait_change('button1')
def redraw_scene1(self):
self.redraw_scene(self.scene1)
@on_trait_change('button2')
def redraw_scene2(self):
self.redraw_scene(self.scene2)
def redraw_scene(self, scene):
# Notice how each mlab call points explicitely to the figure it
# applies to.
mlab.clf(figure=scene.mayavi_scene)
x, y, z, s = np.random.random((4, 100))
mlab.points3d(x, y, z, s, figure=scene.mayavi_scene)
# The layout of the dialog created
view = View(HSplit(
Group(
Item('scene1',
editor=SceneEditor(), height=250,
width=300),
'button1',
show_labels=False,
),
Group(
Item('scene2',
editor=SceneEditor(), height=250,
width=300, show_label=False),
'button2',
show_labels=False,
),
),
resizable=True,
)
m = MyDialog()
m.configure_traits()