用mayavi和python中的图像对球体的段进行纹理处理

问题描述

我想在mayavi中对网格进行纹理处理,其中网格是球体表面的一部分。作为背景,我使用的是从航天器拍摄的太阳风的遥感图像。我想将此图像投影到摄像机视场所跨越的天空部分。

我试图修改mayavi示例中给出的解决方案,以对具有地球表面图像的球体进行纹理化,但是该图像无法正确渲染,我认为这是因为我不知道如何告诉mayavi将图像仅投影到球体的一部分上。

这与我到目前为止的距离很近:

import numpy as np
from mayavi import mlab
from tvtk.api import tvtk

# Observer location
obs_x = 0 
obs_y = -240
obs_z = 0
obs = mlab.points3d(obs_x,obs_y,obs_z,color=(1,0),scale_factor=10)

#Set the obsserver field of view
obs_phi = np.arctan2(obs_y,obs_x)
if obs_phi > np.pi:
    obs_phi = 2*np.pi - obs_phi

e_min = np.deg2rad(4.0)
e_max = np.deg2rad(24.0)
b1 = np.pi - np.abs(obs_phi) - 2*e_min
b2 = np.pi - np.abs(obs_phi) - 2*e_max
b_lim = np.sort(np.array([b1,b2]))

# Compute the longitude and latitude of the section of
# the sphere within the observer field of view
lon_sub = np.arange(0,720)
lat_sub = np.arange(0,720)
bw = (b_lim[1] - b_lim[0])
lon_sub = (lon_sub/lon_sub.size)*bw + b_lim[0]
lat_sub = (lat_sub/lat_sub.size)*bw -bw/2
lon_sub,lat_sub = np.meshgrid(lon_sub,lat_sub)

# Mesh the sphere
r = 240.0
x = r*np.cos(lat_sub)*np.cos(lon_sub)
y = r*np.cos(lat_sub)*np.sin(lon_sub)
z = r*np.sin(lat_sub)
hi1 = mlab.mesh(x,y,z)

# Texture the sphere
hi1.actor.actor.mapper.scalar_visibility = False
hi1.actor.enable_texture = True  # probably redundant assigning the texture later
image_file = 'image_test.jpg'
img = tvtk.JPEGReader(file_name=image_file)
texture = tvtk.Texture(input_connection=img.output_port,interpolate=0,repeat=0)
hi1.actor.actor.texture = texture

# tell mayavi that the mapping from points to pixels happens via a sphere
hi1.actor.tcoord_generator_mode = 'sphere' # map is already given for a spherical mapping

# Add on boundary lines from the observer to the field of view limits.
id_1 = np.nonzero((lon_sub == lon_sub.max()) & (lat_sub == lat_sub.max()))
id_2 = np.nonzero((lon_sub == lon_sub.max()) & (lat_sub == lat_sub.min()))
id_3 = np.nonzero((lon_sub == lon_sub.min()) & (lat_sub == lat_sub.max()))
id_4 = np.nonzero((lon_sub == lon_sub.min()) & (lat_sub == lat_sub.min()))

for idn in [id_1,id_2,id_3,id_4]:
    xl = np.array([obs_x,x[idn][0]])
    yl = np.array([obs_y,y[idn][0]])
    zl = np.array([obs_z,z[idn][0]])
    mlab.plot3d(xl,yl,zl,color=(0,1),tube_radius=1)

mlab.show()

我要用作纹理的图像是

Solar wind example picture

以上代码mayavi输出看起来像这样

mayavi output of example code

所以看起来好像很接近,但不正确。

感谢您能提供的任何帮助。

干杯

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...