简体   繁体   English

Mayavi 查看当前相机设置

[英]Mayavi view current camera settings

I would like to be able to set the view of my mayavi plot to a view that I have set in the interactive window.我希望能够将我的 mayavi plot 的视图设置为我在交互式 window 中设置的视图。 The view can be set with the mlab.view interface.可以使用mlab.view界面设置视图。 However, I can't seem to find the view parameters from within the mayavi interactive GUI.但是,我似乎无法从 mayavi 交互式 GUI 中找到视图参数。

When viewing a plot in interactive mode in matplotlib , the camera angle and azimuth are displayed in the bottom of the screen as seen here:在 matplotlib 中以交互模式查看matplotlib时,相机角度和方位角显示在屏幕底部,如下所示:

在此处输入图像描述

This is convenient, because to replicate a view I like, I can just read off the elevation and azimuth and set them in my code (in this case with ax.view_init(elev=-9, azim=84) . I would like to do the same in mayavi . Given this code example:这很方便,因为要复制我喜欢的视图,我可以读取仰角和方位角并将它们设置在我的代码中(在本例中为ax.view_init(elev=-9, azim=84) 。我想在mayavi中做同样的事情给定这个代码示例:

from mayavi import mlab
import numpy as np
    
img = np.random.uniform(0, 255, size=(512, 512)).astype(np.int)

N = 10000
event_size = 2
xs = np.random.uniform(img.shape[1], size=N)
ys = np.random.uniform(img.shape[0], size=N)
ts = np.sort(np.random.uniform(1000, size=N))
ps = np.random.randint(0,2,size=N)

mlab.imshow(img, colormap='gray', extent=[0, img.shape[0], 0, img.shape[1], ts[0], ts[1]])
colors = [0 if p>0 else 240 for p in ps]
ones = np.ones(len(xs))
p3d = mlab.quiver3d(ys, xs, ts, ones, ones,
            ones, scalars=colors, mode='sphere', scale_factor=event_size)
p3d.glyph.color_mode = 'color_by_scalar'

p3d.module_manager.scalar_lut_manager.lut.table = colors
mlab.draw()
mlab.show()

This code should create an image and a point cloud and display it in an interactive window.此代码应创建图像和点云,并将其显示在交互式 window 中。 Where in the window can I tell what the current camera parameters are and how would I apply them in the code?在 window 中的什么位置,我可以知道当前的相机参数是什么,以及如何在代码中应用它们? Many thanks!非常感谢!

One solution I found in the documentation was to use the mayavi record feature in the UI.我在文档中找到的一种解决方案是在 UI 中使用mayavi记录功能 This will log all actions to a python executable script, which will print the camera positions you place the scene in.这会将所有操作记录到 python 可执行脚本中,该脚本将打印您放置场景的相机位置。

Alternatively, when in the mayavi UI, one can type python commands in the UI terminal, so entering或者,在mayavi UI 中,可以在 UI 终端中键入 python 命令,因此输入

from mayavi import mlab
print(mlab.view())

will also give the camera params.还将提供相机参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM