2 years ago
#14967
taras
Mayavi multiple embedded scenes with volume render
I want to get a multiscene layout described in https://docs.enthought.com/mayavi/mayavi/auto/example_multiple_mlab_scene_models.html
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 explicitly 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()
Each scene has to render a separate volume object.
I have provided a custom redraw_scene
function with
def redraw_scene(self, scene):
# Notice how each mlab call points explicitly to the figure it
# applies to.
mlab.clf(figure=scene.mayavi_scene)
s = np.random.random((100, 100, 100))
mlab.pipeline.volume(mlab.pipeline.scalar_field(s), figure=scene.mayavi_scene)
but ended up getting both volumes rendered on the second scene.
I have also tried the setup with a separate engine per scene but it yields the same result.
How I do get volume renders in separate scenes with Mayavi?
python
render
mayavi
traitsui
0 Answers
Your Answer