欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

如何使用Python?VTK繪制線條

 更新時(shí)間:2022年04月18日 13:14:04   作者:派大大大星?  
這篇文章主要介紹了如何使用Python-VTK繪制線條,主要繪制直線和曲線,下面文章詳細(xì)實(shí)現(xiàn)過(guò)程需要的小伙伴可以參考一下

主要函數(shù)介紹:

vtk.vtkPoints() 在VTK中用于定義點(diǎn)的類,使用points.InsertPoint(index, x, y, z) 即可插入點(diǎn)集。函數(shù)中,第一個(gè)參數(shù)是點(diǎn)的序號(hào),后面是三個(gè)參數(shù)是點(diǎn)的坐標(biāo)。

vtk.vtkLineSource() 在VTK中定義直線的類,通過(guò)SetPoints(points),輸入直線經(jīng)過(guò)的點(diǎn)。

vtk.vtkParametricSpline() 在VTK中定義曲線的類,通過(guò)SetPoints(points),輸入曲線經(jīng)過(guò)的點(diǎn)。

vtk.vtkParametricFunctionSource() 曲線插值擬合函數(shù),可以將輸入的點(diǎn)集擬合成一條曲線。有很多生成方法。我們可以簡(jiǎn)單的看一下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()  # 定義一個(gè)點(diǎn)工具
points.InsertPoint(0, 329, 338, 45)  # 使用InsertPoint可以插入點(diǎn)
# 注意:points.InsertPoint(a, b, c, d)
# 其中a表示點(diǎn)的序號(hào),(b,c,d)表示點(diǎn)的三維坐標(biāo)
points.InsertPoint(1, 328, 319, 46)
points.InsertPoint(2, 300, 329, 96)
# 定義曲線工具
# 將前面的幾個(gè)點(diǎn)插值擬合成一條曲線
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()

image.png

繪制直線代碼

import vtk

points = vtk.vtkPoints()  # 定義一個(gè)點(diǎn)工具
points.InsertPoint(0, 329, 338, 45)  # 使用InsertPoint可以插入點(diǎn)
# 注意:points.InsertPoint(a, b, c, d)
# 其中a表示點(diǎn)的序號(hào),(b,c,d)表示點(diǎn)的三維坐標(biāo)
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()

1636445384(1).jpg

到此這篇關(guān)于如何使用Python-VTK繪制線條的文章就介紹到這了,更多相關(guān)Python-VTK繪制線條內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • python實(shí)現(xiàn)網(wǎng)頁(yè)錄音效果

    python實(shí)現(xiàn)網(wǎng)頁(yè)錄音效果

    這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)網(wǎng)頁(yè)錄音效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-10-10
  • Python如何通過(guò)變量ID得到變量的值

    Python如何通過(guò)變量ID得到變量的值

    這篇文章主要介紹了Python如何通過(guò)變量ID得到變量的值,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-05-05
  • django-crontab 定時(shí)執(zhí)行任務(wù)方法的實(shí)現(xiàn)

    django-crontab 定時(shí)執(zhí)行任務(wù)方法的實(shí)現(xiàn)

    這篇文章主要介紹了django-crontab 定時(shí)執(zhí)行任務(wù)方法的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-09-09
  • Python使用CMD模塊更優(yōu)雅的運(yùn)行腳本

    Python使用CMD模塊更優(yōu)雅的運(yùn)行腳本

    這篇文章主要介紹了Python使用CMD模塊更優(yōu)雅的運(yùn)行腳本的方法,實(shí)例分析了Python中cmd模塊的相關(guān)使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-05-05
  • 一個(gè)Python優(yōu)雅的數(shù)據(jù)分塊方法詳解

    一個(gè)Python優(yōu)雅的數(shù)據(jù)分塊方法詳解

    在做需求過(guò)程中有一個(gè)對(duì)大量數(shù)據(jù)分塊處理的場(chǎng)景,具體來(lái)說(shuō)就是幾十萬(wàn)量級(jí)的數(shù)據(jù),分批處理,每次處理100個(gè)。這時(shí)就需要一個(gè)分塊功能的代碼。本文為大家分享了一個(gè)Python中優(yōu)雅的數(shù)據(jù)分塊方法,需要的可以參考一下
    2022-05-05
  • 一篇文章帶你搞懂Python類的相關(guān)知識(shí)

    一篇文章帶你搞懂Python類的相關(guān)知識(shí)

    今天我們要說(shuō)的是面向?qū)ο蟮暮诵?----類,類能幫我們把復(fù)雜的事情變得有條理,有順序,希望大家通過(guò)學(xué)習(xí)類能改善自己的編碼風(fēng)格,使代碼變得更為好看,更加通俗易懂,需要的朋友可以參考下
    2021-05-05
  • 解決python logging遇到的坑 日志重復(fù)打印問(wèn)題

    解決python logging遇到的坑 日志重復(fù)打印問(wèn)題

    這篇文章主要介紹了解決python logging遇到的坑 日志重復(fù)打印問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2021-03-03
  • mac安裝python3后使用pip和pip3的區(qū)別說(shuō)明

    mac安裝python3后使用pip和pip3的區(qū)別說(shuō)明

    這篇文章主要介紹了mac安裝python3后使用pip和pip3的區(qū)別說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-09-09
  • 如何利用Python和matplotlib更改縱橫坐標(biāo)刻度顏色

    如何利用Python和matplotlib更改縱橫坐標(biāo)刻度顏色

    對(duì)于圖表來(lái)說(shuō)最簡(jiǎn)單的莫過(guò)于作出一個(gè)單一函數(shù)的圖像,下面這篇文章主要給大家介紹了關(guān)于如何利用Python和matplotlib更改縱橫坐標(biāo)刻度顏色的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-08-08
  • Python ljust rjust center輸出

    Python ljust rjust center輸出

    Python中打印字符串時(shí)可以調(diào)用ljust(左對(duì)齊),rjust(右對(duì)齊),center(中間對(duì)齊)來(lái)輸出整齊美觀的字符串,使用起來(lái)非常簡(jiǎn)單,包括使用第二個(gè)參數(shù)填充(默認(rèn)為空格)。
    2008-09-09

最新評(píng)論