我正在尝试使用 mlab 到 mayavi 的界面来可视化地球表面上的一个点。主要问题是地球很大,但我希望能够放大看到它的一个非常小的区域。
似乎在 mayavi 窗口中使用滚轮会改变相机与其焦点的距离。如果我把注意力集中在我感兴趣的点上并放大,最终相机到焦点的距离小于近裁剪距离,我就看不到感兴趣的点了。
我可以像这样以编程方式设置相机的近剪切点:
eng = mlab.get_engine()
scene = eng.scenes[0].scene
cam = scene.camera
scene.camera.clipping_range = [10000, 100000]
并且正确显示了我想看到的点,但是如果我用鼠标做任何事情(通过拖动旋转视图,移动滚轮),剪切平面会被重置,我什么也看不到。这中途破坏了 mayavi 窗口的目的。
问题:我怎样才能使这个例子工作,以便我可以看到我正在绘制的点(字形是 1 米宽)并且仍然与窗口交互?
这是我的代码(为了便于阅读,drawSphere函数如下):
import numpy as np
from numpy import r_, c_, pi
from mayavi import mlab
rE = 6378137 #radius of the earth, in meters
drawSphere(r=rE)
pointAEcef = c_[-2252280.7, -5867391.7, 1100769.5]
mlab.points3d(pointAEcef[:,0],pointAEcef[:,1],pointAEcef[:,2],
color=(0.0,0.0,1.0),scale_factor=1.0
)
mlab.view(
azimuth=-110.09214289721747,
elevation=102.86270612105356,
distance=80.0,
focalpoint=pointAEcef[0,:],
)
eng = mlab.get_engine()
scene = eng.scenes[0].scene
cam = scene.camera
scene.camera.clipping_range = [50, 27e6]
scene.render()
mlab.show()
这是drawSphere函数:
def drawSphere(r=1,fig=None):
"""
Draw a sphere of the given radius in the given figure
"""
r = float(r)
# Create a sphere
pi = np.pi
cos = np.cos
sin = np.sin
phi, theta = np.mgrid[0:pi:101j, 0:2*pi:101j]
x = r*sin(phi)*cos(theta)
y = r*sin(phi)*sin(theta)
z = r*cos(phi)
if fig is not None:
fig = mlab.figure(fig)
else:
fig = mlab.gcf()
colorsphere=mlab.mesh(x,y,z,
figure=fig,
color=(0,0,1),
opacity=0.1,
)
grid = mlab.mesh(x,y,z,
figure=fig,
mask_points=100,
color=(1,0,0),
representation="wireframe",
opacity=0.1,
)
xaxis = mlab.quiver3d(0,0,0,1.5*r,0,0,color=(1,0,0),scale_mode='none',scale_factor=r);
yaxis = mlab.quiver3d(0,0,0,0,1.5*r,0,color=(0,1,0),scale_mode='none',scale_factor=r);
zaxis = mlab.quiver3d(0,0,0,0,0,1.5*r,color=(0,0,1),scale_mode='none',scale_factor=r);
#mlab.view(azimuth=0,elevation=90,distance=1.1,focalpoint=(0,0,0));
#mlab.roll(30);
#cam = fig.scene.camera;
return (colorsphere,grid,xaxis,yaxis,zaxis)