为什么显示的颜色不是VTK中的预期颜色?

时间:2016-01-06 13:51:00

标签: c++ colors vtk

问题是我传递给vtkProperty的RGB值不会产生预期的颜色。例如,由RGB(146,110,218)识别的slateblue显示为白色。

以下是相关代码:

vtk.vtkLineSource line = new vtkLineSource();
line.SetPoint1(0.0, 0.0, 0.0);
line.SetPoint2(50, 50, 0.0);

vtkPolyDataMapper mapper = new vtkPolyDataMapper();

mapper.SetInput(line.GetOutput());

vtkActor lineActor = new vtkActor();
lineActor.SetMapper(mapper);

double r = 146.0;
double g = 110.0;
double b = 218.0;

vtkProperty property = new vtkProperty();
property.SetColor(r, g, b);
lineActor.SetProperty(property);

1 个答案:

答案 0 :(得分:3)

此行为的原因是VTK使用标准化颜色值。

所以解决方案非常简单:我们必须将值除以255

[...]

double r = 146.0 / 255.0;
double g = 110.0 / 255.0;
double b = 218.0 / 255.0;

vtkProperty property = new vtkProperty();
property.SetColor(r, g, b);
lineActor.SetProperty(property);