通过字段nam获取vtkintarray的值

2024-10-01 04:44:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个用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)

有人知道我怎么处理吗?在


Tags: 代码selfids示例hereneedodssomething
1条回答
网友
1楼 · 发布于 2024-10-01 04:44:01

所以正确的方法是:

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)

相关问题 更多 >