[vtkusers] coloring PolyDataMappers in python
Tudor Achim
tachim at cs.stanford.edu
Tue Aug 18 14:10:45 EDT 2015
Nevermind - this was happening because I was using rgb scalars in [0, 256)
instead of [0, 1].
On Mon, Aug 17, 2015 at 4:31 PM, Tudor Achim <tachim at cs.stanford.edu> wrote:
> Thanks for the pointers - your suggestions worked. On a related note, is
> there some trick to getting shading to work? Right now the colors are super
> intense and it's tough to tell the contour of the solids.
>
> [image: Inline image 1]
>
> On Tue, Aug 4, 2015 at 2:29 PM, David Gobbi <david.gobbi at gmail.com> wrote:
>
>> 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/20150818/13c3b60d/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 45160 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150818/13c3b60d/attachment.png>
More information about the vtkusers
mailing list