[vtkusers] coloring PolyDataMappers in python

Tudor Achim tachim at cs.stanford.edu
Mon Aug 3 15:43:00 EDT 2015


Hi all,
I have a quick question about coloring vtkPolyMappers. I have the following
code:

for cluster_ind in ...:
threshold = vtk.vtkImageThreshold()
threshold.SetInputConnection(importer.GetOutputPort())
threshold.ThresholdBetween(cluster_ind-0.1, cluster_ind+0.1)
threshold.ReplaceInOn()
threshold.SetInValue(0)
threshold.ReplaceOutOn()
threshold.SetOutValue(1)
threshold.Update()

dmc = vtk.vtkDiscreteMarchingCubes()
dmc.SetInputConnection(threshold.GetOutputPort())
dmc.GenerateValues(1, 1, 1)
dmc.Update()

mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(dmc.GetOutputPort())

lut = vtk.vtkLookupTable()
lut.SetNumberOfTableValues(2)
lut.SetTableValue(0, 0, 0, 255)
lut.SetTableValue(1, *rgb_cluster_mapping[cluster_ind])
lut.Build()
mapper.SetLookupTable(lut)
mapper.SetScalarModeToUseCellData()

However, when I run it only one of the mappers is colored correctly; the
other one is just rendered as black. I can tell that it's rendered black
because when I spin around the clusters in my viewer I can see it
obstructing the other clusters. The intended colors are (0, 255, 0) and
(88, 86, 214) (that's what's in rgb_cluster_mapping for these clusters).

Any ideas?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150803/493b755e/attachment.html>


More information about the vtkusers mailing list