# Advantage of adding annotations to a look up table?

**URL:** https://discourse.vtk.org/t/advantage-of-adding-annotations-to-a-look-up-table/3907
**Category:** Support
**Created:** [August 4, 2020, 1:30pm UTC](https://discourse.vtk.org/t/advantage-of-adding-annotations-to-a-look-up-table/3907 "2020-08-04T13:30:24Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![dmgroppe](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dmgroppe/32/25_2.png) [@dmgroppe](https://discourse.vtk.org/u/dmgroppe)
#### Post date: [August 4, 2020, 1:30pm UTC](https://discourse.vtk.org/t/advantage-of-adding-annotations-to-a-look-up-table/3907/1 "2020-08-04T13:30:24Z")

</div>

Hi VTKers,  
I’m trying to use VTK to visualize some data with a categorical color map in C# and am having some issues adding annotations to the look up table. I can work around the issues by setting the table indexing to ORDINAL and ignoring the annotations. Is there any disadvantage to doing this?  
much thanks,  
-David

---

<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: [August 5, 2020, 1:51pm UTC](https://discourse.vtk.org/t/advantage-of-adding-annotations-to-a-look-up-table/3907/2 "2020-08-05T13:51:22Z")

</div>

Hi, David,

Annotations work just fine for me, though it is not obvious make it work as expected:

```cpp
vtkSmartPointer<vtkLookupTable> View3dColorTables::getCategoricalColorTable( CategoryDefinition *cd, bool useGSLibColors )
{
    cd->loadQuintuplets();
    int catCount = cd->getCategoryCount();

    //determine the greatest categorical code
    int maxCatCode = 0;
    for( int i = 0; i < catCount; ++i )
        maxCatCode = std::max<int>( maxCatCode, cd->getCategoryCode(i) );

    //table color indexes must go from 0 to greatest facies code, without skipping values
    size_t tableSize = maxCatCode + 1;
    vtkSmartPointer<vtkLookupTable> lut = vtkSmartPointer<vtkLookupTable>::New();
    lut->SetNumberOfTableValues(tableSize);

    //but assign only the codes defined in the category definition
    //which may be less than the total number of entries in the color table
    //this is a requirement by the way VTK's LUT work for categorical color tables
    for(size_t i = 0; i < tableSize; ++i)
    {
        if( cd->codeExists( i ) ){
            double rgb[3];
            QColor color;
            int catIndex = cd->getCategoryIndex( i );
            if( useGSLibColors )
                color = Util::getGSLibColor( cd->getColorCode( catIndex ) );
            else
                color = cd->getCustomColor( catIndex );
            rgb[0] = color.redF();
            rgb[1] = color.greenF();
            rgb[2] = color.blueF();
            lut->SetTableValue(i, rgb[0], rgb[1], rgb[2], 1.0);
            lut->SetAnnotation(i, QString::number(i).toStdString() );
        } else {
            lut->SetTableValue(i, 1.0, 0.0, 1.0, 0.3); //ilegal color codes are rendered as pink 70% transparent.
            lut->SetAnnotation(i, "UNKNOWN CATEGORY" );
        }
    }
    lut->SetNanColor( 1.0, 0.0, 1.0, 0.3 ); //unvalued locations are rendered as pink 70% transparent.
    lut->IndexedLookupOn();
    lut->Build();

    return lut;
}

```

From: [https://github.com/PauloCarvalhoRJ/gammaray/blob/master/viewer3d/view3dcolortables.cpp](https://github.com/PauloCarvalhoRJ/gammaray/blob/master/viewer3d/view3dcolortables.cpp)

For some reason, the annotation table cannot have numbers like, 1, 13, 7, 20, etc. It must be in ascending order and cannot skip values.

regards,

Paulo

---

<div class="post-metadata">

### Author: ![dmgroppe](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dmgroppe/32/25_2.png) [@dmgroppe](https://discourse.vtk.org/u/dmgroppe)
#### Post date: [August 6, 2020, 1:53pm UTC](https://discourse.vtk.org/t/advantage-of-adding-annotations-to-a-look-up-table/3907/3 "2020-08-06T13:53:45Z")

</div>

Thanks very much @Paulo_Carvalho. I’m trying to use vtkColorSeries to make the lookup table. I’ll see if I can just create the table from scratch as you’ve done.
