Einführung in Visual Computing 186.822 Polygon Filling Werner Purgathofer
Linked Lists flexible data structure … x 1 x 2 pointer data (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 2 3 4 5 list = list^.next Werner Purgathofer / Einf. in Visual Computing 3
Linked Lists: Inserting New First Element list 1 2 3 4 5 new 0 new^.next = list Werner Purgathofer / Einf. in Visual Computing 4
Linked Lists: Inserting New First Element list 1 2 3 4 5 new 0 new^.next = list list = new Werner Purgathofer / Einf. in Visual Computing 5
Linked Lists: Exchanging Elements 2 & 4 last1 help last2 list 1 2 3 4 5 help = last1^.next^.next Werner Purgathofer / Einf. in Visual Computing 6
Linked Lists: Exchanging Elements 2 & 4 last1 help last2 list 1 2 3 4 5 help = last1^.next^.next last1^.next^.next = last2^.next^.next Werner Purgathofer / Einf. in Visual Computing 7
Linked Lists: Exchanging Elements 2 & 4 last1 help last2 list 1 2 3 4 5 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 last1 help last2 list 1 2 3 4 5 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 last1 help last2 list 2 3 4 5 1 help = last1^.next^.next last1^.next^.next = last2^.next^.next last2^.next^.next = help help = last1^.next last1^.next = last2^.next Werner Purgathofer / Einf. in Visual Computing 10
Linked Lists: Exchanging Elements 2 & 4 last1 help last2 list 1 2 4 5 3 help = last1^.next^.next last1^.next^.next = last2^.next^.next last2^.next^.next = help help = last1^.next last1^.next = last2^.next last2^.next = help Werner Purgathofer / Einf. in Visual Computing 11
Repetition: What is Inside a Polygon? odd-even rule nonzero-winding- number rule ??? Werner Purgathofer / Einf. in Visual Computing 12
Inside-Outside Tests area-filling algorithms “interior”, “exterior” for self-intersecting polygons? odd-even rule nonzero-winding-number rule same result for simple polygons Werner Purgathofer / Einf. in Visual Computing 13
What is Inside?: Odd-Even Rule inside/outside switches at every edge straight line to the outside: even # edge intersections = outside odd # edge intersections = inside 4 3 2 1 2 1 2 1 4 3 1 1 2 3 Werner Purgathofer / Einf. in Visual Computing 14
What is Inside?: Nonzero Winding Number point is inside if polygon surrounds it straight line to the outside: same # edges up and down = outside different # edges up and down = inside Werner Purgathofer / Einf. in Visual Computing 15
Fill-Area Primitives for polygon area (solid-color, patterned) scan-line polygon fill algorithm intersection points located and sorted consecutive pairs define interior span attention with vertex intersections exploit coherence (incremental calculations) flood fill algorithm Werner Purgathofer / Einf. in Visual Computing 16
Scan-Line Fill: Sorted Edge Table E y E x D 1/m DE D B y B x C 1/m CB y D x C 1/m CD C F y E x F 1/m FE y F x A 1/m AF y B x A 1/m AB A The sorted edge table contains all polygon edges sorted by lowest y-value y max x start 1/m Werner Purgathofer / Einf. in Visual Computing 17
Scan-Line Fill: Sorted Edge Table sort all edges by smallest y-value edge entry: [max. y-value, x-intercept, inverse slope] y B x C 1/m CB y D x C 1/m CD active-edge list for each 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 y E x D 1/m DE D B y B x C 1/m CB y D x C 1/m CD C F y E x F 1/m FE y F x A 1/m AF y B x A 1/m AB A The sorted edge table contains all polygon edges sorted by lowest y-value y max x start 1/m Werner Purgathofer / Einf. in Visual Computing 19
Sorted Edge Table / Active Edge List E y E x D 1/m DE D B y B x C 1/m CB y D x C 1/m CD C F y E x F 1/m FE y F x A 1/m AF y B x A 1/m AB A Active Edge List When processing from bottom to top, keep a list of all active edges Werner Purgathofer / Einf. in Visual Computing 20
Sorted Edge Table / Active Edge List E y E x D 1/m DE D B y B x C 1/m CB y D x C 1/m CD C F y E x F 1/m FE y F x A 1/m AF 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 y E x D 1/m DE D B y B x C 1/m CB y D x C 1/m CD C F y E x F 1/m FE y F x A 1/m AF 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 y E x D 1/m DE D B y B x C 1/m CB y D x C 1/m CD C F y E x F 1/m FE y F x A 1/m AF 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 y E x D 1/m DE D B y B x C 1/m CB y D x C 1/m CD C F y E x F 1/m FE y F x A 1/m AF 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 y E x D 1/m DE D B y B x C 1/m CB y D x C 1/m CD C F y E x F 1/m FE y F x A 1/m AF 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 y E x D 1/m DE D B y B x C 1/m CB y D x C 1/m CD C F y E x F 1/m FE y F x A 1/m AF 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 y E x D 1/m DE D B y B x C 1/m CB y D x C 1/m CD C F y E x F 1/m FE y F x A 1/m AF 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 y E x D 1/m DE D B y B x C 1/m CB y D x C 1/m CD C F y E x F 1/m FE y F x A 1/m AF 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 y E x D 1/m DE D B y B x C 1/m CB y D x C 1/m CD C F y E x F 1/m FE y F x A 1/m AF 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 y E x D 1/m DE D B y B x C 1/m CB y D x C 1/m CD C F y E x F 1/m FE y F x A 1/m AF 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 y E x D 1/m DE D B y B x C 1/m CB y D x C 1/m CD C F y E x F 1/m FE y F x A 1/m AF 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
Sorted Edge Table / Active Edge List E y E x D 1/m DE D B y B x C 1/m CB y D x C 1/m CD C F y E x F 1/m FE y F x A 1/m AF y B x A 1/m AB A Active Edge List Werner Purgathofer / Einf. in Visual Computing 32
Scan-Line Fill: Incremental Update incremental update of intersection point slope of polygon boundary line: m 1 = + = + x x y y 1 m k+1 k k+1 k (for 2 successive scanlines) (x k+1 , y k+1 ) y k + 1 (x k , y k ) y k Werner Purgathofer / Einf. in Visual Computing 33
Scan-Line Fill: Intersecting Vertices 2 intersection 1 points along scan lines that 1 2 intersect polygon 2 vertices → either special handling (1 or 2 intersections?) → or move vertices up or down by ε Werner Purgathofer / Einf. in Visual Computing 34
Flood-Fill Algorithm pixel filling of area areas with no single color boundary start from interior point “flood” internal region 4-connected, 8-connected areas reduce stack size by eliminating several recursive calls Werner Purgathofer / Einf. in Visual Computing 35
Flood-Fill: Boundary and Seed Point area must be distinguishable from boundaries seed point example: area defined within multiple color boundaries Werner Purgathofer / Einf. in Visual Computing 36
Flood-Fill: Connectedness Definition: Definition: 4-connected means, that a 8-connected means, that a connection is only valid in connection is valid in these these 4 directions 8 directions Werner Purgathofer / Einf. in Visual Computing 37
Examples for 4-connected and 8-connected a 4-connected area an 8-connected area has an 8-connected border has a 4-connected border Werner Purgathofer / Einf. in Visual Computing 38
Recommend
More recommend