[vtkusers] can vtkDiscretizableColorTransferFunction deal with non-contiguous dicrete values?

Luca Pallozzi Lavorante lplavorante at gmail.com
Mon Aug 15 09:49:57 EDT 2016


Hi everibody, I found the example TestColorByCellDataStringArray.cxx that
creates a categorical LookupTable using
vtkDiscretizableColorTransferFunction. I had to switch the IndexedColor
flag on and provide the colors using the SetIndexedColor(value, annotation)
method, where value is a vtkVariant object containing the current
celldata's unsigned short id (this is the type of data that I am storing in
the cells) and annotation is a vtkStdString.
It worked fine. I am appending  the code in case anybody need the same
feature.

      Thank you,

Luca Pallozzi Lavorante

// This is an example

std::vetor<uint32> listIds = {3, 5, 6, 7, 8};

table = vtkSmartPointer<vtkDiscretizableColorTransferFunction>::New();
table->IndexedLookupOn();

table->SetNumberOfIndexedColors(listIds.size());

size_t colorIndex = 0;

foreach (uint32 id, listaIds) {

   QColor color(myFunctionTogetColorsFromIds(id));
    vtkVariant value(static_cast<unsigned short>(id));

    vtkStdString annotation (nameOfMyId());

    table->SetIndexedColor(colorIndex, color.redF(), color.greenF(),
color.blueF());
    table->SetAnnotation(value, annotation);
    colorIndex++;
}

// table->Build(); // This was not necessary
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160815/bacc5f91/attachment.html>


More information about the vtkusers mailing list