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. d = ArraySource() sc, vec = self.make_data() d.origin = (-5, -5, -5) d.scalar_data = sc d.vector_data = vec e.add_source(d) # Create an outline for the data. o = Outline() e.add_module(o) # View the data. st = Streamline() e.add_module(st) widget = st.seed.widget widget.set(radius=1.0, center=(-4.0, -4.0, -4.0), theta_resolution=4, phi_resolution=4) st = Streamline(streamline_type='ribbon') seed = st.seed seed.widget = seed.widget_list[1] e.add_module(st) seed.widget.set(point1=(-5.0, -4.5, -4.0), point2=(-5.0, -4.5, 4.0)) st.ribbon_filter.width = 0.25 st = Streamline(streamline_type='tube') seed = st.seed seed.widget = seed.widget_list[2] e.add_module(st) seed.widget.set(center=(-5.0, 1.5, -2.5)) st.tube_filter.radius = 0.15 st = Streamline(streamline_type='tube') seed = st.seed seed.widget = seed.widget_list[3] e.add_module(st) seed.widget.position = (-5.0, 3.75, 3.75) st.tube_filter.radius = 0.2 self.st = st self.scene = e.current_scene return
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
scene.scene.camera.view_up = [ 0.17522011839126639, 0.35024314762581926, 0.92012371323214404 ] scene.scene.camera.clipping_range = [16.803351361631922, 58.674779759221536] scene.scene.camera.compute_view_plane_normal() scene.scene.render() surface.actor.property.edge_visibility = True surface.actor.property.line_width = 1.1832000017166138 surface.actor.property.line_width = 1.1831999999999998 vtkxml_file_reader1 = engine.open( u'/Users/prabhu/work/MEDIA/m2/data/shuttle_flow_vel.vti', scene) from enthought.mayavi.filters.extract_vector_norm import ExtractVectorNorm extract_vector_norm = ExtractVectorNorm() engine.add_filter(extract_vector_norm, vtkxml_file_reader1) from enthought.mayavi.modules.streamline import Streamline streamline = Streamline() engine.add_filter(streamline, extract_vector_norm) from enthought.mayavi.modules.outline import Outline outline = Outline() module_manager1 = extract_vector_norm.children[0] engine.add_filter(outline, module_manager1) scene.scene.camera.position = [ -35.527291132838059, 1.5271766756373661, 3.1941487321866866 ] scene.scene.camera.focal_point = [ -0.30313491821289062, 0.0, 1.4027749300003052 ] scene.scene.camera.view_angle = 30.0 scene.scene.camera.view_up = [ 0.061459962287939186, 0.30146804029963314, 0.9514934018233987 ]
gp.actor.mapper.scalar_visibility = True gp.actor.property.representation = 'surface' gp.actor.property.diffuse = 0.0 gp.actor.property.ambient = 1.0 gp.actor.property.opacity = 1 gp = GridPlane() script.add_module(gp) gp.grid_plane.axis = 'z' gp.actor.mapper.scalar_visibility = False gp.actor.property.representation = 'wireframe' gp.actor.property.diffuse = 0.0 gp.actor.property.ambient = 1.0 gp.actor.property.opacity = 1 strl = Streamline() script.add_module(strl) strl.streamline_type = "tube" # tube, ribbon or line strl.tube_filter.number_of_sides = 10 strl.tube_filter.radius = 0.1 strl.seed.widget = strl.seed.widget_list[1] # [Sphere, Line, Plane, Point] strl.seed.widget.align = "z_axis" # or "x_axis", "y_axis" strl.seed.widget.point1 = (-0.7, 0, 0) strl.seed.widget.point2 = (-0.7, 0, 4.82) strl.seed.widget.resolution = 10 strl.seed.widget.enabled = False # <markdowncell> # This should look like: #
def do(self): ############################################################ # Imports. script = self.script from enthought.mayavi.sources.array_source import ArraySource from enthought.mayavi.modules.outline import Outline from enthought.mayavi.modules.streamline import Streamline ############################################################ # Create a new scene and set up the visualization. s = self.new_scene() d = ArraySource() sc, vec = self.make_data() d.origin = (-5, -5, -5) 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. st = Streamline() script.add_module(st) widget = st.seed.widget widget.set(radius=1.0, center=(-4.0, -4.0, -4.0), theta_resolution=4, phi_resolution=4) st = Streamline(streamline_type='ribbon') seed = st.seed seed.widget = seed.widget_list[1] script.add_module(st) seed.widget.set(point1=(-5.0, -4.5, -4.0), point2=(-5.0, -4.5, 4.0)) st.ribbon_filter.width = 0.25 st = Streamline(streamline_type='tube') seed = st.seed seed.widget = seed.widget_list[2] script.add_module(st) seed.widget.set(center=(-5.0, 1.5, -2.5)) st.tube_filter.radius = 0.15 st = Streamline(streamline_type='tube') seed = st.seed seed.widget = seed.widget_list[3] script.add_module(st) seed.widget.position = (-5.0, 3.75, 3.75) st.tube_filter.radius = 0.2 # Set the scene to a suitable view. s.scene.z_plus_view() c = s.scene.camera c.azimuth(-30) c.elevation(30) s.render() # Now compare the image. self.compare_image(s, 'images/test_streamline.png') ############################################################ # Test if the modules respond correctly when the components # are changed. tf = st.tube_filter st.tube_filter = tf.__class__() st.tube_filter = tf st.ribbon_filter = st.ribbon_filter.__class__() seed = st.seed st.seed = seed.__class__() st.seed = seed st.actor = st.actor.__class__() tracer = st.stream_tracer st.stream_tracer = tracer.__class__() st.stream_tracer = tracer s.render() # Now compare the image. self.compare_image(s, 'images/test_streamline.png') s.render() ############################################################ # 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.render() s.scene.background = bg # Now compare the image. self.compare_image(s, 'images/test_streamline.png') ############################################################ # 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() # Now compare the image. self.compare_image(s, 'images/test_streamline.png') # 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.compare_image(s, 'images/test_streamline.png')
def do(self): ############################################################ # Imports. script = self.script from enthought.mayavi.sources.array_source import ArraySource from enthought.mayavi.modules.outline import Outline from enthought.mayavi.modules.streamline import Streamline ############################################################ # Create a new scene and set up the visualization. s = self.new_scene() d = ArraySource() sc, vec = self.make_data() d.origin = (-5, -5, -5) 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. st = Streamline() script.add_module(st) widget = st.seed.widget widget.set(radius=1.0, center=(-4.0, -4.0, -4.0), theta_resolution=4, phi_resolution=4) st = Streamline(streamline_type='ribbon') seed = st.seed seed.widget = seed.widget_list[1] script.add_module(st) seed.widget.set(point1=(-5.0, -4.5, -4.0), point2=(-5.0, -4.5, 4.0)) st.ribbon_filter.width = 0.25 st = Streamline(streamline_type='tube') seed = st.seed seed.widget = seed.widget_list[2] script.add_module(st) seed.widget.set(center=(-5.0, 1.5, -2.5)) st.tube_filter.radius = 0.15 st = Streamline(streamline_type='tube') seed = st.seed seed.widget = seed.widget_list[3] script.add_module(st) seed.widget.position=(-5.0, 3.75, 3.75) st.tube_filter.radius = 0.2 # Set the scene to a suitable view. s.scene.z_plus_view() c = s.scene.camera c.azimuth(-30) c.elevation(30) s.render() # Now compare the image. self.compare_image(s, 'images/test_streamline.png') ############################################################ # Test if the modules respond correctly when the components # are changed. tf = st.tube_filter st.tube_filter = tf.__class__() st.tube_filter = tf st.ribbon_filter = st.ribbon_filter.__class__() seed = st.seed st.seed = seed.__class__() st.seed = seed st.actor = st.actor.__class__() tracer = st.stream_tracer st.stream_tracer = tracer.__class__() st.stream_tracer = tracer s.render() # Now compare the image. self.compare_image(s, 'images/test_streamline.png') s.render() ############################################################ # 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.render() s.scene.background = bg # Now compare the image. self.compare_image(s, 'images/test_streamline.png') ############################################################ # 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() # Now compare the image. self.compare_image(s, 'images/test_streamline.png') # 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.compare_image(s, 'images/test_streamline.png')