A Triangulation for Optimal Strip Decomposition in Simple Polygons Siu-Wing Cheng
Jae-Sook Cheong
Department of Computer Science Hong Kong University of Science and Technology E-mail: fscheng,
[email protected]
Abstract
triangle is defined by three data points, thus, 3n data points are needed to render n triangles. A triangle strip is a set of triangles in a triangulation, whose dual graph is a path. (Figure 1 (a)) Hamiltonian triangulation is a triangulation of a polygon that is composed of one triangle strip. (Figure 1 (a)) If the triangles of a triangulation make one strip, triangles in the middle of the strip can be formed incrementally by sending one additional data point at a time; n + 2 data points are needed in this case. Rendering the first triangle needs three data points, but from the second triangle onwards, one new point is enough for rendering the next triangle because the other two points are already defined by the previous triangle. Not all polygons, however, have triangulations that have a single triangle strip. In other words, many polygons do not have Hamiltonian triangulations. For these polygons, data of some vertices have to be sent to the rendering engine more than once. Yet, if we can find the triangulation of a polygon which has a minimum number of triangle strips, the number of duplicated data points will be minimized. This paper introduces an algorithm to construct a triangulation that can be decomposed into a minimum number of triangle strips in a simple polygon. It is a polynomial time (O(n3 )) algorithm, using dynamic program-
In computer graphics, most polygonal surfaces are rendered via triangles. Rendering a set of triangles needs the data of the triangle vertices. Since the speed of rendering is bounded by data rate, reducing the amount of data will make rendering faster. This can be attained by ordering triangles so that consecutive triangles share an edge, that is, only one additional vertex need to be transmitted to describe each triangle. There exists such an order if and only if the dual graph of the triangulation contains a Hamiltonian path. Many polygons, however, do not have Hamiltonian triangulation; they can not be triangulated into a single triangle strip. Triangle strip is a set of triangles whose dual is a Hamiltonian path. This paper introduces an algorithm to construct a triangulation that can be decomposed into minimum number of triangle strips in simple polygons. This algorithm uses dynamic programming techniques and has O(n3 ) time bound.
1 Introduction The triangulation of polygons is an important factor for a fast rendering process in computer graphics, because the speed of a rendering engine is bounded by the data rate. A 1
ming. [4]
is shown in Figure 1 (a). In the dual graph, there are two end nodes with degree one. We will call the triangle corresponding to an end node an ending triangle. A diagonal of P which is incident on exactly one triangle in a triangle strip is called an ending diagonal. In Figure 1 (a), ending triangles are 4v0 v1 v9 , 4v5v6 v7 , and ending diagonals are d01, d09 , d56 , and d67 . As one can see in Figure 1, a dual graph of a triangle strip does not have an edge corresponding to the ending diagonals. Optimal triangulation for optimal strip decomposition of P is a triangulation that has the minimum number of triangle strips. Our goal is to construct such a triangulation.
2 Previous Work The problem of constructing good triangle strips has gained attention from the computer graphics community as well as the computational geometry community. Arkin et al. [2] proved that any set of n points in a general position in a plane has a Hamiltonian triangulation and gave an optimal (n log n)-time algorithm to construct one. In the same paper, Arkin et al. also gave an O(n2 )-time algorithm to test whether or not a simple polygon has a Hamiltonian triangulation, and showed that it is NP-complete for polygons with holes. The O (n2 )-time for constructing a Hamiltonian triangulation was improved to O (n log n) by Narasimhan [6]. Bose and Toussaint [3] have studied the problem of quadrangulation of point sets, and obtained an alternate method of computing Hamiltonian triangulations. Other than these, the problem of the stripification of a triangulation was studied as well. Evans, Skiena, and Varshney [5] gave an algorithm to construct triangle strips from partially triangulated models. Akeley, Haeberli, and Burns [1] have written a program to convert triangle meshes into triangle strips.
4 Algorithm and analysis The proposed algorithm is based on dynamic programming techniques. The size of a polygon is the number of its edges. We first divide a subpolygon, say, P , into two smaller subpolygons: P and P . Then we combine the triangulations for P and P to make that of P . Remember that the triangulations of P and P were already computed, for the sizes of P and P are smaller than that of P . First, we begin with some notations which are used in the algorithm. The triangulation of a subpolygon P is denoted by S , which is a triangulation with the minimum number of triangle strips in P . Besides, S always has diagonal d as an ending diagonal of a triangle strip except only when d never appears as an ending diagonal in any optimal triangulation. A flag ag is used to indicate whether or not d in S is ending diagonal: ag is true if d is an ending diagonal of a triangle strip in S , otherwise it is false. This is used for determining the number of triangle strips of S when combining S and S . The triangulation for subpolygon P that contains 4v v v is denoted by S . The number of triangle strips in S is denoted ij
it
tj
it
tj
ij
it
tj
it
tj
ij
ij
ij
ij
3 Preliminaries
ij
ij
ij
We begin with some basic definitions and notations. P is a given simple polygon composed of vertices v0 ; v1 ; ; v ;1 in clockwise order. The diagonal connecting v and v is denoted by d . We treat the edges of the polygon P , such as d0 1 , as diagonals as well. A subpolygon bounded by d , is denoted by P , and this is composed of the edge chain v ; v +1 ; v ;1 ; v . A triangle strip is a set of triangles in a triangulation, whose dual graph is a path. This n
ij
i
j
ij
ij
;
ij
i
j
ij
ij
ij
i
ij
ij
ij
j
it
tj
ij
i
t
j
itj
itj
2
Algorithm T RIANGULATION F ORO PTIMAL S TRIP D ECOMPOSITION(P) Input: A simple polygon P of n vertices. Output: Triangulation with minimum number of triangle strips of P . 1. for k 0 to n ; 1 2. do ag +1 false 3. N 0 +1 4. endfor 3 to n 5. for k 6. do for each diagonal d where P has k edges 7. do for each vertex v of P that forms a triangle with d 8. do if ag = true and ag = true 9. then N N + N ;1 10.
ag false 11. if ( ag = true and ag = false) or 12. ( ag = false and ag = true) 13. then N N + N 14.
ag true 15. if ag = false and ag = false 16. then N N + N +1 17.
ag true 18. endfor 19. if N is minimum and ag = true for a vertex v 20. then N N 21.
ag true 22. c v 23. else if N is minimum and ag = false for a vertex v 24. then N N 25.
ag false 26. c v 27. endfor 28. endfor 29. return S0 ;1 . k;k
k;k
ij
ij
t
ij
ij
it
tj
itj
it
tj
itj
it
tj
it
tj
itj
it
tj
itj
it
tj
itj
it
tj
itj
itj
t
itj
ij
itj
ij
ij
t
itj
ij
ij
itj
ij
ij
t
;n
3
t
v0
4v0v1v9 v9
v1
4v1v2 v9 4v2v3v9 4v3v8v9 4v3v7 v8 4v3v4 v7 4v4v5v7 4v5v6v7
v8 v7
v2
v3 v5
v4
v6
(a) Hamiltonian triangulation of simple polygon P . v0 v1 v9 and v5 v6 v7 are ending triangles and v0 v1 , v0 v9 , v5 v6 , v6 v7 are ending diagonals of the triangle strip.
4
4
(b) Dual graph of the triangulation in (a)
Figure 1: Triangle strip and its dual graph by N and the flag for S as ag . S is chosen by comparing N and ag for all vertices v in P that form triangles with diagonal d . itj
itj
itj
t
containing d are examined in the algorithm. Among all these possibilities, the combined triangulation that has the minimum number of triangle strips and that has d as an ending diagonal will be chosen as S . If there is no such triangulations, in other words, d is not an ending diagonal in any of the triangulation that has the minimum number of triangle strips, any triangulation with the minimum number of triangle strips will be chosen as S . This process is continued until S0 ;1 is computed. A data structure called c is used to store the vertex, say, v , which forms a triangle with diagonal d in S . This is to trace back the chosen diagonals to form S0 ;1 , the triangulation with minimum number of strips of P. The next theorem will show why this algorithm computes a triangulation of polygon P that can be decomposed into the minimum number of triangle strips.
ij
itj
ij
itj
ij
ij
ij
The computation of N depends on the flags. When both d and d are ending diagonals, that is, both ag and ag are true, 4v v v is in the middle of a triangle strip in the combined triangulation. The number of triangle strips, thus, in the combined triangulation is N + N ; 1. When one of the diagonals is an ending diagonal while the other is not, i.e., only one of the flags is true, 4v v v is an ending triangle in the combined triangulation, thus the number of triangle strips in the combined triangulation is simply addition of N and N . If both d and d are not ending diagonals, which means that both
ag and ag are false, 4v v v cannot be included in any triangle strip of S or S , so this will make a new triangle strip. Therefore, the number of triangle strips in the combined triangulation is N + N + 1. Theorem 1 The concatenation of S and S For a subpolygon P , all possible triangles always satisfies the following two conditions: ij
itj
it
ij
tj
it
i
t
tj
j
it
ij
tj
i
t
;n
ij
j
t
ij
ij
;n
it
it
tj
it
i
tj
t
tj
j
it
it
tj
tj
it
ij
4
tj
vt
(a)
ag = false
ag = false it
tj
vi vj
vt
(b)
ag = false
ag = true it
tj
vi vj
vt (c)
ag = true
ag = true it
tj
vi vj
Figure 2: Three cases when S and S are combined it
produce the triangle 4v ;1 v v +1 itself, which is obviously optimal triangulation with the minimum number of strips of triangle 4v ;1 v v +1 .
(i) it is an optimal triangulation for optimal strip decomposition that contains d and d in it. (ii) d is not an ending diagonal in the concatenation iff d is not an ending diagonal in any triangulation of P that contains d and d and has the minimum number of strips. it
tj
i
tj
ij
ij
i
i
i
i
i
ij
Inductive step : Suppose when the number of edges of P k, S satisfies the two conditions stated above. We will show that S still satisfies them Proof : This will be proved using mathematical induction on k, the size of polygons. when the size of P is k + 1. Let S be the Basis step : Consider a triangle concatenation of S and S , and N be the 4v ;1v v +1 . There are diagonals d ;1 number of triangle strips in S . and d +1 , so we pick v . The concatenation of S ;1 and S +1 in the algorithm will 1. Suppose that N is not minimum. it
tj
ij
ij
ij
ij
itj
it
i
i
i
i
i;i
i
tj
itj
;i
i
;i
itj
i;i
itj
5
vt (a) O : an optimal triangulation with the minimum number of triangle strips that contains diagonal d and d . itj
vi
it
tj
vj
vt
vt
vt
vi
vi
vj
vj (b)
(c)
: after the truncation of with diagonal d .
Oit
Oitj
it
: after the truncation of with diagonal d .
Otj
Oitj
tj
Figure 3: Truncation of O
itj
N X and N X . Case 3, 4, and 5 contradicts this fact, so these cases will be excluded from the possibilities.
Let O be a triangulation with minimum number of triangle strips of subpolygon P that contains d and d in it. Truncate O with diagonal d and d , and let O and O be the truncated O by d and d respectively. (Figure 3) The number of triangle strips in O is denoted by X , and those in O and O by X and X respectively. itj
ij
it
tj
itj
tj
tj
tj
itj
itj
it
tj
it
is one of the three cases: N +N ; + N , or N + N +1. Likewise, X is one of the three cases: X + X ; 1, X + X , or X + X + 1. If we combine the cases, the assumption that X < N can be divided into five cases: 1) X + X < N + N + 2, 2) X + X < N + N + 1, 3) X + X < N + N , 4) X + X < N + N ; 1, 5) X + X < N + N ; 2. it
Nit
tj
it
it
tj
it
it
tj
tj
it
tj
it
it
tj
it
it
tj
tj
it
tj
it
it
tj
it
tj
tj
tj
it
it
tj
tj
tj
tj
tj
it
tj
tj
it
Since N and N are the minimum numbers of triangle strips in P and P , it
it
it
tj
it
tj
it
itj
tj
it
it
tj
it
tj
it
tj
it
tj
itj
tj
Nitj
1,
tj
it
tj
it
it
Case 2 is possible only when X = N and X = N . There are two combinations that result in Case 2: one is when N = N + N +1 and X = X + X , the other is when N = N + N and X = X + X ; 1. In the first case, neither d nor d is ending diagonal in S and S , but either O or O has a triangle strip ending at the corresponding diagonal. This is a contradiction in that S and S satisfy the second condition in the assumption. In the second case, either of d or d is the ending diagonal in S or S , but both O and O have triangle strips that end at the corresponding diagonals. This leads to a contradiction to the assumption as well.
it
it
itj
it
tj
tj
it
tj
Since case 2 is not true, Case 1 is auto-
tj
6
matically false. Therefore, the number S ’s that satisfy the two conditions in Theoof triangle strips in S is minimum. rem 1 will be S . Now, we analyze the time that this algo2. If there is no optimal triangulation of the rithm needs. The two for loops in line 5 and combination of P and P without any 6 will be executed as many times as the numtriangle strip that ends at d , it is trivial ber of diagonals of polygon P , which is at that d is not an ending diagonal in S . most O (n2 ). For each diagonal d , there are Now we use contradiction to prove that at most O (n) vertices that form triangles with if d is not an ending diagonal in S , d (the innermost f or -loop). Hence, the althere is no optimal triangulation that gorithm runs in O (n3 ) time. The storage for ag and N for each dicontains d and d and has d as an ending diagonal. Suppose that there agonal d takes O (n2 ) space. N in the exists an optimal triangulation that in- innermost f or loop can be implemented as cludes d and d and has d as an end- a length-n-array of temporary variables. To ing diagonal. Let this optimal triangu- check whether or not v v is a diagonal, we lation be O . Truncate O with diag- need an n n boolean array. Therefore the onal d and d , and let O and O be algorithm needs O (n2 ) space. 2 the truncated O by d and d respectively. We call the number of triangle strips in O X and those in O and O 5 Discussion will be X and X respectively. (Figure The proposed algorithm constructs a triangu3) lation for a simple polygon with minimum There are two cases in which d is an number of strips in O (n3 ) time. This is not ending diagonal of a triangle strip in a fast algorithm for practical purpose in genO : one is that either of d or d is eral. However, triangulation is done before an ending diagonal in O or O , and rendering process in most cases: time to conthe other is that neither of d nor d is struct the data is not very critical for renderan ending diagonal in O or O . The ing as long as the amount of data is minfirst case leads to the fact that X + Nevertheless a faster algorithm to X = N + N ; 1, which contra- imized. construct such triangulations should be redicts the assumption that N and N are searched more. If it is not easy or possible to minimum. The second case means that find a triangulation with a minimum number X + X + 1 = N + N ; 1, which is of triangle strips, an approximation algorithm also a contradiction for the same reason should be studied. as in the first case. Therefore, S does The same problem in polygons with holes not have a triangle strip that ends at d . is also an area that needs attention: to investigate whether or not it is tractable to construct Thus the concatenation of S and S satisfies a triangulation with a minimum number of the two conditions. 2 strips for such polygons. If it is tractable an Theorem 2 The algorithm computes S0 ;1 algorithm can be proposed, otherwise an approximation algorithm can be devised. in O(n3 ) time and O (n2 ) space. itj
itj
ij
it
tj
ij
ij
itj
ij
ij
ij
itj
it
tj
ij
ij
ij
ij
it
tj
itj
ij
i
itj
it
itj
tj
it
itj
tj
it
tj
itj
it
j
it
tj
tj
ij
itj
it
it
tj
tj
it
tj
it
tj
it
tj
it
tj
it
it
tj
it
tj
tj
itj
ij
it
tj
;n
Proof : S is the optimal triangulation of P with the minimum number of triangle strips, References since the algorithm checks S for all vertices v that form a triangle with d , and one of the [1] K. Akeley, P. Haeberli, and D. Burns. C ij
ij
itj
t
ij
7
Program on SGI Debveloper’s Toolbox CD. 1990. [2] E. M. Arkin, M. Held, J. S. B. Mitchell, and S. S. Skiena. Hamiltonian triangulations for fast rendering. Second Annual European Symposium on Algorithms, 855:36–47, 1994. [3] Prosenjit Bose and Godfried Toussaint. No quadrangulation is extremely odd. In Proc. 6th Annu. Internat. Sympos. Algorithms Comput., volume 1004 of Lecture Notes Comput. Sci., pages 372–381. Springer-Verlag, 1995. [4] Thomas H. Cormen, Charles E. Leiserson, and Ronald L. Rivest. Introduction to Algorithms. MIT Press and McGrawHill Book Company, 6th edition, 1992. [5] F. Evans, Steven S. Skiena, and A. Varshney. Optimizing triangle strips for fast rendering. In IEEE Visualization ’96 Proceedings, pages 319–326, October 1996. [6] G. Narasimhan. On Hamiltonian triangulations in simple polygons. In Proc. 5th Workshop Algorithms Data Struct., volume 1272 of Lecture Notes Comput. Sci., pages 321–330. Springer-Verlag, 1997.
8