[vtkusers] Adding chars to 3D char array in python or how to add colors to array?

David Gobbi david.gobbi at gmail.com
Mon Dec 21 14:56:42 EST 2009


On Mon, Dec 21, 2009 at 12:32 PM,  <lynx.abraxas at freenet.de> wrote:
> On 21/12/09 01:42:22, David Gobbi wrote:
>> Hi Lynx,
>>
>> Use SetTuple3(), the doubles are converted to the array type before
>> they are stored.
>
> Thanks David G. for this hint. It works nicely with this.
>
>> Also a note about this example: it's best to use SetScalars() to add
>> colors to the data, so that you don't have to do anything special in
>> order to display them.  That example is misleading, the array name
>> "Colors" doesn't have any special meaning in VTK.
>>
>> smoothed_polys.GetPointData().SetScalars(colors)
>
> Hm, I'm not getting this. Isn't my colors actually a vector? If I use
> smoothed_polys.GetPointData().SetScalars(colors) instead of
> smoothed_polys.GetPointData().AddArray(colors)

VTK Scalars are allowed to have multiple components, so that is not a problem.

> I get an error in vtkDataArray.cxx line 470:
> vtkUnsignedCharArray ...: The number of components do not match the number requested: 3 != 1

Before you add any tuples, you have to set the number of components in
your array:

colors.SetNumberOfComponents(3)

   David



More information about the vtkusers mailing list