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 # Read a VTK (old style) data file. r = VTKXMLFileReader() r.initialize(get_example_data('pyramid_ug.vtu')) e.add_source(r) # Create the filters. # CellDerivatives cd = tvtk.CellDerivatives() ud = UserDefined(filter=cd) e.add_filter(ud) ctp = CellToPointData() ctp.filter.pass_cell_data = False e.add_filter(ctp) evn = ExtractVectorNorm() e.add_filter(evn) evc = ExtractVectorComponents(component='y-component') o = Optional(filter=evc) e.add_filter(o) e.add_module(ScalarCutPlane()) self.scene = e.current_scene s = self.scene return
def main(): # Create the MayaVi engine and start it. e = Engine() # Starting the engine registers the engine with the registry and # notifies others that the engine is ready. e.start() # Do this if you need to see the MayaVi tree view UI. ev = EngineView(engine=e) ui = ev.edit_traits() # Create a new scene. scene = e.new_scene() # Now create a new scene just for kicks. scene1 = e.new_scene() # Now setup a normal MayaVi pipeline. src = VTKXMLFileReader() src.initialize(join(get_data_dir(abspath(__file__)), 'fire_ug.vtu')) e.add_source(src) e.add_module(Outline()) e.add_module(ScalarCutPlane()) e.add_module(Streamline()) return e, ui
def main(): # Create the MayaVi offscreen engine and start it. e = OffScreenEngine() # Starting the engine registers the engine with the registry and # notifies others that the engine is ready. e.start() # Create a new scene. win = e.new_scene() # Now setup a normal MayaVi pipeline. src = VTKXMLFileReader() src.initialize( join(get_data_dir(dirname(abspath(__file__))), 'fire_ug.vtu')) e.add_source(src) e.add_module(Outline()) e.add_module(ScalarCutPlane()) e.add_module(Streamline()) win.scene.isometric_view() # Change the size argument to anything you want. win.scene.save('offscreen.png', size=(800, 800))
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
def do(self): ############################################################ # Imports. from mayavi.modules.api import ScalarCutPlane from mayavi.modules.labels import Labels from mayavi.sources.vtk_xml_file_reader import VTKXMLFileReader ############################################################ # Create a new scene and set up the visualization. s = self.new_scene() script = mayavi = self.script # Read a VTK (old style) data file. r = VTKXMLFileReader() r.initialize(get_example_data('fire_ug.vtu')) script.add_source(r) # Create the filters. cp = ScalarCutPlane() script.add_module(cp) l = Labels(object=cp) script.add_module(l) s.scene.isometric_view() GUI.process_events() self.check(saved=False) ############################################################ # Test if saving a visualization and restoring it works. # Save visualization. f = BytesIO() f.name = abspath('test.mv2') # We simulate a file. script.save_visualization(f) f.seek(0) # Remove existing scene. engine = script.engine engine.close_scene(s) # Load visualization script.load_visualization(f) s = engine.current_scene s.scene.isometric_view() # Seems to be needed for the test to pass. :( Just flushes the # pipeline. s.children[0].pipeline_changed = True GUI.process_events() # Check. # Now do the check. self.check(saved=True) ############################################################ # Test if the Mayavi2 visualization can be deep-copied. # Pop the source object. source = s.children.pop() # Add it back to see if that works without error. s.children.append(source) GUI.process_events() # Now do the check. s.scene.isometric_view() self.check(saved=True) # 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 GUI.process_events() # Now do the check. s.scene.isometric_view() self.check(saved=True) GUI.process_events()
def do(self): ############################################################ # Imports. from mayavi.sources.api import VTKXMLFileReader,\ VRMLImporter from mayavi.modules.api import ScalarCutPlane,\ IsoSurface ############################################################ # Create a new scene and set up the visualization. s = self.new_scene() script = mayavi = self.script # Read a VRML file. w = VRMLImporter() w.initialize(get_example_data('room_vis.wrl')) script.add_source(w) # Read a VTK data file. r = VTKXMLFileReader() r.initialize(get_example_data('fire_ug.vtu')) script.add_source(r) # Create the modules. scp = ScalarCutPlane() script.add_module(scp) iso = IsoSurface() script.add_module(iso) # Check. self.check(saved=False) ############################################################ # Test if saving a visualization and restoring it works. # Save visualization. f = BytesIO() 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 s.scene.isometric_view() # Now do the check. self.check(saved=True) ############################################################ # Test if the Mayavi2 visualization can be deep-copied. # Pop the source object. sources = s.children s.children = [] # Add it back to see if that works without error. s.children.extend(sources) # Now do the check. s.scene.isometric_view() self.check(saved=True) # 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[:] = sources1 # Now do the check. s.scene.isometric_view() self.check(saved=True)
def do(self): ############################################################ # Imports. from mayavi.filters.optional import Optional from mayavi.filters.user_defined import UserDefined from mayavi.filters.api import (CellToPointData, ExtractVectorNorm, ExtractVectorComponents) from mayavi.modules.api import ScalarCutPlane from mayavi.sources.vtk_xml_file_reader import VTKXMLFileReader ############################################################ # Create a new scene and set up the visualization. s = self.new_scene() script = mayavi = self.script # Read a VTK (old style) data file. r = VTKXMLFileReader() r.initialize(get_example_data('fire_ug.vtu')) script.add_source(r) # Create the filters. # CellDerivatives cd = tvtk.CellDerivatives() ud = UserDefined(filter=cd) script.add_filter(ud) ctp = CellToPointData() ctp.filter.pass_cell_data = False script.add_filter(ctp) evn = ExtractVectorNorm() script.add_filter(evn) evc = ExtractVectorComponents(component='y-component') o = Optional(filter=evc) script.add_filter(o) script.add_module(ScalarCutPlane()) s.scene.isometric_view() # Check. self.check(saved=False) ############################################################ # 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 s.scene.isometric_view() # Now do the check. self.check(saved=True) ############################################################ # Test if the Mayavi2 visualization can be deep-copied. # Pop the source object. source = s.children.pop() # Add it back to see if that works without error. s.children.append(source) # Now do the check. s.scene.isometric_view() self.check(saved=True) # 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 # Now do the check. s.scene.isometric_view() self.check(saved=True)