ParaView has always been able to map numerical values associated with points and cells to colors. ParaView 4.3 has the ability to map string arrays to colors. This feature works for string arrays in point data, cell data, and field data using the new feature that enables you to color by the first tuple in a field data array.
Coloring by string arrays is possible when the color map option “Interpret Values As Categories” is enabled and a set of annotations whose values are strings in the data array is defined. As with other cases where values are interpretted as categories, a set of active values can be obtained automatically from the data and defined as annotations using the tools in the Color Map Editor’s Annotations section.
Let’s take a look at an example data set that contains the countries of the world. The cells in the file that defined the countries have an associated string array named “REGION” that encodes the region in which the country is located. The image below shows the results of coloring by this region string array. Labels in the color legend show the region string values in the map data set.
The data file and ParaView state file that produced this image is attached to this post. You can try it out with ParaView 4.3 Release Candidate 1, available at the ParaView downloads page.
Mapping string arrays to colors in VTK
Coloring by string arrays is implemented in VTK, so any VTK-based application can do it. For example, imagine you have a data set where the colors to be used for cell data are defined by strings naming the colors. You can set up a vtkLookupTable to map these strings to the actual colors using the following code:
vtkLookupTable* lut = vtkLookupTable::New(); lut->IndexedLookupOn(); lut->SetNumberOfTableColors(5); lut->SetTableValue(0, 1.0, 0.0, 0.0); // red lut->SetTableValue(1, 0.0, 0.0, 1.0); // blue lut->SetTableValue(2, 0.0, 1.0, 0.0); // green lut->SetTableValue(3, 1.0, 1.0, 0.0); // yellow lut->SetTableValue(4, 0.0, 1.0, 1.0); // cyan vtkStdString red("red"); lut->SetAnnotation(red, red); vtkStdString blue("blue"); lut->SetAnnotation(blue, blue); vtkStdString green("green"); lut->SetAnnotation(green, green); vtkStdString yellow("yellow"); lut->SetAnnotation(yellow, yellow); vtkStdString cyan("cyan"); lut->SetAnnotation(cyan, cyan);
Happy color mapping!