2

我需要使用 vtk 和 paraview 显示 50 个粒子空间中的轨迹。目前我的数据是pos(x,y,t,n)其中 n 是第 n 个粒子的标签。我已将所有数据保存在一个 vtk 文件中,该文件组织为:

# vtk DataFile Version 3.0
VTK from Matlab
BINARY

DATASET POLYDATA
POINTS 199250 double
[PROPERLY ORGANIZED BINARY COORDINATES OF THE 199250 POINTS]

上面的文件可以正确导入到 ParaView 中,乍一看我可以应用下面的 programmagle 过滤器

pdi = self.GetPolyDataInput()
pdo =  self.GetPolyDataOutput()
newPoints = vtk.vtkPoints()
numPoints = pdi.GetNumberOfPoints()

for i in range(0, numPoints):
    coord = pdi.GetPoint(i)
    x, y, z = coord[:3]
    x = x * 0.03
    y = y * 0.03
    z = z * 2
    newPoints.InsertPoint(i, x, y, z)

pdo.SetPoints(newPoints)
aPolyLine = vtk.vtkPolyLine()
aPolyLine.GetPointIds().SetNumberOfIds(numPoints)

for i in range(0,numPoints):
 aPolyLine.GetPointIds().SetId(i, i)

pdo.Allocate(1, 1)
pdo.InsertNextCell(aPolyLine.GetCellType(), aPolyLine.GetPointIds())

创建以下图形

在此处输入图像描述

过滤器基本上创建了一条连接所有其他点的线,但在我的情况下,它将一个粒子轨迹的最后一个点连接到以下轨迹的第一个点。

我想为每个粒子创建一个不同的 polydata 对象,所以我什至可以分别标记或着色它们(并消除“全连接”问题)。我对类似过滤器的第一个猜测是

pdi = self.GetPolyDataInput()
pdo =  self.GetPolyDataOutput()
nParts = 50
newPoints = vtk.vtkPoints()
numPoints = pdi.GetNumberOfPoints()
numPointsPart = int(numPoints/nParts)

for i in range(0, numPoints):
    coord = pdi.GetPoint(i)
    x, y, z = coord[:3]
    x = x * 0.03
    y = y * 0.03
    z = z * 2
    newPoints.InsertPoint(i, x, y, z)

pdo.SetPoints(newPoints)
pdo.Allocate(nParts, 1)

for i in range(0,nParts):
  aPolyLine = vtk.vtkPolyLine()
  aPolyLine.GetPointIds().SetNumberOfIds(numPointsPart)
  indStart=int(i*numPointsPart)
  indEnd=int((i+1)*numPointsPart)
  for i in range(indStart,indEnd):
    aPolyLine.GetPointIds().SetId(i, i)
  pdo.InsertNextCell(aPolyLine.GetCellType(), aPolyLine.GetPointIds())

但是,当我运行它时,ParaView 只是由于段错误而关闭。奖励:代码编写正确:如果我将 nParts 设置为 1,我会得到与上面相同的图表。

编辑:数据集可以在这里找到

4

1 回答 1

3

问题在于迭代逻辑:

for i in range(indStart, indEnd):
    aPolyLine.GetPointIds().SetId(i, i)

必须更改为以下内容:

for i in range(indStart, indEnd):
    aPolyLine.GetPointIds().SetId(i - indStart, i)

原始代码SetId使用不正确的索引调用。另外,请注意阴影变量i。虽然这不是导致问题的原因,但如果您i在第二个for循环之后使用,结果可能不是您所期望的。

于 2014-09-16T15:06:46.267 回答