[vtkusers] coloring PolyDataMappers in python

David Gobbi david.gobbi at gmail.com
Tue Aug 4 14:29:35 EDT 2015


Don't forget that use of SetColor() often requires this:

  mapper.ScalarVisibilityOff()

SetColor() is ignored if scalars are present and visible.

 - David


On Tue, Aug 4, 2015 at 12:24 PM, Cory Quammen <cory.quammen at kitware.com>
wrote:

> In that case, you can leave out the vtkLookupTable altogether and set the
> color in your actor instead
>
> actor = vtk.vtkActor()
> actor.SetMapper(mapper)
> property = actor.GetProperty()
> property.SetColor(*rgb_cluster_mapping[cluster_ind])
>
> HTH,
> Cory
>
> On Tue, Aug 4, 2015 at 2:15 PM, Tudor Achim <tachim at cs.stanford.edu>
> wrote:
>
>> No, I'd like the entire mesh to be one color (and opacity).
>>
>> On Tue, Aug 4, 2015 at 2:04 PM, Cory Quammen <cory.quammen at kitware.com>
>> wrote:
>>
>>> Are you trying to color map a particular data array in the contour?
>>>
>>> On Mon, Aug 3, 2015 at 3:43 PM, Tudor Achim <tachim at cs.stanford.edu>
>>> wrote:
>>>
>>>> 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/20150804/c960a965/attachment.html>


More information about the vtkusers mailing list