# Paraview has nice lookup tables, is there an easy way to use them in VTK?

**URL:** https://discourse.vtk.org/t/paraview-has-nice-lookup-tables-is-there-an-easy-way-to-use-them-in-vtk/14260
**Category:** Support
**Created:** [July 19, 2024, 3:46pm UTC](https://discourse.vtk.org/t/paraview-has-nice-lookup-tables-is-there-an-easy-way-to-use-them-in-vtk/14260 "2024-07-19T15:46:07Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![rexthor](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rexthor/32/6481_2.png) [@rexthor](https://discourse.vtk.org/u/rexthor)
#### Post date: [July 19, 2024, 3:46pm UTC](https://discourse.vtk.org/t/paraview-has-nice-lookup-tables-is-there-an-easy-way-to-use-them-in-vtk/14260/1 "2024-07-19T15:46:07Z")

</div>

Paraview has a nice set of preset lookup tables, is there any way to use those in VTK?

---

<div class="post-metadata">

### Author: ![rexthor](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rexthor/32/6481_2.png) [@rexthor](https://discourse.vtk.org/u/rexthor)
#### Post date: [July 19, 2024, 6:11pm UTC](https://discourse.vtk.org/t/paraview-has-nice-lookup-tables-is-there-an-easy-way-to-use-them-in-vtk/14260/2 "2024-07-19T18:11:45Z")

</div>

Here’s a few of them that aren’t too long:

```python
from vtkmodules.vtkRenderingCore import vtkColorTransferFunction

def table_factory(name):
    "Return one of a few example color lookup tables."
    ctf = vtkColorTransferFunction()
    match name:
        case "CoolToWarm":
            ctf.SetColorSpaceToDiverging()
            ctf.AddRGBPoint(0.0, 0.23137, 0.29803, 0.75294)
            ctf.AddRGBPoint(0.5, 0.86499, 0.86499, 0.86499)
            ctf.AddRGBPoint(1.0, 0.70588, 0.01568, 0.14901)
            ctf.SetNanColor(1.0, 1.0, 0.0)

        case "Blackbody":
            ctf.AddRGBPoint(0.0, 0.00000, 0.00000, 0.00000)
            ctf.AddRGBPoint(0.4, 0.90196, 0.00000, 0.00000)
            ctf.AddRGBPoint(0.8, 0.90196, 0.90196, 0.00000)
            ctf.AddRGBPoint(1.0, 1.00000, 1.00000, 1.00000)
            ctf.SetNanColor(0.00000, 0.49803, 1.00000)

        case "XRay":
            ctf.AddRGBPoint(0.0, 1.00000, 1.00000, 1.00000)
            ctf.AddRGBPoint(1.0, 0.00000, 0.00000, 0.00000)
            ctf.SetNanColor(1.0, 0.0, 0.0)

        case "BlackBlueWhite":
            ctf.AddRGBPoint(0.000, 0.00000, 0.00000, 0.00000)
            ctf.AddRGBPoint(0.333, 0.00000, 0.00000, 0.50196)
            ctf.AddRGBPoint(0.666, 0.00000, 0.50196, 1.00000)
            ctf.AddRGBPoint(1.000, 1.00000, 1.00000, 1.00000)
            ctf.SetNanColor(1.0, 1.0, 0.0)

        case _:
            raise ValueError("unexpected lookup table name")

    return ctf

t1 = table_factory("CoolToWarm")
t2 = table_factory("Blackbody")
t3 = table_factory("XRay")
t4 = table_factory("BlackBlueWhite")

```

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [July 19, 2024, 6:34pm UTC](https://discourse.vtk.org/t/paraview-has-nice-lookup-tables-is-there-an-easy-way-to-use-them-in-vtk/14260/3 "2024-07-19T18:34:41Z")

</div>

There is a function to export color maps in ParaView out to a JSON representation. In the UI, go to the _Choose Preset_ dialog, click on the color map you want to export, and click the “Export” button. “X- Ray” looks like:

```json
[
        {
                "ColorSpace" : "RGB",
                "DefaultMap" : true,
                "Name" : "X Ray",
                "NanColor" : 
                [
                        1,
                        0,
                        0
                ],
                "RGBPoints" : 
                [
                        0,
                        1,
                        1,
                        1,
                        1,
                        0,
                        0,
                        0
                ]
        }
]

```

Note: the RGBPoints array is interleaved as XRGB 4-tuples where X is the data value that maps to the RGB color.

You can use the Python `json` module to import that file and set the RGB points and color space like you are doing in your example script.

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [July 20, 2024, 11:56am UTC](https://discourse.vtk.org/t/paraview-has-nice-lookup-tables-is-there-an-easy-way-to-use-them-in-vtk/14260/4 "2024-07-20T11:56:03Z")

</div>

A lot of the work has already been done for you:

- [JSONColorMapToLUT](https://examples.vtk.org/site/Python/Utilities/JSONColorMapToLUT/)
- [XMLColorMapToLUT](https://examples.vtk.org/site/Python/Utilities/XMLColorMapToLUT/)
- [RescaleReverseLUT](https://examples.vtk.org/site/Python/Utilities/RescaleReverseLUT/)

---

<div class="post-metadata">

### Author: ![whereismymoney](https://discourse.vtk.org/user_avatar/discourse.vtk.org/whereismymoney/32/6859_2.png) [@whereismymoney](https://discourse.vtk.org/u/whereismymoney)
#### Post date: [July 22, 2024, 5:18am UTC](https://discourse.vtk.org/t/paraview-has-nice-lookup-tables-is-there-an-easy-way-to-use-them-in-vtk/14260/5 "2024-07-22T05:18:58Z")

</div>

The info provided by Cory is, of course, correct. However, some people may find this example confusing because the RGB values are integers. Here is some more info from PresetColorTables.cxx

```auto
static constexpr ColorTable<2> XRay = {
  vtkm::cont::ColorSpace::RGB,
  { 0, 1, 1, 1,
    1, 0, 0, 0
  }
};

static constexpr ColorTable<4> BlackBlueWhite = {
  vtkm::cont::ColorSpace::RGB,
  { 0, 0, 0, 0,
    0.333, 0, 0, 0.501960784314,
    0.666, 0, 0.501960784314, 1,
    1, 1, 1, 1
  }
};

```

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [July 22, 2024, 10:05am UTC](https://discourse.vtk.org/t/paraview-has-nice-lookup-tables-is-there-an-easy-way-to-use-them-in-vtk/14260/6 "2024-07-22T10:05:43Z")

</div>

Thanks, @whereismymoney, that is an important detail!

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [July 22, 2024, 10:07am UTC](https://discourse.vtk.org/t/paraview-has-nice-lookup-tables-is-there-an-easy-way-to-use-them-in-vtk/14260/7 "2024-07-22T10:07:14Z")

</div>

> [@amaclean](#):
>
> A lot of the work has already been done for you:

Brilliant! I didn’t know about those examples (clearly).
