Polygon Filling Werner Purgathofer Linked Lists flexible data - - PowerPoint PPT Presentation

polygon filling
SMART_READER_LITE
LIVE PREVIEW

Polygon Filling Werner Purgathofer Linked Lists flexible data - - PowerPoint PPT Presentation

Einfhrung 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


slide-1
SLIDE 1

Einführung in Visual Computing

186.822

Polygon Filling

Werner Purgathofer

slide-2
SLIDE 2

Werner Purgathofer / Einf. in Visual Computing 2

flexible data structure

Linked Lists

x1 x2

data pointer (link to next element)

x1 x2

x1 x2

x1 x2

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

slide-3
SLIDE 3

Werner Purgathofer / Einf. in Visual Computing 3

Linked Lists: Removal of First Element

1 2 3 4 5 list

list = list^.next

slide-4
SLIDE 4

Werner Purgathofer / Einf. in Visual Computing 4

Linked Lists: Inserting New First Element

1 2 3 4 5 new

new^.next = list

list

slide-5
SLIDE 5

Werner Purgathofer / Einf. in Visual Computing 5

Linked Lists: Inserting New First Element

1 2 3 4 5 new new^.next = list list = new list

slide-6
SLIDE 6

Werner Purgathofer / Einf. in Visual Computing 6

Linked Lists: Exchanging Elements 2 & 4

1 2 3 4 5 last1 last2 list

help = last1^.next^.next

help

slide-7
SLIDE 7

Werner Purgathofer / Einf. in Visual Computing 7

Linked Lists: Exchanging Elements 2 & 4

1 2 3 4 5 last1 last2 list

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

help

slide-8
SLIDE 8

Werner Purgathofer / Einf. in Visual Computing 8

Linked Lists: Exchanging Elements 2 & 4

1 2 3 4 5 last1 last2 list

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

help

slide-9
SLIDE 9

Werner Purgathofer / Einf. in Visual Computing 9

Linked Lists: Exchanging Elements 2 & 4

1 2 3 4 5 last1 last2 list

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

help

slide-10
SLIDE 10

Werner Purgathofer / Einf. in Visual Computing 10

Linked Lists: Exchanging Elements 2 & 4

1 2 3 4 5 last1 last2 list

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

help

slide-11
SLIDE 11

Werner Purgathofer / Einf. in Visual Computing 11

Linked Lists: Exchanging Elements 2 & 4

1 2 3 4 5 last1 last2 list

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

help

slide-12
SLIDE 12

Werner Purgathofer / Einf. in Visual Computing 12

  • dd-even rule

nonzero-winding- number rule

Repetition: What is Inside a Polygon?

???

slide-13
SLIDE 13

Werner Purgathofer / Einf. in Visual Computing 13

area-filling algorithms

“interior”, “exterior” for self-intersecting polygons?

  • dd-even rule

nonzero-winding-number rule same result for simple polygons

Inside-Outside Tests

slide-14
SLIDE 14

Werner Purgathofer / Einf. in Visual Computing 14

inside/outside switches at every edge straight line to the outside:

even # edge intersections = outside

  • dd # edge intersections = inside

What is Inside?: Odd-Even Rule

1 2 3 4 1 2 3 4 1 2 3 1 2 1

slide-15
SLIDE 15

Werner Purgathofer / Einf. in Visual Computing 15

point is inside if polygon surrounds it straight line to the outside:

same # edges up and down = outside different # edges up and down = inside

What is Inside?: Nonzero Winding Number

slide-16
SLIDE 16

Werner Purgathofer / Einf. in Visual Computing 16

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

Fill-Area Primitives

slide-17
SLIDE 17

Werner Purgathofer / Einf. in Visual Computing 17

Scan-Line Fill: Sorted Edge Table

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

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

slide-18
SLIDE 18

Werner Purgathofer / Einf. in Visual Computing 18

sort all edges by smallest y-value edge entry: [max. y-value, x-intercept, inverse slope] active-edge list

for each scan line contains all edges crossed by that scan line incremental update

consecutive intersection pairs (spans) filled

Scan-Line Fill: Sorted Edge Table

yB xC 1/mCB yD xC 1/mCD

slide-19
SLIDE 19

Werner Purgathofer / Einf. in Visual Computing 19

Sorted Edge Table

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

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

slide-20
SLIDE 20

Werner Purgathofer / Einf. in Visual Computing 20

Sorted Edge Table / Active Edge List

Active Edge List When processing from bottom to top, keep a list of all active edges

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

slide-21
SLIDE 21

Werner Purgathofer / Einf. in Visual Computing 21

Active Edge List

Sorted Edge Table / Active Edge List

incremental update!

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

slide-22
SLIDE 22

Werner Purgathofer / Einf. in Visual Computing 22

Active Edge List

Sorted Edge Table / Active Edge List

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

slide-23
SLIDE 23

Werner Purgathofer / Einf. in Visual Computing 23

Active Edge List

Sorted Edge Table / Active Edge List

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

slide-24
SLIDE 24

Werner Purgathofer / Einf. in Visual Computing 24

Active Edge List

Sorted Edge Table / Active Edge List

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

slide-25
SLIDE 25

Werner Purgathofer / Einf. in Visual Computing 25

Active Edge List

Sorted Edge Table / Active Edge List

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

slide-26
SLIDE 26

Werner Purgathofer / Einf. in Visual Computing 26

Active Edge List

Sorted Edge Table / Active Edge List

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

slide-27
SLIDE 27

Werner Purgathofer / Einf. in Visual Computing 27

Active Edge List

Sorted Edge Table / Active Edge List

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

slide-28
SLIDE 28

Werner Purgathofer / Einf. in Visual Computing 28

Active Edge List

Sorted Edge Table / Active Edge List

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

slide-29
SLIDE 29

Werner Purgathofer / Einf. in Visual Computing 29

Active Edge List

Sorted Edge Table / Active Edge List

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

slide-30
SLIDE 30

Werner Purgathofer / Einf. in Visual Computing 30

Active Edge List

Sorted Edge Table / Active Edge List

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

slide-31
SLIDE 31

Werner Purgathofer / Einf. in Visual Computing 31

Active Edge List

Sorted Edge Table / Active Edge List

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

slide-32
SLIDE 32

Werner Purgathofer / Einf. in Visual Computing 32

Active Edge List

Sorted Edge Table / Active Edge List

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

slide-33
SLIDE 33

Werner Purgathofer / Einf. in Visual Computing 33

incremental update of intersection point 1 + =

k k+1

y y m x x

k k+1

1 + = slope of polygon boundary line: m (for 2 successive scanlines)

Scan-Line Fill: Incremental Update

yk + 1 yk (xk , yk) (xk+1, yk+1)

slide-34
SLIDE 34

Werner Purgathofer / Einf. in Visual Computing 34

intersection points along scan lines that intersect polygon vertices → either special handling (1 or 2 intersections?) → or move vertices up or down by ε

Scan-Line Fill: Intersecting Vertices

1 1 2 2 2

slide-35
SLIDE 35

Werner Purgathofer / Einf. in Visual Computing 35

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

Flood-Fill Algorithm

slide-36
SLIDE 36

Werner Purgathofer / Einf. in Visual Computing 36

area must be distinguishable from boundaries example: area defined within multiple color boundaries

Flood-Fill: Boundary and Seed Point

seed point

slide-37
SLIDE 37

Werner Purgathofer / Einf. in Visual Computing 37

Definition: 4-connected means, that a connection is only valid in these 4 directions Definition: 8-connected means, that a connection is valid in these 8 directions

Flood-Fill: Connectedness

slide-38
SLIDE 38

Werner Purgathofer / Einf. in Visual Computing 38

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

Examples for 4-connected and 8-connected

slide-39
SLIDE 39

Werner Purgathofer / Einf. in Visual Computing 39

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+1, y, new, old); /* right */ floodFill4 (x, y–1, new, old) /* down */ }} 1 2 4 3 recursion sequence

slide-40
SLIDE 40

Werner Purgathofer / Einf. in Visual Computing 40

Bad Behavior of Simple Flood-Fill

1 2 4 3 recursion sequence

slide-41
SLIDE 41

Werner Purgathofer / Einf. in Visual Computing 41

floodFill4 produces too high stacks (recursion!) solution:

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

Span Flood-Fill Algorithm

slide-42
SLIDE 42

Werner Purgathofer / Einf. in Visual Computing 42

Good Behavior of Span Flood-Fill

1 2 recursion sequence

slide-43
SLIDE 43

Werner Purgathofer / Einf. in Visual Computing 43

Span Flood-Fill Example

Stack: x

slide-44
SLIDE 44

Werner Purgathofer / Einf. in Visual Computing 44

Span Flood-Fill Example

B A 1 2 3 Stack: x A B

slide-45
SLIDE 45

Werner Purgathofer / Einf. in Visual Computing 45

Span Flood-Fill Example

A 1 2 3 Stack: A B C D E F F E C D 4 5 6 7 8 9 10 11

slide-46
SLIDE 46

Werner Purgathofer / Einf. in Visual Computing 46

Span Flood-Fill Example

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

slide-47
SLIDE 47

Werner Purgathofer / Einf. in Visual Computing 47

Span Flood-Fill Example

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

slide-48
SLIDE 48

Werner Purgathofer / Einf. in Visual Computing 48

Span Flood-Fill Example

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

slide-49
SLIDE 49

Werner Purgathofer / Einf. in Visual Computing 49

Span Flood-Fill Example

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

slide-50
SLIDE 50

Werner Purgathofer / Einf. in Visual Computing 50

Span Flood-Fill Example

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

slide-51
SLIDE 51

Werner Purgathofer / Einf. in Visual Computing 51

Span Flood-Fill Example

A 1 2 3 Stack: A C I K C

K

4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

slide-52
SLIDE 52

Werner Purgathofer / Einf. in Visual Computing 52

Span Flood-Fill Example

A=N 1 2 3 Stack: A C K L M N C M 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 L

slide-53
SLIDE 53

Werner Purgathofer / Einf. in Visual Computing 53

Span Flood-Fill Example

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

slide-54
SLIDE 54

Werner Purgathofer / Einf. in Visual Computing 54

Span Flood-Fill Example

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

slide-55
SLIDE 55

Werner Purgathofer / Einf. in Visual Computing 55

Span Flood-Fill Example

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

slide-56
SLIDE 56

Werner Purgathofer / Einf. in Visual Computing 56

Span Flood-Fill Example

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

slide-57
SLIDE 57

3D Polygons

normally surface elements of 3D objects attributes are surface attributes

color, material, transparency, texture, geometric microstructure, reflection properties, …

attributes and normal vectors often at the vertices triangles: linear interpolation with barycentric coordinates

Werner Purgathofer / Einf. in Visual Computing 57