就像使用 Mayavi 的mlab
界面来执行此操作的一个简单示例(甚至使用一些地质数据!):
from mayavi import mlab
import geoprobe
vol = geoprobe.volume('Volumes/example.vol')
data = vol.load() #"data" here is just a 3D numpy array of uint8's
fig = mlab.figure(bgcolor=(1., 1., 1.), fgcolor=(0., 0., 0.), size=(800,800))
grid = mlab.pipeline.scalar_field(data)
# Have things display in kilometers with no vertical exxageration
# Each voxel actually represents a 12.5 by 18.5 by 5 meter volume.
grid.spacing = [vol.dxW / 1000, vol.dyW / 1000, vol.dz / 1000]
# Now, let's display a few cut planes. These are interactive, and are set up to
# be dragged around through the volume. If you'd prefer non-interactive cut
# planes, have a look at mlab.pipeline.scalar_cut_plane instead.
orientations = ['x', 'x', 'y', 'z']
starting_positions = [vol.nx//4, 3*vol.nx//4, vol.ny//2, vol.nz]
for orientation, start_pos in zip(orientations, starting_positions):
plane = mlab.pipeline.image_plane_widget(grid, colormap='gray',
plane_orientation='%s_axes' % orientation, slice_index=start_pos)
# High values should be black, low values should be white...
plane.module_manager.scalar_lut_manager.reverse_lut = True
mlab.show()
(数据和数据格式处理代码(geoprobe
模块)可在此处获得:http ://code.google.com/p/python-geoprobe/ )
虽然我同意从长远来看学习 VTK 会更好,但您可以使用 Mayavi 快速启动并运行。最大的优势是不必费力地将数据转换为 VTK 格式。TVTK 和 Mayavi 允许您直接使用 numpy 数组。