locking camera in mayavi

偶尔善良 提交于 2019-12-05 04:23:57

for anyone still interested in this, you could try wrapping whatever work you're doing in this context, which will disable rendering and return the disable_render value and camera views to their original states after the context exits.

with constant_camera_view():
    do_stuff()

Here's the class:

class constant_camera_view(object):
def __init__(self):
    pass

def __enter__(self):
    self.orig_no_render = mlab.gcf().scene.disable_render
    if not self.orig_no_render:
        mlab.gcf().scene.disable_render = True
    cc = mlab.gcf().scene.camera
    self.orig_pos = cc.position
    self.orig_fp = cc.focal_point
    self.orig_view_angle = cc.view_angle
    self.orig_view_up = cc.view_up
    self.orig_clipping_range = cc.clipping_range

def __exit__(self, t, val, trace):
    cc = mlab.gcf().scene.camera
    cc.position = self.orig_pos
    cc.focal_point = self.orig_fp
    cc.view_angle =  self.orig_view_angle 
    cc.view_up = self.orig_view_up
    cc.clipping_range = self.orig_clipping_range

    if not self.orig_no_render:
        mlab.gcf().scene.disable_render = False
    if t != None:
        print t, val, trace
        ipdb.post_mortem(trace)

I do not really see the problem in your plot but to reset the view after each plotting instance insert your view point:

mlab.view(azimuth=45, elevation=60, distance=0.01, focalpoint=(0,0,0))

directly above your mlab.savefig callwithin your for loop .

You could just use the vmin and vmax function in your mesh command, if u do so the scale will not change with your data and your camera should stay where it is. Like this:

f = mlab.mesh(x, y, -Mz/1.5,representation = 'wireframe',vmin='''some value''',vmax='''some value''',opacity=0.3,line_width=1)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!