主要函数介绍:
vtk.vtkPoints()在VTK中用于定义点的类,使用points.InsertPoint(index, x, y, z)即可插入点集。函数中,第一个参数是点的序号,后面是三个参数是点的坐标。
vtk.vtkLineSource()在VTK中定义直线的类,通过SetPoints(points),输入直线经过的点。
vtk.vtkParametricSpline()在VTK中定义曲线的类,通过SetPoints(points),输入曲线经过的点。
vtk.vtkParametricFunctionSource()曲线插值拟合函数,可以将输入的点集拟合成一条曲线。有很多生成方法。我们可以简单的看一下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) # 设置线条颜色 splineActor.GetProperty().SetColor(0.3800, 0.7000, 0.1600) # 设置线条宽度 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) # 设置线条颜色 splineActor.GetProperty().SetColor(0.3800, 0.7000, 0.1600) # 设置线条宽度 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()
到此这篇关于如何使用Python-VTK绘制线条的文章就介绍到这了,更多相关Python-VTK绘制线条内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
X 关闭
X 关闭
- 15G资费不大降!三大运营商谁提供的5G网速最快?中国信通院给出答案
- 2联想拯救者Y70发布最新预告:售价2970元起 迄今最便宜的骁龙8+旗舰
- 3亚马逊开始大规模推广掌纹支付技术 顾客可使用“挥手付”结账
- 4现代和起亚上半年出口20万辆新能源汽车同比增长30.6%
- 5如何让居民5分钟使用到各种设施?沙特“线性城市”来了
- 6AMD实现连续8个季度的增长 季度营收首次突破60亿美元利润更是翻倍
- 7转转集团发布2022年二季度手机行情报告:二手市场“飘香”
- 8充电宝100Wh等于多少毫安?铁路旅客禁止、限制携带和托运物品目录
- 9好消息!京东与腾讯续签三年战略合作协议 加强技术创新与供应链服务
- 10名创优品拟通过香港IPO全球发售4100万股 全球发售所得款项有什么用处?