Color specific mesh elements

Hi!
I want to plot my STL-Model (or general 3D object) using VTK. For this, I used the STLReader.
My next step is to give some facets of the model different colors, so e.g.:
Face 1-10 shall be red
Face 11 - 20 shall be blue.

Since I am relatively new to VTK and the intellisense of my IDE is not giving me further interesting options, it’s hard for me to achieve this task.
I read a lot about color lookup tables and scalararrays which are applied to the mapper but somehow, all I’ve done so far does not work.
I am using Python for VTK.

Can somebody help me here?

Best regards
Benny

Benny,

These examples from the VTK Examples Project. may help. They coth color individual cells.

  1. ColorCells
  2. ColorCellsWithRGB

Enjoy VTK,

Bill

With vtkplotter helper module:

from vtkplotter import *

s = load(datadir+'shuttle.stl')

cols, als = [], []
for i in range(s.NCells()):
    cols.append(i) # i-th color
    als.append(i/s.NCells()) #opacity

s.colorCellsByArray(cols, als).lw(1).show()

Screenshot%20from%202019-08-01%2001-42-12

Thanks for your answers, I solved the problem using following exemplary code:

reader = vtkOFFReader()
reader.SetFileName(meshfile)

vtkpolydata = reader.GetPolyData()
scalarArray = numpy_support.numpy_to_vtk(scalararray)

vtkpolydata.GetCellData().SetScalars(scalarArray)

lut = vtk.vtkLookupTable()
lut.SetNumberOfTableValues(len(labels.Categories))
lut.SetTableRange(0,len(labels.Categories)-1)
lut.SetHueRange(0.2,0.667);
lut.Build()