一旦拥有了你的星球,使用mayavi.mlab.plot3d绘制轨迹很容易,所以我将专注于使用mayavi将行星映射到球体的纹理。 (原则上我们可以使用matplotlib执行任务,但与mayavi相比,性能和质量要差得多,请参阅本答案的结尾。)
漂亮的场景:球体上的球体
事实证明,如果你想将一个球形的参数化图像映射到一个球体上,你必须让你的手有点脏,并使用一些裸vtk,但实际上很少有工作要做,结果看起来很棒。 他们的自述文件说这些图像有
地理(PlateCarrée)投影,基于相等的纬度 - 经度网格间距(不是等面积投影!)
在维基百科中查找它,结果证明这也称为equirectangular投影 。 换句话说,沿x像素直接对应于经度,沿y像素直接对应于纬度。 这就是我所说的“球形参数化”。
因此在这种情况下,我们可以使用低级TexturedSphereSource来生成可以映射到纹理的球体。 自己构造一个球体网格可能会导致映射中的工件(稍后会详细介绍)。
对于低级别的vtk工作,我重写了这里发现的官方示例 。 这就是它所需要的一切:
from mayavi import mlab
from tvtk.api import tvtk # python wrappers for the C++ vtk ecosystem
def auto_sphere(image_file):
# create a figure window (and scene)
fig = mlab.figure(size=(600, 600))
# load and map the texture
img = tvtk.JPEGReader()
img.file_name = image_file
texture = tvtk.Texture(input_connection=img.output_port, interpolate=1)
# (interpolate for a less raster appearance when zoomed in)
# use a TexturedSphereSource, a.k.a. getting our hands dirty
R = 1
Nrad = 180
# create the sphere source with a given radius and angular resolution
sphere = tvtk.TexturedSphereSource(radius=R, theta_resolution=Nrad,
phi_resolution=Nrad)
# assemble rest of the pipeline, assign texture
sphere_mapper = tvtk.PolyDataMapper(input_connection=sphere.output_port)
sphere_a