[英]Get value of a vtkintarray by the field name
我有一個用python編寫的Paraview programmable filter
,我在一個點表上運行以將RGB顏色分配為UnsignedCharArray
。 我只是停留在代碼的一部分中,以獲取范圍內的R,G,B字段的值。 這是表格示例:
這是示例代碼:
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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.