Polygon Filling Werner Purgathofer Linked Lists flexible data - - PDF document

polygon filling
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

1

Einführung in Visual Computing

186.822 186.822

Polygon Filling

Werner Purgathofer flexible data structure Linked Lists

x1x2 x1x2

data pointer (link to next element)

list^ list^ next^

Werner Purgathofer / Einf. in Visual Computing 1

x1 x2

x1 x2

x1 x2

list list^.next list^.next^.next list list .next

slide-2
SLIDE 2

2

Linked Lists: Removal of First Element 1 2 3 4 5

list

1 2 3 4 5

list = list^.next

Werner Purgathofer / Einf. in Visual Computing 2

Linked Lists: Inserting New 1st Element 1 2 3 4 5

list

1 2 3 4 5

new new^.next = list

Werner Purgathofer / Einf. in Visual Computing 3

slide-3
SLIDE 3

3

Linked Lists: Inserting New 1st Element 1 2 3 4 5

list

1 2 3 4 5

new new^.next = list list = new

Werner Purgathofer / Einf. in Visual Computing 4

list = new

Linked Lists: Exchanging Elements 2 & 4 1 2 3 4 5

last1 last2 list help

1 2 3 4 5

help = last1^.next^.next

Werner Purgathofer / Einf. in Visual Computing 5

slide-4
SLIDE 4

4

Linked Lists: Exchanging Elements 2 & 4 1 2 3 4 5

last1 last2 list help

1 2 3 4 5

help = last1^.next^.next last1^.next^.next = last2^.next^.next

Werner Purgathofer / Einf. in Visual Computing 6

Linked Lists: Exchanging Elements 2 & 4 1 2 3 4 5

last1 last2 list help

1 2 3 4 5

help = last1^.next^.next last1^.next^.next = last2^.next^.next

Werner Purgathofer / Einf. in Visual Computing 7

last2^.next^.next = help

slide-5
SLIDE 5

5

Linked Lists: Exchanging Elements 2 & 4 1 2 3 4 5

last1 last2 list help

1 2 3 4 5

help = last1^.next^.next last1^.next^.next = last2^.next^.next

Werner Purgathofer / Einf. in Visual Computing 8

last2^.next^.next = help help = last1^.next

Linked Lists: Exchanging Elements 2 & 4 1 2 3 4 5

last1 last2 list help

1 2 3 4 5

help = last1^.next^.next last1^.next^.next = last2^.next^.next

Werner Purgathofer / Einf. in Visual Computing 9

last2^.next^.next = help help = last1^.next last1^.next = last2^.next

slide-6
SLIDE 6

6

Linked Lists: Exchanging Elements 2 & 4 1 2 3 4 5

last1 last2 list help

1 2 3 4 5

help = last1^.next^.next last1^.next^.next = last2^.next^.next

Werner Purgathofer / Einf. in Visual Computing 10

last2^.next^.next = help help = last1^.next last1^.next = last2^.next last2^.next = help

for polygon area (solid-color, patterned)

scan-line polygon fill algorithm

intersection points located and sorted

Fill-Area Primitives

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 11

slide-7
SLIDE 7

7

Scan-Line Fill: Sorted Edge Table

D E yE xD 1/mDE A B C F yF xA 1/mAF yB xA 1/mAB yE xF 1/mFE yB xC 1/mCB yD xC 1/mCD

Werner Purgathofer / Einf. in Visual Computing 12

A

The sorted edge table contains all polygon edges sorted by lowest y-value

ymax xstart 1/m

sort all edges by smallest y-value edge entry: [max y value x intercept inverse slope] Scan-Line Fill: Sorted Edge Table [max y-value, x-intercept, inverse slope] active-edge list

for each scan line

yB xC 1/mCB yD xC 1/mCD

Werner Purgathofer / Einf. in Visual Computing 13

contains all edges crossed by that scan line incremental update

consecutive intersection pairs (spans) filled

slide-8
SLIDE 8

8

Sorted Edge Table

D E yE xD 1/mDE A B C F yF xA 1/mAF yB xA 1/mAB yE xF 1/mFE yB xC 1/mCB yD xC 1/mCD

Werner Purgathofer / Einf. in Visual Computing 14

A

The sorted edge table contains all polygon edges sorted by lowest y-value

ymax xstart 1/m

Sorted Edge Table / Active Edge List

D E yE xD 1/mDE A B C F yF xA 1/mAF yB xA 1/mAB yE xF 1/mFE yB xC 1/mCB yD xC 1/mCD

Werner Purgathofer / Einf. in Visual Computing 15

Active Edge List When processing from bottom to top, keep a list

  • f all active edges

A

slide-9
SLIDE 9

9

Sorted Edge Table / Active Edge List

D E yE xD 1/mDE A B C F yF xA 1/mAF yB xA 1/mAB yE xF 1/mFE yB xC 1/mCB yD xC 1/mCD

Werner Purgathofer / Einf. in Visual Computing 16

Active Edge List

yF xA 1/mAF yB xA 1/mAB A

incremental update! Sorted Edge Table / Active Edge List

D E yE xD 1/mDE A B C F yF xA 1/mAF yB xA 1/mAB yE xF 1/mFE yB xC 1/mCB yD xC 1/mCD

Werner Purgathofer / Einf. in Visual Computing 17

Active Edge List

yF xA 1/mAF yB xA 1/mAB A

slide-10
SLIDE 10

10

Sorted Edge Table / Active Edge List

D E yE xD 1/mDE A B C F yF xA 1/mAF yB xA 1/mAB yE xF 1/mFE yB xC 1/mCB yD xC 1/mCD

Werner Purgathofer / Einf. in Visual Computing 18

Active Edge List

yE xF 1/mFE yB xA 1/mAB A

Sorted Edge Table / Active Edge List

D E yE xD 1/mDE A B C F yF xA 1/mAF yB xA 1/mAB yE xF 1/mFE yB xC 1/mCB yD xC 1/mCD

Werner Purgathofer / Einf. in Visual Computing 19

Active Edge List

yE xF 1/mFE yB xA 1/mAB A

slide-11
SLIDE 11

11

Sorted Edge Table / Active Edge List

D E yE xD 1/mDE A B C F yF xA 1/mAF yB xA 1/mAB yE xF 1/mFE yB xC 1/mCB yD xC 1/mCD

Werner Purgathofer / Einf. in Visual Computing 20

Active Edge List

yE xF 1/mFE yB xA 1/mAB A

Sorted Edge Table / Active Edge List

D E yE xD 1/mDE A B C F yF xA 1/mAF yB xA 1/mAB yE xF 1/mFE yB xC 1/mCB yD xC 1/mCD

Werner Purgathofer / Einf. in Visual Computing 21

Active Edge List

yE xF 1/mFE yB xA 1/mAB yB xC 1/mCB yD xC 1/mCD A

slide-12
SLIDE 12

12

Sorted Edge Table / Active Edge List

D E yE xD 1/mDE A B C F yF xA 1/mAF yB xA 1/mAB yE xF 1/mFE yB xC 1/mCB yD xC 1/mCD

Werner Purgathofer / Einf. in Visual Computing 22

Active Edge List

yE xF 1/mFE yB xA 1/mAB yB xC 1/mCB yD xC 1/mCD A

Sorted Edge Table / Active Edge List

D E yE xD 1/mDE A B C F yF xA 1/mAF yB xA 1/mAB yE xF 1/mFE yB xC 1/mCB yD xC 1/mCD

Werner Purgathofer / Einf. in Visual Computing 23

Active Edge List

yE xF 1/mFE yD xC 1/mCD A

slide-13
SLIDE 13

13

Sorted Edge Table / Active Edge List

D E yE xD 1/mDE A B C F yF xA 1/mAF yB xA 1/mAB yE xF 1/mFE yB xC 1/mCB yD xC 1/mCD

Werner Purgathofer / Einf. in Visual Computing 24

Active Edge List

yE xF 1/mFE yD xC 1/mCD A

Sorted Edge Table / Active Edge List

D E yE xD 1/mDE A B C F yF xA 1/mAF yB xA 1/mAB yE xF 1/mFE yB xC 1/mCB yD xC 1/mCD

Werner Purgathofer / Einf. in Visual Computing 25

Active Edge List

yE xF 1/mFE yE xD 1/mDE A

slide-14
SLIDE 14

14

Sorted Edge Table / Active Edge List

D E yE xD 1/mDE A B C F yF xA 1/mAF yB xA 1/mAB yE xF 1/mFE yB xC 1/mCB yD xC 1/mCD

Werner Purgathofer / Einf. in Visual Computing 26

Active Edge List

yE xF 1/mFE yE xD 1/mDE A

Sorted Edge Table / Active Edge List

D E yE xD 1/mDE A B C F yF xA 1/mAF yB xA 1/mAB yE xF 1/mFE yB xC 1/mCB yD xC 1/mCD

Werner Purgathofer / Einf. in Visual Computing 27

Active Edge List

A

slide-15
SLIDE 15

15

incremental update of intersection point slope of polygon boundary line: m Scan-Line Fill: Incremental Update

1

1

 

 k k

y y m x x

k k

1

1

 

(for 2 successive scanlines)

Werner Purgathofer / Einf. in Visual Computing 28

yk +1 yk (xk, yk) (xk+1, yk+1) intersection points along li th t Scan-Line Fill: Intersecting Vertices

1 1 2

scan lines that intersect polygon vertices.

→ either special handling (1 or 2 intersections?)

1 2 2

Werner Purgathofer / Einf. in Visual Computing 29

p g ( )

→ or move vertices up or down by ε

slide-16
SLIDE 16

16

pixel filling of area

areas with no single color boundary

Flood-Fill Algorithm

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 30

recursive calls

area must be distinguishable from boundaries Flood-Fill: Boundary and Seed Point boundaries seed point

Werner Purgathofer / Einf. in Visual Computing 31

example: area defined within multiple color boundaries

slide-17
SLIDE 17

17

Flood-Fill: Connectedness Definition: 4-connected means, that a connection is Definition: 8-connected means, that a connection is

Werner Purgathofer / Einf. in Visual Computing 32

  • nly valid in these 4

directions valid in these 8 directions Examples for 4- and 8-connected an 8 connected area a 4 connected area

Werner Purgathofer / Einf. in Visual Computing 33

has an 8-connected border an 8-connected area has a 4-connected border a 4-connected area

slide-18
SLIDE 18

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 */

Werner Purgathofer / Einf. in Visual Computing 34

floodFill4 (x, y+1, new, old); / up / floodFill4 (x+1, y, new, old); /* right */ floodFill4 (x, y–1, new, old) /* down */ }} 1 2 3 Bad Behavior of Simple Flood-Fill 4 recursion sequence

Werner Purgathofer / Einf. in Visual Computing 35

slide-19
SLIDE 19

19

floodFill4 produces too high stacks (recursion!) Span Flood-Fill Algorithm ( ) solution:

incremental horizontal fill (left to right) recursive vertical fill (first up then down)

Werner Purgathofer / Einf. in Visual Computing 36

1 Good Behavior of Span Flood-Fill 2 recursion sequence

Werner Purgathofer / Einf. in Visual Computing 37

slide-20
SLIDE 20

20

Span Flood-Fill Example Stack: x

Werner Purgathofer / Einf. in Visual Computing 38

Span Flood-Fill Example Stack: x B A 1 2 3 A B

Werner Purgathofer / Einf. in Visual Computing 39

slide-21
SLIDE 21

21

Span Flood-Fill Example Stack: A A 1 2 3 B C D E F F E C D 4 5 6 7 8 9 10 11

Werner Purgathofer / Einf. in Visual Computing 40

Span Flood-Fill Example Stack: A G A 1 2 3 C D E F G E C D 4 5 6 7 8 9 10 11 12 13 14

Werner Purgathofer / Einf. in Visual Computing 41

slide-22
SLIDE 22

22

Span Flood-Fill Example Stack: A 15 16 17 18 A 1 2 3 C D E G H E=H C D 4 5 6 7 8 9 10 11 12 13 14

Werner Purgathofer / Einf. in Visual Computing 42

Span Flood-Fill Example Stack: A 15 16 17 18 A 1 2 3 C D E H C D 4 5 6 7 8 9 10 11 12 13 14 19 (E)

Werner Purgathofer / Einf. in Visual Computing 43

slide-23
SLIDE 23

23

Span Flood-Fill Example Stack: A 15 16 17 18 A 1 2 3 C D I J C I 4 5 6 7 8 9 10 11 12 13 14 19 J 20 21 22

Werner Purgathofer / Einf. in Visual Computing 44

Span Flood-Fill Example Stack: A 15 16 17 18 A 1 2 3 C I J C I 4 5 6 7 8 9 10 11 12 13 14 19 20 21 22 23

Werner Purgathofer / Einf. in Visual Computing 45

slide-24
SLIDE 24

24

Span Flood-Fill Example Stack: A 15 16 17 18 A 1 2 3 C I K C 4 5 6 7 8 9 10 11 12 13 14 19 20 21 22 23 24 25

Werner Purgathofer / Einf. in Visual Computing 46

K Span Flood-Fill Example Stack: A 15 16 17 18 A=N 1 2 3 C K L M N C 4 5 6 7 8 9 10 11 12 13 14 19 20 21 22 23 24 25

Werner Purgathofer / Einf. in Visual Computing 47

M 26 27 28 29 30 L

slide-25
SLIDE 25

25

Span Flood-Fill Example Stack: A 15 16 17 18 (A) 1 2 3 C L M N C 4 5 6 7 8 9 10 11 12 13 14 19 20 21 22 23 24 25 31 32 33

Werner Purgathofer / Einf. in Visual Computing 48

M 26 27 28 29 30 L Span Flood-Fill Example Stack: C 15 16 17 18 1 2 3 L M C 4 5 6 7 8 9 10 11 12 13 14 19 20 21 22 23 24 25 31 32 33

Werner Purgathofer / Einf. in Visual Computing 49

26 27 28 29 30 L 34 35

slide-26
SLIDE 26

26

Span Flood-Fill Example Stack: C 15 16 17 18 1 2 3 L C 4 5 6 7 8 9 10 11 12 13 14 19 20 21 22 23 24 25 31 32 33

Werner Purgathofer / Einf. in Visual Computing 50

26 27 28 29 30 34 35 36 37 Span Flood-Fill Example Stack: C 15 16 17 18 1 2 3 4 5 6 7 8 9 10 11 12 13 14 19 20 21 22 23 24 25 31 32 33 38

Werner Purgathofer / Einf. in Visual Computing 51

26 27 28 29 30 34 35 36 37 finished!