# Color scalar overlay on VTK models

**URL:** <https://discourse.slicer.org/t/color-scalar-overlay-on-vtk-models/2675>\
**Category:** Development\
**Created:** [April 24, 2018, 5:18pm UTC](https://discourse.slicer.org/t/color-scalar-overlay-on-vtk-models/2675 "2018-04-24T17:18:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![priya.vada4](https://avatars.discourse-cdn.com/v4/letter/p/d26b3c/32.png) [@priya.vada4](https://discourse.slicer.org/u/priya.vada4)\
**Post date:** [April 24, 2018, 5:18pm UTC](https://discourse.slicer.org/t/color-scalar-overlay-on-vtk-models/2675/1 "2018-04-24T17:18:49Z")

</div>

Hi

Is it possible to overlay a color scalar value from an RGB image on a VTK model in Slicer?

I tried to setup the color scalar in the following way but when the model is displayed in Slicer, it does not show the image scalar and defaults to another color table.

```
vtkSmartPointer<vtkUnsignedCharArray> ColorArray = vtkSmartPointer<vtkUnsignedCharArray>::New();
ColorArray->SetName("ModelColor");
ColorArray->SetNumberOfComponents(3);
...ColorArray initialized here...
this->ModelPoly->GetPointData()->SetScalars(ColorArray);

```

Thanks

---

<div class="post-metadata">

**Author:** ![adamrankin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/adamrankin/32/155_2.png) [@adamrankin](https://discourse.slicer.org/u/adamrankin)\
**Post date:** [April 24, 2018, 6:03pm UTC](https://discourse.slicer.org/t/color-scalar-overlay-on-vtk-models/2675/3 "2018-04-24T18:03:20Z")

</div>

In the model module, have you scrolled down to the Scalars collapsible button to enable scalar colorization?

---

<div class="post-metadata">

**Author:** ![RafaelPalomar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rafaelpalomar/32/1436_2.png) [@RafaelPalomar](https://discourse.slicer.org/u/RafaelPalomar)\
**Post date:** [April 25, 2018, 5:03am UTC](https://discourse.slicer.org/t/color-scalar-overlay-on-vtk-models/2675/4 "2018-04-25T05:03:35Z")

</div>

Hello Priya.

When you say color scalar from an RGB image, does that mean that you want to apply a texture to a model? If so, you can have a look at [GPU-based Projective Texture Mapping in a Loadable Module](https://discourse.slicer.org/t/gpu-based-projective-texture-mapping-in-a-loadable-module/941) and see if you find some answers there.

If what you really want is applying scalar color values, you can have a look at [https://github.com/RafaelPalomar/vtkColorCellsRGBA](https://github.com/RafaelPalomar/vtkColorCellsRGBA) for an example on mapping RGBA scalars to a model (this is a VTK example, but you can use it in 3D Slicer. To enable the visualization of scalars you can use the Models module as suggested by @adamrankin or programmatically by calling vtkMRMLModelDisplayNode::ScalarVisibilityOn() ([http://apidocs.slicer.org/master/classvtkMRMLDisplayNode.html#a9dd055841d24d46216c72f5cce97e6e8](http://apidocs.slicer.org/master/classvtkMRMLDisplayNode.html#a9dd055841d24d46216c72f5cce97e6e8)) from the vtkMRMLModelDisplayNode corresponding to your vtkMRMLModelNode.

I hope this helps.  
Rafael.

---

<div class="post-metadata">

**Author:** ![priya.vada4](https://avatars.discourse-cdn.com/v4/letter/p/d26b3c/32.png) [@priya.vada4](https://discourse.slicer.org/u/priya.vada4)\
**Post date:** [April 26, 2018, 7:01pm UTC](https://discourse.slicer.org/t/color-scalar-overlay-on-vtk-models/2675/5 "2018-04-26T19:01:29Z")

</div>

Thank you, Adam and Rafael.

I am looking to apply a texture on the model. I still seem to have a problem displaying texture on the model.

I have computed the color at every point and I am trying to save the texture as a scalar for the model. I am able to display the texture as a scalar field on the model. However, the color mapping seems completely off and the original colors of the texture are not displayed. As a check, when I use the `this->ModelDisplayNode->SetAndObserveColorNodeID("vtkMRMLColorTableNodeGrey");` the texture shows correctly on the model, although in grayscale. I have set AutoScalarRange to zero and disabled the choice of the ColorNode but still the original colors of the texture are not being displayed.

Thanks

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [April 26, 2018, 7:23pm UTC](https://discourse.slicer.org/t/color-scalar-overlay-on-vtk-models/2675/6 "2018-04-26T19:23:02Z")

</div>

This topic should answer your questions, but feel free to follow up here, if something is not clear:

> [@Displaying textured 3D models](https://discourse.slicer.org/t/displaying-textured-3d-models/2521):
>
> I have a PLY made from a stereophotogrammatic scanner. It also has a texture file in jpg format. I tried setting the option for these texture files to “scalar overlay” and asked it to apply to the model I already loaded. When I do that, nothing happens, no error message nor the trace of the texture files as far as I can tell. There is no scalar listed under the “Scalar” tab of the models module. This is with 4.8.1 on windows.
