Viewshed Analysis
Viewshed Analysis
art ic l e i nf o a b s t r a c t
Article history: Viewshed analysis, often supported by geographic information systems, is widely used in the three-
Received 17 April 2014 dimensional (3D) Digital Earth system. Many of the analyzes involve the siting of features and real-
Received in revised form timedecision-making. Viewshed analysis is usually performed at a large scale, which poses substantial
16 October 2014
computational challenges, as geographic datasets continue to become increasingly large. Previous re-
Accepted 29 October 2014
search on viewshed analysis has been generally limited to a single data structure (i.e., DEM), which
Available online 6 November 2014
cannot be used to analyze viewsheds in complicated scenes. In this paper, a real-time algorithm for
Keywords: viewshed analysis in Digital Earth is presented using the parallel computing of graphics processing units
Viewshed analysis (GPUs). An occlusion for each geometric entity in the neighbor space of the viewshed point is generated
Digital Earth
according to line-of-sight. The region within the occlusion is marked by a stencil buffer within the
GPU
programmable 3D visualization pipeline. The marked region is drawn with red color concurrently. In
Visualization
Vertex shader contrast to traditional algorithms based on line-of-sight, the new algorithm, in which the viewshed
Pixel shader calculation is integrated with the rendering module, is more efficient and stable. This proposed method
of viewshed generation is closer to the reality of the virtual geographic environment. No DEM inter-
polation, which is seen as a computational burden, is needed. The algorithm was implemented in a 3D
Digital Earth system (GeoBeans3D) with the DirectX application programming interface (API) and has
been widely used in a range of applications.
& 2014 Elsevier Ltd. All rights reserved.
http://dx.doi.org/10.1016/j.cageo.2014.10.012
0098-3004/& 2014 Elsevier Ltd. All rights reserved.
58 W. Feng et al. / Computers & Geosciences 75 (2015) 57–65
intervisibility calculations to all vertices of the DEM based on line- method, and this algorithm is considered more effective than the
of-sight (LOS), are mainly executed on a computer's central pro- LOS algorithm because no DEM interpolation is needed. A re-
cessing unit (CPU) without making full use of high-end GPUs. With ference plane, based on the spatial topological relation of the
the development of GPUs, some GPU-based viewshed algorithms viewpoint and the target point, is generated to calculate the visi-
have been proposed in recent three years. bility. Unlike the LOS algorithm, this method generates viewshed
The present research focuses on solving the performance issues without redundant computation. However, this technique is lim-
described above and providing users with an effective, real-time, ited to DEMs and not suited to calculating a viewshed from varying
parallel, and GPU-based viewshed analysis algorithm. This algo- resolutions.
rithm has been applied in our 3D Digital Earth application (Geo- Generally, GPUs are designed to exploit data parallelism. It has
Beans) with good results. been reported that GPUs can achieve 10 times more floating-point
operations per second (FLOPS) than CPUs (Govindaraju et al.,
2006). With the rapid development of modern GPUs, transferring
2. An overview of previous work traditional algorithms that were previously executed on CPUs to
GPUs is becoming increasingly popular. This technique enables
Viewshed analysis, as an important branch of 3D spatial ana- GPUs to process repeated computing tasks to speed up the com-
lysis, has received increasing attention among researchers. Related putation. Chen et al. (2010) implemented a rapid contour-line-
academic, conference, and research monographs regarding this extraction algorithm by using traditional methods on GPUs. Par-
approach are gradually increasing (Han, 2011). Current research allel processing techniques have also been applied to improve
mainly focuses on viewshed analyzes in terrain models whose computational performance in viewshed analyzes (Mills et al.,
data structure is a DEM or triangulated irregular network (TIN). 1992, Gao et al., 2011, Zhao et al., 2013). All these methods pro-
Other previous studies have investigated building-blocks analysis posed strategies for implementing traditional LOS-based inter-
and sunlight analysis (Ying, 2005). polation viewshed algorithm with NVIDIA CUDA. Although made a
The basic algorithm for generating a viewshed from raster progress in efficiency, those methods are limited to regular square
elevation data, known as intervisibility, is based on the estimation grids (RSGs) and not suitable for triangulated irregular networks
of the elevation difference of intermediate pixels between the (TINs), neither for complicated scene with geometry features. Fang
viewpoint and target pixels. A line segment between a viewpoint et al. (2011) introd Fang uced a real-time parallel algorithm for
O and a target point A, which makes up the LOS, is created to viewshed analysis known as shadow map-based algorithm. This
determine the visibility of target point A. Moving along the line algorithm is executed on GPUs and uses a depth buffer to store the
segment OA and testing all of the points along this line, target pixel's minimum depth. Comparing the depth of the current pixel
point A is visible only if all of the points on OA have an elevation with the depth of a corresponding pixel recorded on the depth
higher than the elevation of the corresponding point on the ter- buffer, one pixel is visible only if its depth is lower than the
rain. Otherwise, target point A is invisible from the viewpoint (see minimum depth. This method has an advantage of avoiding most
Fig. 1). The LOS computation is repeated for all target points within of the computation on a CPU and without consideration of the
the viewshed range of the viewpoint during viewshed analysis. data-structure and DEM resolution. Nevertheless, one of the dis-
This process is extremely time consuming, and its time complexity advantages of this method is its low accuracy. In Fang's method,
is expressed as O(n2). the size and depth of the shadow map determine the quality of the
The brute-force algorithm described above is simple but com- final results, and low-accuracy areas are usually visible as aliasing
putationally intense. A variety of algorithms have been developed or shadow continuity glitches.
to speed up these calculations. De Floriani et al. (1994) proposed
an algorithm, named the key slope method that is a huge im-
provement over LOS. This method continually computes the slope 3. GPU-based parallel algorithm for viewshed analysis
along the sightline and updates the maximum slope. The slope of
the current point is compared with the max slope to determine 3.1. Principle
the visibility. Unnecessary computations are greatly reduced, re-
sulting in a time complexity of O(n) using this method. A new, Our parallel algorithm takes a new approach to simulating
double increment method is presented by Yin shen to speed up viewshed analysis by creating occlusive volumes to shield the
the calculation. The accuracy, indeterminacy, and invariance of geometric features in the neighborhood of the viewpoint. In con-
viewsheds are also discussed (Ying, 2005). Liu et al. (2010) trast to the proposed GPU-based algorithm (Yanli Zhao et al.,
proposed an improved algorithm by using the slope and elevation 2013), this method avoid the interpolation operation which is time
between the target pixel and viewshed point to reduce the consuming. The surface of the geometry features is used to display
required computation. the analysis result, called the receiver. Occlusive volumes, known
Yanlan (2001) introduced a new algorithm to determine as caster, are generated according to the position of the viewpoint
viewshed without using sightline, named the reference plane and geometric feature outlines by casting the feature's outline
along the sightline to infinity. Although this process still utilizes a
sightline to generate occlusive volumes, it differs from the LOS
method because DEM interpolation is not required and calculation
redundancy is extremely reduced. All of the geometric features,
including terrain, models, and trees, in the specific space of the
required viewpoint can be used for both the caster and receiver.
Therefore, our proposed algorithm performs well in complicated
three-dimensional scenes, whereas traditional methods do not.
Users only have to add the updated feature as a new caster when
the scene is updated, and no changes to the code logic are re-
Fig. 1. Overview of the traditional LOS algorithm showing a comparison of the
height of the target point with other points along the sight line to determine the
quired. With this prerequisite, our algorithm can conveniently and
visibility. This process is computationally intense. Point B is visible from the efficiently simulate viewshed calculations by transforming this
viewpoint while point A is invisible. process to identify and label the pixels that are within the
W. Feng et al. / Computers & Geosciences 75 (2015) 57–65 59
Fig. 4. Introduction of occlusive volume generation extends the back cap of mesh by a large distance along the line of sight. The red line indicates the back cap and the green
line indicates the front cap. The occlusive volume must be enclosed. The orange line indicates the broadside. (For interpretation of the references to color in this figure
legend, the reader is referred to the web version of this article.)
stencil buffer according to whether the pixels are within silhouette for a long distance along the direction from which the
the occlusive volume, the viewshed is finally, successfully light originates. These methods are typically conducted using CPUs
labeled. Eventually, the viewshed can be displayed in the and have proven inefficient and time consuming. Therefore, in-
complicated scene by flushing the screen and changing stead of determining the silhouette and generating the occlusive
the color according to the value of the stencil buffer. volume geometry on the CPU, our algorithm first generates a mesh
that represents the occlusive volume regardless of light direction
and uses a vertex shader to preform vertex extrusion.
3.2. Algorithm implementation The underlying concept is that triangles that face the light can
be used as-is for the front cap of the occlusive volume. The vertices
3.2.1. Data extraction and preprocessing of triangles that face away from the light are translated a large
Three-dimensional Digital Earth is a complex system for si- distance, usually to the far plane of the frustum, along the light
mulating real-world geospatial data using terrain, images, and all direction at each vertex; they can then be used as the back cap.
types of geometric features such as buildings and forest models. However, a problem occurs at silhouette edges where one triangle
The methods of terrain construction can be divided into regular- faces the light and its neighbor faces away from the light. In this
grid, TIN, and mixed grid-TIN. The regular-grid, which is easier for situation, the geometry mesh will split when performing vertex
spatial analyzes and calculations and has a small storage capacity, extrusion.
is more suitable for flat areas. However, precision is poor when the An effective way of solving this issue is duplicating the shared
regular-grid is used to stimulate mountainous areas. In contrast, vertices for the two triangles that share an edge, so that each
TIN expresses the surface morphology more precisely, especially in triangle has its own unique three vertices, and attaching a de-
complicated areas. Although it easily expresses topological re- generated quad to each shared edge. When the common edge
lationships, TIN has the disadvantages of large storage capacity between the triangles becomes the silhouette edge, one triangle
and complicated computation. There are various methods for stays where it is and the other moves along the light direction.
viewshed calculation according to different data structures, which This process, however, creates a gap between the two triangles,
differ in their output and cost. whereas a closed occlusive volume cannot have any gap or hole.
The 3D Digital Earth platform GeoBeans3D contains global and This problem can be fixed by adding a degenerated quad to the
multi-resolution terrain data. Level of detail (LOD) is used to occlusive volume between the original two triangles, thereby
render terrain in real time to improve efficiency. To process the creating two new triangles. Fig. 5 illustrates this process.
viewshed analysis in complicated scenes, the first step is to collect There are concrete steps:
geometric features and terrain in the neighborhood of the view-
point. In our algorithm, the terrain data, whose data structures Duplicate the vertices of the original mesh and make sure every
correspond to the rendering model, are extracted in three different triangle has its own unique three vertices and edges for vertex
resolutions. This process allows the original mesh data of com- extrusion.
plicated features, such as building models, to be used in our al- The normals of the new vertices are computed to be the normal
gorithm directly. To reduce computation, we can simplify certain of the new face. This step is necessary because the normal of
tree models using the bounding box for a given tree model. the vertex is used to determine whether the vertices should be
extruded. We refer to the vector of the current vertex to
3.2.2. Generation of occlusive volume viewpoint as L. If the dot value of vertex normal and L is less
The traditional approaches to generating occlusive volume are than 0, the vertex must be extruded.
usually two-step processes that determine the silhouette edges of The three edges of a triangle are added to an edge-mapping
the geometric features according to the viewpoint and extend the table. An edge-mapping entry contains the vertex information
Fig. 5. Detailed illustration of mesh pre-processing, duplicating the mesh vertex, and filling in the gap by regenerating new triangles with the original four vertices.
W. Feng et al. / Computers & Geosciences 75 (2015) 57–65 61
of an edge. For each edge of the added face, the algorithm looks
through the edge mapping table to find the entry of the source
edge. If the target is hit, four vertices are elicited to generate
two triangles by connecting the vertices with a specific se-
quence (clockwise in DirectX 9.0). The new triangles will be
added to the original mesh as new elements. Finally, the edge-
mapping entry should be removed from the table.
After step 3, if there are edges in the mapping table, which
means the edges are not shared in the original mesh, we must
patch the volume because it should be closed. The existence of
these edges implies the original mesh has holes in it. The
patching algorithm examines the mapping table and identifies
two edges that share a vertex in the original mesh. Then, the
algorithm patches the hole by generating three new vertices
and a new triangle using the two neighboring edges' vertices.
Fig. 7. The process of labeling the pixel using the stencil buffer. After the process,
To connect the patched face with the mesh, two degenerated
pixel O is visible because its stencil value is equal to 0, whereas P is invisible be-
quads should be generated. This process is illustrated in Fig. 6. cause its value is not equal to 0. This process is executed on GPUs in parallel.
Fig. 8. Screenshots of the viewshed analysis in GeoBeans3D. The red area is invisible, and the green area is visible from the viewpoint. (a and b) The viewpoint is identified
on the plateau with rich topography; (c) the viewshed with complicated features from a viewpoint over a flat plain. (For interpretation of the references to color in this figure,
the reader is referred to the web version of this article.)
Table 1
The detailed configuration of our testing platform.
CPU Intel Core2 Q6600 Intel Core2 Quad Intel Core2 Duo
CPU frequency (GHz) 2.4 2.5 2.4
RAM (GB) 3.25 3.25 2
GPU NVIDIA GTX280 NVIDIA GF9800 NVIDIA GF8600
GPU memory 1 GB 1 GB 256 MB
Table 2
Testing two viewshed algorithms on our platforms.
Table 3
same PC, we observed that our algorithm can improve the per-
Testing five viewshed algorithms in GeoBeans3D in the same platform (No. 1).
formance by an average of 35.3%.
Algorithms A1 (ms) A2 (ms) A3 (ms) A4 (ms) A5 (ms) Additionally, we conducted other experiments to further ana-
lyze the performance of viewshed analysis algorithms. Five dif-
LOD 1 0.97 0.64 0.74 0.69 0.42
ferent viewshed analysis algorithms, including an LOS algorithm
LOD 2 1.84 1.41 0.89 0.76 0.48
LOD 3 4.56 3.24 1.06 0.83 0.55
referred to as the double increment algorithm, a reference plane
algorithm, a GPU-based parallel algorithm (Yanli Zhao et al., 2013),
the shadow map-based algorithm, and our algorithm, were tested
they are both mainly composed of processes involving vertex and on computer No. 1 with the same configuration. A1 through A5
pixel shaders on GPUs. Therefore, we believe that a high-perfor- represent the five algorithms accordingly. The sample data in our
mance graphic card will accelerate the viewshed analysis algo- experiment were extracted from GeoBeans3D at three levels of
rithms (including our algorithm) when performed on GPUs. LOD. The terrain resolution is 6 m in LOD1, 2.5 m in LOD2, and
Comparing the performance of the two algorithms run on the 0.6 m in LOD3. For each level, twenty groups of viewpoints and
W. Feng et al. / Computers & Geosciences 75 (2015) 57–65 63
Fig. 10. Frame-rate with different viewpoint altitudes and ranges: (a) viewpoint altitude ¼ 215 m, range¼ 5000 m, frame-rate¼60 fps; and (b) viewpoint altitude ¼123 m,
range¼ 2500 m, frame-rate¼59 fps.
view ranges are randomly chosen as the experimental data, which algorithm. In these methods, the process of viewshed generation is
are tested using the five algorithms. After the computation time is integrated into the render pipeline and DEM interpolation is not
calculated, we calculate the average (Table 3). As shown in Table 3 necessary. Thus, the algorithms are able to maintain a consistent
and Fig. 9, the viewshed analysis algorithms executed on GPUs frame-rate when the viewpoint and view range are changed and
have a better performance than those processed on CPUs. The time additional geometric features are added to the scene. By contrast,
consumption in the five algorithms increases with the terrain re- applications using the traditional algorithms usually have a pre-
solution. However, algorithms executed on GPUs have much less cision loss in frame-rate because most of the processor cores are
slope in Fig. 9. Our viewshed analysis algorithm performed best used to interpolate the DEM terrain rather than render the whole
among the five algorithms tested. scene. However, in our algorithm, rendering the scene is the main
Generally, the time consumption of viewshed analysis increases operation, and the viewshed computation has been combined
with the view range because the larger range incorporates more with this operation; thus, changing the input parameters does not
terrain data and geometry features. However, this scenario has affect the efficiency of viewshed generation. The only process re-
little effect on the shadow map-based algorithm and our quired in our algorithm is to change the position value of the
64 W. Feng et al. / Computers & Geosciences 75 (2015) 57–65
Fig. 11. Comparison of two-point intervisibility and our proposed method. The two lines under the white line are generated using the method of two-point intervisibility.
The green segment of the line is visible, and the red segment is invisible. The results of two-point intervisibility and our method show a consistent match. (For interpretation
of the references to color in this figure legend, the reader is referred to the web version of this article.)
Fig. 12. Illustration of future improvements to our method: (a) indicates the original geometry features and their occlusive volumes; (b) using a culling algorithm to exclude
feature O1, O2, O3 whose occlusive volume is totally included by others; and (c) avoid unnecessary rendering by clamping the limits of the occlusive volume.
viewpoint transmitted into the vertex shader. In Fig. 10, we can method keeps the same with result using two-point intervisibility.
observe that the frame-rate of the application is consistent and Thus, the proposed algorithm is shown to have the same accuracy
stable. The frame-rate remains at a value of approximately 60 as the traditional DEM interpolation algorithm, which is only in-
when we halve the view range and change the altitude of the fluenced by the terrain resolution.
viewpoint. Although the experiment proves that our algorithm can greatly
The performance of an algorithm can be measured based on improve the efficiency and accuracy in the generation of view-
two aspects: efficiency and accuracy. The experimental results sheds, work must still be done to improve its efficiency. Microsoft
above indicate that the proposed algorithm can greatly improve DirectX 11 has increased primitive tessellation in the program-
the efficiency, and additional experiments should be performed to mable rendering pipeline, which enables users to generate new
demonstrate the accuracy of our algorithm. In Section 2, we in- primitives and vertices according to their needs. Therefore, we can
dicated that a flaw of the shadow map-based algorithm is its low transplant the duplication of vertices in the original mesh from the
accuracy. The depth buffer used to store the minimum depth has a
CPU to GPU and process it in parallel with the help of the geo-
maximum resolution of 4096 4096. The shadow map-based al-
metry shader to further improve the efficiency.
gorithm rasterizes the point before identifying its intervisibility.
Applicable for viewshed analyzes in complicated scenes, our
Consequently, the results are visible as aliasing, and their qualifi-
algorithm is a batch-generating process that calculates the view-
cation worsens with increasing view range. Our proposed algo-
shed for all features in the neighboring space of the viewpoint. It is
rithm avoids this flaw by creating an occlusive volume as vector
easy to handle cases in which the geometric features must be
data to identify the intervisibility. The accuracy of our algorithm is
updated by inserting them into and removing them from the
only limited to the original mesh data or DEM as a traditional DEM
feature list. However, as geometric features in the complicated
algorithm, and it will not show a reduction in accuracy at any
scene increase, it is extremely challenging to simulate viewshed
process stage in our algorithm. For the Geobeans3D platform, two-
point intervisibility is utilized, and DEM interpolation is performed analysis, which is reflected in two aspects. First, too many features
to verify the accuracy of our experimental results (Fig. 11). must be rendered and rasterized. The overlapping areas will pro-
Random points A and B with the same view point in our al- duce redundant computations when there are multiple occlusive
gorithm are chosen for two-point intervisibility. The height of the volume objects. Second, because occlusive volumes extend away
view point is 258 m. By overlapping the results, the visible and from casters toward the far plane of the view frustum, they
invisible areas of the two experiments are consistently matched in sometimes cover much of the screen. Therefore, the rasterization
every perspective. That is to say all the points along the result line of occlusive volumes is very expensive. This condition is illustrated
of two-point intervisibility have the same visibility with the result in Fig. 12. However, in the future, we can use a volume-culling
calculated with this proposed method. The points marked with algorithm to eliminate the casters to solve the first issue. To ad-
flag in Fig. 11 are the specialized case. Their visibility using our dress the second issue, we can clamp the extents of the occlusive
W. Feng et al. / Computers & Geosciences 75 (2015) 57–65 65