def do(self): ############################################################ # Imports. script = self.script from mayavi.sources.array_source import ArraySource from mayavi.modules.outline import Outline from mayavi.modules.surface import Surface from mayavi.modules.vectors import Vectors ############################################################ # Create a new scene and set up the visualization. s = self.new_scene() d = ArraySource() self.check_input_validation(d) sc, vec = self.make_2d_data() d.origin = (-1, -1, 0) d.scalar_data = sc d.vector_data = vec script.add_source(d) # Create an outline for the data. o = Outline() script.add_module(o) # View the data. s = Surface() script.add_module(s) v = Vectors() script.add_module(v) # Add a 3D data source d = ArraySource() sc, vec = self.make_3d_data() d.scalar_data = sc d.vector_data = vec script.add_source(d) # Create an outline for the data. o = Outline() script.add_module(o) # View a slice. s = Surface() script.add_module(s) v = Vectors() script.add_module(v) # Set the scene to a suitable view. s.scene.z_plus_view() c = s.scene.camera c.azimuth(-30) c.elevation(30) self.check() ############################################################ # Test if saving a visualization and restoring it works. bg = s.scene.background # 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 # Set the scene to a suitable view. s.scene.z_plus_view() c = s.scene.camera c.azimuth(-30) c.elevation(30) s.scene.background = bg self.check() ############################################################ # Test if the MayaVi2 visualization can be deepcopied. # Pop the source object. sources = s.children s.children = [] # Add it back to see if that works without error. s.children.extend(sources) s.scene.reset_zoom() 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. sources1 = copy.deepcopy(sources) s.children[:] = sources s.scene.reset_zoom() self.check()