1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

98
1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai
  • date post

    19-Dec-2015
  • Category

    Documents

  • view

    228
  • download

    1

Transcript of 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

Page 1: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

1

CSCE 441: Computer GraphicsScan Conversion of Polygons

Jinxiang Chai

Page 2: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

2/95

OpenGL Geometric Primitives

All geometric primitives are specified by vertices

GL_QUAD_STRIPGL_QUAD_STRIP

GL_POLYGONGL_POLYGON

GL_TRIANGLE_STRIPGL_TRIANGLE_STRIP

GL_TRIANGLE_FANGL_TRIANGLE_FAN

GL_POINTSGL_POINTSGL_LINESGL_LINES

GL_LINE_LOOPGL_LINE_LOOPGL_LINE_STRIPGL_LINE_STRIP

GL_TRIANGLESGL_TRIANGLES

GL_QUADSGL_QUADS

Page 3: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

3/95

OpenGL Geometric Primitives

All geometric primitives are specified by vertices

GL_QUAD_STRIPGL_QUAD_STRIP

GL_POLYGONGL_POLYGON

GL_TRIANGLE_STRIPGL_TRIANGLE_STRIP

GL_TRIANGLE_FANGL_TRIANGLE_FAN

GL_POINTSGL_POINTSGL_LINESGL_LINES

GL_LINE_LOOPGL_LINE_LOOPGL_LINE_STRIPGL_LINE_STRIP

GL_TRIANGLESGL_TRIANGLES

GL_QUADSGL_QUADS

Page 4: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

4/95

OpenGL Geometric Primitives

All geometric primitives are specified by vertices

GL_QUAD_STRIPGL_QUAD_STRIP

GL_POLYGONGL_POLYGON

GL_TRIANGLE_STRIPGL_TRIANGLE_STRIP

GL_TRIANGLE_FANGL_TRIANGLE_FAN

GL_POINTSGL_POINTSGL_LINESGL_LINES

GL_LINE_LOOPGL_LINE_LOOPGL_LINE_STRIPGL_LINE_STRIP

GL_TRIANGLESGL_TRIANGLES

GL_QUADSGL_QUADS

Page 5: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

5/95

Drawing General Polygons

How to draw every interior pixels?

?

Page 6: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

6/95

Drawing Curved Objects

How to draw every interior pixels?

?

Page 7: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

7/95

Outline

Methods for drawing polygons or curved objects

- Scanline conversion of polygons

- Boundary-fill

- Flood-fill

Required readings:

- HB 4-9 to 4-14

Page 8: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

8/95

Drawing Rectangles

Which pixels should be filled?

Page 9: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

9/95

Drawing Rectangles

Is this correct?

Page 10: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

10/95

Drawing Rectangles

What if two rectangles overlap?

Page 11: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

11/95

Drawing Rectangles

Is this correct?

Page 12: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

12/95

Drawing Rectangles

Is this correct? Overlap!!!

Page 13: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

13/95

Drawing Rectangles

Solution: Exclude pixels on top and right

Page 14: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

14/95

Drawing Rectangles

Artifacts are possible

Page 15: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

15/95

General Polygons – Basic Idea

How to draw every interior pixels?

Page 16: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

16/95

General Polygons – Basic Idea

How to draw every interior pixels for a scan line?

Page 17: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

17/95

General Polygons – Basic Idea

Intersect scan lines with edges Find ranges along x Fill interior of those

ranges

Don’t fill top/right

Edges may NOT match

with line drawing algo

Page 18: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

18/95

General Polygons – Basic Idea

Intersect scan lines with edges Find ranges along x Fill interior of those

ranges

Don’t fill top/right

Edges may NOT match

with line drawing algo

Use coherence to

speed up

Page 19: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

19/95

General Polygons – Basic Idea

Intersect scan lines with edges Find ranges along x Fill interior of those

ranges

Use coherence to

speed up

Edges intersecting one scan line are

mostly same as those intersecting

previous scan line

Page 20: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

20/95

General Polygons – Basic Idea

Intersect scan lines with edges Find ranges along x Fill interior of those

ranges

Use coherence to

speed up

The x-value of an intersection with

one scan line is close to the

intersection with the previous one

Page 21: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

21/95

How to store polygon edges?

Page 22: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

22/95

General Polygons – Data Structures

Sorted Edge Table:

01234567

Sca

n L

ines

Edges

Store a linked-list per scan-line.

Insert edges into table at scan-

line associated with lowest end-

point.

Page 23: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

23/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

Sorted Edge Table

Page 24: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

24/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

Sorted Edge Table

Page 25: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

25/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

AB AG

Sorted Edge Table

Page 26: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

26/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

AB AG

Sorted Edge Table

Exclude horizontal edges!

Page 27: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

27/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

AB AG

FG ED

Sorted Edge Table

Page 28: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

28/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

AB AG

FG ED

CD

Sorted Edge Table

Page 29: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

29/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

AB AG

FG ED

CD

BC

Sorted Edge Table

Page 30: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

30/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

AB AG

FG ED

CD

BC

Sorted Edge Table

Which edges are intersecting with the current scan

line?

Page 31: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

31/95

General Polygons – Data Structures

Active Edge List:

Edges

List of all edges intersecting

current scan-line sorted by their

x-values

Page 32: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

32/95

General Polygons – Data Structures

Active Edge List:

Edges

List of all edges intersecting

current scan-line sorted by their

x-values

Implement active edge list with linked list

Page 33: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

33/95

General Polygons – Data Structures

Active Edge List:

Edges

List of all edges intersecting

current scan-line sorted by their

x-values

Implement active edge list with linked list

So what kind of information should be stored in the linked list for our polygon drawing algorithm?

Page 34: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

34/95

General Polygons – Data Structures

Edge:

maxY: highest y-value

currentX: x-value of end-point

with lowest y-value

xIncr: 1 / slope

mazY

currentX

xIncr

Edge

Page 35: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

35/95

Scan line intersection

kk

kk

xx

yym

1

1

Scan line yk+1Scan line yk

mxx kk

11

),( 00 yx

m

kxxk 0

),( endend yx

),( 11 kk yx

),( kk yx

Page 36: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

36/95

Scan line intersection

),( 11 kk yx

),( kk yx

kk

kk

xx

yym

1

1

Scan line yk+1Scan line yk

mxx kk

11

),( 00 yx

m

kxxk 0

),( endend yx

Page 37: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

37/95

General Polygons – Data Structures

Edge:

maxY: highest y-value

currentX: x-value of end-point

with lowest y-value

xIncr: 1 / slope

mazY

currentX

xIncr

Edge

Horizontal edges will not be used!!!

Page 38: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

38/95

General Polygons – Algorithm

line = 0

While (line < height )

Add edges to Active Edge List from Sorted Edge Table starting at line

Remove edges that end at line

Fill pixels

Increment x-values on edges in Active Edge List

Increment line

Page 39: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

39/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

AB AG

FG ED

CD

BC

Sorted Edge Table

Active Edge List

Page 40: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

40/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

AB AG

FG ED

CD

BC

Sorted Edge Table

Active Edge List

maxY

currentX

xIncr

AG

30

32

600

AB

Page 41: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

41/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

AB AG

FG ED

CD

BC

Sorted Edge Table

Active Edge List?

Page 42: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

42/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

AB AG

FG ED

CD

BC

Sorted Edge Table

Active Edge List

maxY

currentX

xIncr

ED

55

21

33

21

FG

Page 43: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

43/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

AB AG

FG ED

CD

BC

Sorted Edge Table

Active Edge List

maxY

currentX

xIncr

ED

55

21

33

21

FG

Is it correct?

Page 44: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

44/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

AB AG

FG ED

CD

BC

Sorted Edge Table

Active Edge List

AG

33

2

32

600

AB

maxY

currentX

xIncr

ED

55

21

33

21

FG

Page 45: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

45/95

General Polygons – Algorithm

line = 0

While (line < height )

Add edges to Active Edge List from Sorted Edge Table starting at line

Remove edges that end at line

Fill pixels

Increment x-values on edges in Active Edge List

Increment line

Page 46: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

46/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

AB AG

FG ED

CD

BC

Active Edge Table

Active Edge List

AG

33

2

32

600

AB

maxY

currentX

xIncr

ED

55

21

33

21

FG

Page 47: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

47/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

AB AG

FG ED

CD

BC

Active Edge Table

Active Edge List

AG

33

2

32

600

AB

maxY

currentX

xIncr

ED

55

21

33

21

FG

? ? ? ?

Page 48: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

48/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

AB AG

FG ED

CD

BC

Active Edge Table

Active Edge List

AG

33

4

32

600

AB

maxY

currentX

xIncr

ED

52

15

21

32

12

21

FG

Page 49: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

49/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

AB AG

FG ED

CD

BC

Active Edge Table

Active Edge List

AG

33

4

32

600

AB

maxY

currentX

xIncr

ED

52

15

21

32

12

21

FG

Page 50: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

50/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

AB AG

FG ED

CD

BC

Active Edge Table

Active Edge List

AG

32

32

600

AB

maxY

currentX

xIncr

ED

56

21

32

21

FG

Page 51: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

51/95

General Polygons – Algorithm

line = 0

While (line < height )

Add edges to Active Edge List from Active Edge Table starting at line

Remove edges that end at line

Fill pixels

Increment x-values on edges in Active Edge List

Increment scan line

Page 52: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

52/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

AB AG

FG ED

CD

BC

Active Edge Table

Active Edge List

AG

32

32

600

AB

maxY

currentX

xIncr

ED

56

21

32

21

FG

Page 53: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

53/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

AB AG

FG ED

CD

BC

Active Edge Table

Active Edge List

600

AB

maxY

currentX

xIncr

ED

56

21

Page 54: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

54/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

AB AG

FG ED

CD

BC

Active Edge Table

Active Edge List

600

AB

maxY

currentX

xIncr

ED

56

21

Page 55: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

55/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

AB AG

FG ED

CD

BC

Active Edge Table

Active Edge List

600

AB

maxY

currentX

xIncr

ED

52

16

21

Page 56: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

56/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

AB AG

FG ED

CD

BC

Active Edge Table

Active Edge List

600

AB

maxY

currentX

xIncr

ED

52

16

21

Page 57: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

57/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

AB AG

FG ED

CD

BC

Active Edge Table

Active Edge List

600

AB

maxY

currentX

xIncr

ED

57

21

CD

77

2

Page 58: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

58/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

AB AG

FG ED

CD

BC

Active Edge Table

Active Edge List

600

AB

maxY

currentX

xIncr

ED

52

16

21

CD

772

Page 59: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

59/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

AB AG

FG ED

CD

BC

Active Edge Table

Active Edge List

600

AB

maxY

currentX

xIncr

CD

772

Page 60: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

60/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

AB AG

FG ED

CD

BC

Active Edge Table

Active Edge List

600

AB

maxY

currentX

xIncr

CD

772

Page 61: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

61/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

AB AG

FG ED

CD

BC

Active Edge Table

Active Edge List

703

BC

maxY

currentX

xIncr

CD

752

600

AB

Page 62: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

62/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

AB AG

FG ED

CD

BC

Active Edge Table

Active Edge List

703

BC

maxY

currentX

xIncr

CD

752

600

AB

Page 63: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

63/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

AB AG

FG ED

CD

BC

Active Edge Table

Active Edge List

703

BC

maxY

currentX

xIncr

CD

752

Page 64: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

64/95

General Polygons – Example

0 1 2 3 4 5 6 70

1

2

3

4

5

6

7

A

B

C

D

EF

G

01234567

AB AG

FG ED

CD

BC

Active Edge Table

Active Edge List

733

BC

maxY

currentX

xIncr

CD

732

Page 65: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

65/95

General Polygons – Algorithm

line = 0

While (line < height )

Add edges to Active Edge List from Sorted Edge Table starting at line

Remove edges that end at line

Fill pixels

Increment x-values on edges in Active Edge List

Increment scan line

Page 66: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

66/95

Pixel Fill-in

Which intervals should we draw?

Page 67: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

67/95

Pixel Fill-in

Which intervals should we draw? - Odd intervals. But need to pay attention to scan lines

passing through vertices.

Page 68: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

68/95

General Polygons – Problems

Sliver polygons may not be drawn correctly

No simple solution Long, thin triangles

cause problems Want triangles with

good aspect ratio (close to equilateral)

Page 69: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

69/95

Curved Boundaries

How to deal with curved boundaries?

Page 70: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

70/95

Boundary Fill

Start with drawn boundaries and an interior point

Recursively recolor outward from that point If neighbor different, then recolor and

recur

Everything within the boundary is changed to that color

Page 71: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

71/95

Boundary Fill

Start with drawn boundaries and an interior point

Recursively recolor outward from that point If neighbor different, then recolor and

recur

Everything within the boundary is changed to that color

Page 72: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

72/95

Boundary Fill

Work for inner and outer boundaries

Page 73: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

73/95

Boundary Fill

Start with drawn outline of a polygon and an interior point

Recursively recolor outward from that point If neighbor different, then recolor and

recur

Everything within the boundary is changed to that color

Page 74: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

74/95

Boundary Fill

How to define a neigbhbor?

4-connected 8-connected

Page 75: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

75/95

Boundary Fill – Example

Black pixels indicate boundary pixels

Page 76: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

76/95

Boundary Fill – Example

Page 77: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

77/95

Boundary Fill – Example

Continue checking neighboring pixels until reaching boundary pixels or previously visited pixels!

Page 78: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

78/95

Boundary Fill – Example

Continue checking neighboring pixels until reaching boundary pixels or previously visited pixels!

Page 79: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

79/95

Boundary Fill – Example

Continue checking neighboring pixels until reaching boundary pixels or previously visited pixels!

Page 80: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

80/95

Boundary Fill – Example

Continue checking neighboring pixels until reaching boundary pixels or previously visited pixels!

Page 81: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

81/95

Boundary Fill – Example

Continue checking neighboring pixels until reaching boundary pixels or previously visited pixels!

Page 82: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

82/95

Boundary Fill

Page 83: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

83/95

How to deal with this?

Multiple color boundaries?

How to paint this region to yellow?

Page 84: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

84/95

How to deal with this?

Multiple color boundaries?

How to paint this region to yellow?

Three keys:- a start pixel

- a target color

- a paint color

Page 85: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

85/95

Flood Fill

Start with a point Define color under that point as the interior

color Recursively recolor outward from that point

If neighbor is interior color, then recolor and recur

Contiguous regions are recolored

Page 86: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

86/95

Flood Fill – Example

Page 87: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

87/95

Flood Fill – Example

Page 88: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

88/95

Flood Fill – Example

Continue setting the colors for neighboring pixels if it is interior pixels!

Page 89: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

89/95

Flood Fill – Example

Continue setting the colors for neighboring pixels if it is interior pixels!

Page 90: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

90/95

Flood Fill – Example

Continue setting the colors for neighboring pixels if it is interior pixels!

Page 91: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

91/95

Flood Fill – Example

Continue setting the colors for neighboring pixels if it is interior pixels!

Page 92: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

92/95

Flood Fill – Example

Continue setting the colors for neighboring pixels if it is interior pixels!

Page 93: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

93/95

Flood Fill – Example

Continue setting the colors for neighboring pixels if it is interior pixels!

Page 94: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

94/95

Flood Fill – Example

Continue setting the colors for neighboring pixels if it is interior pixels!

Page 95: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

95/95

Flood Fill – Example

Continue setting the colors for neighboring pixels if it is interior pixels!

Page 96: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

96/95

Flood Fill – Example

Continue setting the colors for neighboring pixels if it is interior pixels!

Page 97: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

97/95

Flood Fill – Example

Continue setting the colors for neighboring pixels if it is interior pixels!

Page 98: 1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.

98/95

Flood Fill – Example

Continue setting the colors for neighboring pixels if it is interior pixels!