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() 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 one ContourGridPlane normal to the 'x' axis. cgp1 = ContourGridPlane() e.add_module(cgp1) # Set the position to the middle of the data. cgp1.grid_plane.position = 15 # Another with filled contours normal to 'y' axis. cgp2 = ContourGridPlane() cgp2.contour.filled_contours = True # Set the axis and position to the middle of the data. cgp2.grid_plane.axis = 'y' cgp2.grid_plane.position = 15 e.add_module(cgp2) # An isosurface module. iso = IsoSurface(compute_normals=True) e.add_module(iso) iso.contour.contours = [5] # An interactive scalar cut plane. cp = ScalarCutPlane() e.add_module(cp) ip = cp.implicit_plane ip.normal = 0, 0, 1 ip.origin = 0.5, 0.5, 1.0 # Since this is running offscreen this seems necessary. ip.widget.origin = 0.5, 0.5, 1.0 ip.widget.enabled = False self.scene = e.current_scene self.cgp2 = cgp2 self.iso = iso self.cp = cp return
def contour(i, x): """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 in datacube fd = open("output/output-cube-%.8d-%.3d" % (i, 0)) rho, rhovx, rhovz, rhovy = numpy.fromfile(file=fd, dtype=numpy.float32).reshape( (4, x, x, x)) src = ArraySource(transpose_input_array=False) src.scalar_data = numpy.log10(rho).T.copy() mayavi.add_source(src) # Create an outline for the data. o = Outline() mayavi.add_module(o) # 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 = 0 # Another 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 = 0 # Another normal to 'z' axis. cgp = ContourGridPlane() mayavi.add_module(cgp) # Set the axis and position to the middle of the data. cgp.grid_plane.axis = 'z' cgp.grid_plane.position = 0 # An isosurface module. iso = IsoSurface(compute_normals=False) 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 streamline(): """Sets up the mayavi pipeline for the visualization. """ # Create an outline for the data. o = Outline() mayavi.add_module(o) s = Streamline(streamline_type='tube') mayavi.add_module(s) s.stream_tracer.integration_direction = 'both' s.seed.widget.center = 3.5, 0.625, 1.25 s.module_manager.scalar_lut_manager.show_scalar_bar = True i = IsoSurface() mayavi.add_module(i) i.contour.contours[0] = 550 i.actor.property.opacity = 0.5
for file0 in os.listdir('.'): if fnmatch.fnmatch(file0, '*AMP.rec'): filename = file0 print filename savename = filename ## scene1 = engine.new_scene() scene1.scene.off_screen_rendering = True jesse_mat_lab_coord_source1 = engine.open(filename, scene1) ## from enthought.mayavi.modules.iso_surface import IsoSurface iso_surface1 = IsoSurface() engine.add_filter(iso_surface1, jesse_mat_lab_coord_source1) iso_surface1.contour.contours[0:1] = [0.5] ##Orientation axes orientation_axes = OrientationAxes() engine.add_module(orientation_axes, obj=None) orientation_axes.text_property.shadow_offset = array([1, -1]) orientation_axes.text_property.font_family = 'times' orientation_axes.text_property.shadow_offset = array([1, -1]) orientation_axes.text_property.font_size = 15 orientation_axes.axes.axis_labels = False ## if os.path.isdir(dir + '/pics/') == False: os.mkdir(dir + '/pics/')
from enthought.mayavi.modules.iso_surface import IsoSurface from enthought.mayavi.filters.threshold import Threshold # <markdowncell> # then, set the threshold values: # # <codecell> thh = Threshold() script.add_filter(thh) thh.lower_threshold = 0.4 thh.upper_threshold = 0.6 isosurf = IsoSurface() thh.add_module(isosurf) isosurf.contour.contours = [0.5] isosurf.compute_normals = True isosurf.actor.property.opacity = 0.2 isosurf.module_manager.scalar_lut_manager.data_range = [0, 1] # <markdowncell> # and you're done ! # # This should look like this: # # ![](files/MayaVi(2f)ScriptingMayavi2(2f)Filters_attachments/filter_thrld2.png # # You can notice on the two previous figures that the Threshold module
# Using the !IsoSurface module is not more difficult. As an example, say # that we want the same result as the Surface module displays. # # <codecell> from enthought.mayavi.modules.iso_surface import IsoSurface # <markdowncell> # and # # <codecell> isosurf = IsoSurface() script.add_module(isosurf) isosurf.contour.contours = [0.1111, 0.2222, 0.3333, 0.4444, 0.5555, 0.6666, 0.7777, 0.8888] isosurf.compute_normals = True isosurf.actor.property.opacity = 0.2 isosurf.module_manager.scalar_lut_manager.data_range = [0, 1] # <markdowncell> # This yelds the same scene as previous, of course, but now, you can # control each isovalue separately. # # ![](files/MayaVi(2f)ScriptingMayavi2(2f)MainModules_attachments/module_isosurface.png # # The funny part is that you can set the minimum/maximum contour for # Surface or Contours for !IsoSurface in "real-time", moving the
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 enthought.mayavi.sources.vtk_file_reader import VTKFileReader from enthought.mayavi.modules.outline import Outline from enthought.mayavi.modules.axes import Axes from enthought.mayavi.modules.grid_plane import GridPlane from enthought.mayavi.modules.image_plane_widget import ImagePlaneWidget from enthought.mayavi.modules.text import Text from enthought.mayavi.modules.contour_grid_plane import ContourGridPlane from enthought.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 enthought.mayavi.sources.vtk_file_reader import VTKFileReader from enthought.mayavi.modules.outline import Outline from enthought.mayavi.modules.iso_surface import IsoSurface from enthought.mayavi.modules.contour_grid_plane \ import ContourGridPlane from enthought.mayavi.modules.scalar_cut_plane import ScalarCutPlane ############################################################ # 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 one ContourGridPlane normal to the 'x' axis. cgp1 = ContourGridPlane() script.add_module(cgp1) # Set the position to the middle of the data. cgp1.grid_plane.position = 15 # Another with filled contours normal to 'y' axis. cgp2 = ContourGridPlane() cgp2.contour.filled_contours = True # Set the axis and position to the middle of the data. cgp2.grid_plane.axis = 'y' cgp2.grid_plane.position = 15 script.add_module(cgp2) # An isosurface module. iso = IsoSurface(compute_normals=True) script.add_module(iso) iso.contour.contours = [200.0] # An interactive scalar cut plane. cp = ScalarCutPlane() script.add_module(cp) ip = cp.implicit_plane ip.normal = 0,0,1 ip.origin = 0,0,5 ip.widget.enabled = False # Set the scene to an isometric view. s.scene.isometric_view() # Now test. self.check() ############################################################ # Test if the modules respond correctly when the components # are changed. ctr = cgp2.contour cgp2.contour = ctr.__class__() cgp2.contour = ctr cgp2.actor = cgp2.actor.__class__() iso.contour = iso.contour.__class__() iso.contour.contours = [200.0] iso.actor = iso.actor.__class__() iso.normals = iso.normals.__class__() ip = cp.implicit_plane cp.implicit_plane = cp.implicit_plane.__class__() cp.implicit_plane = ip ip.widget.enabled = False cp.contour = cp.contour.__class__() cp.cutter = cp.cutter.__class__() cp.actor = cp.actor.__class__() s.render() # Now check. 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 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 set the enabled status of the widget, this is impossible # to get correctly. cp = source.children[0].children[-1] cp.implicit_plane.widget.enabled = False 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 cp = source1.children[0].children[-1] cp.implicit_plane.widget.enabled = False self.check()
filename = file0 print filename savename = filename numb = numb + 1 jesse_mat_lab_coord_source1 = engine.open(filename) #if os.path.isdir(dir+'/rec_movie_pics/') == False: # os.mkdir(dir+'/rec_movie_pics/') #filename=dir+'/rec_movie_pics/' this_dir = dir from enthought.mayavi.modules.iso_surface import IsoSurface iso_surface = IsoSurface() engine.add_filter(iso_surface, jesse_mat_lab_coord_source1) iso_surface.contour.contours[0:1] = [thresh] scene = engine.scenes[0] scene.scene.render() scene.scene.x_plus_view() scene.scene.camera.zoom(mag) #scene.scene.render() ## change the color bar range if transparent != 0: module_manager = engine.scenes[0].children[0].children[0] module_manager.scalar_lut_manager.show_scalar_bar = True module_manager.scalar_lut_manager.show_legend = True module_manager.scalar_lut_manager.scalar_bar.position2 = array( [0.17, 0.8]) module_manager.scalar_lut_manager.scalar_bar.position = array(
def do(self): # Setup the source. self.make_data() from enthought.mayavi.modules.outline import Outline from enthought.mayavi.modules.iso_surface import IsoSurface from enthought.mayavi.modules.contour_grid_plane \ import ContourGridPlane from enthought.mayavi.modules.scalar_cut_plane import ScalarCutPlane script = self.script s = script.engine.current_scene # Create an outline for the data. o = Outline() script.add_module(o) # 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.position = 15 # Another with filled contours normal to 'y' axis. cgp = ContourGridPlane() cgp.contour.filled_contours = True # Set the axis and position to the middle of the data. cgp.grid_plane.axis = 'y' cgp.grid_plane.position = 15 script.add_module(cgp) # An isosurface module. iso = IsoSurface(compute_normals=True) script.add_module(iso) iso.contour.contours = [200.0] # An interactive scalar cut plane. cp = ScalarCutPlane() script.add_module(cp) ip = cp.implicit_plane ip.normal = 0, 0, 1 ip.origin = 0, 0, 5 ip.widget.enabled = False # 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 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 set the enabled status of the widget, this is impossible # to get correctly. cp = source.children[0].children[-1] cp.implicit_plane.widget.enabled = False 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 cp = source1.children[0].children[-1] cp.implicit_plane.widget.enabled = False self.check()