# Logic of the Colors attribute

**URL:** https://discourse.paraview.org/t/logic-of-the-colors-attribute/5669
**Category:** Development
**Created:** [October 28, 2020, 8:03am UTC](https://discourse.paraview.org/t/logic-of-the-colors-attribute/5669 "2020-10-28T08:03:03Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![cobo](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@cobo](https://discourse.paraview.org/u/cobo)
#### Post date: [October 28, 2020, 8:03am UTC](https://discourse.paraview.org/t/logic-of-the-colors-attribute/5669/1 "2020-10-28T08:03:03Z")

</div>

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.

 ![grafik](https://discourse.paraview.org/uploads/default/original/2X/e/e3295cfedec507649212cb81a8468ed29cfce5ef.png)

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

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [October 28, 2020, 8:26am UTC](https://discourse.paraview.org/t/logic-of-the-colors-attribute/5669/2 "2020-10-28T08:26:14Z")

</div>

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

---

<div class="post-metadata">

### Author: ![cobo](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@cobo](https://discourse.paraview.org/u/cobo)
#### Post date: [October 28, 2020, 9:30am UTC](https://discourse.paraview.org/t/logic-of-the-colors-attribute/5669/3 "2020-10-28T09:30:49Z")

</div>

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

[This document](https://www.paraview.org/Wiki/ParaView/Data_formats) 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.

---

<div class="post-metadata">

### Author: ![cobo](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@cobo](https://discourse.paraview.org/u/cobo)
#### Post date: [October 28, 2020, 9:39am UTC](https://discourse.paraview.org/t/logic-of-the-colors-attribute/5669/4 "2020-10-28T09:39:16Z")

</div>

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”??).

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [October 28, 2020, 9:48am UTC](https://discourse.paraview.org/t/logic-of-the-colors-attribute/5669/5 "2020-10-28T09:48:38Z")

</div>

> [@cobo](#):
>
> The name “Colors” is probably not even required for the whole thing to work!

It is not.

---

<div class="post-metadata">

### Author: ![Kenneth\_Moreland](https://discourse.paraview.org/user_avatar/discourse.paraview.org/kenneth_moreland/32/15033_2.png) [@Kenneth\_Moreland](https://discourse.paraview.org/u/Kenneth_Moreland)
#### Post date: [October 28, 2020, 2:04pm UTC](https://discourse.paraview.org/t/logic-of-the-colors-attribute/5669/6 "2020-10-28T14:04:45Z")

</div>

> [@cobo](#):
>
> 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.

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

---

<div class="post-metadata">

### Author: ![cobo](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@cobo](https://discourse.paraview.org/u/cobo)
#### Post date: [October 28, 2020, 3:32pm UTC](https://discourse.paraview.org/t/logic-of-the-colors-attribute/5669/7 "2020-10-28T15:32:35Z")

</div>

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:

 ![grafik](https://discourse.paraview.org/uploads/default/original/2X/3/337347b69f6ee7d18bbc331e00ed885edbd3170c.png)

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

 ![grafik](https://discourse.paraview.org/uploads/default/original/2X/4/4f7c1043dfb972d13c36ca8e94d29a41680a62e6.png)
