def add_data(tvtk_data): """Add a TVTK data object `tvtk_data` to the mayavi pipleine. """ d = VTKDataSource() d.data = tvtk_data mayavi.add_source(d) return d
def Scatter(): # Create some random points to view. data = Data() p, r = data.slice pd = tvtk.PolyData() pd.points = p verts = arange( 0, len( r ), 1 ) verts.shape = ( len( r ), 1 ) pd.verts = verts pd.point_data.scalars = r pd.point_data.scalars.name = 'scalars' # Now visualize it using mayavi2. from enthought.mayavi.sources.vtk_data_source import VTKDataSource from enthought.mayavi.modules.outline import Outline from enthought.mayavi.modules.surface import Surface mayavi.new_scene() d = VTKDataSource() d.data = pd mayavi.add_source( d ) mayavi.add_module( Outline() ) s = Surface() mayavi.add_module( s ) s.actor.property.set( representation='p', point_size=2 )
def Lines(): # Create some random points to view. data = Data() p, r = data.slice pd = tvtk.PolyData() pd.points = p verts = arange( 0, len( r ), 1 ) verts.shape = ( len( r ), 1 ) pd.verts = verts pd.point_data.scalars = r pd.point_data.scalars.name = 'scalars' pd.lines = arange( 0, len( r ), 1 ).reshape( len( r ) / 15, 15 ) # Now visualize it using mayavi2. from enthought.mayavi.sources.vtk_data_source import VTKDataSource from enthought.mayavi.modules.outline import Outline from enthought.mayavi.modules.surface import Surface from enthought.mayavi.modules.iso_surface import IsoSurface from enthought.mayavi.modules.streamline import Streamline mayavi.new_scene() d = VTKDataSource() d.data = pd mayavi.add_source( d ) o = Outline() mayavi.add_module( o ) s = Surface() #enable_contours=True mayavi.add_module( s ) s.actor.property.set( representation='p', point_size=2 )
def add_points(self, points): g = mlab.Glyphs(points, None, None) d = VTKDataSource() d.data = g.poly_data self.scene.add_child(d) v = Vectors() v.glyph.color_mode = "no_coloring" v.glyph.glyph_source = tvtk.PointSource(radius=0, number_of_points=1) d.add_child(v)
def add_points(self, points): g = mlab.Glyphs(points, None, None) d = VTKDataSource() d.data = g.poly_data self.scene.add_child(d) v = Vectors() v.glyph.color_mode = 'no_coloring' v.glyph.glyph_source = tvtk.PointSource(radius=0, number_of_points=1) d.add_child(v)
def add_dataset(dataset, name='', **kwargs): """Add a dataset object to the Mayavi pipeline. **Parameters** :dataset: a tvtk dataset, or a Mayavi source. The dataset added to the Mayavi pipeline :figure: a figure identifier number or string, None or False, optionnal. If no `figure` keyword argument is given, the data is added to the current figure (a new figure if created if necessary). If a `figure` keyword argument is given, it should either the name the number of the figure the dataset should be added to, or None, in which case the data is not added to the pipeline. If figure is False, a null engine is created. This null engine does not create figures, and is mainly usefull for tensting, or using the VTK algorithms without visualization. **Returns** The corresponding Mayavi source is returned. """ if isinstance(dataset, tvtk.Object): d = VTKDataSource() d.data = dataset elif isinstance(dataset, Source): d = dataset else: raise TypeError, \ "first argument should be either a TVTK object"\ " or a mayavi source" if len(name) > 0: d.name = name if not 'figure' in kwargs: # No figure has been specified, retrieve the default one. gcf() engine = get_engine() elif kwargs['figure'] is False: # Get a null engine that we can use. engine = get_null_engine() elif kwargs['figure'] is not None: figure = kwargs['figure'] engine = engine_manager.find_figure_engine(figure) engine.current_scene = figure else: # Return early, as we don't want to add the source to an engine. return d engine.add_source(d) return d
def add_source_data(self, data): from enthought.mayavi.filters.poly_data_normals import PolyDataNormals d = VTKDataSource() d.data = data obj = self.scene.add_child(d) w = WarpScalar() d.add_child(w) n = PolyDataNormals() n.filter.feature_angle = 45 w.add_child(n) s = Surface() n.add_child(s)
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. #Make the grid grid = self.make_grid4scatter() e.add_source(grid) eg = ExtractGrid() e.add_filter(eg) nb_ticks = 6 eg.x_ratio = eg.y_ratio = eg.z_ratio = 100 / (nb_ticks - 1) / 2 gpx = GridPlane() e.add_module(gpx) gpx.grid_plane.axis = 'x' gpy = GridPlane() e.add_module(gpy) gpy.grid_plane.axis = 'y' gpz = GridPlane() e.add_module(gpz) gpz.grid_plane.axis = 'z' #Add the scatter d = VTKDataSource() d.data = self.make_scatter() e.add_source(d) a = Axes() e.add_module(a) a.axes.number_of_labels = nb_ticks self.eg = eg self.gpx = gpx self.gpy = gpy self.gpz = gpz self.scene = e.current_scene return
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. # Make the grid grid = self.make_grid4scatter() e.add_source(grid) eg = ExtractGrid() e.add_filter(eg) nb_ticks = 6 eg.x_ratio = eg.y_ratio = eg.z_ratio = 100 / (nb_ticks - 1) / 2 gpx = GridPlane() e.add_module(gpx) gpx.grid_plane.axis = "x" gpy = GridPlane() e.add_module(gpy) gpy.grid_plane.axis = "y" gpz = GridPlane() e.add_module(gpz) gpz.grid_plane.axis = "z" # Add the scatter d = VTKDataSource() d.data = self.make_scatter() e.add_source(d) a = Axes() e.add_module(a) a.axes.number_of_labels = nb_ticks self.eg = eg self.gpx = gpx self.gpy = gpy self.gpz = gpz self.scene = e.current_scene return
def make_grid4scatter(self): src = VTKDataSource() xmin, xmax, dx = 100, 200, 2 nx = int((xmax - xmin) / dx) + 1 ymin, ymax, dy = 100, 200, 2 ny = int((ymax - ymin) / dy) + 1 zmin, zmax, dz = 100, 200, 2 nz = int((zmax - zmin) / dz) + 1 image_data = tvtk.ImageData(origin=(xmin, ymin, zmin), spacing=(dx, dy, dz), extent=(0, nx - 1, 0, ny - 1, 0, nz - 1)) image_data.whole_extent = image_data.extent src.data = image_data return src
def make_grid4scatter(self): src = VTKDataSource() xmin, xmax, dx = 100, 200, 2 nx = int((xmax - xmin) / dx) + 1 ymin, ymax, dy = 100, 200, 2 ny = int((ymax - ymin) / dy) + 1 zmin, zmax, dz = 100, 200, 2 nz = int((zmax - zmin) / dz) + 1 image_data = tvtk.ImageData( origin=(xmin, ymin, zmin), spacing=(dx, dy, dz), extent=(0, nx - 1, 0, ny - 1, 0, nz - 1) ) image_data.whole_extent = image_data.extent src.data = image_data return src
def add_lines(self, points): np = len(points) - 1 lines = scipy.zeros((np, 2), "l") lines[:, 0] = scipy.arange(0, np - 0.5, 1, "l") lines[:, 1] = scipy.arange(1, np + 0.5, 1, "l") pd = tvtk.PolyData(points=points, lines=lines) d = VTKDataSource() d.data = pd self.scene.add_child(d) filter = tvtk.TubeFilter(number_of_sides=6) filter.radius = 0.01 f = FilterBase(filter=filter, name="TubeFilter") d.add_child(f) s = Surface() s.actor.mapper.scalar_visibility = False d.add_child(s)
def add_lines(self, points): np = len(points) - 1 lines = scipy.zeros((np, 2), 'l') lines[:,0] = scipy.arange(0, np-0.5, 1, 'l') lines[:,1] = scipy.arange(1, np+0.5, 1, 'l') pd = tvtk.PolyData(points=points, lines=lines) d = VTKDataSource() d.data = pd self.scene.add_child(d) filter = tvtk.TubeFilter(number_of_sides=6) filter.radius = 0.01 f = FilterBase(filter=filter, name='TubeFilter') d.add_child(f) s = Surface() s.actor.mapper.scalar_visibility = False d.add_child(s)
def main(): # Create some random points to view. pd = tvtk.PolyData() pd.points = np.random.random((1000, 3)) verts = np.arange(0, 1000, 1) verts.shape = (1000, 1) pd.verts = verts pd.point_data.scalars = np.random.random(1000) pd.point_data.scalars.name = "scalars" # Now visualize it using mayavi2. from enthought.mayavi.sources.vtk_data_source import VTKDataSource from enthought.mayavi.modules.outline import Outline from enthought.mayavi.modules.surface import Surface mayavi.new_scene() d = VTKDataSource() d.data = pd mayavi.add_source(d) mayavi.add_module(Outline()) s = Surface() mayavi.add_module(s) s.actor.property.set(representation="p", point_size=2)
def main(): # Create some random points to view. pd = tvtk.PolyData() pd.points = np.random.random((1000, 3)) verts = np.arange(0, 1000, 1) verts.shape = (1000, 1) pd.verts = verts pd.point_data.scalars = np.random.random(1000) pd.point_data.scalars.name = 'scalars' # Now visualize it using mayavi2. from enthought.mayavi.sources.vtk_data_source import VTKDataSource from enthought.mayavi.modules.outline import Outline from enthought.mayavi.modules.surface import Surface mayavi.new_scene() d = VTKDataSource() d.data = pd mayavi.add_source(d) mayavi.add_module(Outline()) s = Surface() mayavi.add_module(s) s.actor.property.set(representation='p', point_size=2)
def plot_slice_mayavi(dat_filename,output_file,hyp_x,hyp_y,hyp_z,search_grid_file_name,max_stack_value): base_path=os.getenv('WAVELOC_PATH') lib_path="%s/lib"%base_path # grid geometry hdr_file=lib_path + os.sep + search_grid_file_name # detection detection=50 # stations stations_file="%s/coord_stations_piton"%lib_path sta=StationList() sta.read_from_file(stations_file) # create the object to contain the stations pd = tvtk.PolyData() pd.points = [[s.x/1000.0, s.y/1000.0, -s.elev/1000.0] for s in sta.stations.values()] # create the object to contain the stations try: pd_hyp = tvtk.PolyData() pd_hyp.points=[[hyp_x,hyp_y,hyp_z]] except TypeError: pass # read the dat file print dat_filename data=QDGrid() data.read_NLL_hdr_file(hdr_file) data.buf=numpy.fromfile(dat_filename, dtype=numpy.int16) max_ib=numpy.argmax(data.buf) print max_ib max_val=data.buf[max_ib] ix,iy,iz=data.get_ix_iy_iz(max_ib) #data.buf=numpy.array(data.buf, dtype=numpy.float) data.buf.shape = (data.nx, data.ny, data.nz) # 'mayavi' is always defined on the interpreter. e = OffScreenEngine() #e = Engine() e.start() win = e.new_scene(magnification=1) e.current_scene.scene.off_screen_rendering = True win.scene.isometric_view() # Make the data and add it to the pipeline. src = ArraySource(transpose_input_array=True) src.scalar_data = data.buf src.spacing=(data.dx, data.dy, -data.dz) src.origin=(data.x_orig, data.y_orig, -data.z_orig) e.add_source(src) # Visualize the data. o = Outline() e.add_module(o) lut=e.scenes[0].children[0].children[0].scalar_lut_manager lut.data_range=[-1,max_stack_value] lut.show_legend = True lut.data_name = 'Stack' # Create one ContourGridPlane normal to the 'x' axis. cgp = ContourGridPlane() e.add_module(cgp) # Set the position to the middle of the data. if max_val > detection: cgp.grid_plane.position = ix else: cgp.grid_plane.position = data.nx/2 cgp.contour.filled_contours = True cgp.actor.property.opacity = 0.6 output=cgp.grid_plane.outputs[0] x_data=numpy.array(output.point_data.scalars.to_array()) # Another with filled contours normal to 'y' axis. cgp = ContourGridPlane() e.add_module(cgp) # Set the axis and position to the middle of the data. cgp.grid_plane.axis = 'y' if max_val > detection: cgp.grid_plane.position = iy else: cgp.grid_plane.position = data.ny/2 cgp.contour.filled_contours = True cgp.actor.property.opacity = 0.6 output=cgp.grid_plane.outputs[0] y_data=numpy.array(output.point_data.scalars.to_array()) # Another with filled contours normal to 'z' axis. cgp = ContourGridPlane() e.add_module(cgp) # Set the axis and position to the middle of the data. cgp.grid_plane.axis = 'z' if max_val > detection: cgp.grid_plane.position = iz else: cgp.grid_plane.position = data.nz/2 cgp.contour.filled_contours = True cgp.actor.property.opacity = 0.6 output=cgp.grid_plane.outputs[0] z_data=numpy.array(output.point_data.scalars.to_array()) a=Axes() e.add_module(a) d=VTKDataSource() d.data=pd e.add_source(d) g=Glyph() e.add_module(g) g.glyph.glyph_source.glyph_source=g.glyph.glyph_source.glyph_list[4] g.glyph.glyph_source.glyph_source.radius=0.1 d=VTKDataSource() d.data=pd_hyp e.add_source(d) g=Glyph() e.add_module(g) g.glyph.glyph_source.glyph_source=g.glyph.glyph_source.glyph_list[4] g.glyph.glyph_source.glyph_source.radius=0.5 g.actor.property.color=(0.0,0.0,0.0) #view(azimuth=-60,elevation=60,distance=120) win.scene.save(output_file,size=(800,800)) e.stop() del win del e return (x_data, y_data, z_data)
# STATIONS #d=VTKDataSource() #d.data=pd #e.add_source(d) #g=Glyph() #e.add_module(g) #g.glyph.glyph_source.glyph_source=g.glyph.glyph_source.glyph_list[4] #g.glyph.glyph_source.glyph_source.radius=0.1 # DEM d=VTKDataSource() d.data=dem_data e.add_source(d) df=Delaunay2D() e.add_filter(df) s=Surface() e.add_module(s) #s.actor.property.set(representation='p', point_size=100) #view(azimuth=-60,elevation=60,distance=120) output_file="tmp.png" win.scene.save(output_file,size=(800,600))
def run(self): from enthought.mayavi.sources.vtk_file_reader import VTKFileReader #import modules here from enthought.mayavi.modules import surface, glyph , axes, outline, orientation_axes, scalar_cut_plane from enthought.mayavi.sources.vtk_data_source import VTKDataSource from enthought.tvtk.api import tvtk #CitcomS filter from plugins.filter.CitcomSshowCaps import CitcomSshowCaps from plugins.filter.CitcomSreduce import CitcomSreduce import re script = self.script #DEFINES orange = (1.0,0.5,0) ################ #Read Meta information meta = "" try: vtk = open(self.filename, "r") vtk.readline() meta = vtk.readline() except IOError: print 'cannot open file' try: print "Reading meta-information" m = re.search('(?<=NX:)\d+', meta) nx = int(m.group(0)) print "NX: ", nx m = re.search('(?<=NY:)\d+', meta) ny = int(m.group(0)) print "NY: ", ny m = re.search('(?<=NZ:)\d+', meta) nz = int(m.group(0)) print "NZ: ", nz m = re.search('(?<=Radius_Inner:)(\d+|.)+', meta) print m.group(0) radius_inner = float(m.group(0)) print "Radius Inner: ", radius_inner except ValueError: print "Non-valid meta information in file..." vtk.close() ################ #Read Vtk file src_vtkf = VTKFileReader() src_vtkf.initialize(self.filename) ###########Display Data############ #Create new scene script.new_scene() script.add_source(src_vtkf) scap = CitcomSshowCaps() script.add_filter(scap) #Show ScalarCutPlane scp = scalar_cut_plane.ScalarCutPlane() script.add_module(scp) #Add filter for a reduce grid redu = CitcomSreduce() script.add_filter(redu) #Shows Glyph on reduce grid gly = glyph.Glyph() gly.glyph.glyph_source.scale = 0.082 gly.glyph.scale_mode = 'scale_by_scalar' gly.glyph.color_mode = 'color_by_scalar' script.add_module(gly) mm = gly.module_manager mm.scalar_lut_manager.use_default_range = False mm.scalar_lut_manager.data_range = 0.0, 1.0 ################### Create CORE ################################ #Load VTK Data Sets sphere = tvtk.SphereSource() sphere.radius = radius_inner sphere.theta_resolution = 24 sphere.phi_resolution = 24 # Create a mesh from the data created above. src = VTKDataSource() src.data = sphere.output script.add_source(src) #Show Surface surf_module = surface.Surface() surf_module.actor.property.color = orange script.add_module(surf_module)
# STATIONS #d=VTKDataSource() #d.data=pd #e.add_source(d) #g=Glyph() #e.add_module(g) #g.glyph.glyph_source.glyph_source=g.glyph.glyph_source.glyph_list[4] #g.glyph.glyph_source.glyph_source.radius=0.1 # DEM d = VTKDataSource() d.data = dem_data e.add_source(d) df = Delaunay2D() e.add_filter(df) s = Surface() e.add_module(s) #s.actor.property.set(representation='p', point_size=100) #view(azimuth=-60,elevation=60,distance=120) output_file = "tmp.png" win.scene.save(output_file, size=(800, 600)) # s = Surface() # e.add_module(s)
def run(self): from enthought.mayavi.sources.vtk_file_reader import VTKFileReader #import modules here from enthought.mayavi.modules import surface, glyph , axes, outline, orientation_axes, scalar_cut_plane from enthought.mayavi.sources.vtk_data_source import VTKDataSource from enthought.tvtk.api import tvtk #citcomS Filter and Modules from plugins.CitcomSHDFUgrid import CitcomSHDFUgrid from plugins.filter.CitcomSshowCaps import CitcomSshowCaps from plugins.filter.CitcomSreduce import CitcomSreduce import re script = self.script #DEFINES orange = (1.0,0.5,0) reduce_factor = 2 #Read Hdf file src_hdf = CitcomSHDFUgrid() hexgrid = src_hdf.initialize(self.filename,self.timestep,self.nx_redu,self.ny_redu,self.nz_redu) radius_inner = src_hdf._radius_inner data = VTKDataSource() data.data = hexgrid ###########Display Data############ #Create new scene script.new_scene() script.add_source(data) scap = CitcomSshowCaps() script.add_filter(scap) #Show ScalarCutPlane scp = scalar_cut_plane.ScalarCutPlane() script.add_module(scp) #Add filter for a reduce grid redu = CitcomSreduce() #redu.setvalues(nx,ny,nz) script.add_filter(redu) gly = glyph.Glyph() gly.glyph.glyph_source.scale = 0.082 gly.glyph.scale_mode = 'scale_by_scalar' gly.glyph.color_mode = 'color_by_scalar' script.add_module(gly) mm = gly.module_manager mm.scalar_lut_manager.use_default_range = False mm.scalar_lut_manager.data_range = 0.0, 1.0 ################### Create CORE ################################ #Load VTK Data Sets sphere = tvtk.SphereSource() sphere.radius = radius_inner sphere.theta_resolution = 24 sphere.phi_resolution = 24 # Create a mesh from the data created above. src = VTKDataSource() src.data = sphere.output script.add_source(src) #Show Surface surf_module = surface.Surface() surf_module.actor.property.color = orange script.add_module(surf_module)
def plot_slice_mayavi(dat_filename, output_file, hyp_x, hyp_y, hyp_z, search_grid_file_name, max_stack_value): base_path = os.getenv('WAVELOC_PATH') lib_path = "%s/lib" % base_path # grid geometry hdr_file = lib_path + os.sep + search_grid_file_name # detection detection = 50 # stations stations_file = "%s/coord_stations_piton" % lib_path sta = StationList() sta.read_from_file(stations_file) # create the object to contain the stations pd = tvtk.PolyData() pd.points = [[s.x / 1000.0, s.y / 1000.0, -s.elev / 1000.0] for s in sta.stations.values()] # create the object to contain the stations try: pd_hyp = tvtk.PolyData() pd_hyp.points = [[hyp_x, hyp_y, hyp_z]] except TypeError: pass # read the dat file print dat_filename data = QDGrid() data.read_NLL_hdr_file(hdr_file) data.buf = numpy.fromfile(dat_filename, dtype=numpy.int16) max_ib = numpy.argmax(data.buf) print max_ib max_val = data.buf[max_ib] ix, iy, iz = data.get_ix_iy_iz(max_ib) #data.buf=numpy.array(data.buf, dtype=numpy.float) data.buf.shape = (data.nx, data.ny, data.nz) # 'mayavi' is always defined on the interpreter. e = OffScreenEngine() #e = Engine() e.start() win = e.new_scene(magnification=1) e.current_scene.scene.off_screen_rendering = True win.scene.isometric_view() # Make the data and add it to the pipeline. src = ArraySource(transpose_input_array=True) src.scalar_data = data.buf src.spacing = (data.dx, data.dy, -data.dz) src.origin = (data.x_orig, data.y_orig, -data.z_orig) e.add_source(src) # Visualize the data. o = Outline() e.add_module(o) lut = e.scenes[0].children[0].children[0].scalar_lut_manager lut.data_range = [-1, max_stack_value] lut.show_legend = True lut.data_name = 'Stack' # Create one ContourGridPlane normal to the 'x' axis. cgp = ContourGridPlane() e.add_module(cgp) # Set the position to the middle of the data. if max_val > detection: cgp.grid_plane.position = ix else: cgp.grid_plane.position = data.nx / 2 cgp.contour.filled_contours = True cgp.actor.property.opacity = 0.6 output = cgp.grid_plane.outputs[0] x_data = numpy.array(output.point_data.scalars.to_array()) # Another with filled contours normal to 'y' axis. cgp = ContourGridPlane() e.add_module(cgp) # Set the axis and position to the middle of the data. cgp.grid_plane.axis = 'y' if max_val > detection: cgp.grid_plane.position = iy else: cgp.grid_plane.position = data.ny / 2 cgp.contour.filled_contours = True cgp.actor.property.opacity = 0.6 output = cgp.grid_plane.outputs[0] y_data = numpy.array(output.point_data.scalars.to_array()) # Another with filled contours normal to 'z' axis. cgp = ContourGridPlane() e.add_module(cgp) # Set the axis and position to the middle of the data. cgp.grid_plane.axis = 'z' if max_val > detection: cgp.grid_plane.position = iz else: cgp.grid_plane.position = data.nz / 2 cgp.contour.filled_contours = True cgp.actor.property.opacity = 0.6 output = cgp.grid_plane.outputs[0] z_data = numpy.array(output.point_data.scalars.to_array()) a = Axes() e.add_module(a) d = VTKDataSource() d.data = pd e.add_source(d) g = Glyph() e.add_module(g) g.glyph.glyph_source.glyph_source = g.glyph.glyph_source.glyph_list[4] g.glyph.glyph_source.glyph_source.radius = 0.1 d = VTKDataSource() d.data = pd_hyp e.add_source(d) g = Glyph() e.add_module(g) g.glyph.glyph_source.glyph_source = g.glyph.glyph_source.glyph_list[4] g.glyph.glyph_source.glyph_source.radius = 0.5 g.actor.property.color = (0.0, 0.0, 0.0) #view(azimuth=-60,elevation=60,distance=120) win.scene.save(output_file, size=(800, 800)) e.stop() del win del e return (x_data, y_data, z_data)
# it in !MayaVi2. A more detailed version of this script is given in the # examples pages [:Cookbook/MayaVi/Examples]. # # <codecell> import numpy def f(x, y): return numpy.sin(x*y)/(x*y) x = numpy.arange(-7., 7.05, 0.1) y = numpy.arange(-5., 5.05, 0.05) from enthought.tvtk.tools import mlab s = mlab.SurfRegular(x, y, f) from enthought.mayavi.sources.vtk_data_source import VTKDataSource d = VTKDataSource() d.data = s.data mayavi.add_source(d) from enthought.mayavi.filters.warp_scalar import WarpScalar w = WarpScalar() mayavi.add_filter(w) from enthought.mayavi.modules.outline import Outline from enthought.mayavi.modules.surface import Surface o = Outline() s = Surface() mayavi.add_module(o) mayavi.add_module(s) # <markdowncell> # You can run this script by running "mayavi2 -n -x script.py", loading it # through the menu (File -\> Open File), and pressing Ctrl+R, or entering
def run(self): from enthought.mayavi.sources.vtk_file_reader import VTKFileReader #import modules here from enthought.mayavi.modules import surface, glyph, axes, outline, orientation_axes, scalar_cut_plane from enthought.mayavi.sources.vtk_data_source import VTKDataSource from enthought.tvtk.api import tvtk #CitcomS filter from plugins.filter.CitcomSshowCaps import CitcomSshowCaps from plugins.filter.CitcomSreduce import CitcomSreduce import re script = self.script #DEFINES orange = (1.0, 0.5, 0) ################ #Read Meta information meta = "" try: vtk = open(self.filename, "r") vtk.readline() meta = vtk.readline() except IOError: print 'cannot open file' try: print "Reading meta-information" m = re.search('(?<=NX:)\d+', meta) nx = int(m.group(0)) print "NX: ", nx m = re.search('(?<=NY:)\d+', meta) ny = int(m.group(0)) print "NY: ", ny m = re.search('(?<=NZ:)\d+', meta) nz = int(m.group(0)) print "NZ: ", nz m = re.search('(?<=Radius_Inner:)(\d+|.)+', meta) print m.group(0) radius_inner = float(m.group(0)) print "Radius Inner: ", radius_inner except ValueError: print "Non-valid meta information in file..." vtk.close() ################ #Read Vtk file src_vtkf = VTKFileReader() src_vtkf.initialize(self.filename) ###########Display Data############ #Create new scene script.new_scene() script.add_source(src_vtkf) scap = CitcomSshowCaps() script.add_filter(scap) #Show ScalarCutPlane scp = scalar_cut_plane.ScalarCutPlane() script.add_module(scp) #Add filter for a reduce grid redu = CitcomSreduce() script.add_filter(redu) #Shows Glyph on reduce grid gly = glyph.Glyph() gly.glyph.glyph_source.scale = 0.082 gly.glyph.scale_mode = 'scale_by_scalar' gly.glyph.color_mode = 'color_by_scalar' script.add_module(gly) mm = gly.module_manager mm.scalar_lut_manager.use_default_range = False mm.scalar_lut_manager.data_range = 0.0, 1.0 ################### Create CORE ################################ #Load VTK Data Sets sphere = tvtk.SphereSource() sphere.radius = radius_inner sphere.theta_resolution = 24 sphere.phi_resolution = 24 # Create a mesh from the data created above. src = VTKDataSource() src.data = sphere.output script.add_source(src) #Show Surface surf_module = surface.Surface() surf_module.actor.property.color = orange script.add_module(surf_module)
# <codecell> import numpy def f(x, y): return numpy.sin(x * y) / (x * y) x = numpy.arange(-7., 7.05, 0.1) y = numpy.arange(-5., 5.05, 0.05) from enthought.tvtk.tools import mlab s = mlab.SurfRegular(x, y, f) from enthought.mayavi.sources.vtk_data_source import VTKDataSource d = VTKDataSource() d.data = s.data mayavi.add_source(d) from enthought.mayavi.filters.warp_scalar import WarpScalar w = WarpScalar() mayavi.add_filter(w) from enthought.mayavi.modules.outline import Outline from enthought.mayavi.modules.surface import Surface o = Outline() s = Surface() mayavi.add_module(o) mayavi.add_module(s) # <markdowncell> # You can run this script by running "mayavi2 -n -x script.py", loading it # through the menu (File -\> Open File), and pressing Ctrl+R, or entering
def run(self): from enthought.mayavi.sources.vtk_file_reader import VTKFileReader #import modules here from enthought.mayavi.modules import surface, glyph, axes, outline, orientation_axes, scalar_cut_plane from enthought.mayavi.sources.vtk_data_source import VTKDataSource from enthought.tvtk.api import tvtk #citcomS Filter and Modules from plugins.CitcomSHDFUgrid import CitcomSHDFUgrid from plugins.filter.CitcomSshowCaps import CitcomSshowCaps from plugins.filter.CitcomSreduce import CitcomSreduce import re script = self.script #DEFINES orange = (1.0, 0.5, 0) reduce_factor = 2 #Read Hdf file src_hdf = CitcomSHDFUgrid() hexgrid = src_hdf.initialize(self.filename, self.timestep, self.nx_redu, self.ny_redu, self.nz_redu) radius_inner = src_hdf._radius_inner data = VTKDataSource() data.data = hexgrid ###########Display Data############ #Create new scene script.new_scene() script.add_source(data) scap = CitcomSshowCaps() script.add_filter(scap) #Show ScalarCutPlane scp = scalar_cut_plane.ScalarCutPlane() script.add_module(scp) #Add filter for a reduce grid redu = CitcomSreduce() #redu.setvalues(nx,ny,nz) script.add_filter(redu) gly = glyph.Glyph() gly.glyph.glyph_source.scale = 0.082 gly.glyph.scale_mode = 'scale_by_scalar' gly.glyph.color_mode = 'color_by_scalar' script.add_module(gly) mm = gly.module_manager mm.scalar_lut_manager.use_default_range = False mm.scalar_lut_manager.data_range = 0.0, 1.0 ################### Create CORE ################################ #Load VTK Data Sets sphere = tvtk.SphereSource() sphere.radius = radius_inner sphere.theta_resolution = 24 sphere.phi_resolution = 24 # Create a mesh from the data created above. src = VTKDataSource() src.data = sphere.output script.add_source(src) #Show Surface surf_module = surface.Surface() surf_module.actor.property.color = orange script.add_module(surf_module)