def contour(): """The script itself. We needn't have defined a function but having a function makes this more reusable. """ # 'mayavi' is always defined on the interpreter. # Create a new scene. mayavi.new_scene() # Read a VTK (old style) data file. r = VTKFileReader() filename = join(mayavi2.get_data_dir(dirname(abspath(__file__))), 'heart.vtk') r.initialize(filename) mayavi.add_source(r) # Create an outline for the data. o = Outline() mayavi.add_module(o) # Create three simple grid plane modules. # First normal to 'x' axis. gp = GridPlane() mayavi.add_module(gp) # Second normal to 'y' axis. gp = GridPlane() mayavi.add_module(gp) gp.grid_plane.axis = 'y' # Third normal to 'z' axis. gp = GridPlane() mayavi.add_module(gp) gp.grid_plane.axis = 'z' # Create one ContourGridPlane normal to the 'x' axis. cgp = ContourGridPlane() mayavi.add_module(cgp) # Set the position to the middle of the data. cgp.grid_plane.position = 15 # Another with filled contours normal to 'y' axis. cgp = ContourGridPlane() mayavi.add_module(cgp) # Set the axis and position to the middle of the data. cgp.grid_plane.axis = 'y' cgp.grid_plane.position = 15 cgp.contour.filled_contours = True # An isosurface module. iso = IsoSurface(compute_normals=True) mayavi.add_module(iso) iso.contour.contours = [220.0] # An interactive scalar cut plane. cp = ScalarCutPlane() mayavi.add_module(cp) cp.implicit_plane.normal = 0, 0, 1
def setUp(self): """Initial setting up of test fixture, automatically called by TestCase before any other test method is invoked""" e = NullEngine() # Uncomment to see visualization for debugging etc. #e = Engine() e.start() s = e.new_scene() self.e = e self.s = s ############################################################ # Create a new scene and set up the visualization. #Make the grid grid = self.make_grid4scatter() e.add_source(grid) eg = ExtractGrid() e.add_filter(eg) nb_ticks = 6 eg.x_ratio = eg.y_ratio = eg.z_ratio = 100 / (nb_ticks - 1) / 2 gpx = GridPlane() e.add_module(gpx) gpx.grid_plane.axis = 'x' gpy = GridPlane() e.add_module(gpy) gpy.grid_plane.axis = 'y' gpz = GridPlane() e.add_module(gpz) gpz.grid_plane.axis = 'z' #Add the scatter d = VTKDataSource() d.data = self.make_scatter() e.add_source(d) if is_old_pipeline(): a = Axes() e.add_module(a) a.axes.number_of_labels = nb_ticks self.eg = eg self.gpx = gpx self.gpy = gpy self.gpz = gpz self.scene = e.current_scene return
def setUp(self): """Initial setting up of test fixture, automatically called by TestCase before any other test method is invoked""" e = NullEngine() # Uncomment to see visualization for debugging etc. #e = Engine() e.start() e.new_scene() self.e = e sgrid = datasets.generateStructuredGrid() src = VTKDataSource(data=sgrid) e.add_source(src) # Create an outline for the data. o = Outline() e.add_module(o) # Create three simple grid plane modules. # First normal to 'x' axis. gp1 = GridPlane() e.add_module(gp1) # Second normal to 'y' axis. gp2 = GridPlane() # We'll test how robust things are by setting attributes gp2.grid_plane.axis = 'y' gp2.grid_plane.position = 16 e.add_module(gp2) # Third normal to 'z' axis. gp3 = GridPlane() e.add_module(gp3) gp3.grid_plane.axis = 'z' gp3.grid_plane.position = 6 for gp in (gp1, gp2, gp3): gp.actor.property.trait_set(ambient=1.0) self.scene = e.current_scene return
def run(self): """This is executed once the application GUI has started. *Make sure all other MayaVi specific imports are made here!* """ # Various imports to do different things. from mayavi.sources.vtk_file_reader import VTKFileReader from mayavi.modules.outline import Outline from mayavi.modules.axes import Axes from mayavi.modules.grid_plane import GridPlane from mayavi.modules.image_plane_widget import ImagePlaneWidget from mayavi.modules.text import Text from mayavi.modules.contour_grid_plane import ContourGridPlane from mayavi.modules.iso_surface import IsoSurface script = self.script # Create a new scene. script.new_scene() # Read a VTK (old style) data file. r = VTKFileReader() r.initialize(join(get_data_dir(abspath(__file__)), 'heart.vtk')) script.add_source(r) # Put up some text. t = Text(text='MayaVi rules!', x_position=0.2, y_position=0.9, width=0.8) t.property.color = 1, 1, 0 # Bright yellow, yeah! script.add_module(t) # Create an outline for the data. o = Outline() script.add_module(o) # Create an axes for the data. a = Axes() script.add_module(a) # Create three simple grid plane modules. # First normal to 'x' axis. gp = GridPlane() script.add_module(gp) # Second normal to 'y' axis. gp = GridPlane() gp.grid_plane.axis = 'y' script.add_module(gp) # Third normal to 'z' axis. gp = GridPlane() script.add_module(gp) gp.grid_plane.axis = 'z' # Create one ImagePlaneWidget. ipw = ImagePlaneWidget() script.add_module(ipw) # Set the position to the middle of the data. ipw.ipw.slice_position = 16 # Create one ContourGridPlane normal to the 'x' axis. cgp = ContourGridPlane() script.add_module(cgp) # Set the position to the middle of the data. cgp.grid_plane.axis = 'y' cgp.grid_plane.position = 15 # An isosurface module. iso = IsoSurface(compute_normals=True) script.add_module(iso) iso.contour.contours = [200.0] # Set the view. s = script.engine.current_scene cam = s.scene.camera cam.azimuth(45) cam.elevation(15) s.render()
def do(self): ############################################################ # Imports. script = self.script from mayavi.sources.vtk_file_reader import VTKFileReader from mayavi.modules.outline import Outline from mayavi.modules.grid_plane import GridPlane ############################################################ # Create a new scene and set up the visualization. s = self.new_scene() # Read a VTK (old style) data file. r = VTKFileReader() r.initialize(get_example_data('heart.vtk')) script.add_source(r) # Create an outline for the data. o = Outline() script.add_module(o) # Create three simple grid plane modules. # First normal to 'x' axis. gp1 = GridPlane() script.add_module(gp1) # Second normal to 'y' axis. gp2 = GridPlane() # We'll test how robust things are by setting attributes # *before* we add it to the scene. gp2.grid_plane.axis = 'y' gp2.grid_plane.position = 16 script.add_module(gp2) # Third normal to 'z' axis. gp3 = GridPlane() script.add_module(gp3) gp3.grid_plane.axis = 'z' gp3.grid_plane.position = 6 for gp in (gp1, gp2, gp3): gp.actor.property.set(ambient=1.0) # Set the scene to an isometric view. s.scene.isometric_view() self.check() ############################################################ # Test if saving a visualization and restoring it works. # Save visualization. f = StringIO() f.name = abspath('test.mv2') # We simulate a file. script.save_visualization(f) f.seek(0) # So we can read this saved data. # Remove existing scene. engine = script.engine engine.close_scene(s) # Load visualization script.load_visualization(f) s = engine.current_scene self.check() ############################################################ # Test if the MayaVi2 visualization can be deepcopied. # Pop the source object. source = s.children.pop() # Add it back to see if that works without error. s.children.append(source) self.check() # Now deepcopy the source and replace the existing one with # the copy. This basically simulates cutting/copying the # object from the UI via the right-click menu on the tree # view, and pasting the copy back. source1 = copy.deepcopy(source) s.children[0] = source1 self.check()
def run(self): """This is executed once the application GUI has started. *Make sure all other MayaVi specific imports are made here!* """ # Various imports to do different things. from mayavi.sources.vtk_file_reader import VTKFileReader from mayavi.modules.outline import Outline from mayavi.modules.axes import Axes from mayavi.modules.grid_plane import GridPlane from mayavi.modules.image_plane_widget import ImagePlaneWidget from mayavi.modules.text import Text script = self.script # Create a new scene. script.new_scene() # Read a VTK (old style) data file. r = VTKFileReader() r.initialize( join(get_data_dir(dirname(abspath(__file__))), 'heart.vtk')) script.add_source(r) # Put up some text. t = Text(text='MayaVi rules!', x_position=0.2, y_position=0.9, width=0.8) t.property.color = 1, 1, 0 # Bright yellow, yeah! script.add_module(t) # Create an outline for the data. o = Outline() script.add_module(o) # Create an axes for the data. a = Axes() script.add_module(a) # Create an orientation axes for the scene. This only works with # VTK-4.5 and above which is why we have the try block. try: from mayavi.modules.orientation_axes import OrientationAxes except ImportError: pass else: a = OrientationAxes() a.marker.set_viewport(0.0, 0.8, 0.2, 1.0) script.add_module(a) # Create three simple grid plane modules. # First normal to 'x' axis. gp = GridPlane() script.add_module(gp) # Second normal to 'y' axis. gp = GridPlane() gp.grid_plane.axis = 'y' script.add_module(gp) # Third normal to 'z' axis. gp = GridPlane() script.add_module(gp) gp.grid_plane.axis = 'z' # Create one ImagePlaneWidget. ipw = ImagePlaneWidget() script.add_module(ipw) # Set the position to the middle of the data. ipw.ipw.slice_position = 16