通过字段名称获取 vtkintarray 的值

Get value of a vtkintarray by the field name

我在 python 中写了一个 Paraview programmable filter,我 运行 在 table 个点上将 RGB 颜色分配为 UnsignedCharArray。我只是停留在代码的一部分,以获取范围内 R、G、B 字段的值。这是 table 示例:

这里是示例代码:

ids = self.GetInput()
ods = self.GetOutput()

ocolors = vtk.vtkUnsignedCharArray()
ocolors.SetName("colors")
ocolors.SetNumberOfComponents(3)
ocolors.SetNumberOfTuples(ids.GetNumberOfPoints())

inArray = ids.GetPointData().GetArray(0)
for x in range(0, ids.GetNumberOfPoints()):
  rF = inArray.GetValue(x) # here I need something like GetValue(x, "R")
  gF = inArray.GetValue(x) # here I need something like GetValue(x, "G")
  bF = inArray.GetValue(x) # here I need something like GetValue(x, "B")

  ocolors.SetTuple3(x, rF,gF,bF)

ods.GetPointData().AddArray(ocolors)

有人知道我该如何处理吗?

所以这是正确的做法:

ids = self.GetInput()
ods = self.GetOutput()

ocolors = vtk.vtkUnsignedCharArray()
ocolors.SetName("colors")
ocolors.SetNumberOfComponents(3)
ocolors.SetNumberOfTuples(ids.GetNumberOfPoints())

inArray = ids.GetPointData().GetArray(0)

r = ids.GetPointData().GetArray("R")
g = ids.GetPointData().GetArray("G")
b = ids.GetPointData().GetArray("B")
for x in range(0, ids.GetNumberOfPoints()):
  rF = r.GetValue(x) 
  gF = g.GetValue(x) 
  bF = b.GetValue(x) 

  # if rgb are between 0-1
  #rC = rF*256
  #gC = gF*256
  #bC = bF*256

  ocolors.SetTuple3(x, rF,gF,bF)

ods.GetPointData().AddArray(ocolors)