带 Mayavi 的线框等值面

Wireframe isosurface with Mayavi

Mayavi 中的 mesh 函数接受 representation 关键字,允许将表面视为三角线框网格。如何使用 mlab.pipeline.iso_surfacemlab.contour3d 获得等值面的类似结果?

比如我想实现的效果是:

import numpy as np
from mayavi import mlab

# Create image volume with sphere as zero level surface.
x,y,z = np.mgrid[-20:21, -20:21, -20:21].astype(np.float)
vol = np.sqrt(x**2 + y**2 + z**2) - 7

# Visualize the level surface.
sf = mlab.pipeline.scalar_field(vol)
mlab.pipeline.iso_surface(sf, contours=[0.0],
                          representation='wireframe')
mlab.show()

当然,此代码不会 运行 因为 representation 关键字参数对于 iso_surface 函数不存在。

我已经通过使用 mlab.view_pipeline() 命令并使用 GUI 探索创建的管道的属性来解决这个问题。

线框图可以通过以下方式实现:

sf = mlab.pipeline.scalar_field(vol)
iso = mlab.pipeline.iso_surface(sf, contours=[0.0])

# Added line.
iso.actor.property.representation = 'wireframe'

mlab.show()

这导致