View
3.591
Download
5
Category
Preview:
DESCRIPTION
In this webinar, Didrik Pinte provides an introduction to MayaVi, the 3D interactive visualization library for the open source Enthought Tool Suite. These tools provide scientists and engineers a sophisticated Python development framework for analysis and visualization.
Citation preview
3D visualisation with Mayavi
March 19, 2010
What is Mayavi ?
• Mayavi is a general purpose, cross-platform tool for 3-D scientific data visualization
o Visualization of scalar, vector and tensor data in 2 and 3 dimensions.o Easy scriptability using Python.o Easy extendability via custom sources, modules, and data filters.o Reading several file formats: VTK, PLOT3D, etc.o Saving of visualizations.o Saving rendered visualization in a variety of image formats.o Convenient functionality for rapid scientific plotting via mlabo A very example of what you can build on top of ETS
Enthought Tool Suite
Mayavi user interface
Mayavi user interface
• DataSource, Filter and Modules• Recording• Shell plugin and scripting
Mayavi user interface
• DataSource, Filter and Modules• Recording• Shell plugin and scripting
Mayavi user interface
• DataSource, Filter and Modules• Recording• Shell plugin and scripting
Mayavi “API” or scripting with mlab
# Create the data.from numpy import pi, sin, cos, mgriddphi, dtheta = pi/250.0, pi/250.0[phi,theta] = mgrid[0:pi+dphi*1.5:dphi,0:2*pi+dtheta*1.5:dtheta]m0 = 4; m1 = 3; m2 = 2; m3 = 3; m4 = 6; m5 = 2; m6 = 6; m7 = 4;r = sin(m0*phi)**m1 + cos(m2*phi)**m3 + sin(m4*theta)**m5 + cos(m6*theta)**m7x = r*sin(phi)*cos(theta)y = r*cos(phi)z = r*sin(phi)*sin(theta)
# View it.from enthought.mayavi import mlabs = mlab.mesh(x, y, z)mlab.show()
9
Running mlab within ipython
C:\ ipython –wthread
>>> from enthought.mayavi import mlab
matplotlib also has an mlab namespace. Be sure you are using the one from enthought.mayavi
10
Plotting commands
• 0D data• mlab.points3d(x, y,
z)
1D datamlab.plot3d(x, y, z)
3D datamlab.contour3d(x, y, z)
Vector fieldmlab.quiver(x, y, z, u, v, w)
2D datamlab.surf(x, y, z)
11
Example with points in 3D
mlab.points3d(x, y, z, color=(1.0,0.0,1.0), mode=‘sphere’, scale_factor=0.1)
x.shape == y.shape == z.shape
color = (R, G, B)
0.0 <= R, G, B <= 1.0
default is (1.0, 1.0, 1.0)
mode = ‘sphere’, ‘cone’, ‘cube’, ‘arrow’, ‘cylinder’, ‘point’, ‘2darrow’, ‘2dcircle’, ‘2dcross’, ‘2ddash’, ‘2ddiamond’, ‘2dhooked_arrow’, ‘2dsquare’, ‘2dthick_arrow’, ‘2dthick_cross’, ‘2dtriangle’, ‘2dvertex’
scaling applied
from numpy.random import randx,y,z = rand(30),rand(30),rand(30)mlab.axes()
12
Mlab decorations
• mlab.title('A title')• mlab.axes()• mlab.colorbar()
• mlab.clf()• mlab.figure()• mlab.gcf()
13
Mlab helper functions and the engine pipeline
>>> mlab.figure() >>> mlab.surf(call_values) >>> mlab.axes()
Array2DSource \__ WarpScalar \__ PolyDataNormals \__ Colors and legends \__ Surface
Array2DSource \__ WarpScalar \__ PolyDataNormals \__ Colors and leg \__ Surface
def complete_pipeline_call(data_array): src = mlab.pipeline.array2d_source(data_array) warp = mlab.pipeline.warp_scalar(src) normals = mlab.pipeline.poly_data_normals(warp) return mlab.pipeline.surface(normals)
14
Looking for help and demo’s
• mlab.test_points3d()
• mlab.test_plot3d()
• mlab.test_surf()
• mlab.test_contour3d()
• mlab.test_quiver3d()
• mlab.test_molecule()
• mlab.test_flow()
• mlab.test_mesh()
Use ?? in IPython to look at the source code of these examples.
1. Documentation2. Mayavi examples coming with EPD3. enthought-dev mailing list 4. Mlab test functions :
Mlab and Traits (mlab_traits_ui.py)class ActorViewer(HasTraits): scene = Instance(MlabSceneModel, ()) view = View(Item(name='scene‘, editor=SceneEditor(scene_class=MayaviScene), show_label=False, resizable=True, height=500, width=500), resizable=True)
def __init__(self, **traits): HasTraits.__init__(self, **traits) self.generate_data()
def generate_data(self): X, Y = mgrid[-2:2:100j, -2:2:100j] R = 10*sqrt(X**2 + Y**2) Z = sin(R)/R self.scene.mlab.surf(X, Y, Z, colormap='gist_earth')
if __name__ == '__main__': a = ActorViewer() a.configure_traits()
Mlab and Traits (lorenz_ui.py)
Traits, Mayavi and Chaco
Vtk_commodities.py (Thanks to Travis Vaught for the example)
EPDhttp://www.enthought.com/products/epd.php
Enthought Training:http://www.enthought.com/training/
Webinarshttp://www.enthought.com/training/webinars.php
Recommended