[vtkusers] why use SetScalars instead of SetVectors for coloring

David Gobbi david.gobbi at gmail.com
Thu Jan 12 11:17:56 EST 2012


On Thu, Jan 12, 2012 at 8:53 AM, David Gobbi <david.gobbi at gmail.com> wrote:
> On Thu, Jan 12, 2012 at 8:27 AM, David Doria <daviddoria at gmail.com> wrote:
>> On Sun, Oct 16, 2011 at 1:37 PM, Yifei Li <yifli82 at gmail.com> wrote:
>>> Hi,
>>>
>>> I saw examples using SetScalars(colors) to color cells/points, where
>>> 'colors' is a vtkUnsignedCharArray with 3 components in each tuple.
>>>
>>> A (r, g, b) color can be considered as a vector, I don't understand why vtk
>>> treast color as scalar data instead of vector data. Why can't I use
>>> SetVectors?
>>>
>>> Can someone please  explain the reason?
>>>
>>> Thanks
>>>
>>> Yifei
>>
>> I think the idea is that VTK treats "vectors" only as "things that
>> indicate a direction", rather than "something with multiple elements".
>> For example, normals to a surface (normal vectors) are "vectors", the
>> gradient of an image would be "vectors", but colors, though they have
>> 3 components, do not represent a direction so they are "scalars".
>>
>> David
>
> That is correct.  Where vtkDataSets are concerned, vector data is data
> that has magnitude and direction, using the physics definition of
> vector rather than the much looser definition that is encountered in
> computer science and linear algebra.  In VTK, color data would be
> called multi-component data rather than vector data, and each RGB
> triplet would be a tuple rather than a vector.
>
> In VTK all vector data is multi-component data, but not all
> multi-component data is vector data.
>
> Unfortunately the new vtkVector class that was recently added to VTK
> has muddied the definition, and in retrospect it probably should have
> been named vtkTuple.
>
>  - David

One thing that was missing from my previous email was an example,
so here is a short one:

Lets say that you have vector data stored in a vtkDataSet.  Then you
rotate the data by passing it through vtkTransformFilter.  It should
be obvious that when you rotate the data set, the direction of each of
the vectors should be rotated.  This is what VTK does.

Now let's say that you store RGB colors in a vtkDataSet as vectors
(instead of as multi-component scalars).  If you passed the data
through vtkTransformFilter, then each RGB component would be treated
as a "direction" and would be rotated.  You don't want this to happen.
 A geometric transformation should not modify the color data, it
should leave it as is.

This leads us to the definition of "scalar."  In VTK a scalar is a
quantity that has no direction.  This is the physics definition of
scalar.  So colors are scalars, because they are unchanged under
geometric transformations.  In VTK, as in physics, the number of
components has nothing to do with whether a component is a scalar.
The only thing that makes a scalar a "scalar" is that it is unchanged
when a geometric transformation is applied to the data.

   - David



More information about the vtkusers mailing list