polygon filling
play

Polygon Filling Werner Purgathofer Linked Lists flexible data - PDF document

Einfhrung in Visual Computing 186.822 186.822 Polygon Filling Werner Purgathofer Linked Lists flexible data structure x 1 x 2 x 1 x 2 pointer data (link to next element) list^ list list .next list^ next^ list x 1


  1. Einführung in Visual Computing 186.822 186.822 Polygon Filling Werner Purgathofer Linked Lists flexible data structure … x 1 x 2 x 1 x 2 pointer data (link to next element) list^ list list .next list^ next^ list … … … x 1 x 2 x 1 x 2 x 1 x 2 list^.next list^.next^.next 1 Werner Purgathofer / Einf. in Visual Computing 1

  2. Linked Lists: Removal of First Element list 1 1 2 2 3 3 4 4 5 5 list = list^.next 2 Werner Purgathofer / Einf. in Visual Computing Linked Lists: Inserting New 1 st Element list 1 1 2 2 3 3 4 4 5 5 new 0 new^.next = list 3 Werner Purgathofer / Einf. in Visual Computing 2

  3. Linked Lists: Inserting New 1 st Element list 1 1 2 2 3 3 4 4 5 5 new 0 new^.next = list list = new list = new 4 Werner Purgathofer / Einf. in Visual Computing Linked Lists: Exchanging Elements 2 & 4 help last2 last1 list 1 1 2 2 3 3 4 4 5 5 help = last1^.next^.next 5 Werner Purgathofer / Einf. in Visual Computing 3

  4. Linked Lists: Exchanging Elements 2 & 4 help last2 last1 list 1 1 2 2 3 3 4 4 5 5 help = last1^.next^.next last1^.next^.next = last2^.next^.next 6 Werner Purgathofer / Einf. in Visual Computing Linked Lists: Exchanging Elements 2 & 4 help last2 last1 list 1 1 2 2 3 3 4 4 5 5 help = last1^.next^.next last1^.next^.next = last2^.next^.next last2^.next^.next = help 7 Werner Purgathofer / Einf. in Visual Computing 4

  5. Linked Lists: Exchanging Elements 2 & 4 help last2 last1 list 1 1 2 2 3 3 4 4 5 5 help = last1^.next^.next last1^.next^.next = last2^.next^.next last2^.next^.next = help help = last1^.next 8 Werner Purgathofer / Einf. in Visual Computing Linked Lists: Exchanging Elements 2 & 4 help last2 last1 list 1 1 2 2 3 3 4 4 5 5 help = last1^.next^.next last1^.next^.next = last2^.next^.next last2^.next^.next = help help = last1^.next last1^.next = last2^.next 9 Werner Purgathofer / Einf. in Visual Computing 5

  6. Linked Lists: Exchanging Elements 2 & 4 help last2 last1 list 1 1 2 2 3 3 4 4 5 5 help = last1^.next^.next last1^.next^.next = last2^.next^.next last2^.next^.next = help help = last1^.next last1^.next = last2^.next last2^.next = help 10 Werner Purgathofer / Einf. in Visual Computing Fill-Area Primitives for polygon area (solid-color, patterned) scan-line polygon fill algorithm intersection points located and sorted intersection points located and sorted consecutive pairs define interior span attention with vertex intersections exploit coherence (incremental calculations) flood fill algorithm 11 Werner Purgathofer / Einf. in Visual Computing 6

  7. 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 A The sorted edge table contains all polygon edges sorted by lowest y-value y max x start 1/m 12 Werner Purgathofer / Einf. in Visual Computing Scan-Line Fill: Sorted Edge Table sort all edges by smallest y-value edge entry: [max y value x intercept inverse slope] [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 13 Werner Purgathofer / Einf. in Visual Computing 7

  8. 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 A The sorted edge table contains all polygon edges sorted by lowest y-value y max x start 1/m 14 Werner Purgathofer / Einf. in Visual Computing 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 A Active Edge List When processing from bottom to top, keep a list of all active edges 15 Werner Purgathofer / Einf. in Visual Computing 8

  9. 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 A Active Edge List incremental update! y F x A 1/m AF y B x A 1/m AB 16 Werner Purgathofer / Einf. in Visual Computing 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 A Active Edge List y F x A 1/m AF y B x A 1/m AB 17 Werner Purgathofer / Einf. in Visual Computing 9

  10. 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 A Active Edge List y E x F 1/m FE y B x A 1/m AB 18 Werner Purgathofer / Einf. in Visual Computing 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 A Active Edge List y E x F 1/m FE y B x A 1/m AB 19 Werner Purgathofer / Einf. in Visual Computing 10

  11. 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 A Active Edge List y E x F 1/m FE y B x A 1/m AB 20 Werner Purgathofer / Einf. in Visual Computing 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 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 21 Werner Purgathofer / Einf. in Visual Computing 11

  12. 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 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 22 Werner Purgathofer / Einf. in Visual Computing 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 A Active Edge List y E x F 1/m FE y D x C 1/m CD 23 Werner Purgathofer / Einf. in Visual Computing 12

  13. 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 A Active Edge List y E x F 1/m FE y D x C 1/m CD 24 Werner Purgathofer / Einf. in Visual Computing 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 A Active Edge List y E x F 1/m FE y E x D 1/m DE 25 Werner Purgathofer / Einf. in Visual Computing 13

  14. 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 A Active Edge List y E x F 1/m FE y E x D 1/m DE 26 Werner Purgathofer / Einf. in Visual Computing 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 A Active Edge List 27 Werner Purgathofer / Einf. in Visual Computing 14

  15. 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 28 Werner Purgathofer / Einf. in Visual Computing Scan-Line Fill: Intersecting Vertices 2 intersection 1 points along scan lines that li th t 1 1 2 intersect polygon 2 vertices. → either special handling (1 or 2 intersections?) p g ( ) → or move vertices up or down by ε 29 Werner Purgathofer / Einf. in Visual Computing 15

  16. 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 recursive calls 30 Werner Purgathofer / Einf. in Visual Computing Flood-Fill: Boundary and Seed Point area must be distinguishable from boundaries boundaries seed point example: area defined within multiple color boundaries 31 Werner Purgathofer / Einf. in Visual Computing 16

  17. Flood-Fill: Connectedness Definition: Definition: 4-connected means, 8-connected means, that a connection is that a connection is only valid in these 4 valid in these 8 directions directions 32 Werner Purgathofer / Einf. in Visual Computing Examples for 4- and 8-connected a 4 connected area a 4-connected area an 8 connected area an 8-connected area has an 8-connected has a 4-connected border border 33 Werner Purgathofer / Einf. in Visual Computing 17

  18. Simple Flood-Fill Algorithm void floodFill4 (int x, int y, int new, int old) { int color; /* set current color to new */ getPixel (x, y, color); if (color = old) { setPixel (x, y); floodFill4 (x–1, y, new, old); /* left */ floodFill4 (x, y+1, new, old); / up / floodFill4 (x y+1 new old); /* up */ floodFill4 (x+1, y, new, old); /* right */ floodFill4 (x, y–1, new, old) /* down */ }} 34 Werner Purgathofer / Einf. in Visual Computing Bad Behavior of Simple Flood-Fill 2 1 3 4 recursion sequence 35 Werner Purgathofer / Einf. in Visual Computing 18

  19. Span Flood-Fill Algorithm floodFill4 produces too high stacks (recursion!) ( ) solution: incremental horizontal fill (left to right) recursive vertical fill (first up then down) 36 Werner Purgathofer / Einf. in Visual Computing Good Behavior of Span Flood-Fill 1 2 recursion sequence 37 Werner Purgathofer / Einf. in Visual Computing 19

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend