EUROGRAPHICS '95 / Frits Post and Martin Göbel (Guest Editors), Blackwell Publishers © Eurographics Association, 1995
Volume 14, (1995), Number 3
Visibility and Dead-Zones in Digital Terrain Maps Daniel Cohen-Or1,2 and Amit Shaked1 School of Mathematical Sciences Tel-Aviv University, Ramat-Aviv 69978, Israel Department of Mathematics and Computer Science Ben Gurion University, Beer Sheva 84015, Israel
Abstract The problem of detecting the visible and hidden areas of a topographic surface from a given viewpoint is well known, and has applications in GIS and other fields. The computational geometry literature is rich with solutions based on a polygonal representation of the surface. This work confronts the problem by working directly on the Digital Elevation Map which represents the terrain surface. We present an algorithm that processes discrete lines of sight from the viewpoint t o the surface perimeter, and tests the unit-sized terrain elements along the discrete cross-sections defined by these lines. The algorithm is very efficient, performing O(n) testing operations, consisting of a few additions and no more than one multiplication each, where n is the number of the terrain elements in the map. Keywords: Digital Terrain Maps, GIS, Terrain Modeling, Discrete Lines, Visibility Maps.
1
Introduction
Given a terrain surface and a viewpoint, the visibility problem is defined as the detection of the portion of the terrain that is visible from the viewpoint. This problem has a large variety of applications in the geographical information systems (GIS). For example, the selection of the best locations for viewpoints, which is important to widely differing tasks like tourism and military monitoring. The visibility from specific points of view is an important tool for path planning, especially in a cluttered environment. For landmark-based navigation the visibility information assists in locating landmarks expected from a certain viewpoint, in an algorithm that iteratively decreases location error. It is important to note that the terrain visibility problem addressed by this paper is not the classical problem of rendering a terrain model through a viewport Since the terrain models are represented by digital maps, the problem can be redefined as a problem of coloring the discrete points of the map which are visible or hidden from a given viewpoint. The digital terrain map is a finite set of points on the terrain surface. The set of points can be the vertices of a polyhedral surface, usually consisting of a triangular irregular subdivision, or it can be regularly spaced in a grid form. The latter case is internally represented by an array of heights which we call digital elevation maps (DEM). An elevation map colored by the colors of the corresponding aerial photograph is called a digital terrain map (DTM). DTMs are usually produced from a pair of stereo photographs and thus they
C-172
D. Cohen-Or et al. / Visibility and Dead-Zones in Digital Terrain Maps
Figure 1: Visibility along the cross-section curve.
is visible,
© Eurographics Association, 1995
as not.
have the high resolution of the original digital photographs. Each point of the DTM is called a texel and contains the height and color values. The DTM representation is an alternative approach to polyhedral terrain representation which usually only approximates the terrain surface. Recently DTMs have gained increasing popularity in the GIS community. The problem of visibility on polyhedral terrains has been addressed in the computational geometry literature. A thorough survey of algorithms for visibility on triangular terrain models can be found in [4]. However, those solutions are too slow for processing digital terrain maps of high resolutions which are equivalent to regular polyhedral terrains consisting of millions of polygons. Although they have low asymptotic time complexities [3], they are non-linear in the number of points and not efficient enough for interactive response time. DTMs require algorithms that exploit their regular and simple structure to treat the huge datasets in interactive time [2, 5]. The algorithm introduced in this paper extracts the visible areas or the dead-zone areas by directly processing the discrete values of the DTM. The visibility problem is closely related to the hidden surface removal problem. A common technique for detecting the visible polygon of a polyhedral terrain exploits the ease and speed of the a-buffer hardware. Each polygon is assigned a unique index. Then, the polygons are rendered unshaded to the frame buffer colored with their index identifier. All polygons which are even partially visible contribute at least one pixel to the frame buffer. Then, the set of visible polygons can be detected by scanning the frame buffer to collect all the indices that were displayed. This technique can be adapted to the visibility of DTMs where the texel’scoordinates are used as its index. However, the viewing parameters must set a very wide angel in order to cover the area in as little as possible projections. The wide angel causes texels in a distance from the center of projection to collapse into a small number of frame buffer pixels. Thus, their visibility test is not exact. On the other hand, using small angles requires several passes of the algorithm to cover the 360 degrees with narrow sections. The algorithm presented in this paper determines the visibility of all the texels of the DTM without use of a special hardware. It gains speed by avoiding the costly mapping of the texels towards the screen. Examining a possible reduction of the problem to a 1.5D visibility problem (Section 2) leads to an algorithm that extracts thin cross-sections of texels, and incrementally determines the visibility of texels in a front to back traversal (Section 3). The complexity of the algorithm is linear in the number of texels of the DTM. On average, every texel is processed twice and the cost of its visibility test is several additions and comparisons, and at most one multiplication (Section 4). In last section of the paper results and conclusions are presented.
2 The 1.5D Visibility Problem Consider the following simplified visibility problem which we call the 1.5D visibility problem. Given a 2D plane with a U horizontal axis and an H vertical axis, and assume each point on the U axis is assigned with one and only one positive H height value. The set of all the height values form a
© Eurographics Association, 1995
D. Cohen-Or et al. / Visibility and Dead-Zones in Digital Terrain Maps
C-173
Figure 2: Determining point visibility by testing the turning-direction of the vector from the previous point to the new one. continuous curve L. Let be some point on the positive H axis (Figure 1). The 1.5D visibility problem in the U H plane is the problem of finding all the points on the curve L which are visible from We say that a point v on the curve is visible from if there exists a straight line segment beginning at such that its first intersection with L is at the point For example, the point while is not. in Figure 1 is visible from In discrete spaces, it is not necessary to determine point-visibility for the complete continuum of real points along the U axis. Instead, we consider a discrete representation of the problem, where the U axis is broken up into a sequence of evenly spaced points. We can also assume that this set is finite. In the following sections we describe an efficient 2D visibility algorithm based on this reduced 1.5D discrete visibility detection.
2.1
Incremental Visibility Detection
In this section we present an incremental algorithm for determining the visibility of the set of points along the discrete representation of L in the positive U direction. Let the series be a discretization of the U axis into uniformly spaced points, where Let be the point on L corresponding to for each i: is the point on the curve which lies vertically under the viewing point The algorithm scans the points starting from and for each point determines whether it is visible from or not. The incremental algorithm is based on the solution to the following problem. Given a 2D vector from point to point and another point does the vector turn to the right (clockwise) or to the left (counterclockwise), with respect to the direction of ? This question can be answered simply by testing the sign of the cross product between the vectors and [6]. This solution can be applied directly to the visibility problem (see Figure 2). If point is known to be visible from the viewpoint then is visible if and only if the vector from to turns counterclockwise with respect to the line of sight from to The cross product between these vectors is where is a unit-vector perpendicular to the plane containing the two vectors, and is the angle between the vectors. Since both vectors are in the U H plane, we can neglect and use the following computation:
But since
we get:
C-174
D. Cohen-Or et al. / Visibility and Dead-Zones in Digital Terrain Maps
© Eurographics Association, 1995
Figure 3: I n c r e m e n t a l stepping along a dead zone. Based on this calculation we can determine the visibility of the points as follows. Let the last visible point detected before and let S be the sign of the cross product:
denote
If then is visible and is updated. Otherwise, if then is hidden from and remains as the last visible point. Then the calculation is repeated for The cost of testing each point using this method is one sign test, two multiplications and three additions. This can be improved by an incremental calculation, observing that the distance between is known to be adjacent points along the U axis is constant. There are two cases. First, if visible,the computation of the next point can be simplified because Equation 1 yields:
Thus, the cost of testing each point in a sequence of visible points is reduced to one comparison, one multiplication and three additions. The other case is where is a hidden point. Assuming that the last visible point that was detected is where then the value of the cross product computed for the following point can be obtained by adding a difference value to the previous cross product which The calculation of was computed for Let be the value of the cross product for based on Equation 1 is:
Thus, by incrementally evaluating the cost of testing the visibility of one point is reduced to one comparison, four additions, and one multiplication. This cost can further be reduced by examining more carefully the details of the “dead-zone”traversal. Once the above incremental search algorithm encounters a non-visible point, each of the following points along the cross-section will not be visible as long as their heights are below the line-of-sight defined by the last visible point (see Figure 3). Therefore, once the algorithm detects a non-visible point, it switches to a dead-zone mode for testing the following points, until a visible point is encountered again. Suppose that is visible, and the next point is non-visible. When the algorithm
© Eurographics Association, 1995
C-175
D. Cohen-Or et al. / Visibility and Dead-Zones in Digital Terrain Maps
Figure 4: T h e algorithm f o r detecting t h e hidden points along t h e discrete curve L , f r o m determines that
is not visible, the slope m of the line-of-sight from
to
Pi
to
is computed:
and since the length of the step in the U direction to the next point is one, the height of the ray over is For each of the following points starting with we only need to add the slope to the current height of the ray, and to compare the result to the height of the point. As a result, the cost of testing each point in the traversal of the dead-zone is only one comparison and one addition. This computation is more efficient than the incremental computation given by Equation 4. However, we have to remember that upon altering to the dead zone traversal, we pay the cost of a division operation for the computation of slope m. The discussion so far can be summarized in the pseudo-C code of an algorithm that detects the hidden points along the discrete curve L , presented in Figure 4. Assume that the last U coordinate of is and that the function marks the point as a non-visible point.
3
DTM Visibility Detection
The visibility problem on DTM is a 2.5D problem, since the DTM data represents a terrain-surface over a rectangle in the XY plane, such that above each point in the rectangle there is exactly one surface point, with height Let E be a plane going through and perpendicular to the XY plane. We can define a 2D coordinate system for E as follows. Let the point be the projection of on the XY plane. The vertical line emanating from perpendicularly to the XY plane defines the vertical (H) axis. The horizontal (U) axis is defined by the intersection of the E and the XY plane (see Figure 5 ) . The intersection between E and the terrain surface defines a curve L , preserving the property that above each point u on the U axis there is exactly one point on the curve, with height h(u). Let be some viewpoint for which the visibility problem should be solved, and let be the projection of on the XY plane. For a given point on the terrain perimeter, we can define a U H coordinate system by defining a plane, denoted as the plane which contains the three
C-176
D. Cohen-Or et al. / Visibility and Dead-Zones in Digital Terrain Maps
© Eurographics Association, 1995
Figure 5: The discrete DTM cross-section defined by texel t , with respect t o viewpoint points and The intersection of the terrain surface with is a curve is termed the continuous cross-section defined by with respect to the viewpoint The union of all the continuous cross-sections, defined by all the points on the terrain perimeter, is equal to the terrain surface. In this paper we deal with a discrete representation of the terrain, and therefore instead of solving the visibility problem for a continuous terrain surface, we solve a discrete problem in which the terrain is represented by a rectangular mesh of the unit-sized texels of the DTM data. Each of the texels is defined by its location on the XY plane, and has a height value h and a color associated with it. Thus, we need to redefine the definitions for a discrete cross-section. Let t be a texel on the DTM As shown above, t defines a continuous cross section with respect to perimeter, at location is defined as the connected set of texels which are the viewpoint The discrete cross-section intersected by the continuous cross-section (see Figure 5). Hence, for a given viewpoint each texel t on the DTM perimeter defines a discrete cross-section Let be the finite set of all the discrete cross-sections defined by all the texels on the DTM perimeter, with respect to It is easy to see that for any the DTM is covered by the set in the sense that for any given texel in the DTM, there is at least one cross-section in that contains that texel. In other words, the discrete representation of the lines emanating from towards the perimeter texels are dense, and leave no empty gaps. Let be the number of texels on the DTM perimeter, which is also the number of discrete cross-sections in the set By treating the D TM as a union of a finite set of discrete cross-sections, the 2.5D visibility problem can be reduced to a series of 1.5D problems, each of which can be solved using the incremental algorithm described above. Consider a cross section defined by a texel t , at location on the X Y plane. The set of texels along the discrete cross section does not fully represent the set of points along the continuous line-of-sight between and because of the nature of the discrete lines. The discrete lines which form the basis of the DTM cross sections can be represented either by 4-connected 2D lines, or by 8-connected 2D lines. There is a tradeoff between the two representations. Using 8-connected lines may cause the algorithm to skip texels along the line, thus hidden texels may be marked as visible. On the other hand, using 4-connected lines might cause a texel to falsely hide another texel. These minor inaccuracies are inherent in the discrete nature of the problem, and are insignificant for most applications, therefore the 8-connected representation was preferred merely because it uses less discrete points that the 4-connected representation. The length of the discrete 8-connected line from to is while For the sake of efficiency 8-connected the length of its associated 4-connected line is lines are preferable since they contain less texels than their 4-connected counterparts. In any case,
© Eurographics Association, 1995
D. Cohen-Or et al. / Visibility and Dead-Zones in Digital Terrain Maps
C-177
Figure 6: T h e location of the viewpoint i n the corner of the D T M yields the worst case i n terms of the total lengths of the discrete lines. these distances are measured in texel units, while the physical distance is the Euclidean distance. This implies that the size of the step between adjacent samples along the discrete cross-section is not a unit-distance, and might be scaled up by a factor of up to 1.4. This is compensated by scaling the height of the viewpoint respectively, so that the ratio of the height of the ray to the size of a step is preserved. Concluding this discussion, the structure of the algorithm is as follows. Given a viewpoint for each texel t on the DTM perimeter the algorithm generates the discrete cross-section defined by t . The 1.5D discrete visibility problem is solved for using the procedure described in Section 4. During the processing of each cross-section, the texel-testing operation is interleaved with the generation of the steps along the discrete cross-section. In every step, the algorithm generates the coordinates of the next point along the discrete line using forward differencing and a midpoint technique [1]. Since the cost of each texel-testing operation is one comparison plus one multiplication plus two additions per visible texel, and one comparison plus one addition per hidden texel, the overall cost of computing the visible/hidden areas decreases as the area of the dead zones increases. However, the total cost of the texel-testing operations has to account for and include the operations needed for generating the 8-connected lines, which is two additions and one sign test per texel.
4
The Algorithm Cost
The development of the new visibility algorithm was motivated by the need for a fast and efficient computation, which enables an interactive operation. In this section we show that the complexity of the algorithm is linear in the number of DTM texels. This is asserted by showing that the average of the number of times the texels are tested is bounded by a constant. Since it was shown above that the cost of each texel-examination is no more than a small constant number of arithmetic operations, the overall complexity is O(n). In the algorithm, each DTM texel is covered by a discrete line, emanating from the viewpoint and ending in a perimeter texel. Of course, some texels may be visited by more than one discrete line. Texels closer to the viewpoint are covered by a number of lines proportional to Therefore, the number of times a texel is tested cannot be bounded by a constant. However, the total number of texels that are tested by the algorithm can be obtained by evaluating the length of each discrete line, and summing for all the lines used to cover the DTM. Since the algorithm generates a discrete line from the viewpoint to each texel on the DTM perimeter, the number of lines is equal to the number of perimeter texels. Lets and denote the DTM width and length in texels. The total number of lines generated by the algorithm is exactly The discrete lines are 8-connected, therefore the length of a line from to is The worst case, in terms of the total lines length, occurs when the viewpoint is located
D. Cohen-Or et al. / Visibility and Dead-Zones in Digital Terrain Maps
C-178
© Eurographics Association, 1995
Table 1: The average number of times each texel was tested in four test-case DTM maps, with different locations of the viewpoint. at one of the corners of the DTM, as illustrated in Figure 6. In this case, the length of a line from the viewpoint to a perimeter texel on an opposite edge (a or b in Figure 6 ) is at least and at most The lengths of the lines from the viewpoint to the texels on the adjacent edges of the DTM (c or d in Figure 6) are: Then the sum of the lengths of lines Without loss of generality, let us assume that to texels on both adjacent edges is bounded by The number of lines to the texels on the Let n be the opposite edges is bounded by and the length of each line is bounded by number of DTM texels and T(n) denote the worst case number of texels tested by the algorithm:
But
is
therefore:
The best case is obtained when the viewpoint is located in the middle of the DTM, and the width and length of the DTM are equal. In that case, the length of each discrete line is yielding:
The different cases indicate that the average texel is tested between two and three. This conclusion is supported by experimental results, as shown in Table 1 which presents results for the test case shown in Figure 9, and other test cases. Of course, each texel must be visited at least once, otherwise a texel which was not visited might actually occlude a texel that we marked as visible. Therefore, the lower bound is: It is important to note that the computational complexity does not depend on the model complexity, and the upper bound for the number of operations is the same for any area structure. However, when we test visibiIity from a point that has a lot of dead areas, the cost is lower. Thus, a flat terrain surface is likely to be processed longer than a ragged terrain surface with valleys and mountains.
5
Final Remarks
The visibility algorithm was implemented on a silicon graphics workstation with a system that can read a DTM and interactively create a map of the visible areas and deadzone areas from a user-specified location and height. Figure 8*presents an example of a synthetic 512 x 512 DTM database, made up by three building-like objects of different heights and colors placed on a flat surface. The time required to create the deadzone map is approximately two seconds, on an silicon graphics “indy” workstation. Figure 9*shows an example of a sampled DTM dataset, and Figure 7 presents a sketch describing the dataset’sgeography, and three examples of deadzone maps from different viewpoints.
* See pages C-486 and C-487 for Figures 8 and 9.
©Eurographics Association, 1995
D. Cohen-Or et al. / Visibility and Dead-Zones in Digital Terrain Maps
C-179
Figure 7: Examples of Deadzone maps (a) DTM structure:1. a hill; 2. a flat hill; 3. a valley; 4. a climbing surface; 5. a hollow. (b) View from the top of a hill. (c) View from the valley. (d) View from the bottom of the hollow.
C-180
D. Cohen-Or et al. / Visibility and Dead-Zones in Digital Terrain Maps
© Eurographics Association, 1995
Unlike previously known algorithms that approximate the DTM with a polygon mesh, our algorithm improves running time by operating directly on the DTM with an incremental algorithm. We have introduced the concept of discrete cross-sections, by which we reduced the problem from a 2.5D to a series of 1.5D problems. We have shown that the algorithm performs in time complexity linear to the number of texels. It is important to note that the implementation is purely software based, and is independent of any hardware or architecture. The algorithm was implemented in a portable user-interactive system, and due to the efficiency of the algorithm, the system performs in interactive response times.
References 1. J. R. Van Aken and M. Novak. Curve-drawing algorithms for raster displays. ACM Transactions on Graphics, 4(2):147-169, April 1985. 2. D. Cohen and A. Shaked. Photo-realistic imaging of digital terrains. Computer Graphics Forum, 12(3):363-373, 1993. 3. R. Cole and M. Sharir. Visibility problems for polyhedral terains. Journal of Symbolic Computation, 7:11-30, 1989. 4. Leila De Floriani and Paola Magillo. Visibility algorithms on triangulated digital terrain models. International Journal of GIS, 8(1):13-41, 1994. 5. A. Kaufman, D. Cohen, and R. Yagel. Volume graphics. IEEE Computer, 26(7):51-64, July 1993.
6. F. P. Preparata and M. I. Shamos. Computational Geometry: A n Intoduction. Springer-Verlag, New York, 1985.