Paraview VtkPolyData为线段添加宽度

问题描述

我想在Paraview中创建线段。我针对每个线段的输入数据格式为:x0,y0,z0,x1,y1,z1,width我尝试使用“ Line”命令并使用https://stackoverflow.com/a/64140580/14367898 @Nico Vuaille的https://stackoverflow.com/users/10219194/nico-vuaille回答我设法做到了。但是,由于线段的数量非常多,因此我需要一种运行速度更快的方法。 我搜索并发现此方法https://discourse.paraview.org/t/rendering-a-few-lines-takes-an-unreasonable-amount-of-memory/667/2

import vtk
from random import uniform
points = vtk.vtkPoints()
lines = vtk.vtkCellArray()
for i in xrange(600):
  pt1 = points.InsertNextPoint(uniform(0,100),uniform(0,0)
  pt2 = points.InsertNextPoint(uniform(0,0)
  lines.InsertNextCell(2,[pt1,pt2])

output.SetPoints(points)
output.SetLines(lines)

运行速度非常快,但是线段没有宽度。 我想知道如何使用以上(或任何其他合适的方法)为每个线段绘制具有特定宽度的线。 非常感谢您的帮助, 问候, 哈米德·拉贾比。

解决方法

您可以将宽度添加为数据数组:

import vtk
from random import uniform
points = vtk.vtkPoints()
lines = vtk.vtkCellArray()
widths = vtk.vtkDoubleArray()
widths.SetName("width")

for i in range(60):
  pt1 = points.InsertNextPoint(uniform(0,100),uniform(0,0)
  pt2 = points.InsertNextPoint(uniform(0,0)
  w = uniform(0,3)
  widths.InsertNextValue(w)
  widths.InsertNextValue(w)
  lines.InsertNextCell(2,[pt1,pt2])

output.SetPoints(points)
output.GetPointData().AddArray(widths)
output.SetLines(lines)

然后添加一个Tube过滤器,选择Vary Radius / By Absolute Scalar(并可能更改因子)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...