6.2. Elevation Management

The first step consists of initializing the TerrainViz module by calling the static method init() of the SoTViz class.

The SoTVizRender class is the main node that manages data and textures. It can be tuned by adjusting the number of displayed triangles and turning the frustum culling on/off (enabled by default).

The terrain is managed by being divided into patches so as to split the tessellation work. Frustum culling eliminates the patches of the terrain outside the view volume so as to concentrate on the visible region. So, fewer patches are tessellated and the same number of triangles required are displayed but in the visible region.

The tessellator refines parts of the terrain depending on the gradient of elevation and on the size of the on-screen projection. This means that a mountain will be more refined than a flat lake, even if it is farther away because its on-screen projection is greater than that of a flat region.

The triangle size attenuation and the distance attenuation parameters are deprecated beginning with TerrainViz 2.0. The new tessellation engine no longer uses these parameters.

TerrainViz mesh density

Figure 6.2.  TerrainViz mesh density

In the following example, this node uses a regular grid elevation file (susanville.dat) that can be binary or ASCII. The data is handled by an SbTVizRegularGridData object. Sampling steps for X, Y, Z, and offset (translation) of the terrain must be provided.

Example 6.1.  A simple example using SoTVizRender

#include <Inventor/Xt/viewers/SoXtExaminerViewer.h>
#include <Inventor/nodes/SoSeparator.h>
#include <TerrainViz/nodes/SoTViz.h>
#include <TerrainViz/nodes/SoTVizRender.h>
#include <TerrainViz/SbTVizRegularGridData.h>

  main(int argc, char **argv)
  // Initialize Inventor. This returns a main window to use.
  // If unsuccessful, exit.
  Widget mainWindow = SoXt::init(argv[0]);    // pass the app name
    if (mainWindow == NULL) exit(1);

  // Initialize TerrainViz

    SoXtExaminerViewer *mainViewer = new SoXtExaminerViewer(mainWindow);
    SoSeparator *mainRoot = new SoSeparator;


    SoTVizRender *dtmRender = new SoTVizRender();


  // The data file is 601*601, maximum height is 1470
    SbTVizRegularGridData *data = new SbTVizRegularGridData();
    SbVec3d(1./601., 1./1470., 1./601.),
    SbVec3d(0., 0., 0.));
    dtmRender->maxRenderedTriangles = 10000;


    SoXt::show(mainWindow);      // Display main window

    // Main Inventor event loop
    SoXt::main Loop();
    return 0;