def __init__(self): HasTraits.__init__(self) x, y, z = ogrid[-10:10:100j, -10:10:100j, -10:10:100j] scalars = sin(x*y*z)/(x*y*z) src = ArraySource(scalar_data=scalars) self.scene.mayavi_scene.add_child(src) src.add_module(IsoSurface())
def __init__(self): HasTraits.__init__(self) x, y, z = ogrid[-10:10, -10:10, -10:10] scalars = x**2 + y**2 + z**2 src = ArraySource(scalar_data=scalars) self.scene.mayavi_scene.add_child(src) src.add_module(IsoSurface())
def on_patient_loaded(self, msg): self.data = msg.data ct_data = self.data.voxelplan_images x, y, z = ogrid[0:1:ct_data.dimx, 0:1:ct_data.dimy, 0:1:ct_data.dimz] src = ArraySource(scalar_data=ct_data.cube) self.scene.engine.add_source(src) src.add_module(IsoSurface())
def __init__(self): HasTraits.__init__(self) # Create some data, and plot it using the embedded scene's engine x, y, z = ogrid[-10:10:100j, -10:10:100j, -10:10:100j] scalars = sin(x * y * z) / (x * y * z) src = ArraySource(scalar_data=scalars) self.scene.engine.add_source(src) src.add_module(IsoSurface())
def view(): from mayavi import mlab from mayavi.sources.vtk_data_source import VTKDataSource from mayavi.modules.outline import Outline from mayavi.modules.surface import Surface from mayavi.modules.vectors import Vectors from mayavi.modules.api import IsoSurface scene = mayavi.new_scene() #scene.background = "black" # The single type one src = VTKDataSource(data=ug) mayavi.add_source(src) mayavi.add_module(Outline()) #mayavi.add_module(Surface()) #mayavi.add_module(Vectors()) #translucent isosurfaces iso = IsoSurface() mayavi.add_module(iso) iso.module_manager.scalar_lut_manager.lut_mode = "plasma" iso.contour.contours = np.linspace(0.0, 0.03, 30).tolist() iso.actor.property.opacity = 0.3 #iso = mayavi.mlab.pipeline.iso_surface(ug, contours=[1e-15,1e-14,1e-12], opacity=0.3) #from mayavi import mlab #mlab.contour3d(ug, opacity=0.3) #corned outline = engine.scenes[0].children[0].children[0].children[0] outline.outline_filter.reference_count = 2 outline.outline_filter.progress = 1.0 outline.actor.mapper.scalar_range = np.array([0., 1.]) outline.actor.mapper.progress = 1.0 outline.outline_mode = 'cornered' #show the xyz arrow axis scene.scene.show_axes = True scene.scene.background = (0.0, 0.0, 0.0) scene.scene.isometric_view() #v = mlab.view() (azimuth, elevation, distance, focalpoint) = mlab.view() elevation += 20.0 #move cam a little lower distance *= 0.6 for i, ang in enumerate(np.linspace(0.0, 360, 100)): si = str(i).rjust(4, '0') scene.scene.save('out/snapshot{}.png'.format(si)) mlab.view(azimuth=azimuth + ang, elevation=elevation, distance=distance, focalpoint=focalpoint) scene.scene.render()
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.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)