I'm trying to assign custom colours to cells in VTK. If I render my model without any colour assignment, it looks like this:
Inspired by
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()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.