如何使用Python?VTK繪制線條
主要函數(shù)介紹:
vtk.vtkPoints() 在VTK中用于定義點的類,使用points.InsertPoint(index, x, y, z) 即可插入點集。函數(shù)中,第一個參數(shù)是點的序號,后面是三個參數(shù)是點的坐標。
vtk.vtkLineSource() 在VTK中定義直線的類,通過SetPoints(points),輸入直線經(jīng)過的點。
vtk.vtkParametricSpline() 在VTK中定義曲線的類,通過SetPoints(points),輸入曲線經(jīng)過的點。
vtk.vtkParametricFunctionSource() 曲線插值擬合函數(shù),可以將輸入的點集擬合成一條曲線。有很多生成方法。我們可以簡單的看一下VTK官方文檔介紹
S\CALAR_NONE - Scalars are not generated (default).
SCALAR_U - The scalar is set to the u-value.
SCALAR_V - The scalar is set to the v-value.
SCALAR_U0 - The scalar is set to 1 if u = (u_max - u_min)/2 = u_avg, 0 otherwise.
SCALAR_V0 - The scalar is set to 1 if v = (v_max - v_min)/2 = v_avg, 0 otherwise.
SCALAR_U0V0 - The scalar is set to 1 if u == u_avg, 2 if v == v_avg, 3 if u = u_avg && v = v_avg, 0 otherwise.
SCALAR_MODULUS - The scalar is set to (sqrt(uu+vv)), this is measured relative to (u_avg,v_avg).
SCALAR_PHASE - The scalar is set to (atan2(v,u)) (in degrees, 0 to 360), this is measured relative to (u_avg,v_avg).
SCALAR_QUADRANT - The scalar is set to 1, 2, 3 or 4. depending upon the quadrant of the point (u,v).
SCALAR_X - The scalar is set to the x-value.
SCALAR_Y - The scalar is set to the y-value.
SCALAR_Z - The scalar is set to the z-value.
SCALAR_DISTANCE - The scalar is set to (sqrt(xx+yy+z*z)). I.e. distance from the origin.
SCALAR_USER_DEFINED - The scalar is set to the value returned from EvaluateScalar().
actor.GetProperty().SetColor() 線條顏色配置
actor.GetProperty().SetLineWidth() 線條寬度配置
擬合曲線代碼:
import vtk points = vtk.vtkPoints() # 定義一個點工具 points.InsertPoint(0, 329, 338, 45) # 使用InsertPoint可以插入點 # 注意:points.InsertPoint(a, b, c, d) # 其中a表示點的序號,(b,c,d)表示點的三維坐標 points.InsertPoint(1, 328, 319, 46) points.InsertPoint(2, 300, 329, 96) # 定義曲線工具 # 將前面的幾個點插值擬合成一條曲線 spline = vtk.vtkParametricSpline() spline.SetPoints(points) splineSource = vtk.vtkParametricFunctionSource() splineSource.SetParametricFunction(spline) splineSource.Update() splineMapper = vtk.vtkPolyDataMapper() splineMapper.SetInputConnection(splineSource.GetOutputPort()) splineActor = vtk.vtkActor() splineActor.SetMapper(splineMapper) # 設(shè)置線條顏色 splineActor.GetProperty().SetColor(0.3800, 0.7000, 0.1600) # 設(shè)置線條寬度 splineActor.GetProperty().SetLineWidth(5) ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) ren1.AddActor(splineActor) ren1.SetBackground(1, 1, 1) renWin.SetSize(250, 250) renWin.Render() iren.Start()

繪制直線代碼
import vtk points = vtk.vtkPoints() # 定義一個點工具 points.InsertPoint(0, 329, 338, 45) # 使用InsertPoint可以插入點 # 注意:points.InsertPoint(a, b, c, d) # 其中a表示點的序號,(b,c,d)表示點的三維坐標 points.InsertPoint(1, 328, 319, 46) points.InsertPoint(2, 300, 329, 96) # 定義直線工具 lineSource = vtk.vtkLineSource() lineSource.SetPoints(points) lineSource.Update() lineMapper = vtk.vtkPolyDataMapper() lineMapper.SetInputConnection(lineSource.GetOutputPort()) splineActor = vtk.vtkActor() splineActor.SetMapper(lineMapper) # 設(shè)置線條顏色 splineActor.GetProperty().SetColor(0.3800, 0.7000, 0.1600) # 設(shè)置線條寬度 splineActor.GetProperty().SetLineWidth(5) ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) ren1.AddActor(splineActor) ren1.SetBackground(1, 1, 1) renWin.SetSize(250, 250) renWin.Render() iren.Start()

到此這篇關(guān)于如何使用Python-VTK繪制線條的文章就介紹到這了,更多相關(guān)Python-VTK繪制線條內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python3.6筆記之將程序運行結(jié)果輸出到文件的方法
下面小編就為大家分享一篇Python3.6筆記之將程序運行結(jié)果輸出到文件的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-04-04
python3用PIL把圖片轉(zhuǎn)換為RGB圖片的實例
今天小編就為大家分享一篇python3用PIL把圖片轉(zhuǎn)換為RGB圖片的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-07-07
Django上使用數(shù)據(jù)可視化利器Bokeh解析
這篇文章主要介紹了Django上使用數(shù)據(jù)可視化利器Bokeh解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2019-07-07
解決django xadmin主題不顯示和只顯示bootstrap2的問題
這篇文章主要介紹了解決django xadmin主題不顯示和只顯示bootstrap2的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03
Tensorflow中批量讀取數(shù)據(jù)的案列分析及TFRecord文件的打包與讀取
這篇文章主要介紹了Tensorflow中批量讀取數(shù)據(jù)的案列分析及TFRecord文件的打包與讀取,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-06-06
Python3與fastdfs分布式文件系統(tǒng)如何實現(xiàn)交互
這篇文章主要介紹了Python3與fastdfs分布式文件系統(tǒng)如何實現(xiàn)交互,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2020-06-06

