vtkOBJImporter k3d颜色映射

问题描述

代码here之后,可以获取粒状vtkpolyData并在python中传递给k3d。但是我目前正在像这样为k3d分配颜色;

def rgb2hex(r,g,b):
     return eval("0x{:02x}{:02x}{:02x}".format(r,b))

#using the actors from [referenced code][1] to get the granular actors from .OBJ
col = actor.Getproperty().GetDiffuseColor()
rgb2hex(int(col[0]*255),int(col[1]*255),int(col[2]*255))

这很丑陋且效率低下。 vtkpolyDataMapper应该已经在处理颜色了,因此必须有一种更直接的方式来进行颜色处理。如何使用vtkpolyDataMapper获取要传递给k3d.vtk_poly_data()颜色参数的颜色列表?

mapper = actor.GetMapper() 
mapper.SetInputData(vtkpolyData)

解决方法

VTK本身不提供颜色的这种格式(0xrrggbb)。您始终必须处理3分量浮点数或整数。