Problem Definition Problem Definition CG Lecture 5 CG Lecture 5 - - PDF document

problem definition problem definition cg lecture 5 cg
SMART_READER_LITE
LIVE PREVIEW

Problem Definition Problem Definition CG Lecture 5 CG Lecture 5 - - PDF document

Problem Definition Problem Definition CG Lecture 5 CG Lecture 5 Point Location Point Location Preprocess a planar map S. Given a query point q , report the face of S containing q. S 1. Problem definition and motivation A Goal : O (


slide-1
SLIDE 1

1

1

CG Lecture 5 CG Lecture 5 Point Location Point Location

1. Problem definition and motivation 2. Point in polygon queries revisited 3. The slab method 4. The monotone chain method 5. The trapezoidal map method

  • Subdivision properties
  • Random incremental construction
  • Expected complexity analysis

6. The triangulation refinement method

2

Problem Definition Problem Definition

  • Preprocess a planar map S.

Given a query point q, report the face of S containing q.

  • Goal: O(n)-size data structure

that enables O(logn) query time.

  • Application: Region containing

acquired GPS coordinates.

  • Trivial Solution: O(n) query time,

where n is the complexity of the map. (Question: Why is the query time O(n)?)

S

q

A D E G F C B

3

Point in polygon queries revisited Point in polygon queries revisited

  • Problem: preprocess a polygon to quickly answer

whether an input point is inside or outside.

  • Special cases:
  • Convex polygons
  • Star shaped polygons
  • Both processes in O(n) time and storage, query

time O(logn).

  • What about monotone polygons?

4

Preprocessing monotone polygons Preprocessing monotone polygons

  • Compute trapezoidal decomposition in O(n) time.
  • Binary search for x-coordinate.
  • Point is either in, above, or below trapezoid.

5

The slab method The slab method

  • Draw vertical lines through

all the vertices of the subdivision.

  • Store the x-coordinates of the

vertices in an ordered binary tree.

  • Within each slab, sort the

segments separately along y.

  • Query time: O(log n). Quick!
  • Problem: Too delicate

subdivision, of size Θ(n2) in the worst case.

6

Example of the slab method Example of the slab method

Partition is a refinement of original subdivision Partition is a refinement of original subdivision

slide-2
SLIDE 2

2

7

The monotone chain method The monotone chain method

  • Motivation: keep simple query algorithm of slab

method while decreasing storage to O(n).

  • The idea:
  • A binary search is based on the ability to

discriminate our query against the data.

  • Construct a subdivision that allows

discrimination of the query point against it.

  • A point is discriminated against a monotone

chain of p vertices in O(p) time.

  • Construct a monotone complete set of chains.

8

Discriminating against chains Discriminating against chains

  • Complete each chain with horizontal segments to

infinity.

  • Binary search for x-coordinate, and discriminate.

9

Monotone complete set of chains Monotone complete set of chains

  • Let G be a planer subdivision given by a planar

straight line graph (PSLG).

  • Let S = {C1,C2,…,Cr } be a set of chains which are

monotone with respect to the same line L.

  • We call S a monotone complete set of chains for G

if the following properties hold:

  • Property 1: the union of members of S contains G.
  • Property 2: For any two chains Ci and Cj of S, the

vertices of Ci which are not vertices of Cj lie on the same side of Cj.

10

Point location in monotone chains Point location in monotone chains

  • Apply the bisection principle (binary search) to S:
  • Search primitive is a point-chain discrimination:
  • If point lies above current chain, search rest of

chains above current, otherwise search chains below.

  • Each discrimination costs O(logp) if p is the

length of longest chain.

  • If there are r chains, then total cost for search is

O(logr*logp).

  • Worst case is O(log2n).

11

Regular graphs Regular graphs

  • Question: can we find a monotone complete set of

chains for any planar graph G?

  • Answer: no, only for regular graphs.
  • Definition: Let {v1,…,vn} be the vertices of G,

sorted such that i < j iff either viy < vjy or viy = vjy and vix > vjx. A vertex vj is regular if there are integers i < j < k such that (vi,vj) and (vj,vk) are edges of G. Graph G is regular if each vj is regular, 1 < j < n.

  • Theorem 1: a regular graph admits a complete set
  • f chains monotone with respect to the y-direction.

12

Example: regular graphs Example: regular graphs

slide-3
SLIDE 3

3

13

Proof of theorem, part I Proof of theorem, part I

  • Imagine edge (vi,vj) is directed from vi to vj if i < j.
  • Define In(vj) and Out(vj) to be the set of incoming

and outgoing edges, respectively.

  • Lemma: for any vj (j > 1) we can construct a y-

monotone chain from v1 to vj.

  • Proof: by induction on j.
  • Define the weight of edge e, W(e), to be number of

chains to which e belongs.

  • Define incoming and outgoing weights of vertex v,

Win(v) and Wout(v), to be sum of incoming and

  • utgoing edge weights.

14

Proof of theorem, part II Proof of theorem, part II

  • To complete proof, the set of chains must meet

the following conditions:

  • 1. Each edge has positive weight.
  • 2. For each vj (j ≠ 1,n): Win(vj) = Wout(vj).
  • Condition 1 ensures property 1.
  • Condition 2 ensures we can choose the chain so

that they do not cross at vj (property 2).

  • Weight-Balancing-Regular-Graph algorithm:

classical flow problem, solved by two passes on G (forward and backward passes).

  • Forward pass makes outgoing flow equal to

incoming, backward pass does the opposite.

15

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Weight balancing example Weight balancing example

2 3 2 3

16

Total order on chains Total order on chains

C1

1

C2

2

C3

3

C4

4

C5

5

C6

6

C C4

4

C C2

2

C C1

1

C C3

3

C C6

6

C C5

5

17

Regularizing a planar map graph Regularizing a planar map graph

  • Sweepline from top to bottom.
  • Events: vertices of graph.
  • Status: balanced tree on edges intersecting

sweepline, plus pointer to helper vertex for each interval in tree (vertex with lowest y-coordinate above interval).

  • Sweep maintains status structure, identifies non-

regular vertices, and connects them to helper vertex of interval.

  • Two passes, adding upward and downward edges.
  • Complexity: O(n) space and O(nlogn) time.

18

Algorithm complexity Algorithm complexity

  • In the worst case, the graph results in n/2 chains,

each with n/2 vertices.

  • Query in this graph is O(log2n).
  • Storage seems to be O(n2)!
  • Edges shared by several chains have one

representative in search tree, which is the ancestor

  • f all other edges.
  • Store chains using ‘bypass pointers’.
  • Theorem: Point location in n-vertex planar

subdivision can be effected in O(log2n) time using O(n) storage and O(nlogn) preprocessing time.

slide-4
SLIDE 4

4

19

The trapezoidal map The trapezoidal map

  • Also known as a vertical

decomposition.

  • Construct a bounding box.
  • Assume general position:

unique x-coordinates.

  • Extend upward and

downward the vertical line from each vertex until it touches another segment.

  • This works also for non-

crossing line segments.

20

Properties Properties

  • Contains triangles and trapezoids.
  • Each trapezoid or triangle is determined:
  • By two vertices that define vertical sides, and
  • By two segments that define nonvertical sides.
  • A refinement of the original subdivision.

21

Another trapezoidal map Another trapezoidal map

22

Notation Notation

  • Every trapezoid (triangle) ∆ is defined by

top(∆):

a segment.

bottom(∆):

a segment.

leftp(∆):

a segment endpoint (right or left).

rightp(∆):

a segment endpoint (right or left).

  • Five cases for left (right) sides of trapezoid.

23

Five cases for left Five cases for left leftp leftp( (∆ ∆) )

  • Case number five involves the bounding rectangle

R, where leftp is the lower left corner of R.

24

Complexity Complexity

  • Theorem (linear complexity):

A trapezoidal map of n segments contains at most 6n+4 vertices and at most 3n+1 faces.

  • Proof:

Vertices: 2n + 2(2n) + 4 = 6n + 4 ↑ ↑ ↑ ↑ ↑ ↑ Faces: Count leftp(∆). 2n + n + 1 = 3n + 1 ↑ ↑ ↑ ↑ ↑ ↑

  • riginal extensions box
  • riginal extensions box

left left e.p e.p. right . right e.p e.p. box . box

slide-5
SLIDE 5

5

25

Map Data Structure Map Data Structure

  • Possibly by DCEL.
  • An alternative: for each

trapezoid store:

The top and bottom

segments.

The vertices that define its

right and left sides.

The neighboring trapezoids

  • n right and left (up to two

each for general position) .

Denote map structure by M(S).

Note Note: Computing any : Computing any trapezoid from the trapezoid from the trapezoidal structure trapezoidal structure can be done in can be done in constant time. constant time.

27

Search structure: branching rules Search structure: branching rules

  • Assumption: query point q has unique x-coord.
  • Search structure D(S) is a rooted DAG with out-degree 2.
  • Search proceeds at node s as follows:
  • x-nodes: s is a segment endpoint:

If q is to the right of s: go right. If q is to the left of s: go left.

  • y-nodes: s is a the segment itself:

If q is below s: go right. If q is above s: go left.

Search ends in leaf representing a trapezoid. Cross-pointers between leaves and trapezoids.

28

Q1 P1 Q2 P3 S3 B C S1 P2 A S3 S2 D E F G D H Q3 S2 S3 J K

Search structure query example Search structure query example

B A C D E F H G J K

P1 P2 P3 Q1 Q2 Q3 S1 S3 S2 29

Search structure: construction Search structure: construction

  • Find a Bounding Box.
  • Randomly permute the

segments.

  • Insert the segments one by one

into the map.

  • Update the map and search

structure in each insertion.

  • The size of the map is Θ(n).

(This was proven earlier.)

  • The size of the search structure

depends on the order of insertion.

32

Updating the structures Updating the structures

  • Find in the existing structure

the face ∆0 that contains the left endpoint of the new segment.*

  • Find all other trapezoids

∆1,∆2,…, ∆k intersected by this segment by moving to the right. (In each move choose between two options: Up or Down.)

  • Si = {s1,s2,…,si}.
  • Update the map Mi = M(Si) and

the search structure Di = D(Si).

(*) Note (*) Note: Since endpoints may be shared by segments, : Since endpoints may be shared by segments, we need to handle query coinciding with existing vertex. we need to handle query coinciding with existing vertex. ∆0 ∆1

33

Update: simple case Update: simple case

  • The segment is contained

entirely in one trapezoid.

  • In Mi: Split the trapezoid into

four trapezoids.

  • In Di: The leaf will be

replaced by a subtree.

  • Everything is

done in O(1) time.

Pi A Qi B C Si D A B C D T M

Qi Pi

slide-6
SLIDE 6

6

34

  • General Case: The ith

segment intersects with ki>1 trapezoids.

  • Split trapezoids.
  • Merge trapezoids that can

be united.

  • Total update time: O(ki).

Update: general case Update: general case

  • uter trapezoids
  • uter trapezoids

35

Updating Updating D D: Split : Split

  • Each inner

trapezoid in Di is replaced by:

  • Each outer

trapezoid in Di is replaced by:

Si A B Qi A Si B C

slide-7
SLIDE 7

7

42

Expected Depth of Expected Depth of D, D, part III part III

  • Last transition is due to bound on the

harmonic number.

  • Conclusion: the expected point

location query time on the structure D is O(logn).

q

[ ]

. ) log ( ) 3 ( E E

1 1 1 12 1

∑ ∑ ∑ ∑

= = = =

= ≤ ≤ = ⎥ ⎦ ⎤ ⎢ ⎣ ⎡

n i n i n i i i i n i i

n O P X X

43

Expected Size of Expected Size of D D

  • Define an indicator
  • ki: Number of leaves created in the ith step.
  • Si: The set of the first i segments.
  • Average on s:

⎩ ⎨ ⎧ ∆ = ∆

  • therwise

removed is if from disappears 1 ) , ( s M s

i

δ ). 1 ( O analysis) backward (same |) | 4 ( ) , ( ) , ( ] [ E

) ( O 1 1 1

= = ≤ ⎟ ⎟ ⎠ ⎞ ⎜ ⎜ ⎝ ⎛ ∆ = ⎟ ⎟ ⎠ ⎞ ⎜ ⎜ ⎝ ⎛ ∆ =

∑ ∑ ∑ ∑

∈ ∈ ∆ ∈ ∈ ∆ i i i i S s M i S s M i i

M s s k

i i i i

δ δ

44

Expected Size of Expected Size of D D (cont.) (cont.)

  • ki-1: Number of internal nodes created in the ith step.
  • Total size:

↑ ↑ ↑ ↑ leaves internal leaves internal ). ( O E ) ( O ) 1 ( E ) ( O

1 1

n k n k n

n i i n i i

= ⎟ ⎠ ⎞ ⎜ ⎝ ⎛ + = ⎟ ⎠ ⎞ ⎜ ⎝ ⎛ − +

∑ ∑

= =

s

45

Expected Construction Time of Expected Construction Time of D D

( )

) log ( ]) [ E ( O ) (log O

1

n n O k i

n i i

= +

=

Finding the first trapezoid The rest of the work in the ith step

46

Handling Handling degeneracies degeneracies: symbolic perturbation : symbolic perturbation

  • What happens if two segment endpoints have

the same x coordinate?

  • Use a shearing

transformation:

  • Higher points will move more to the right.
  • ε should be small enough so that this

transform will not change the order of two points with different x coordinates.

  • In fact, no need to shear the plane.

Comparison rules mimic the shearing. ⎟ ⎟ ⎠ ⎞ ⎜ ⎜ ⎝ ⎛ + = ⎟ ⎟ ⎠ ⎞ ⎜ ⎜ ⎝ ⎛ y y x y x ε ϕ

47

Correctness of perturbation Correctness of perturbation

  • Algorithm does not compute new geometric
  • bjects: no intersection points found for vertical

lines.

  • Two geometric operations:
  • Check if point lies on, left, or right of a vertical

line.

  • Check if point lies on, above, or below segment

given by endpoints (applied only when known that vertical line through point intersects segment).

  • Semantics of shear transform make computations

correct for degenerate cases!

slide-8
SLIDE 8

8

48

Trapezoidal map summary Trapezoidal map summary

  • Theorem: The trapezoidal map method computes

the map M(S) of a set S of non-crossing line segments and a search structure D(S) in O(nlogn) expected time. The expected size of search structure is O(n) and for any query point the expected query time is O(logn).

  • Tail estimate: the probability of the worst case is

very small.

  • Deterministic algorithm with same properties

exists.

49

Triangulation refinement method Triangulation refinement method

  • Optimal point location data structure

[Kirkpatrick, 1983].

  • Deterministic algorithm.
  • Method useful in other applications.
  • The idea: start with a triangulation of the

planar map, then create a hierarchy of subdivisions with less triangles, with guaranteed depth of O(logn).

50

Algorithm outline Algorithm outline

Algorithm TriangulationRefinment 1. Triangulate all faces of subdivision (keep duplicate labels). 2. Enclose all subdivision in a triangle. 3. Triangulate faces of enclosing triangle. 4. Construct subdivision graph G. 5. Iterate until only enclosing triangle is left: a. Initialize independent set I to be empty. b. Mark all nodes of G with degree ≥ 9. c. While some nodes are unmarked: i. Choose unmarked node v. ii. Mark v and all its neighbors. iii. I = I ∪{v} d. Remove nodes of I from G. e. Re-triangulate created faces. f. Connect new G triangles to overlapped old triangles.

51

Running example: input Running example: input

52

Running example: step 1 Running example: step 1

53

Running example: steps 2,3 Running example: steps 2,3

slide-9
SLIDE 9

9

54

Running example: steps 5a Running example: steps 5a-

  • c

c

55

Running example: step 5d Running example: step 5d

56

Running example: step 5e Running example: step 5e

57

Running example: step 5f Running example: step 5f

58

Running example: query example Running example: query example

59

Algorithm complexity Algorithm complexity

  • Observation: in every level of DAG, triangles are

disjoint, so overall O(n) vertices per level.

  • Lemma: to achieve O(logn) DAG depth, it

suffices to delete a constant fraction of nodes from G at each iteration.

  • Proof:
  • Independent set I of size cn, c < 1.
  • After k steps, we have n(1-c)k nodes left.
  • n(1-c)k = 4 k = logn/-log(1-c) - 2/-log(1-c)
  • Constant times logn minus constant.
  • Example: n=220, c = 1/10 k = 118.
slide-10
SLIDE 10

10

60

Size of independent set Size of independent set

  • Lemma: the independent sets produced by steps

5a-c have size of at least n/18, where n is the number of nodes in the current graph G.

  • Proof:

From Euler’s formula: |E| ≤ 3n–6. Sum of degrees of all nodes: Σ ≤ 6n–12. At least n/2 vertices with degree ≤ 8 (otherwise

we have 9n/2 + 3n/2 = 6n > 6n-12).

m unmarked nodes, at most 9 nodes marked

each time, so |I| ≥ m/9 ≥ n/18.

Corollary: c = 1/18, so depth of DAG is O(logn).

61

Space complexity Space complexity

  • Question: how many nodes in entire DAG?
  • Answer: Each level has at most 17/18 of nodes

from previous level, so total is: |V| = n[(17/18)+(17/18)2+(17/18)3+…+(17/18)k]

  • Bound this summation with infinite series, so:

|DAG| ≤ 1/(1-(1-c))n = n/c = 18n = O(n)

  • Question: how many edges are in the DAG?
  • Answer: each triangle points to overlapping

triangles in lower level: at most 8 triangles, so |E| ≤ 8n = O(n).

  • Large constants in space complexity (can be

reduced)

62

Time complexity Time complexity

  • DAG construction time:
  • Triangulate all faces in linear time.
  • Find independent set in linear time.
  • Remove nodes and re-triangulate in linear time.
  • Construct pointers in linear time.
  • Overall O(n) time for construction.
  • Query time complexity:
  • Constant number of triangle inclusion checks

per node in DAG.

  • O(logn) levels, so total query time is O(logn).

63

Summary Summary

  • Point location in a planar subdivision can be

preprocessed in O(n) space and time for O(logn) query time.

  • Four optimal approaches for this problem:
  • 1. Triangulation refinement [Kirkpatrick, 1983]
  • 2. The chain method [Edelsbrunner, 1986]
  • 3. Persistency-based method [Cole, 1986]
  • 4. Randomized incremental [Mulmuley, 1990]
  • Variants: dynamic point location, higher

dimensions (open problem), curved data.