Logic of the Colors attribute

Recently I learned that it is possible to add a Colors attribute to an object if you want so assign fixed color values to points or cells. It is a 4-component double type array, with values between 0 and 255, representing RGBA color components - I assumed! But I am probably wrong.

I generated an unstructured grid with such an attribute and filled it with different values in different zones, but I cannot understand the result at all: In the bubbles I wrote the 4 Colors values that I assigned.

This makes absolutely no sense for me! Any helpful hint?

You are coloring using the magnitude here. Just uncheck the “Map Scalars” option and you should obtain the result you are looking for.

Thanks! But first it did not work: The display simply disappeared.

This document that I found with Google for “Map Scalars” gave me the impression that I should possibly try 3 components only (RGB) instead of 4 (RGBA), which finally did the trick to get some display, although completely wrong colors still.

Finally I was taking the hint in the same document seriously that it works with “byte sized data” only, so I changed the vtkDoubleArray attribute to vtkUnsignedCharArray - which finally gave me the desired result.

1 Like

Further guess: The name “Colors” is probably not even required for the whole thing to work!? Initially my idea was that it has this specific meaning of defining explicit colors, like the “Normals” attribute also has a specific meaning.

But this brings me to the idea that I could do the same for my custom application and somehow ensure that if a “Colors” attribute appears, it will automatically be ensured that the data type is unsigned char (easy because I have my own model reader) and at the same time switch the “map scalars” option off as soon as a “Colors” attribute would be displayed (no idea how to do this: adapt some “behaviours”??).

It is not.

If you have float or double data, you need to set the components of colors between 0 and 1, not 0 and 255.

Great - also that is working!

Only little problem: One of my filters where I am using that feature is actually a reader from another file format that is able to transport transparency:

On the VTK-Side the same building becomes now this one - with finally correct coloring, but everything opaque: