これを行うために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 配列を直接使用できます。