通过字段名称获取vtkintarray的值

时间:2017-08-08 10:44:54

标签: python csv vtk paraview rgbcolor

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

xyz 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)

有谁知道如何处理这个问题?

1 个答案:

答案 0 :(得分:0)

所以这是正确的方法:

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)