イメージカーソルフィルタの例

UserDefinedフィルタを使用して抽出し,特殊な位置を示すために,データに十字型のカーソルを描画します.

カーソルを作成するには,UserDefinedフィルタ ImageCursor3D を使用します.ガウスデータフィールドはカーソルで描画され,ImagePlaneWIdgetモジュールを使用して視覚化されます.

ImageCursor3Dは,UserDefinedの多くの使用例の1つであり,では使用されないTVTKフィルタを使用できます.詳細については, UserDefined フィルタの使用 を参照してください.また,UserDefinedフィルタを使用する他の例は, Mriの例 および Tvtkセグメンテーションの例 にあります.

MayaviパイプラインでUserDefinedフィルタを選択すると,追加のフィルタを簡単に検索できます. TVTK class chooser というダイアログが表示され,目的のアクションやプロパティを検索するための Search フィールドが表示されます.たとえば, cursor を検索すると,Cursor3DとImageCursor3Dを含む複数のフィルタが返されます.一般的には,TVTK ImageDataデータセットに作用するTVTKフィルタの名前は, Image (ImageDataは,たとえば mlab.pipeline.scalar_field によって作成されたVTKデータセットのタイプです.VTKデータセットの詳細は, Mayaviでのデータ表現 を参照してください)で始まります.UserDefinedフィレットをインタラクティブに追加するためのダイアログでは, ImageCursor3D を選択できます.ダイアログの Class name フィールドでフィルタ名を選択すると,フィルタのドキュメントが表示されます.

Pythonソースコード: image_cursor_filter.py


# Authors: Emmanuelle Gouillart <emmanuelle.gouillart@normalesup.org>
# and Gael Varoquaux <gael.varoquaux@normalesup.org>
# Copyright (c) 2009, Enthought, Inc.
# License: BSD Style.


from mayavi import mlab
import numpy as np

# Define Gaussian data field
x, y, z = np.ogrid[0:1:40j, 0:1:40j, 0:1:40j]
sig = 0.5
center = 0.5
g = np.exp(-((x-center)**2 + (y-center)**2 + (z-center)**2)/(2*sig**2))

################################################################################

mlab.figure(fgcolor=(0, 0, 0), bgcolor=(1, 1, 1))

# Define the cursor
s = mlab.pipeline.scalar_field(g)
cursor = mlab.pipeline.user_defined(s, filter='ImageCursor3D')

# The TVTK filter used by Mayavi is accessible as the '.filter'
# attribute of the Mayavi filtered returned by user_defined.
# We can set the graphical properties of the cross via attributes of
# cursor.filter, and not of cursor itself. Here cursor is a Mayavi filter,
# that is an object that inserts in the Mayavi pipeline, whereas
# cursor.filter is the TVTK filter that actually does the work.

# Put the cursor at the center of the field volume (default is (0, 0, 0))
cursor.filter.cursor_position = np.array([20, 20, 20])
# Define the value of the cursor (default is 255) so that there is
# enough contrast between the cursor and the data values in the neighbourhood
# of the cursor. The cursor value is within the data value range so that
# the contrast of the data is not altered.
cursor.filter.cursor_value = 0
# Define the radius of the cross (the extent of the cross is 2xcursor_radius)
cursor.filter.cursor_radius = 10


# Display data and cursor using an image_plane_widget that intersects the
# cursor.
ipw = mlab.pipeline.image_plane_widget(cursor, plane_orientation='x_axes',
            slice_index=20)

# View
mlab.colorbar()
mlab.view(15, 70, 100, [20, 20, 20])
mlab.show()