[vtkusers] Color a vtkcell

David Gobbi david.gobbi at gmail.com
Tue Jan 12 17:48:15 EST 2010


No, the CellArray is for something else.  The best way is with RGB scalars:

vtkUnsignedCharArray *faceColors = vtkUnsignedCharArray::New();
faceColors->SetNumberOfComponents(3);
faceColors->InsertNextTuple(r1, b1, g1);
faceColors->InsertNextTuple(r2, b2, g2);

Etcetera, until you have six colors.  Use values between 0 and 255 for r, g, b.

Next is the tricky part.  I don't think that VTK has a pipeline filter
that allows you to add these scalars (except for the programmable
filters) so the easiest way to add the colors is like this:

1) make a vtkCubeSource
2) make a vtkPolyData
3) DeepCopy the output of the CubeSource into the PolyData
4) do PolyData->GetCellData()->SetScalars(colors) as Darshan said

Does anyone know if there is a VTK filter that can add field data or
attribute data to a dataset, so that these sorts of DeepCopy tricks
aren't necessary?

   David


On Tue, Jan 12, 2010 at 3:27 PM, awabi <aw.ndaw at gmail.com> wrote:
>
> Thank you.
>
> Is it possible via a vtkcellarray?
>
> awa.
>
> dpai wrote:
>>
>> Yes you can
>>
>> Add Attributes as follows PolyData->GetCellData()->SetScalars()
>> and put a lookupTable with the required colors
>>
>> On Tue, Jan 12, 2010 at 5:03 PM, awabi <aw.ndaw at gmail.com> wrote:
>>
>>>
>>> Hello,
>>>
>>> I'd like to know if it is possible with vtk to color the faces of a
>>> vtkpolydata as I want. For example I have a cube and I'd like to color
>>> the
>>> faces differently.
>>>
>>> Thank you,
>>>
>>> Awa
>>> --
>>> View this message in context:
>>> http://old.nabble.com/Color-a-vtkcell-tp27135594p27135594.html
>>> Sent from the VTK - Users mailing list archive at Nabble.com.
>>>
>>> _______________________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Please keep messages on-topic and check the VTK FAQ at:
>>> http://www.vtk.org/Wiki/VTK_FAQ
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.vtk.org/mailman/listinfo/vtkusers
>>>
>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at:
>> http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>>
>>
>
> --
> View this message in context: http://old.nabble.com/Color-a-vtkcell-tp27135594p27135949.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>



More information about the vtkusers mailing list