6.9. Terrain Viewer

The Terrain Viewer is a constrained viewer that has been customized for terrain viewing. It has new navigation modes and navigation tools. The default mode of this viewer is the Walk mode: the camera keeps a constant altitude and rises in case of collision. You can switch between Walk mode and Fly mode by pressing a viewer button (the one with the airplane icon).

The constant elevation mode (also accessible using a viewer button) keeps the camera at a fixed relative height when navigating. If you set the relative elevation to 100 meters, the effective relative elevation may vary above and below this reference altitude because of trajectory smoothing and gravity effects.

Terrain viewer

Figure 6.15. Terrain viewer

Two navigation tools are provided by default with the viewer: the compass in the bottom left corner and the altimeter/speedometer in the bottom right corner.

  • The compass displays the camera orientation, the north being along the Y-axis by default.

  • The altimeter/speedometer tool displays the relative elevation (height between camera and terrain), the terrain height (under the camera), and the current navigation speed.

The unit system can be changed (metric/US units).

These tools are loaded from .iv files found in the path defined by $TVIZ_VIEWER_DATA_PATH, $OIVHOME/data/TerrainViz/viewer, or the working directory.

New tools can be created and added to the viewer; they should derive from SoTVizNavigationToolBase which has virtual methods allowing you to be notified of position, speed, orientation, or elevation changes (notifyPosition(), notifySpeed(), notifyOrientation(), notifyElevation()).

If you want to change only the graphical appearance of the tools supplied with the viewer, you will need to keep the names given to the nodes in the related .iv files to preserve the same behavior. Keep CompassFixedPart and CompassMobilePart in the. iv file related to SoTVizCompass . Keep RelativeElevation, GroundElevation, and Speed in the .iv file related to SoTVizAltimeterSpeedometer .

Example 6.7. A simple example using the Terrain Viewer

#include <TerrainViz/nodes/SoTViz.h>
#include <TerrainViz/nodes/SoTVizRender.h>
#include <TerrainViz/SbTVizRegularGridData.h>
#include <TerrainViz/viewer/SoTVizViewer.h>

 main(int argc, char **argv)
 // If unsuccessful, exit.
   Widget mainWindow = SoXt::init(argv[0]);

 // Initialize TerrainViz

   SoTVizViewer *mainViewer = new SoTVizViewer(mainWindow);

   SoTVizRender *dtmRender = new SoTVizRender;
   SbTVizRegularGridData *data = new SbTVizRegularGridData();
   SbVec3d(1./599., 1./599., 0.2/599.),
   SbVec3d(0., 0., 0.));

   dtmRender->maxRenderedTriangles = 10000;


 // Units and scale
 // Maximum speed : 1000 km/h

 // Display main window

 // Main Inventor event loop