# Why does the opacity get changed when using vtkLookupTable to set cell color?

**URL:** https://discourse.vtk.org/t/why-does-the-opacity-get-changed-when-using-vtklookuptable-to-set-cell-color/7684
**Category:** Support
**Created:** [January 20, 2022, 8:09am UTC](https://discourse.vtk.org/t/why-does-the-opacity-get-changed-when-using-vtklookuptable-to-set-cell-color/7684 "2022-01-20T08:09:22Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![AlexLuya](https://discourse.vtk.org/user_avatar/discourse.vtk.org/alexluya/32/4036_2.png) [@AlexLuya](https://discourse.vtk.org/u/AlexLuya)
#### Post date: [January 20, 2022, 8:09am UTC](https://discourse.vtk.org/t/why-does-the-opacity-get-changed-when-using-vtklookuptable-to-set-cell-color/7684/1 "2022-01-20T08:09:22Z")

</div>

Hello,blow code was used to set cell color:

> void SceneObject::coloringSelectedCells() {  
> vtkNew nc;  
> auto orbg = property()-\>GetColor();  
> double originalColor[4] = { orbg[0] \* 255, orbg[1] \* 255, orbg[2] \* 255, 1 };  
> auto newColor = nc-\>GetColor4d(“Red”).GetData();  
> auto const originalColorIdx = 0;  
> auto const newColorIdx = 1;  
> auto size = data()-\>GetNumberOfCells();
> 
> //setup scalars  
> vtkNew scalars;  
> scalars-\>SetNumberOfTuples(size); //LP why can’t size be 2 here?  
> //preserve surface color  
> for (vtkIdType i = 0; i \< size; i++) {  
> scalars-\>SetTuple1(i, originalColorIdx);  
> }
> 
> //set cell color  
> for (auto const id : selectedCells) {  
> scalars-\>SetTuple1(id, newColorIdx);  
> }  
> data()-\>GetCellData()-\>SetScalars(scalars);  
> asActor()-\>GetMapper()-\>SetScalarRange(0, size - 1);
> 
> //setup lookup table  
> vtkNew lut;  
> lut-\>SetNumberOfTableValues(size);  
> lut-\>SetTableValue(originalColorIdx, originalColor);  
> lut-\>SetTableValue(newColorIdx, newColor);  
> // lut-\>SetVectorModeToRGBColors();  
> lut-\>Build();  
> asActor()-\>GetMapper()-\>SetLookupTable(lut);
> 
> \_parent-\>rerender(this);  
> }

Strangely,opacity got changed,how to prevent opactiy change?

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [January 23, 2022, 2:08pm UTC](https://discourse.vtk.org/t/why-does-the-opacity-get-changed-when-using-vtklookuptable-to-set-cell-color/7684/2 "2022-01-23T14:08:30Z")

</div>

Hello,

Is there any reason to multiply the RGB components by 255? Those values should vary between 0.0 and 1.0. VTK is likely proportionally unitizing values greater than 1.0, so the last component, the alpha channel, rescales to 1/255, which results in a highly translucent color.

I suggest doing either:

```cpp
double originalColor[4] = { orbg[0], orbg[1], orbg[2], 1 };

```

or

```cpp
double originalColor[4] = { orbg[0] * 255, orbg[1] * 255, orbg[2] * 255, 255 };

```

regards,

Paulo
