網(wǎng)站首頁(yè) 編程語(yǔ)言 正文
主要函數(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中定義直線的類,通過SetPoints(points),輸入直線經(jīng)過的點(diǎn)。
vtk.vtkParametricSpline()?在VTK中定義曲線的類,通過SetPoints(points),輸入曲線經(jīng)過的點(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()
繪制直線代碼
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()
原文鏈接:https://juejin.cn/post/7028480115742867470
相關(guān)推薦
- 2022-12-09 react?hooks?UI與業(yè)務(wù)邏輯分離必要性技術(shù)方案_React
- 2022-03-28 用python實(shí)現(xiàn)九九乘法表實(shí)例_python
- 2023-07-09 el-table操作列的按鈕超過三個(gè)時(shí),動(dòng)態(tài)計(jì)算,將多余的按鈕放入更多el-dropdown-men
- 2022-10-29 線性回歸(基于python的理論與實(shí)現(xiàn))的RuntimeWaring溢出問題
- 2021-12-03 Centos8環(huán)境下修改ssh端口號(hào)方法_Linux
- 2024-02-29 Android系統(tǒng)中g(shù)etCacheDir()、getFilesDir()、getExternalF
- 2022-08-05 C#?GDI+實(shí)現(xiàn)時(shí)鐘表盤_C#教程
- 2022-08-05 Python時(shí)間操作之pytz模塊使用詳解_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支