# Transparent NaN scalars (vtk.js)

**URL:** https://discourse.vtk.org/t/transparent-nan-scalars-vtk-js/5167
**Category:** Web
**Created:** [February 10, 2021, 8:52am UTC](https://discourse.vtk.org/t/transparent-nan-scalars-vtk-js/5167 "2021-02-10T08:52:02Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Uros\_Stankovic](https://discourse.vtk.org/user_avatar/discourse.vtk.org/uros_stankovic/32/2992_2.png) [@Uros\_Stankovic](https://discourse.vtk.org/u/Uros_Stankovic)
#### Post date: [February 10, 2021, 8:52am UTC](https://discourse.vtk.org/t/transparent-nan-scalars-vtk-js/5167/1 "2021-02-10T08:52:02Z")

</div>

On the picture gray areas have NaN value, i need them to be transparent.  
I used lookupTable.setNanColor(1.0, 1.0, 1.0, 0), but alpha value doesn’t work.

```
const lookupTable = vtkColorTransferFunction.newInstance();
    const preset = vtkColorMaps.getPresetByName('Cool to Warm');
    lookupTable.applyColorMap(preset);
    lookupTable.updateRange();
    // lookupTable.addRGBPoint(0, 1.0, 0.0, 0.0);
    // lookupTable.addRGBPoint(1, 0.0, 0.0, 1.0);
    lookupTable.setNanColor(1.0, 1.0, 1.0, 0);
    lookupTable.build();
    mapper.setLookupTable(lookupTable);

```

 ![image](https://discourse.vtk.org/uploads/default/original/2X/3/33908bf48f1c61f574c0fa598fcc698ffbc4529d.jpeg)

---

<div class="post-metadata">

### Author: ![ken-martin](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ken-martin/32/884_2.png) [@ken-martin](https://discourse.vtk.org/u/ken-martin)
#### Post date: [February 11, 2021, 3:31pm UTC](https://discourse.vtk.org/t/transparent-nan-scalars-vtk-js/5167/2 "2021-02-11T15:31:33Z")

</div>

Colortransferfunction does not handle opacity, only color. Give LookupTable a try as it handles opacity as well as color.

---

<div class="post-metadata">

### Author: ![Uros\_Stankovic](https://discourse.vtk.org/user_avatar/discourse.vtk.org/uros_stankovic/32/2992_2.png) [@Uros\_Stankovic](https://discourse.vtk.org/u/Uros_Stankovic)
#### Post date: [February 12, 2021, 8:34am UTC](https://discourse.vtk.org/t/transparent-nan-scalars-vtk-js/5167/3 "2021-02-12T08:34:53Z")

</div>

If i use only mapper.getLookupTable().setNanColor(1.0, 1.0, 1.0, 0); then it works, but if i use like this it won’t work

```
const lookupTable = vtkColorTransferFunction.newInstance();
const preset = vtkColorMaps.getPresetByName('Cool to Warm');
lookupTable.applyColorMap(preset);
mapper.setLookupTable(lookupTable);
mapper.getLookupTable().setNanColor(1.0, 1.0, 1.0, 0);

```

I need to have option to change color pallete and to set opacity. How to do that with default lookupTable, obviously i cant use vtkColorTransferFunction .

---

<div class="post-metadata">

### Author: ![Sebastien\_Jourdain](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sebastien_jourdain/32/100_2.png) [@Sebastien\_Jourdain](https://discourse.vtk.org/u/Sebastien_Jourdain)
#### Post date: [February 12, 2021, 3:27pm UTC](https://discourse.vtk.org/t/transparent-nan-scalars-vtk-js/5167/4 "2021-02-12T15:27:02Z")

</div>

The default LookupTable is that [one](https://github.com/Kitware/vtk-js/tree/master/Sources/Common/Core/LookupTable).

---

<div class="post-metadata">

### Author: ![Uros\_Stankovic](https://discourse.vtk.org/user_avatar/discourse.vtk.org/uros_stankovic/32/2992_2.png) [@Uros\_Stankovic](https://discourse.vtk.org/u/Uros_Stankovic)
#### Post date: [February 17, 2021, 1:39pm UTC](https://discourse.vtk.org/t/transparent-nan-scalars-vtk-js/5167/5 "2021-02-17T13:39:23Z")

</div>

This is my working code.

```
let rgbColor = [
        [16, 52, 166, 255],
        [65, 47, 136, 255],
        [114, 43, 106, 255],
        [162, 38, 75, 255],
        [211, 33, 45, 255],
        [246, 45, 45, 255]
      ]
      const table = vtkDataArray.newInstance({
        numberOfComponents: 4,
        size: 4 * rgbColor.length,
        dataType: 'Uint8Array',
      });
      for (let i = 0; i < rgbColor.length; i++) {
        table.setTuple(i, rgbColor[i]);
      }
      mapper.getLookupTable().setNanColor(1.0, 1.0, 1.0, 0);
      mapper.getLookupTable().setTable(table);

```

This is the only way, opacity and color work together.

 ![image](https://discourse.vtk.org/uploads/default/original/2X/0/002133da54e1d51e752895dcb1dbe6319d899879.jpeg)
