The SbTVizColorScale class provides an alternative to texture mapping. It specifies a color scale to be applied to a range of elevation values. The terrain is sub-divided into slices of different colors. The number of threshold altitudes should be the number of given colors plus one.
Two additional colors can be set: the extreme colors corresponding to altitudes out of the scale range, above the maximum height and below the minimum height given.
Then two different modes are available: shown on the left, the color contouring mode maps a 1D texture onto the elevations, and makes an accurate sliced representation; shown on the right, the color shading mode sends a color per vertex, producing a smoother color appearance.
|
|
Example 6.4. A simple example using color scale
// Load elevation data SbTVizRegularGridData *data = new SbTVizRegularGridData(); data->loadDataFile("data/susanville.dat", SbVec3d(1./599., 1./599., 0.2/599.), SbVec3d(0., 0., 0.)); // Define the colors of the palette SbTVizColorScale *colorScale = new SbTVizColorScale; SbColor colors[3]; colors[0] = SbColor(0.58f, 0.26f, 0.01f); colors[1] = SbColor(0.12f, 0.50f, 0.12f); colors[2] = SbColor(0.80f, 0.80f, 0.80f); // Define the different altitudes for slicing the terrain float altitudes[4]; altitudes[0] = 0.025f; altitudes[1] = 0.035f; altitudes[2] = 0.05f; altitudes[3] = 0.06f; // Define colors when out of altitude range SbColor lowColor(0.f, 0.f, 1.f), highColor(1.f, 1.f, 1.f); colorScale->setExtremeColors(lowColor, highColor); // Sends altitude and color arrays colorScale->setColors(3, colors); colorScale->setAltitudes(4, altitudes); // Use shading mode for rendering colorScale->setColorMode(SbTVizColorScale::TVIZ_SHADING); // Tells the terrain node which mapping to use dtmRender->mappingMode = SoTVizRender::TVIZ_COLORSCALE; dtmRender->setColorScale(colorScale);