70
1 Dr. Scott Schaefer Scan Conversion of Polygons

Scan Conversion of Polygons

  • Upload
    noma

  • View
    50

  • Download
    0

Embed Size (px)

DESCRIPTION

Scan Conversion of Polygons. Dr. Scott Schaefer. Drawing Rectangles. Which pixels should be filled?. Drawing Rectangles. Is this correct?. Drawing Rectangles. What if two rectangles overlap?. Drawing Rectangles. Is this correct?. Drawing Rectangles. Overlap!!!. Is this correct?. - PowerPoint PPT Presentation

Citation preview

Page 1: Scan Conversion of Polygons

1

Dr. Scott Schaefer

Scan Conversion of Polygons

Page 2: Scan Conversion of Polygons

2/70

Drawing Rectangles

Which pixels should be filled?

Page 3: Scan Conversion of Polygons

3/70

Drawing Rectangles

Is this correct?

Page 4: Scan Conversion of Polygons

4/70

Drawing Rectangles

What if two rectangles overlap?

Page 5: Scan Conversion of Polygons

5/70

Drawing Rectangles

Is this correct?

Page 6: Scan Conversion of Polygons

6/70

Drawing Rectangles

Is this correct? Overlap!!!

Page 7: Scan Conversion of Polygons

7/70

Drawing Rectangles

Solution: Exclude pixels on top and right

Page 8: Scan Conversion of Polygons

8/70

Drawing Rectangles

Artifacts are possible

Page 9: Scan Conversion of Polygons

9/70

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 10: Scan Conversion of Polygons

10/70

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 11: Scan Conversion of Polygons

11/70

General Polygons – Basic Idea

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

ranges

Use coherence to

speed up

Edges intersection one scan line are

mostly same as those intersecting

previous scan line

Page 12: Scan Conversion of Polygons

12/70

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 13: Scan Conversion of Polygons

13/70

General Polygons – Data Structures

Edge:

maxY:

currentX:

xIncr:

maxY

currentX

xIncr

Edge),max( 1ii yy

otherwisex

yyyx

i

iiii

,

),min(,

1

1

ii

ii

yyxx

1

1

),(),( 11 iiii yxyx

Page 14: Scan Conversion of Polygons

14/70

General Polygons – Data Structures

Edge:

maxY:

currentX:

xIncr:

maxY

currentX

xIncr

Edge),max( 1ii yy

otherwisex

yyyx

i

iiii

,

),min(,

1

1

ii

ii

yyxx

1

1

),(),( 11 iiii yxyx

Horizontal edges will not be used!!!

Page 15: Scan Conversion of Polygons

15/70

General Polygons – Data Structures

Active 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 16: Scan Conversion of Polygons

16/70

General Polygons – Data Structures

Active Edge List:

Edges

List of all edges intersecting

current scan-line sorted by their

x-values

Page 17: Scan Conversion of Polygons

17/70

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 line

Page 18: Scan Conversion of Polygons

18/70

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

Active Edge Table

Active Edge List

Page 19: Scan Conversion of Polygons

19/70

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

Active Edge Table

Active Edge List

Page 20: Scan Conversion of Polygons

20/70

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

BC

Active Edge Table

Active Edge List

Page 21: Scan Conversion of Polygons

21/70

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

CD

BC

Active Edge Table

Active Edge List

Page 22: Scan Conversion of Polygons

22/70

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

ED

CD

BC

Active Edge Table

Active Edge List

Page 23: Scan Conversion of Polygons

23/70

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

ED

CD

BC

Active Edge Table

Active Edge List

Page 24: Scan Conversion of Polygons

24/70

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

FG ED

CD

BC

Active Edge Table

Active Edge List

Page 25: Scan Conversion of Polygons

25/70

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

Page 26: Scan Conversion of Polygons

26/70

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

maxY

currentX

xIncr

AG

30

32

600

AB

Page 27: Scan Conversion of Polygons

27/70

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 28: Scan Conversion of Polygons

28/70

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 29: Scan Conversion of Polygons

29/70

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 30: Scan Conversion of Polygons

30/70

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 31: Scan Conversion of Polygons

31/70

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 32: Scan Conversion of Polygons

32/70

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 33: Scan Conversion of Polygons

33/70

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 34: Scan Conversion of Polygons

34/70

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 35: Scan Conversion of Polygons

35/70

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 36: Scan Conversion of Polygons

36/70

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 37: Scan Conversion of Polygons

37/70

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 38: Scan Conversion of Polygons

38/70

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 39: Scan Conversion of Polygons

39/70

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 40: Scan Conversion of Polygons

40/70

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 41: Scan Conversion of Polygons

41/70

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 42: Scan Conversion of Polygons

42/70

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 43: Scan Conversion of Polygons

43/70

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 44: Scan Conversion of Polygons

44/70

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 45: Scan Conversion of Polygons

45/70

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 46: Scan Conversion of Polygons

46/70

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 47: Scan Conversion of Polygons

47/70

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 48: Scan Conversion of Polygons

48/70

Boundary Fill

How to define a neighbor?

4-connected 8-connected

Page 49: Scan Conversion of Polygons

49/70

Boundary Fill – Example

Page 50: Scan Conversion of Polygons

50/70

Boundary Fill – Example

Page 51: Scan Conversion of Polygons

51/70

Boundary Fill – Example

Page 52: Scan Conversion of Polygons

52/70

Boundary Fill – Example

Page 53: Scan Conversion of Polygons

53/70

Boundary Fill – Example

Page 54: Scan Conversion of Polygons

54/70

Boundary Fill – Example

Page 55: Scan Conversion of Polygons

55/70

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 of the same color are recolored

Page 56: Scan Conversion of Polygons

56/70

Flood Fill – Example

Page 57: Scan Conversion of Polygons

57/70

Flood Fill – Example

Page 58: Scan Conversion of Polygons

58/70

Flood Fill – Example

Page 59: Scan Conversion of Polygons

59/70

Flood Fill – Example

Page 60: Scan Conversion of Polygons

60/70

Flood Fill – Example

Page 61: Scan Conversion of Polygons

61/70

Flood Fill – Example

Page 62: Scan Conversion of Polygons

62/70

Flood Fill – Example

Page 63: Scan Conversion of Polygons

63/70

Flood Fill – Example

Page 64: Scan Conversion of Polygons

64/70

Flood Fill – Example

Page 65: Scan Conversion of Polygons

65/70

Flood Fill – Example

Page 66: Scan Conversion of Polygons

66/70

Flood Fill – Example

Page 67: Scan Conversion of Polygons

67/70

Flood Fill – Example

Page 68: Scan Conversion of Polygons

68/70

Flood Fill – Example

Page 69: Scan Conversion of Polygons

69/70

OpenGL: Drawing Polygons

Lots of different primitives supported GPU only draws triangles

• OpenGL triangulates all polygons

• Problems with concave polygons! How data is passed to GPU makes a

significant difference in speed

GL_QUAD_STRIPGL_QUAD_STRIPGL_TRIANGLE_STRIPGL_TRIANGLE_STRIP GL_TRIANGLE_FANGL_TRIANGLE_FAN GL_POLYGONGL_POLYGONGL_QUADSGL_QUADSGL_TRIANGLESGL_TRIANGLES

Page 70: Scan Conversion of Polygons

70/70

Performance

Nvidia 7300 GT1

Nvidia 8800 GTX1

ATI Radeon

HD 48502

ATI Radeon

HD 48502

New Drivers

Immediate Mode 15.5 15.5 21.0 33.0

Display Lists 28.3 22.0 463.5 497.5

Vertex Arrays 33.5 35.5 75.0 335.0

Vertex Buffer Objects

50.0 200.0 476.3 506.0

Frames per second displaying a 413,236 triangle model. CPU was an Intel Core 2 67001

or Core i7 9402

.