2017-08-08 32 views
0

我有一个用python编写的Paraview programmable filter,我正在运行一个点表,将RGB颜色分配为UnsignedCharArray。我只是停留在代码的一部分中以获取范围中的R,G,B字段的值。下面是表例如:通过字段名称获得vtkintarray的值

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) 

有谁知道我该怎么处理呢?

回答

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) 
相关问题