[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 15:24:43 EST 2009


On Mon, Dec 21, 2009 at 1:04 PM, David Doria <daviddoria+vtk at gmail.com> wrote:
> On Mon, Dec 21, 2009 at 2:56 PM, David Gobbi <david.gobbi at gmail.com> wrote:
>> 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
>>
>
> Here is another common point of confusions - you can see how most
> people are confused by "scalars" rather than "colors" especially since
> colors typically have 3 components (RGB), which is not a scalar! :)
> The SetPointColors function could go ahead and SetNumberOfComponents
> to 3 as well as do whatever else may be necessary
> (SetScalarModeToUseXXX(); or something).
>
> I will not attempt to fight for adding these functions (as like you
> said they can have many repercussions and may not make sense for all
> users), but a lack of "easy to understand" API certainly calls for a
> good set of examples ;) Lynx, now that David G got you up and running
> with this problem, you've just self-volunteered for adding examples
> demonstrating this :)
>
> Thanks,
>
> David

Ahah, now I start to see where your confusion comes from.  My degree
was in physics, and I was always taught that a vector is something
that has a magnitude and a direction.  And anything that doesn't have
a direction is a scalar.  So for me, the number of components is
irrelevant to whether something is a scalar or a vector.  Colors don't
have a "direction", therefore they aren't a vector to me.

For me, the definition of scalar is "a tensor of rank 0".

   David



More information about the vtkusers mailing list