vs2013在图像处理中的应用(5):3D显示

快乐虾

(QQ群:Visual EmbedLinux Tools 375515651)

欢迎转载,但请保留作者信息

#!/usr/bin/env python # This simple example shows how to do basic rendering and pipeline# creation. import vtk# The colors module defines various useful colors.from vtk.util.colors import tomato # This creates a polygonal cylinder model with eight circumferential# facets.cylinder = vtk.vtkCylinderSource()cylinder.SetResolution(8) # The mapper is responsible for pushing the geometry into the graphics# library. It may also do color mapping, if scalars or other# attributes are defined.cylinderMapper = vtk.vtkPolyDataMapper()cylinderMapper.SetInputConnection(cylinder.GetOutputPort()) # The actor is a grouping mechanism: besides the geometry (mapper), it# also has a property, transformation matrix, and/or texture map.# Here we set its color and rotate it -22.5 degrees.cylinderActor = vtk.vtkActor()cylinderActor.SetMapper(cylinderMapper)cylinderActor.GetProperty().SetColor(tomato)cylinderActor.RotateX(30.0)cylinderActor.RotateY(-45.0) # Create the graphics structure. The renderer renders into the render# window. The render window interactor captures mouse events and will# perform appropriate camera or actor manipulation depending on the# nature of the events.ren = vtk.vtkRenderer()renWin = vtk.vtkRenderWindow()renWin.AddRenderer(ren)iren = vtk.vtkRenderWindowInteractor()iren.SetRenderWindow(renWin) # Add the actors to the renderer, set the background and sizeren.AddActor(cylinderActor)ren.SetBackground(0.1, 0.2, 0.4)renWin.SetSize(200, 200) # This allows the interactor to initalize itself. It has to be# called before an event loop.iren.Initialize() # We’ll zoom in a little by accessing the camera and invoking a "Zoom"# method on it.ren.ResetCamera()ren.GetActiveCamera().Zoom(1.5)renWin.Render() # Start the event loop.iren.Start()

安装就可以了:

—– Installing ‘mayavi’ —–Collecting mayavi Downloading mayavi-4.4.1.tar.gz (8.0MB)Collecting apptools (from mayavi) Downloading apptools-4.3.0.tar.gz (291kB)Requirement already up-to-date: traits in c:\python27\lib\site-packages (from mayavi)Requirement already up-to-date: traitsui in c:\python27\lib\site-packages (from mayavi)Collecting configobj (from apptools->mayavi) Downloading configobj-5.0.6.tar.gzRequirement already up-to-date: pyface in c:\python27\lib\site-packages (from traitsui->mayavi)Requirement already up-to-date: six in c:\python27\lib\site-packages (from configobj->apptools->mayavi)Installing collected packages: configobj, apptools, mayavi Running setup.py install for configobj Running setup.py install for apptools Running setup.py install for mayaviSuccessfully installed apptools-4.3.0 configobj-5.0.6 mayavi-4.4.1—– Successfully installed ‘mayavi’ —–

用一段简单的脚本测试一下:

import numpy as npfrom mayavi import mlabx, y = np.ogrid[-2:2:20j, -2:2:20j]z = x * np.exp( – x**2 – y**2)pl = mlab.surf(x, y, z, warp_scale="auto")mlab.axes(xlabel=’x’, ylabel=’y’, zlabel=’z’)mlab.outline(pl)mlab.show()

写个简单的代码测试一下:

from visual import *floor = box (pos=(0,0,0), length=4, height=0.5, width=4, color=color.blue)ball = sphere (pos=(0,4,0), radius=1, color=color.red)ball.velocity = vector(0,-1,0)dt = 0.01while 1:rate (100)ball.pos = ball.pos + ball.velocity*dtif ball.y < ball.radius:ball.velocity.y = abs(ball.velocity.y)else:ball.velocity.y = ball.velocity.y – 9.8*dt

结果就是这样的:

,听过许多故事,见过旅行风景,就这样,

vs2013在图像处理中的应用(5):3D显示

相关文章:

你感兴趣的文章:

标签云: