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()
參考資料:
http://www.cb.uu.se/~aht/Vis2014/lecture2.pdf
VTK-py讀取與顯示相關函數