# Custom colormap and \`vtkTubeFilter\`

**URL:** https://discourse.vtk.org/t/custom-colormap-and-vtktubefilter/9380
**Category:** Support
**Created:** [September 17, 2022, 9:34am UTC](https://discourse.vtk.org/t/custom-colormap-and-vtktubefilter/9380 "2022-09-17T09:34:45Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Marcin\_Krotkiewski](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcin_krotkiewski/32/1534_2.png) [@Marcin\_Krotkiewski](https://discourse.vtk.org/u/Marcin_Krotkiewski)
#### Post date: [September 17, 2022, 9:34am UTC](https://discourse.vtk.org/t/custom-colormap-and-vtktubefilter/9380/1 "2022-09-17T09:34:45Z")

</div>

Hi!  
I’m having a very hard time convincing VTK to color my data according to the supplied custom lookup table, and I would really appreciate some hints. The problem occurs when using the `vtkTubeFilter`: it seems that the tube colors between the points with defined scalar values are not interpolated from the lookup table, but rather some other interpolation method is used.

Consider this simple case: I have two points connected with a segment, I assign scalars to those points. I then build a `vtkTubeFilter` on top of that `PolyData`, and I set a custom 3-color lookup table on the mapper. The tube is colored, but the color space is wrong: it only spans from the first to the last color in the lookup table, and completely disregards the third color in the middle (see attached picture\_2points). The correct coloring can be seen when I make a 3-point model, with 2 lines, and I color it with the same colormap (see the second picture\_3points).

IMO, those two figures should be colored the same way, but you see that the middle part of the colormap is missing in the first 2-point case. I have attached the python code that generates those figures. Could someone help me to understand what am I doing wrong?

thanks!

![picture_2points](https://discourse.vtk.org/uploads/default/original/2X/e/e024152032a970ffba6e2798dd0524f8bf170df1.png)  
 ![picture_3points](https://discourse.vtk.org/uploads/default/original/2X/e/e070b5a76c33a084c159a6a83e1af183ef723e3c.png)

[main.py](https://discourse.vtk.org/uploads/short-url/cuSB3a05X8omlYvklyjNglzPhB8.py) (3.5 KB)

---

<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: [September 18, 2022, 1:28pm UTC](https://discourse.vtk.org/t/custom-colormap-and-vtktubefilter/9380/2 "2022-09-18T13:28:06Z")

</div>

Hello,

You’re using a four-component `vtkUnsignedCharArray` (`array.SetNumberOfComponents(4)`) to configure your LUT. So, your 12-element array should have 16 elements (red green blue alpha x 4) for a four-point LUT. Either that or set a three-element (red green blue) `vtkUnsignedCharArray` (`array.SetNumberOfComponents(3)`) instead.

regards,

Paulo

---

<div class="post-metadata">

### Author: ![Marcin\_Krotkiewski](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcin_krotkiewski/32/1534_2.png) [@Marcin\_Krotkiewski](https://discourse.vtk.org/u/Marcin_Krotkiewski)
#### Post date: [September 18, 2022, 1:46pm UTC](https://discourse.vtk.org/t/custom-colormap-and-vtktubefilter/9380/3 "2022-09-18T13:46:57Z")

</div>

Hi, @Paulo_Carvalho,

Why do I want a 4 point LUT? I wrote explicitly that I use a 3-point LUT (for simplicity), so 4x3=12. The LUT works as expected for geometry with 3 points / 2 lines, but does not work when I only have 2 points / 1 line.

Cheers,

Marcin

---

<div class="post-metadata">

### Author: ![Marcin\_Krotkiewski](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcin_krotkiewski/32/1534_2.png) [@Marcin\_Krotkiewski](https://discourse.vtk.org/u/Marcin_Krotkiewski)
#### Post date: [September 21, 2022, 9:44am UTC](https://discourse.vtk.org/t/custom-colormap-and-vtktubefilter/9380/5 "2022-09-21T09:44:18Z")

</div>

The solution was to use `InterpolateScalarsBeforeMapping`:

[https://www.kitware.com/what-is-interpolatescalarsbeforemapping-in-vtk/](https://www.kitware.com/what-is-interpolatescalarsbeforemapping-in-vtk/)
