The Terrain Analysis Engine provides viewsheds to compute which parts of a threedimensional scene are visible in the presence of obstacles like buildings and terrain. Conceptually a viewshed divides a volume into visible and invisible regions with respect to an observer. For instance it answers the following questions:

  • Is a vehicle on the ground visible to an observer?

  • Is an air-borne helicopter visible to an observer?

  • is a building casting a shadow on a location?

In general, a viewshed defines an interface to determine whether any point in threedimensional space is visible or not.

viewshed scheme
Figure 1. A viewshed defines an interface to determine whether a point lies inside a visible volume. In this figure the gray regions are invisible to the observer.

Figure 1, “A viewshed defines an interface to determine whether a point lies inside a visible volume. In this figure the gray regions are invisible to the observer.” illustrates the viewshed concept. The gray regions are invisible to the observer for various reasons: a building blocking the view, the terrain or a "cone of silence", a region which the observer cannot see.

The sample samples.tea.gxy.viewshed.positional.MainPanel demonstrates the viewshed functionality for a local observer in a city, with buildings and terrain. The sample samples.tea.gxy.viewshed.directional.MainPanel illustrates how the same functionality can be used to compute which areas are shaded from the sun at a given position.

Creating a viewshed

A viewshed defines a visible volume with respect to an observer. The abstract class ALcdViewshedObserver allows to define such an observer. The Terrain Analysis Engine offers two concrete implementations:

All viewsheds implement the ILcdViewshed interface. It defines a single method getVisibility(ILcdPoint aPoint) which returns a value between 0 and 1, specifying complete invisibility to full visibility. The argument aPoint must be defined in the viewshed’s reference.

Implementations of ILcdViewshedFactory can help creating new ILcdViewshed instances. The createViewshed method creates an ILcdViewshed instance for a given Object, which is typically a domain object belonging to an ILcdModel. The Terrain Analysis Engine provides implementations of ILcdViewshedFactory for common types of domain objects:

Object Factory

ILcd3DMesh

TLcd3DMeshViewshedFactory

ILcdExtrudedShape

TLcdExtrudedPolygonViewshedFactory

ILcdHeightProvider

TLcdTerrainViewshedFactory

ILcdPolygon

TLcdPolygonViewshedFactory

Program: Creating an extruded shape. and Program: Creating a viewshed for an extruded shape. illustrate how you can extrude a polygon and create a viewshed for the extruded shape using TLcdExtrudedPolygonViewshedFactory. Program: Creating a viewshed for a terrain model with TLcdTerrainViewshedFactory. demonstrates how to create a viewshed for terrain data.

Program: Creating an extruded shape. (from samples/tea/viewshed/ExtrudedPolygonFactory)
ILcdBounds polygonBounds = polygon.getBounds();
double buildingHeight = retrieveBuildingHeight(polygonBounds);
double terrainHeight = retrieveTerrainHeight(aHeightProvider, polygonBounds);
TLcdExtrudedShape extrudedShape = new TLcdExtrudedShape(polygon, terrainHeight, buildingHeight + terrainHeight);
Program: Creating a viewshed for an extruded shape. (from samples/tea/viewshed/PolygonViewshedFactory)
ILcdViewshed viewshed = fExtrudedPolygonViewshedFactory.createViewshed(extrudedShape, aTransformation);
Program: Creating a viewshed for a terrain model with TLcdTerrainViewshedFactory. (from samples/tea/viewshed/positional/AbstractCreateViewshedAction)
//Create terrain viewshed
TLcdTerrainViewshedFactory terrainViewshedFactory = new TLcdTerrainViewshedFactory(viewshedReference, observerPositional, fEyePositionPanelModel.getStepSize());
TLcdGeoReference2GeoReference terrainTransformation = ViewshedUtil.createTransformation(terrainModelReference, viewshedReference);
terrainViewshedFactory.setStepSize(fEyePositionPanelModel.getStepSize());
ILcdViewshed terrainViewshed = terrainViewshedFactory.createViewshed(terrainHeightProvider, terrainHeightProvider.getBounds(), terrainTransformation);

Additionally, the Terrain Analysis Engine offers ILcdViewshed implementations for composite viewsheds. Composite viewsheds are containers for viewsheds whose visibility values need to be composited. The Terrain Analysis Engine provides two implementations:

The ALcdCompositeViewshed class defines compositing operations for composite viewsheds. Classes implementing this interface should be stateless and thread-safe. The Terrain Analysis Engine offers the following implementations:

Program: Creating a composite viewshed model. (from samples/tea/viewshed/positional/AbstractCreateViewshedAction)
//Composite the two viewsheds
ILcdViewshed viewshed;
if (terrainViewshed instanceof TLcdBoundedCompositeViewshed && polygonViewshed instanceof TLcdBoundedCompositeViewshed) {
  //If both viewsheds are TLcdBoundedObjectViewshed, then we can merge them into one to improve performance
  TLcdBoundedCompositeViewshed boundedObjectViewshed = new TLcdBoundedCompositeViewshed(viewshedReference, observerPositional);
  boundedObjectViewshed.addAllObjects((TLcdBoundedCompositeViewshed) terrainViewshed);
  boundedObjectViewshed.addAllObjects((TLcdBoundedCompositeViewshed) polygonViewshed);
  viewshed = boundedObjectViewshed;
} else {
  //Fall back if the viewsheds return something else. Viewsheds will be accelerated separately.
  TLcdCompositeViewshed compositeMinimalViewshed = new TLcdCompositeViewshed();
  compositeMinimalViewshed.setComposite(new TLcdMinimalVisibilityComposite());
  compositeMinimalViewshed.addViewshed(terrainViewshed);
  compositeMinimalViewshed.addViewshed(polygonViewshed);
  viewshed = compositeMinimalViewshed;
}

Program: Creating a composite viewshed model. illustrates the creation of a composite viewshed. It holds an extruded polygon and a terrain viewshed. The result is a viewshed which defines which areas and buildings are visible to the observer.

Finally, TLcdConeOfSilenceViewshed clips the horizontal and vertical angles at which the observer can see its surroundings.

Visualizing a viewshed

A viewshed corresponds to a 3D volume that can be sampled. In 2D, the class TLcdViewshedMultilevelRaster can help to visualize a 2D section of that volume. Program: Creating a model to visualize a viewshed with TLcdViewshedMultilevelRaster. illustrates the functionality TLcdViewshedMultilevelRaster provides to visualize a viewshed.

Program: Creating a model to visualize a viewshed with TLcdViewshedMultilevelRaster. (from samples/tea/gxy/viewshed/positional/CreateViewshedAction)
TLcdGeoReference2GeoReference modelToViewshed = ViewshedUtil.createTransformation( aViewshedModelReference, aViewshedReference );
TLcdViewshedMultilevelRaster multilevelRaster = new TLcdViewshedMultilevelRaster( transformedBoundsSFCT, aViewshed, modelToViewshed, colorModel, TLcdSharedBuffer.getBufferInstance() );

multilevelRaster.setHeightProvider( ViewshedUtil.createHeightProvider( aViewshedModelReference, aTerrainModel ) );

multilevelRaster.setTargetHeight( aViewshedSamplingProperty );
viewshed raster sampling
Figure 2. TLcdViewshedMultilevelRaster samples the viewshed at a specified target height. Optionally setHeightProvider( ILcdHeightProvider aHeightProvider ) sets an ILcdHeightProvider whose values augment the target height.

Figure 2, “TLcdViewshedMultilevelRaster samples the viewshed at a specified target height. Optionally setHeightProvider( ILcdHeightProvider aHeightProvider ) sets an ILcdHeightProvider whose values augment the target height.” shows how TLcdViewshedMultilevelRaster samples the viewshed. setTargetHeight( double aTargetHeight ) allows to set the height of these samples. Optionally setHeightProvider( ILcdHeightProvider aHeightProvider ) sets an ILcdHeightProvider whose values augment the target height.

viewshed
Figure 3. Two visualizations computed with TLcdViewshedMultilevelRaster, with different levels of detail. The green dot represents the observer. The dark regions illustrate the regions that are invisible to the observer due to the terrain or buildings.

TLcdViewshedMultilevelRaster implements ILcdMultilevelRaster. Any painter that supports this interface can draw TLcdViewshedMultilevelRaster objects (such as TLcdMultilevelRasterPainter). Figure 3, “Two visualizations computed with TLcdViewshedMultilevelRaster, with different levels of detail. The green dot represents the observer. The dark regions illustrate the regions that are invisible to the observer due to the terrain or buildings.” shows two visualizations of a viewshed for different levels of detail. TLcdViewshedMultilevelRaster computes raster values lazily, in other words when they are needed.