2013-06-12 8 views
7

私はmayaviで一連のデータファイルでアニメーションを作ろうとしています。残念ながら、私はカメラがロックされていないことに気付いています(ズームとズームアウトしています)。私は、私のメッシュのZコンポーネントが変化しており、mayaviがスケールを再計算しようとしているので、それが起こっていると思います。mayaviでカメラをロック

どうすれば修正できますか? enter image description here enter image description here enter image description here

import numpy 
from mayavi import mlab 

mlab.figure(size = (1024,768),bgcolor = (1,1,1)) 
mlab.view(azimuth=45, elevation=60, distance=0.01, focalpoint=(0,0,0)) 
#mlab.move(forward=23, right=32, up=12) 

for i in range(8240,8243): 
    n=numpy.arange(10,400,20) 
    k=numpy.arange(10,400,20) 
    [x,y] = numpy.meshgrid(k,n) 
    z=numpy.zeros((20,20)) 
    z[:] = 5 

    M = numpy.loadtxt('B:\\Dropbox\\Master.Diploma\\presentation\\movie\\1disk_j9.5xyz\\'+'{0:05}'.format(i)+'.txt') 
    Mx = M[:,0]; My = M[:,1]; Mz = M[:,2] 
    Mx = Mx.reshape(20,20); My = My.reshape(20,20); Mz = Mz.reshape(20,20); 


    s = mlab.quiver3d(x,y,z,Mx, My, -Mz, mode="cone",resolution=40,scale_factor=0.016,color = (0.8,0.8,0.01)) 

    Mz = numpy.loadtxt('B:\\Dropbox\\Master.Diploma\\presentation\\movie\\Mzi\\' + '{0:05}'.format(i) + '.txt') 
    n=numpy.arange(2.5,400,2) 
    k=numpy.arange(2.5,400,2) 
    [x,y] = numpy.meshgrid(k,n) 

    f = mlab.mesh(x, y, -Mz/1.5,representation = 'wireframe',opacity=0.3,line_width=1) 

    mlab.savefig('B:\\Dropbox\\Master.Diploma\\presentation\\movie\\figs\\'+'{0:05}'.format(i)+'.png') 
    mlab.clf() 
    #mlab.savefig('B:\\Dropbox\\Master.Diploma\\figures\\vortex.png') 
    print(i) 

mlab.show() 

答えて

1

私は本当にあなたのプロットに問題が表示されていないが、あなたのビューポイントを挿入し、各プロットインスタンスの後にビューをリセットするには:直接あなたのmlab.savefig上記

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

はあなたをcallwithin forループ。

4

これに興味がある人は、このコンテキストで行っている作業をラップして、レンダリングを無効にしてコンテキストが終了した後にdisable_render値とカメラビューを元の状態に戻すことができます。ここで

with constant_camera_view(): 
    do_stuff() 

クラスです:uはスケールがあなたのデータとあなたのカメラで変更されることはありません、そうならばあなただけの、あなたのメッシュコマンドでVMINとVMAXの機能を使用することができます

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) 
1

はどこ滞在する必要がありますそうです。 このように:

f = mlab.mesh(x, y, -Mz/1.5,representation = 'wireframe',vmin='''some value''',vmax='''some value''',opacity=0.3,line_width=1) 
関連する問題