MayaviをPythonのスクリプトで起動したい
Example gallery
API referenceとかを参考にいろいろ検討中。
Cookbook/MayaVi/Examples/のcontour.pyというスクリプト。Windowsにおいて、スクリプトをこのままで実行すると、
NameError: global name 'mayavi' is not defined
となる。なので次のように数行加えて実行すると動く。
#!/usr/bin/env mayavi2 # これはいらない from os.path import join, dirname import enthought.mayavi # いらないみたい from enthought.mayavi.scripts import mayavi2 # この行を加える from enthought.mayavi.sources.vtk_file_reader import VTKFileReader from enthought.mayavi.filters.threshold import Threshold from enthought.mayavi.modules.outline import Outline from enthought.mayavi.modules.grid_plane import GridPlane from enthought.mayavi.modules.contour_grid_plane import ContourGridPlane from enthought.mayavi.modules.iso_surface import IsoSurface from enthought.mayavi.modules.scalar_cut_plane import ScalarCutPlane #from enthought.mayavi.modules.api import Outline, GridPlane, ContourGridPlane, IsoSurface, ScalarCutPlane # これでもいいはず def contour(): mayavi.new_scene() r = VTKFileReader() r.initialize('heart.vtk') mayavi.add_source(r) o = Outline() mayavi.add_module(o) gp = GridPlane() mayavi.add_module(gp) gp = GridPlane() mayavi.add_module(gp) gp.grid_plane.axis = 'y' gp = GridPlane() mayavi.add_module(gp) gp.grid_plane.axis = 'z' cgp = ContourGridPlane() mayavi.add_module(cgp) cgp.grid_plane.position = 15 cgp = ContourGridPlane() mayavi.add_module(cgp) cgp.grid_plane.axis = 'y' cgp.grid_plane.position = 15 cgp.contour.filled_contours = True iso = IsoSurface(compute_normals=True) mayavi.add_module(iso) iso.contour.contours = [220.0] cp = ScalarCutPlane() mayavi.add_module(cp) cp.implicit_plane.normal = 0, 0, 1 @mayavi2.standalone # この行を加える def main(): contour() if __name__ == '__main__': main()