ibl ) Sfzrn size (32 point, 1 point = 1/72 inch) serif ( better - - PDF document

ibl sfzrn
SMART_READER_LITE
LIVE PREVIEW

ibl ) Sfzrn size (32 point, 1 point = 1/72 inch) serif ( better - - PDF document

Einfhrung in Visual Computing Triangles and Polygon Filling Werner Purgathofer Institut fr Computergraphik und Algorithmen 2. Vorlesungseinheit Computergraphik Attributes of Graphics Output Primitives Points and Line Attributes in


slide-1
SLIDE 1

1

Einführung in Visual Computing

Werner Purgathofer

Institut für Computergraphik und Algorithmen

  • 2. Vorlesungseinheit “Computergraphik”

Triangles and Polygon Filling

Attributes of Graphics Output Primitives in 2D

points, lines characters

in 2D and 3D

triangles

Werner Purgathofer / Einf. in Visual Computing 2

triangles

  • ther polygons

((filled) ellipses and other curves)

color type: solid, dashed, dotted,… Points and Line Attributes

Werner Purgathofer / Einf. in Visual Computing 3

width, line caps, corners pen and brush options … text attributes

font (e.g. Courier, Arial, Times, Roman, …) styles (regular, bold, italic, underline,…) size (32 point, 1 point = 1/72 inch)

proportionally sized vs. fixed space fonts

Character Attributes

Werner Purgathofer / Einf. in Visual Computing 4

p p y p

string attributes

  • rientation

alignment (left, center, right, justify)

v e r t i c a l horizontal

Displayed primitives generated by the raster algorithms discussed in Chapter 3 have a jagged, or stairstep, appearance. Displayed primitives generated by the raster algorithms discussed in Chapter 3 have a jagged, or stairstep, appearance. Displayed primitives generated by the raster algorithms discussed in Chapter 3 have a jagged, or stairstep, appearance. Displayed primitives generated by the raster algorithms discussed in Chapter 3 have a jagged,

  • r

stairstep, appearance.

font (typeface)

design style for (family of) characters

Courier, Times, Arial, …

serif (better readable), if (b tt l ibl ) Sfzrn

Sf rn

Character Primitives

Werner Purgathofer 5

sans serif (better legible)

definition model

bitmap font (simple to define and display), needs more space (font cache)

  • utline font (more costly, less space,

geometric transformations)

Sfzrn

slide-2
SLIDE 2

2

Example: Newspaper

Werner Purgathofer 6

Character Generation Examples

Werner Purgathofer 7

the letter B represented with an 8x8 bilevel bitmap pattern and with an outline shape defined with straight line and curve segments fill styles

hollow, solid fill, pattern fill

fill options

edge type, width, color

pattern specification

through pattern tables

Area-Fill Attributes (1) 4 0 4 0 4 0 4 0 4 0

Werner Purgathofer / Einf. in Visual Computing 8

through pattern tables tiling (reference point)

4 0 0 4 4 0 0 4 4 0 0 4 4 0 0 4 4 0 0 4 4 0 0 4 4 0 0 4 4 0 0 4 4 0 0 4 4 0 0 4 4 0 0 4 4 0 0 4 4 0 0 4 combination of fill pattern with background colors soft fill

combination of colors

pattern back- ground and

  • r

xor

Area-Fill Attributes (2)

Werner Purgathofer / Einf. in Visual Computing 9

combination of colors antialiasing at object borders semitransparent brush simulation example: linear soft-fill

xor replace

F...foreground color B...background color

P = tF + (1  t)B

Triangle and Polygon Attributes color material transparency texture f d t il

Werner Purgathofer / Einf. in Visual Computing 10

surface details reflexion properties, … → defined illumination produces effects General Polygon Fill Algorithms triangle rasterization

  • ther polygons: what is inside?

scan-line fill method flood fill method

Werner Purgathofer / Einf. in Visual Computing 11

(α, β ,γ)

barycentric coordinates clean borders between adjacent triangles

slide-3
SLIDE 3

3

General Polygon Fill Algorithms triangle rasterization

  • ther polygons: what is inside?

scan-line fill method flood fill method

Werner Purgathofer / Einf. in Visual Computing 12

“interior”, “exterior” for self-intersecting polygons? General Polygon Fill Algorithms triangle rasterization

  • ther polygons: what is inside?

scan-line fill method flood fill method

Werner Purgathofer / Einf. in Visual Computing 13

interior pixels along a scan line passing through a polygon area General Polygon Fill Algorithms triangle rasterization

  • ther polygons: what is inside?

scan-line fill method flood fill method

Werner Purgathofer / Einf. in Visual Computing 14

starting from a seed point fill until you reach a border (α, β ,γ) Triangles: Barycentric Coordinates

P0(x0, y0) P2(x2, y2) (0, 0, 1) (0 60 0 13 0 27)

Werner Purgathofer / Einf. in Visual Computing 15

P1(x1, y1) (1, 0 ,0) (0, 1, 0) P = αP0 + βP1 + γP2 triangle = {P| α+β+γ=1, 0<α<1, 0<β<1, 0<γ<1} (0.60, 0.13, 0.27)

(α, β ,γ) Barycentric Coordinates

P0(x0,y0,z0) P2(x2,y2,z2) (0, 0, 1) (0 60 0 13 0 27)

Werner Purgathofer / Einf. in Visual Computing 16

P1(x1,y1,z1) (1, 0 ,0) (0, 1, 0) P = αP0 + βP1 + γP2 triangle = {P| α+β+γ=1, 0<α<1, 0<β<1, 0<γ<1} (0.60, 0.13, 0.27)

for all x for all y /* use a bounding box!*/ {compute (α, β ,γ) for (x,y) ; if (0<α<1) and (0<β<1) and (0<γ<1) Triangle Rasterization Algorithm <1 <1 <1

Werner Purgathofer / Einf. in Visual Computing 17

{c = αc0 + βc1 + γc2 ; draw pixel (x,y) with color c }}

P = αA + βB + γC triangle = {P| α+β+γ=1, 0<α<1, 0<β<1, 0<γ<1}

c = αc0 + βc1 + γc2 ; with color c interpolates values at the corners (vertices) linearly inside the triangle (and along edges)

slide-4
SLIDE 4

4

line through P1, P2: l12(x,y) = a12x+b12y+c12=0 then α = l12(x,y) / l12(x0,y0) β,γ analogous Computing (α, β ,γ) for P(x,y)

P2(x2, y2) l ( ) 0 P(x, y)

Werner Purgathofer / Einf. in Visual Computing 18

P = αP0 + βP1 + γP2 triangle = {P| α+β+γ=1, 0<α<1, 0<β<1, 0<γ<1} P0(x0, y0) P1(x1, y1) (α, β ,γ) l12(x,y)=0

Barycentric Coordinates Example

0.6 0 0 0.4 0 2 0.2 0 4 0.0 0 6 0.4 0.0 0.6 0.2 0.2 0.6 0.0 0.4 0.6 0.2 0.0 0.8 0.0 0.2 0.8 0.0 0.0 1.0 1.2 0 6 1.0 0 4 0.8 0 2

  • 0.2

0 8 1.2

  • 0.8

0.6 1.0

  • 0.6

0.6 0.8

  • 0.4

0.6 0.6

  • 0.2

0.6

  • 0.2

0.6 0.6 1.2

  • 1.0

0.8 1.0

  • 0.8

0.8 0.8

  • 0.6

0.8 0.6

  • 0.4

0.8 0.4

  • 0.2

0.8

  • 0.2

0.4 0.8 1.2

  • 1.2

1.0 1.0

  • 1.0

1.0 0.8

  • 0.8

1.0 0.6

  • 0.6

1.0 0.4

  • 0.4

1.0 0.2

  • 0.2

1.0

  • 0.2

0.2 1.0 1.2

  • 1.4

1.2 1.0

  • 1.2

1.2 0.8

  • 1.0

1.2 0.6

  • 0.8

1.2 0.4

  • 0.6

1.2 0.2

  • 0.4

1.2 0.0

  • 0.2

1.2

  • 0.2

0.0 1.2

P = αP0 + βP1 + γP2 triangle = {P| α+β+γ=1, 0<α<1, 0<β<1, 0<γ<1}

Werner Purgathofer / Einf. in Visual Computing 19

1.0 0.0 0.0 0.0 1.0 0.0 0.8 0.2 0.0 0.6 0.4 0.0 0.4 0.6 0.0 0.2 0.8 0.0 0.8 0.0 0.2 0.6 0.2 0.2 0.4 0.4 0.2 0.2 0.6 0.2 0.0 0.8 0.2 0.0 0.4 0.2 0.4 0.4 0.4 0.6 0.4 1.2 0.0

  • 0.2

1.0 0.2

  • 0.2

0.8 0.4

  • 0.2

0.6 0.6

  • 0.2

0.4 0.8

  • 0.2

0.2 1.0

  • 0.2

0.0 1.2

  • 0.2
  • 0.2

1.4

  • 0.2

1.2

  • 0.2

0.0

  • 0.2

1.2 0.0 1.2

  • 0.4

0.2 1.0

  • 0.2

0.2

  • 0.2

1.0 0.2

  • 0.6

0.4

  • 0.4

0.4

  • 0.2

0.4 0.8 0.4

Avoiding to Draw Borders twice don‘t draw the outline of the triangle!

result would depend on rendering order

draw only pixels that are inside exact triangle

i.e. pixels with α, β ,γ = 0, 1 are not drawn

Werner Purgathofer / Einf. in Visual Computing 20

clean borders between adjacent triangles

Pixels exactly on a Border holes if both triangles leave pixels away simplest solution: draw both pixels better: arbitrary choice based on some test

e.g. only right boundaries

Werner Purgathofer / Einf. in Visual Computing 21

clean borders between adjacent triangles

What is Inside a Polygon?

Werner Purgathofer / Einf. in Visual Computing 22

  • dd-even rule

nonzero-winding- number rule ??? area-filling algorithms

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

  • dd-even rule

nonzero winding number rule

Inside-Outside Tests

Werner Purgathofer / Einf. in Visual Computing 23

nonzero-winding-number rule same result for simple polygons

slide-5
SLIDE 5

5

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

Werner Purgathofer / Einf. in Visual Computing 24

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

Werner Purgathofer / Einf. in Visual Computing 25

Polygon Fill Areas polygon classifications

convex: no interior angle > 180° concave: not convex

concavity test

vector method

Werner Purgathofer / Einf. in Visual Computing 26

vector method

all vector cross products have the same sign

 convex

rotational method

rotate polygon-edges onto x-axis, always same direction  convex

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

Fill-Area Primitives

Werner Purgathofer / Einf. in Visual Computing 27

exploit coherence (incremental calculations)

flood fill algorithm

Scan-Line Fill: Sorted Edge Table

B C D E yB xC 1/mCB yD xC 1/mCD yE xD 1/mDE

Werner Purgathofer / Einf. in Visual Computing 28

A F yF xA 1/mAF yB xA 1/mAB yE xF 1/mFE

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

yB xC 1/mCB yD xC 1/mCD

Werner Purgathofer / Einf. in Visual Computing 29

active-edge list

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

consecutive intersection pairs (spans) filled

slide-6
SLIDE 6

6

Sorted Edge Table

B C D E yB xC 1/mCB yD xC 1/mCD yE xD 1/mDE

Werner Purgathofer / Einf. in Visual Computing 30

A F yF xA 1/mAF yB xA 1/mAB yE xF 1/mFE

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

ymax xstart 1/m

Sorted Edge Table / Active Edge List

B C D E yB xC 1/mCB yD xC 1/mCD yE xD 1/mDE

Werner Purgathofer / Einf. in Visual Computing 31

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

  • f all active edges

A F yF xA 1/mAF yB xA 1/mAB yE xF 1/mFE

Sorted Edge Table / Active Edge List

B C D E yB xC 1/mCB yD xC 1/mCD yE xD 1/mDE

Werner Purgathofer / Einf. in Visual Computing 32

Active Edge List

yF xA 1/mAF yB xA 1/mAB A F yF xA 1/mAF yB xA 1/mAB yE xF 1/mFE

incremental update! Sorted Edge Table / Active Edge List

B C D E yB xC 1/mCB yD xC 1/mCD yE xD 1/mDE

Werner Purgathofer / Einf. in Visual Computing 33

Active Edge List

yF xA 1/mAF yB xA 1/mAB A F yF xA 1/mAF yB xA 1/mAB yE xF 1/mFE

Sorted Edge Table / Active Edge List

B C D E yB xC 1/mCB yD xC 1/mCD yE xD 1/mDE

Werner Purgathofer / Einf. in Visual Computing 34

Active Edge List

yE xF 1/mFE yB xA 1/mAB A F yF xA 1/mAF yB xA 1/mAB yE xF 1/mFE

Sorted Edge Table / Active Edge List

B C D E yB xC 1/mCB yD xC 1/mCD yE xD 1/mDE

Werner Purgathofer / Einf. in Visual Computing 35

Active Edge List

yE xF 1/mFE yB xA 1/mAB A F yF xA 1/mAF yB xA 1/mAB yE xF 1/mFE

slide-7
SLIDE 7

7

Sorted Edge Table / Active Edge List

B C D E yB xC 1/mCB yD xC 1/mCD yE xD 1/mDE

Werner Purgathofer / Einf. in Visual Computing 36

Active Edge List

yE xF 1/mFE yB xA 1/mAB A F yF xA 1/mAF yB xA 1/mAB yE xF 1/mFE

Sorted Edge Table / Active Edge List

B C D E yB xC 1/mCB yD xC 1/mCD yE xD 1/mDE

Werner Purgathofer / Einf. in Visual Computing 37

Active Edge List

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

Sorted Edge Table / Active Edge List

B C D E yB xC 1/mCB yD xC 1/mCD yE xD 1/mDE

Werner Purgathofer / Einf. in Visual Computing 38

Active Edge List

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

Sorted Edge Table / Active Edge List

B C D E yB xC 1/mCB yD xC 1/mCD yE xD 1/mDE

Werner Purgathofer / Einf. in Visual Computing 39

Active Edge List

yE xF 1/mFE yD xC 1/mCD A F yF xA 1/mAF yB xA 1/mAB yE xF 1/mFE

Sorted Edge Table / Active Edge List

B C D E yB xC 1/mCB yD xC 1/mCD yE xD 1/mDE

Werner Purgathofer / Einf. in Visual Computing 40

Active Edge List

yE xF 1/mFE yD xC 1/mCD A F yF xA 1/mAF yB xA 1/mAB yE xF 1/mFE

Sorted Edge Table / Active Edge List

B C D E yB xC 1/mCB yD xC 1/mCD yE xD 1/mDE

Werner Purgathofer / Einf. in Visual Computing 41

Active Edge List

yE xF 1/mFE yE xD 1/mDE A F yF xA 1/mAF yB xA 1/mAB yE xF 1/mFE

slide-8
SLIDE 8

8

Sorted Edge Table / Active Edge List

B C D E yB xC 1/mCB yD xC 1/mCD yE xD 1/mDE

Werner Purgathofer / Einf. in Visual Computing 42

Active Edge List

yE xF 1/mFE yE xD 1/mDE A F yF xA 1/mAF yB xA 1/mAB yE xF 1/mFE

Sorted Edge Table / Active Edge List

B C D E yB xC 1/mCB yD xC 1/mCD yE xD 1/mDE

Werner Purgathofer / Einf. in Visual Computing 43

Active Edge List

A F yF xA 1/mAF yB xA 1/mAB yE xF 1/mFE

incremental update of intersection point

1

1

 

 k k

y y m x x

k k

1

1

 

slope of polygon boundary line: m Scan-Line Fill: Incremental Update

Werner Purgathofer / Einf. in Visual Computing 44

m

(for 2 successive scanlines) yk +1 yk (xk, yk) (xk+1, yk+1) intersection points along scan lines that intersect polygon vertices Scan-Line Fill: Intersecting Vertices

1 1 2 2 2

Werner Purgathofer / Einf. in Visual Computing 45

vertices.

→ either special handling (1 or 2 intersections?) → or move vertices up or down by ε

pixel filling of area

areas with no single color boundary start from interior point “flood” internal region

Flood-Fill Algorithm

Werner Purgathofer / Einf. in Visual Computing 46

4-connected, 8-connected areas reduce stack size by eliminating several recursive calls

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

Werner Purgathofer / Einf. in Visual Computing 47

example: area defined within multiple color boundaries

seed point

slide-9
SLIDE 9

9

Definition: Definition: Flood-Fill: Connectedness

Werner Purgathofer / Einf. in Visual Computing 48

Definition: 4-connected means, that a connection is

  • nly valid in these 4

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

Werner Purgathofer / Einf. in Visual Computing 49

has an 8-connected border an 8-connected area has a 4-connected border a 4-connected area 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) {

Werner Purgathofer / Einf. in Visual Computing 50

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 Bad Behavior of Simple Flood-Fill

Werner Purgathofer / Einf. in Visual Computing 51

sequence floodFill4 produces too high stacks (recursion!) solution:

incremental horizontal fill (left to right)

Span Flood-Fill Algorithm

Werner Purgathofer / Einf. in Visual Computing 52

( g ) recursive vertical fill (first up then down)

1 2 recursion Good Behavior of Span Flood-Fill

Werner Purgathofer / Einf. in Visual Computing 53

sequence

slide-10
SLIDE 10

10

Span Flood-Fill Example Stack: x

Werner Purgathofer / Einf. in Visual Computing 54

Span Flood-Fill Example B Stack: x A B

Werner Purgathofer / Einf. in Visual Computing 55

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

Werner Purgathofer / Einf. in Visual Computing 56

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

Werner Purgathofer / Einf. in Visual Computing 57

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

Werner Purgathofer / Einf. in Visual Computing 58

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

Werner Purgathofer / Einf. in Visual Computing 59

A 1 2 3 E H C D

slide-11
SLIDE 11

11

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

Werner Purgathofer / Einf. in Visual Computing 60

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

Werner Purgathofer / Einf. in Visual Computing 61

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

Werner Purgathofer / Einf. in Visual Computing 62

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

Werner Purgathofer / Einf. in Visual Computing 63

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

Werner Purgathofer / Einf. in Visual Computing 64

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

Werner Purgathofer / Einf. in Visual Computing 65

1 2 3 C 20 21 22 24 25 26 27 28 29 30 L 31 32 33 34 35

slide-12
SLIDE 12

12

Span Flood-Fill Example Stack: C L 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 23

Werner Purgathofer / Einf. in Visual Computing 66

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

Werner Purgathofer / Einf. in Visual Computing 67

1 2 3 20 21 22 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 finished!