26
Map Overlay Algorithm

Map Overlay Algorithm. Birch forest Wolves Map 1: Vegetation Map 2: Animals

Embed Size (px)

Citation preview

Page 1: Map Overlay Algorithm. Birch forest Wolves Map 1: Vegetation Map 2: Animals

Map Overlay Algorithm

Page 2: Map Overlay Algorithm. Birch forest Wolves Map 1: Vegetation Map 2: Animals

Birchforest

Wolves

Map 1: Vegetation Map 2: Animals

Page 3: Map Overlay Algorithm. Birch forest Wolves Map 1: Vegetation Map 2: Animals

Birchand wolves

Overlay

Thus we need tofind intersectionsof segments of twoplanar subdivisions

Page 4: Map Overlay Algorithm. Birch forest Wolves Map 1: Vegetation Map 2: Animals

Overlay of two subdivisions

• S1 and S2 are two subdivisions (planar graphs), given in the form of DCEL’s

• Our goal is to compute the DCEL for the overlay O(S1, S2)

• Note: f is a face of O (S1, S2) if and only if there are two faces f1 from S1 and f2 from S2 such that f is the maximal connected component of the intersection f1 and f2

Page 5: Map Overlay Algorithm. Birch forest Wolves Map 1: Vegetation Map 2: Animals

Strategy• Take the union of DCEL’s of S1 and S2

• This union is NOT a valid DCEL (does not represent planar subdivision)

• We need to transform this union into a valid DCEL, i.e. to compute new half-edge records, face records, and vertex records

• For each face record f in O (S1, S2) we also need to report information about faces f1 from S1 and f2 from S2 such that f is the maximal connected component of the intersection f1 and f2

• Recall: any half-edge in DCEL is oriented so that the face it bounds lies to the left. Therefore we can use an unchanged half-edge record from S1 in O(S1, S2) if and only if it is not intersected by any edge from S2, and vice versa

Page 6: Map Overlay Algorithm. Birch forest Wolves Map 1: Vegetation Map 2: Animals

Algorithm - preparation

• By complexity of a subdivision we meanthe num. of vertices + the num. of edges + the num. of faces

• In what follows, k will denote the complexity of D (the resulting subdivision), and n will denote the sum of complexities of S1 and S2

• Note: due to the Euler's formula, the complexity of a connected planar subdivision is O (number of edges)

Page 7: Map Overlay Algorithm. Birch forest Wolves Map 1: Vegetation Map 2: Animals

Algorithm - preparation• Based on the plane sweep algorithm for segment

intersections

• We use it to find intersections of edges from S1 and S2

• Data structures to be used: Q (event queue) and T (status structure) as before

• Additionally, D will be new DCEL

• Together with edges in T, we store pointers to the corresponding half-edges in D

• Initially, D contains the union of DCEL’s of S1 and S2

• During the algorithm, D will be transformed into the correct DCEL for the overlay O (S1, S2)

Page 8: Map Overlay Algorithm. Birch forest Wolves Map 1: Vegetation Map 2: Animals

Algorithm – handling an event point

• We update T and Q as in the case of segment intersection algorithm

• If event point involves segments from only one of S1 or S2, nothing else happens

• If not, we must create new half-edges in D

• This involves several possible case: an edge of S1 crosses and edge of S2

an edge from S1 passes through a vertex of S2 (or vice versa)

a common vertex

Page 9: Map Overlay Algorithm. Birch forest Wolves Map 1: Vegetation Map 2: Animals

Case 1Before After

S1 S2

Similarly in the case of moresegments, going through one point

v – event point

Page 10: Map Overlay Algorithm. Birch forest Wolves Map 1: Vegetation Map 2: Animals

Case 1Before After

S1 S2 S1 S2

v – event point v

Page 11: Map Overlay Algorithm. Birch forest Wolves Map 1: Vegetation Map 2: Animals

Case 1Before After

v – event point v

e1'

e1''

e1e2

e'2

e''2

Updates to D:Next(e'2) = e''1, Next(e''1) = Next (e1), Prev(e'1)= Prev(e1), and so on

Next(e1)

Prev(e1)Clockwise order around v todetermine Next() and Prev()

Page 12: Map Overlay Algorithm. Birch forest Wolves Map 1: Vegetation Map 2: Animals

Case 1After

v

e1'

e1''

e'2

e''2

Clockwise order around v todetermine Next() and Prev()

It takes O(deg v) time todetermine Next() and Prev() relationships around v

It takes constant time to determine Next() and Prev() relationships around every other vertex, involved in the event

Thus, in total (i.e. for all vertices of D)it takes sum of degrees of all vertices of D, which is O(k)

Page 13: Map Overlay Algorithm. Birch forest Wolves Map 1: Vegetation Map 2: Animals

Case 2Before After

S1

S2

v – event point isa vertex of S1

Page 14: Map Overlay Algorithm. Birch forest Wolves Map 1: Vegetation Map 2: Animals

Case 2Before After

S1

S2

v – event point isa vertex of S1

O(k) total time to determine Prev()and Next() relationships

Page 15: Map Overlay Algorithm. Birch forest Wolves Map 1: Vegetation Map 2: Animals

Case 3Before After

S1

S2

event point isa vertex of both S1 and S2

Page 16: Map Overlay Algorithm. Birch forest Wolves Map 1: Vegetation Map 2: Animals

Case 3Before After

S1

S2

event point isa vertex of both S1 and S2

O(k) total time to determine Prev()and Next() relationships

Page 17: Map Overlay Algorithm. Birch forest Wolves Map 1: Vegetation Map 2: Animals

Total Time

• Let k be the complexity of D and n be the sum of complexities of S1 and S2

• Then, according to the time required for the segment intersection algorithm, the previous part of the map overlay algorithm takes O(n log n + k log n) time

Page 18: Map Overlay Algorithm. Birch forest Wolves Map 1: Vegetation Map 2: Animals

Some remarks• During the plane sweep:

1. for each half-edge in D, we can record the corresponding half-edge from S1 or S2 - this will allow us to find the corresponding face record from S1 or S2 by looking at IncidentFace ()

2. for each vertex v of S1 which does not belong to any edge of S2, we can determine a face of S2 that contains it by looking and the edges of S2 in the status T, immediately to the left and to the right of v (and vice versa, for each v of S2)

3. for each vertex we will record the half-edge of D that lies immediately to the left of the vertex with respect to the current position of the sweep line

• By traversing the edges of D, we can find all boundary cycles in O(k) time, where k is the complexity of D

• This will help us to create face records in D

• Moreover, using 1. and 2. from the above, for each new face record we will be able to find faces f1 and f2 of S1 and S2, respectively, such that f is the intersection of f1 and f2

Page 19: Map Overlay Algorithm. Birch forest Wolves Map 1: Vegetation Map 2: Animals

Face records in D• We know all boundary cycles of D

• Problem: which of them are outer boundaries of faces and which are inner cycles, i.e. boundaries of holes inside faces?

• It can be solved as follows

Look at the leftmost vertex of the cycle

If half-edges from the boundary of the cycle, that are incident to this vertex, form an angle < 180o, it is outer cycle, otherwise it is an inner cycle

Page 20: Map Overlay Algorithm. Birch forest Wolves Map 1: Vegetation Map 2: Animals

Face records in D• Another Problem:

which of outer cycles lie in a given inner cycle?

• To decide, we will construct a special graph G as follows:

vertices of G are boundary cycles

additional vertex corresponds to the imaginary outer boundary of the unbounded face

two vertices are joined by an edge if and only if one of the corresponding cycles is the boundary of a hole and the other cycle has a half-edge immediately to the left of the leftmost vertex of that hole cycle

if there is no such half-edge, then the vertex is linked to the vertex, corresponding to the unbounded face

• It takes O(k) time to construct G

Page 21: Map Overlay Algorithm. Birch forest Wolves Map 1: Vegetation Map 2: Animals

Example• Which half-edge is immediately to the left of v?

Sweep linev

e′

e′′

Page 22: Map Overlay Algorithm. Birch forest Wolves Map 1: Vegetation Map 2: Animals

Example

Page 23: Map Overlay Algorithm. Birch forest Wolves Map 1: Vegetation Map 2: Animals

Lemma 2.5

• Each connected component of the graph G corresponds exactly to the set of cycles incident to one face

• Thus, we need to determine connected components of G

• It takes O(k) time to do it (using e.g. a depth-first search)

Page 24: Map Overlay Algorithm. Birch forest Wolves Map 1: Vegetation Map 2: Animals

Total time required for map overlay

• Let n be the sum of complexities of S1 and S2 and k be the complexity of D

• Plan sweep: O (n log n + k log n)

• After the plane sweep:

Finding boundary cycles: O(k)

Constructing the graph: O(k)

Finding connected components of G: O(k)

Thus the total time is still O (n log n + k log n)

Page 25: Map Overlay Algorithm. Birch forest Wolves Map 1: Vegetation Map 2: Animals

Algorithm MAPOVERLAY(S1,S2)Input. S1 and S2 stored as DCEL’s

Output. The overlay of S1 and S2 stored in DCEL D

Copy DCEL’s for S1 and S2 to D

Plane sweep: compute all intersections between edges from S1 and S2

In addition, do the following during the plane sweep:

Update D if the event involves edges of both S1and S2 (create new half-edges and update Next() and Prev() info)

Store the half-edge immediately to the left of the event point at the vertex in D representing it (will be required later to create G)

For each v from S1 which does not belong to any edge of S2, record the face of S2 in which it is contained (and similarly for vertices of S2)

Now D is the DCEL for O(S1,S2), except that the information about the faces has not been computed yet

Page 26: Map Overlay Algorithm. Birch forest Wolves Map 1: Vegetation Map 2: Animals

Determine the boundary cycles in O(S1,S2) by traversing D.

Construct the graph G whose vertices correspond to boundary cycles and whose edges connect each hole cycle to the cycle to the left of its leftmost vertex

Compute connected components of G

For each connected component in G Do

Let C be the unique outer boundary cycle in the component and let f denote the face bounded by this cycle

create a face record for f

set OuterComponent (f) to some half-edge of C

construct the list InnerComponents (f) consisting of pointers to one half-edge in each hole cycle in the component

let the IncidentFace() pointers of all half-edges in the cycles point to the face record of f

End Do

Label each face of O(S1,S2) with the names of the faces of S1 and S2 containing it