enthought / enthought/mayavi

mayavi view (azimuth, elevation, distance)

Open
#1,270 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1.4k
Forks
316
Avg merge
7h 44m
Merged PRs (30d)
5

Description

In the dummy program below I'm just trying to control the properties of some graphics objects with a slider.
The program works as intended but I would like to be able to control the view (the position and direction of the camera) from the program.
I normally do that with mlab.view(azimuth=None, elevation=None, distance=None, focalpoint=None,roll=None, reset_roll=True, figure=None) but that does not seem to work in this case.
What should I do instead ?

Poul Riis
Denmark

import numpy as np
from mayavi import mlab
from traits.api import HasTraits, Range, Instance,on_trait_change
from traitsui.api import View, Item, Group
from mayavi.core.ui.api import MayaviScene, SceneEditor, MlabSceneModel
from matplotlib.colors import hsv_to_rgb

rgb1=hsv_to_rgb((0.2,0.7,1))

#mlab.clf()

class MyModel(HasTraits):

slider = Range(-10., 10., 0,)

scene = Instance(MlabSceneModel, ())

def __init__(self,label='d'):
HasTraits.__init__(self)
#self.s = mlab.surf(x, y, np.asarray(x*1.5, 'd'), figure=self.scene.mayavi_scene)
self.xaxis=mlab.quiver3d(-100, 0, 0, 200,0,0, line_width=1, scale_factor=1,color=(0.8,0.9,0.7), figure=self.scene.mayavi_scene)
self.yaxis=mlab.quiver3d(0, -100, 0, 0,200,0, line_width=1, scale_factor=1, figure=self.scene.mayavi_scene)
self.zaxis=mlab.quiver3d(0, 0,-100, 0,0,200, line_width=1, scale_factor=1,color=(0.8,0.7,0.9), figure=self.scene.mayavi_scene)
self.origo=mlab.points3d(0,0,0,10,resolution=256,scale_factor=1,color=(rgb1[0],rgb1[1],rgb1[2]), figure=self.scene.mayavi_scene)

@on_trait_change('slider')
def slider_changed(self):
#self.s.mlab_source.scalars = np.asarray(x * (self.slider + 1), 'd')
self.origo.glyph.glyph_source.glyph_source.center = [self.slider, self.slider/2, 0]
self.origo.glyph.glyph_source.glyph_source.radius = abs(self.slider/10)+0.5

view = View(Item('scene', editor=SceneEditor(scene_class=MayaviScene),label='Mayavi'),Group("slider",label='d'),width=1200,height=1000)
#view(70,60,100)

my_model = MyModel()
my_model.configure_traits()

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.