Einführung in Visual Computing g p g 186.822 P l Polygon Filling Filli Werner Purgathofer Werner Purgathofer
Linked Lists fl flexible data structure ibl d … x 1 x 2 pointer data (link to next element) (link to next element) list^ list^.next^ list … … … x 1 x 2 x 1 x 2 x 1 x 2 list^.next list^.next^.next Werner Purgathofer / Einf. in Visual Computing 2
Linked Lists: Removal of First Element list 1 1 2 2 3 3 4 4 5 5 list = list^.next Werner Purgathofer / Einf. in Visual Computing 3
Linked Lists: Inserting New First Element g list 1 1 2 2 3 3 4 4 5 5 new 0 new^.next = list Werner Purgathofer / Einf. in Visual Computing 4
Linked Lists: Inserting New 1 st Element g list 1 1 2 2 3 3 4 4 5 5 new 0 new^.next = list list = new Werner Purgathofer / Einf. in Visual Computing 5
Linked Lists: Exchanging Elements 2 & 4 g g help last2 last1 list list 1 2 3 4 5 help = last1^ next^ next help = last1 .next .next Werner Purgathofer / Einf. in Visual Computing 6
Linked Lists: Exchanging Elements 2 & 4 g g help last2 last1 list list 1 2 3 4 5 help = last1^ next^ next help = last1 .next .next last1^.next^.next = last2^.next^.next Werner Purgathofer / Einf. in Visual Computing 7
Linked Lists: Exchanging Elements 2 & 4 g g help last2 last1 list list 1 2 3 4 5 help = last1^ next^ next help = last1 .next .next last1^.next^.next = last2^.next^.next last2^.next^.next = help Werner Purgathofer / Einf. in Visual Computing 8
Linked Lists: Exchanging Elements 2 & 4 g g help last2 last1 list list 1 2 3 4 5 help = last1^ next^ next help = last1 .next .next last1^.next^.next = last2^.next^.next last2^.next^.next = help help = last1^.next Werner Purgathofer / Einf. in Visual Computing 9
Linked Lists: Exchanging Elements 2 & 4 g g help last2 last1 list list 1 2 3 4 5 help = last1^ next^ next help = last1 .next .next last1^.next^.next = last2^.next^.next ast . e t . e t ast . e t . e t last2^.next^.next = help help = last1^.next l last1^.next = last2^.next 1^ l 2^ Werner Purgathofer / Einf. in Visual Computing 10
Linked Lists: Exchanging Elements 2 & 4 g g help last2 last1 list list 1 2 3 4 5 help = last1^ next^ next help = last1 .next .next last1^.next^.next = last2^.next^.next ast . e t . e t ast . e t . e t last2^.next^.next = help help = last1^.next l last1^.next = last2^.next 1^ l 2^ last2^ next = help last2 .next = help Werner Purgathofer / Einf. in Visual Computing 11
Repetition: What is Inside a Polygon? p yg odd-even rule odd even rule nonzero-winding- number rule nonzero winding number rule ??? ??? Werner Purgathofer / Einf. in Visual Computing 12
Inside ‐ Outside Tests area ‐ filling algorithms filli l i h “interior” “exterior” for self intersecting polygons? “interior”, “exterior” for self ‐ intersecting polygons? odd ‐ even rule odd even rule nonzero ‐ winding ‐ number rule g same result for simple polygons Werner Purgathofer / Einf. in Visual Computing 13
What is Inside?: Odd ‐ Even Rule inside/outside switches at every edge i id / id i h d straight line to the outside: t i ht li t th t id even # edge intersections = outside even # edge intersections = outside odd # edge intersections = inside odd # edge intersections inside 4 3 2 2 1 2 1 2 1 4 3 1 1 2 2 3 Werner Purgathofer / Einf. in Visual Computing 14
What is Inside?: Nonzero Winding Number g point is inside if polygon surrounds it i i i id if l d i straight line to the outside: t i ht li t th t id same # edges up and down = outside same # edges up and down = outside different # edges up and down = inside different # edges up and down inside Werner Purgathofer / Einf. in Visual Computing 15
Fill ‐ Area Primitives for polygon area (solid color patterned) for polygon area (solid ‐ color, patterned) scan ‐ line polygon fill algorithm sca e po ygo a go intersection points located and sorted consecutive pairs define interior span attention with vertex intersections attention with vertex intersections exploit coherence (incremental calculations) exploit coherence (incremental calculations) flood fill algorithm Werner Purgathofer / Einf. in Visual Computing 16
Scan ‐ Line Fill: Sorted Edge Table g E E y E x D 1/m DE D D B B y B x C 1/m CB y D x C 1/m CD C C F F y E x F 1/m FE y x 1/m y F x A 1/m AF y F x A 1/m AF y B x A 1/m AB y B x A 1/m AB A The sorted edge table contains all polygon edges Th t d d t bl t i ll l d sorted by lowest y value sorted by lowest y-value y y max x start 1/m x t t 1/m Werner Purgathofer / Einf. in Visual Computing 17
Scan ‐ Line Fill: Sorted Edge Table g sort all edges by smallest y ‐ value t ll d b ll t l edge entry: edge entry: [max y ‐ value, x ‐ intercept, inverse slope] [ y p p ] y B x C 1/m CB y B x C 1/m CB y D x C 1/m CD y D x C 1/m CD active ‐ edge list for each scan line for each scan line contains all edges crossed by that scan line contains all edges crossed by that scan line incremental update consecutive intersection pairs (spans) filled Werner Purgathofer / Einf. in Visual Computing 18
Sorted Edge Table E E y E x D 1/m DE D D B B y B x C 1/m CB y D x C 1/m CD C C F F y y E x F 1/m FE x 1/m y F x A 1/m AF y F x A 1/m AF y B x A 1/m AB y B x A 1/m AB A The sorted edge table contains all polygon edges Th t d d t bl t i ll l d sorted by lowest y value sorted by lowest y-value y y max x start 1/m x t t 1/m Werner Purgathofer / Einf. in Visual Computing 19
Sorted Edge Table / Active Edge List E E y E x D 1/m DE D D B B y B x C 1/m CB y D x C 1/m CD C C F F y E x F 1/m FE y x 1/m y F x A 1/m AF y F x A 1/m AF y B x A 1/m AB y B x A 1/m AB A Active Edge List When processing from bottom to t top, keep a list of all active edges k li t f ll ti d Werner Purgathofer / Einf. in Visual Computing 20
Sorted Edge Table / Active Edge List E E y E x D 1/m DE D D B B y B x C 1/m CB y D x C 1/m CD C C F F y y E x F 1/m FE x 1/m y F x A 1/m AF y F x A 1/m AF y B x A 1/m AB y B x A 1/m AB A Active Edge List incremental update! y F x A 1/m AF y B x A 1/m AB Werner Purgathofer / Einf. in Visual Computing 21
Sorted Edge Table / Active Edge List E E y E x D 1/m DE D D B B y B x C 1/m CB y D x C 1/m CD C C F F y y E x F 1/m FE x 1/m y F x A 1/m AF y F x A 1/m AF y B x A 1/m AB y B x A 1/m AB A Active Edge List y F x A 1/m AF y B x A 1/m AB Werner Purgathofer / Einf. in Visual Computing 22
Sorted Edge Table / Active Edge List E E y E x D 1/m DE D D B B y B x C 1/m CB y D x C 1/m CD C C F F y y E x F 1/m FE x 1/m y F x A 1/m AF y F x A 1/m AF y B x A 1/m AB y B x A 1/m AB A Active Edge List y E x F 1/m FE y B x A 1/m AB Werner Purgathofer / Einf. in Visual Computing 23
Sorted Edge Table / Active Edge List E E y E x D 1/m DE D D B B y B x C 1/m CB y D x C 1/m CD C C F F y y E x F 1/m FE x 1/m y F x A 1/m AF y F x A 1/m AF y B x A 1/m AB y B x A 1/m AB A Active Edge List y E x F 1/m FE y B x A 1/m AB Werner Purgathofer / Einf. in Visual Computing 24
Sorted Edge Table / Active Edge List E E y E x D 1/m DE D D B B y B x C 1/m CB y D x C 1/m CD C C F F y y E x F 1/m FE x 1/m y F x A 1/m AF y F x A 1/m AF y B x A 1/m AB y B x A 1/m AB A Active Edge List y E x F 1/m FE y B x A 1/m AB Werner Purgathofer / Einf. in Visual Computing 25
Sorted Edge Table / Active Edge List E E y E x D 1/m DE D D B B y B x C 1/m CB y D x C 1/m CD C C F F y y E x F 1/m FE x 1/m y F x A 1/m AF y F x A 1/m AF y B x A 1/m AB y B x A 1/m AB A Active Edge List y E x F 1/m FE y B x A 1/m AB y B x C 1/m CB y D x C 1/m CD Werner Purgathofer / Einf. in Visual Computing 26
Sorted Edge Table / Active Edge List E E y E x D 1/m DE D D B B y B x C 1/m CB y D x C 1/m CD C C F F y y E x F 1/m FE x 1/m y F x A 1/m AF y F x A 1/m AF y B x A 1/m AB y B x A 1/m AB A Active Edge List y E x F 1/m FE y B x A 1/m AB y B x C 1/m CB y D x C 1/m CD Werner Purgathofer / Einf. in Visual Computing 27
Sorted Edge Table / Active Edge List E E y E x D 1/m DE D D B B y B x C 1/m CB y D x C 1/m CD C C F F y y E x F 1/m FE x 1/m y F x A 1/m AF y F x A 1/m AF y B x A 1/m AB y B x A 1/m AB A Active Edge List y E x F 1/m FE y D x C 1/m CD Werner Purgathofer / Einf. in Visual Computing 28
Sorted Edge Table / Active Edge List E E y E x D 1/m DE D D B B y B x C 1/m CB y D x C 1/m CD C C F F y y E x F 1/m FE x 1/m y F x A 1/m AF y F x A 1/m AF y B x A 1/m AB y B x A 1/m AB A Active Edge List y E x F 1/m FE y D x C 1/m CD Werner Purgathofer / Einf. in Visual Computing 29
Sorted Edge Table / Active Edge List E E y E x D 1/m DE D D B B y B x C 1/m CB y D x C 1/m CD C C F F y y E x F 1/m FE x 1/m y F x A 1/m AF y F x A 1/m AF y B x A 1/m AB y B x A 1/m AB A Active Edge List y E x F 1/m FE y E x D 1/m DE Werner Purgathofer / Einf. in Visual Computing 30
Sorted Edge Table / Active Edge List E E y E x D 1/m DE D D B B y B x C 1/m CB y D x C 1/m CD C C F F y y E x F 1/m FE x 1/m y F x A 1/m AF y F x A 1/m AF y B x A 1/m AB y B x A 1/m AB A Active Edge List y E x F 1/m FE y E x D 1/m DE Werner Purgathofer / Einf. in Visual Computing 31
Recommend
More recommend