如何在Paraview中连接点?

4

我有一个问题。我是Paraview的新手,正在学习如何使用它。我需要从存储在.csv文件(2列)中的数据制作图表。我已经使用TabletToPoints filter将它们加载并转换了。我想问一下是否可以按点ID连接这些点,以便它们将创建一条线(前一个点与下一个点等等)。

我找到了一个解决方案:

pdi = self.GetPolyDataInput()
pdo =  self.GetPolyDataOutput()
numPoints = pdi.GetNumberOfPoints()
pdo.Allocate()
 for i in range(0, numPoints-1):
 points = [i, i+1]
 # VTK_LINE is 3
 pdo.InsertNextCell(3, 2, points)
2个回答

0

0

对于@NorthySP来说可能有点晚了,但对于想要在ParaView中从点构建线(vtkPolyline)的人可能会有用:

  1. 打开包含点坐标的数据文件(txt、csv和其他ParaView可以读取和解析的格式)。
  2. 在加载的表上应用可编程过滤器
  3. 可编程过滤器设置中,在脚本字段中输入
# the single input table this filter is applied to
table = inputs[0]

# print table properties and metrics just for sure
print("table: ", table)
print("table.GetNumberOfRows() = ", table.GetNumberOfRows())

num_rows = table.GetNumberOfRows()

# usual vtk workflow: fill vtkPoints first
vtkpoints = vtk.vtkPoints()
for i in range(0, num_rows):
    vtkpoints.InsertPoint(i,
        table.GetValue(i,0).ToFloat(), #x column
        table.GetValue(i,1).ToFloat(), #y column
        table.GetValue(i,2).ToFloat()  #z column
        )
output.SetPoints(vtkpoints)

# allocate vtkCell, representing single line
# if more lines, use output.Allocate(N_OF_LINES, 1) 
output.Allocate(1, 1) 

vtkpolyline = vtk.vtkPolyLine()
vtkpolyline.GetPointIds().SetNumberOfIds(num_rows)
# enumerate points to include in polyline
for i in range(0,num_rows):
    vtkpolyline.GetPointIds().SetId(i, i)
# assign vtkPolyLine graphical object to created vtkCell
output.InsertNextCell(vtkpolyline.GetCellType(),
                      vtkpolyline.GetPointIds()) 

或者您可以仅使用可编程源,而不是表格-可编程过滤器链:创建可编程源项目,在其Python代码中打开数据文件,从中获取XYZ,其余的工作流程(vtkPointsvtkPolylinevtkCell)与我的示例中的过滤器完全相同。

此外,我的存储库中有使用可编程源可编程过滤器进行线路示例 https://github.com/Ornstein89/paraview_orbit

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接