简体   繁体   English

"将颜色设置为 vtkPolyData 的奇怪行为"

[英]Weird behavior seting color to vtkPolyData

I'm trying to assign custom colours to cells in VTK.我正在尝试为 VTK 中的单元格分配自定义颜色。 If I render my model without any colour assignment, it looks like this:如果我在没有任何颜色分配的情况下渲染我的模型,它看起来像这样:

在此处输入图像描述<\/a>

Now I'm trying to assign diferent colors to every triangle in the mesh.现在我正在尝试为网格中的每个三角形分配不同的颜色。 Inspired by this<\/a> solution I tryied the following to color it in blue (this is a simplification, my colors will depend on the thickness): 受此<\/a>解决方案的启发,我尝试使用以下方法将其着色为蓝色(这是一种简化,我的颜色将取决于厚度):

color = vtk.vtkUnsignedCharArray() 
color.SetName("Colors") 
color.SetNumberOfComponents(3) 
color.SetNumberOfTuples( surface.GetOutput().GetNumberOfCells() )
    
for i in range(surface.GetOutput().GetNumberOfCells()):
    color_tup=[0,0,255]
    color.SetTuple(i, color_tup)

I found out that this fix my problem:我发现这解决了我的问题:

mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(surface.GetOutputPort())
mapper.SetColorModeToDirectScalars()
mapper.SetScalarModeToUseCellData()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM