VTK-py读取与显示相关函数
在VTK中可视化数据的一般流程如下:
文件输入相关函数:
https://www.vtk.org/Wiki/VTK/Examples/Cxx#Input_and_Output
Readers ● Reads data from file
Filters ● Takes data as input, modifies it in some way, and returns the modified data
Mappers ● Maps data to graphics primitives (points, lines, or triangles) that can be displayed by the renderer
Actors ● vtkActor represents an object (geometry and properties) in a rendering scene
Rendering ● The process of converting 3D graphics primitives (points, lines, triangles, etc), a specification for lights and materials, and a camera view into an 2D image that can be displayed on the screen
Renderer ● vtkRenderer controls the rendering process for actors and scenes
Render window ● The vtkRenderWindow class creates a window for renderers to draw into
Interactors ● The vtkRenderWindowInteractor class provides platform-independent window interaction via the mouse and keyboard
一个读取.obj文件的代码:
1 import vtk 2 3 filename = "xxxxx.obj" 4 reader = vtk.vtkOBJReader() 5 reader.SetFileName(filename) 6 reader.Update() 7 8 mapper = vtk.vtkPolyDataMapper() 9 mapper.SetInputConnection(reader.GetOutputPort()) 10 11 actor = vtk.vtkActor() 12 actor.SetMapper(mapper) 13 14 renderer = vtk.vtkRenderer() 15 renderer.AddActor(actor) 16 #renderer.GetActiveCamera().SetPosition() #设置视点位置 17 #renderer.GetActiveCamera().SetViewUp(0, 1, 0) #设置视点方向 18 renderer.SetBackground(0.1, 0.1, 0.1) #设置背景颜色 19 20 renWin = vtk.vtkRenderWindow() 21 renWin.SetSize(640, 480) #设置窗口大小 22 renWin.AddRenderer(renderer) 23 24 iren = vtk.vtkRenderWindowInteractor() 25 iren.SetRenderWindow(renWin) 26 iren.Initialize() 27 28 renWin.Render() 29 iren.Start()
参考资料: