Anda di halaman 1dari 61

Graphics

2D Viewing
Modified By Prof.Viswanathan.P

pviswanathan@vit.ac.in

Graphics Lab @ Korea University

Contents

3D Rendering Pipeline
2D Rendering Pipeline
Clipping

CGVR

Cohen-Sutherland Line Clipping


Sutherland-Hodgeman Polygon Clipping

Viewport Transformation
Scan Conversion
Summary of Transformation

pviswanathan@vit.ac.in

Graphics Lab @ Korea University

3D Rendering Pipeline

CGVR

3D Primitives
3D Modeling Coordinates
Model Transformation

3D World Coordinates
Lighting

3D World Coordinates
Viewing Transformation

3D Viewing Coordinates
Projection Transformation
2D Projection Coordinates
Clipping

2D Projection Coordinates
Viewport Transformation
2D Device Coordinates
Scan Conversion

2D Device Coordinates

Image
pviswanathan@vit.ac.in

Graphics Lab @ Korea University

3D Rendering Pipeline

CGVR

3D Primitives
3D Modeling Coordinates
Model Transformation

3D World Coordinates
Lighting

3D World Coordinates
Viewing Transformation

3D Viewing Coordinates
Projection Transformation
2D Projection Coordinates
Clipping

2D Projection Coordinates
Viewport Transformation
2D Device Coordinates
Scan Conversion

2D Device Coordinates

Image
pviswanathan@vit.ac.in

Graphics Lab @ Korea University

2D Rendering Pipeline

CGVR

3D Primitives
2D Primitives

Clipping

Viewport Transformation

Scan Conversion

Clip portions of geometric primitives


residing outside window

Transform the clipped primitives


from screen to image coordinates
Fill pixel representing primitives
in screen coordinates

Image
pviswanathan@vit.ac.in

Graphics Lab @ Korea University

2D Rendering Pipeline

CGVR

3D Primitives
2D Primitives

Clipping

Viewport Transformation

Scan Conversion

Clip portions of geometric primitives


residing outside window

Transform the clipped primitives


from screen to image coordinates
Fill pixel representing primitives
in screen coordinates

Image
pviswanathan@vit.ac.in

Graphics Lab @ Korea University

Clipping

CGVR

Avoid Drawing Parts of Primitives Outside


Window

Window defines part of scene being viewed


Must draw geometric primitives only inside window

World
Coordinates
pviswanathan@vit.ac.in

Graphics Lab @ Korea University

Clipping

CGVR

Avoid Drawing Parts of Primitives Outside


Window

Window defines part of scene being viewed


Must draw geometric primitives only inside window

pviswanathan@vit.ac.in

Graphics Lab @ Korea University

Clipping

CGVR

Avoid Drawing Parts of Primitives Outside


Window

Points
Lines
Polygons
Circles
etc.

pviswanathan@vit.ac.in

Graphics Lab @ Korea University

Point Clipping

CGVR

Is Point(x,y) Inside the Clip Window?

wy2

Inside =

(x>=wx1) &&
(x<=wx2) &&

(x, y)

(y>=wy1) &&

(y<=wy2);

wy1
wx1

pviswanathan@vit.ac.in

wx2

10

Graphics Lab @ Korea University

Line Clipping

CGVR

Find the Part of a Line Inside the Clip


Window
P7
P1

P4

P8

P3
P2

P6
P5

pviswanathan@vit.ac.in

11

P10

P9
Before Clipping
Graphics Lab @ Korea University

Line Clipping

CGVR

Find the Part of a Line Inside the Clip


Window
P7

P4

P8

P3
P6
P5
After Clipping
pviswanathan@vit.ac.in

12

Graphics Lab @ Korea University

Cohen-Sutherland Line
Clipping

CGVR

Use Simple Tests to Classify Easy Cases


First
P7
P1

P4

P8

P3
P2

P6
P5

pviswanathan@vit.ac.in

13

P10
P9
Graphics Lab @ Korea University

Cohen-Sutherland Line
Clipping

CGVR

Classify Some Lines Quickly by AND of Bit Codes


Representing Regions of Two Endpoints (Must Be 0)
1001
P7 1000
1010
Bit 4
P1
P4
0001

P3

P2

0000

P6

0101
P5
Bit 1
pviswanathan@vit.ac.in

P8
0010

14

0100

P10
P9

Bit 3

0110

Bit 2
Graphics Lab @ Korea University

Cohen-Sutherland Line
Clipping

CGVR

Classify Some Lines Quickly by AND of Bit Codes


Representing Regions of Two Endpoints (Must Be 0)
1001
P7 1000
1010
Bit 4
P1
P4
0001

P3

P2

0000

P6

0101
P5
Bit 1
pviswanathan@vit.ac.in

P8
0010

15

0100

P10
P9

Bit 3

0110

Bit 2
Graphics Lab @ Korea University

Cohen-Sutherland Line
Clipping

CGVR

Classify Some Lines Quickly by AND of Bit Codes


Representing Regions of Two Endpoints (Must Be 0)
1001
P7 1000
1010
Bit 4
P4
0001

P3

P8
0010

0000

P6
0101
P5
Bit 1
pviswanathan@vit.ac.in

16

0100

P10
P9

Bit 3

0110

Bit 2
Graphics Lab @ Korea University

Cohen-Sutherland Line
Clipping

CGVR

Compute Intersections with Window Boundary for


Lines That Cant be Classified Quickly
1001
P7 1000
1010

P4
0001

P3

P8
0010

0000

P6
0101
P5
Bit 1
pviswanathan@vit.ac.in

17

0100

P10
P9

Bit 4

Bit 3

0110

Bit 2
Graphics Lab @ Korea University

Cohen-Sutherland Line
Clipping

CGVR

Compute Intersections with Window Boundary for


Lines That Cant be Classified Quickly
1001
P7 1000
1010

P4
0001

P3

P8
0010

0000

P6
0101
P5
Bit 1
pviswanathan@vit.ac.in

18

0100

P10
P9

Bit 4

Bit 3

0110

Bit 2
Graphics Lab @ Korea University

Cohen-Sutherland Line
Clipping

CGVR

Compute Intersections with Window Boundary for


Lines That Cant be Classified Quickly
1001
P7 1000
1010

P4
0001

P3

P8
0010

0000

P6
P5
0101
Bit 1
pviswanathan@vit.ac.in

19

0100

P10
P9

Bit 4

Bit 3

0110

Bit 2
Graphics Lab @ Korea University

Cohen-Sutherland Line
Clipping

CGVR

Compute Intersections with Window Boundary for


Lines That Cant be Classified Quickly
1001
P7 1000
1010

P4
0001

P3

P8
0010

0000

P6
P5
0101
Bit 1
pviswanathan@vit.ac.in

20

0100

P10
P9

Bit 4

Bit 3

0110

Bit 2
Graphics Lab @ Korea University

Cohen-Sutherland Line
Clipping

CGVR

Compute Intersections with Window Boundary for


Lines That Cant be Classified Quickly
1001
P7 1000
1010

P4
0001

P3

P8
0010

0000

P6
P5
0101
Bit 1
pviswanathan@vit.ac.in

21

0100

P10
P9

Bit 4

Bit 3

0110

Bit 2
Graphics Lab @ Korea University

Cohen-Sutherland Line
Clipping

CGVR

Compute Intersections with Window Boundary for


Lines That Cant be Classified Quickly
1001
P7 1000
1010

P4
0001

P3

P8
0010

0000

P6
P5
0101
Bit 1
pviswanathan@vit.ac.in

22

0100

P10
P9

Bit 4

Bit 3

0110

Bit 2
Graphics Lab @ Korea University

Cohen-Sutherland Line
Clipping

CGVR

Compute Intersections with Window Boundary for


Lines That Cant be Classified Quickly
1001
1000
1010
P7

P4
0001

P3

P8
0010

0000

P6
P5
0101
Bit 1
pviswanathan@vit.ac.in

23

0100

P10
P9

Bit 4

Bit 3

0110

Bit 2
Graphics Lab @ Korea University

Cohen-Sutherland Line
Clipping

CGVR

Compute Intersections with Window Boundary for


Lines That Cant be Classified Quickly
1001
1000
1010
P7

P4
0001

P3

P8
0010

0000

P6
P5
0101
Bit 1
pviswanathan@vit.ac.in

24

0100

P10
P9

Bit 4

Bit 3

0110

Bit 2
Graphics Lab @ Korea University

Cohen-Sutherland Line
Clipping

CGVR

Compute Intersections with Window Boundary for


Lines That Cant be Classified Quickly
1001
1000
1010
P7

P4
0001

P3

0000

P8
0010

P6
P5
0101
Bit 1
pviswanathan@vit.ac.in

25

0100

P10
P9

Bit 4

Bit 3

0110

Bit 2
Graphics Lab @ Korea University

Cohen-Sutherland Line
Clipping

CGVR

Compute Intersections with Window Boundary for


Lines That Cant be Classified Quickly
1001
1000
1010
P7

P4
0001

P3

0000

P8
0010

P6
P5
0101
Bit 1
pviswanathan@vit.ac.in

26

0100

P10
P9

Bit 4

Bit 3

0110

Bit 2
Graphics Lab @ Korea University

Cohen-Sutherland Line
Clipping

CGVR

Compute Intersections with Window Boundary for


Lines That Cant be Classified Quickly
1001
1000
1010
P7

P4
0001

P3

0000

P8
0010

P6
P5
0101
Bit 1
pviswanathan@vit.ac.in

27

0100

P10
P9

Bit 4

Bit 3

0110

Bit 2
Graphics Lab @ Korea University

Cohen-Sutherland Line
Clipping

CGVR

Compute Intersections with Window Boundary for


Lines That Cant be Classified Quickly
1001
1000
1010
P7

P4
0001

P3

0000

P8
0010

P6
P5
0101
Bit 1
pviswanathan@vit.ac.in

28

0100

P10
P9

Bit 4

Bit 3

0110

Bit 2
Graphics Lab @ Korea University

Cohen-Sutherland Line
Clipping

CGVR

Compute Intersections with Window Boundary for


Lines That Cant be Classified Quickly
1001
1000
1010
P7

P4
0001

P3

0000

P8
0010

P6
P5
0101
Bit 1
pviswanathan@vit.ac.in

29

0100

Bit 4

P10

P90110

Bit 3

Bit 2
Graphics Lab @ Korea University

Cohen-Sutherland Line
Clipping

CGVR

Compute Intersections with Window Boundary for


Lines That Cant be Classified Quickly
1001
1000
1010
P7

P4
0001

P3

0000

P8
0010

P6
P5
0101
Bit 1
pviswanathan@vit.ac.in

30

0100

Bit 4

P10

P90110

Bit 3

Bit 2
Graphics Lab @ Korea University

Cohen-Sutherland Line
Clipping

CGVR

Compute Intersections with Window Boundary for


Lines That Cant be Classified Quickly
1001
1000
1010
P7

P4
0001

P3

0000

Bit 4

P8
0010

P6
P5
0101
Bit 1
pviswanathan@vit.ac.in

31

Bit 3
0100

0110

Bit 2
Graphics Lab @ Korea University

Polygon Clipping

CGVR

Find the Part of a Polygon Inside the Clip


Window?

Before Clipping
pviswanathan@vit.ac.in

32

Graphics Lab @ Korea University

Polygon Clipping

CGVR

Find the Part of a Polygon Inside the Clip


Window?

After Clipping
pviswanathan@vit.ac.in

33

Graphics Lab @ Korea University

Sutherland-Hodgeman Polygon
Clipping

CGVR

Clip to Each Window Boundary One at a


Time

pviswanathan@vit.ac.in

34

Graphics Lab @ Korea University

Sutherland-Hodgeman Polygon
Clipping

CGVR

Clip to Each Window Boundary One at a


Time

pviswanathan@vit.ac.in

35

Graphics Lab @ Korea University

Sutherland-Hodgeman Polygon
Clipping

CGVR

Clip to Each Window Boundary One at a


Time

pviswanathan@vit.ac.in

36

Graphics Lab @ Korea University

Sutherland-Hodgeman Polygon
Clipping

CGVR

Clip to Each Window Boundary One at a


Time

pviswanathan@vit.ac.in

37

Graphics Lab @ Korea University

Sutherland-Hodgeman Polygon
Clipping

CGVR

Clip to Each Window Boundary One at a


Time

pviswanathan@vit.ac.in

38

Graphics Lab @ Korea University

Clipping to a Boundary

CGVR

Do Inside Test for Each Point in Sequence,


Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary
P2

P1

Window
Boundary

Inside
P5

P3

Outside

P4
pviswanathan@vit.ac.in

39

Graphics Lab @ Korea University

Clipping to a Boundary

CGVR

Do Inside Test for Each Point in Sequence,


Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary
P2

P1

Window
Boundary

Inside
P5

P3

Outside

P4
pviswanathan@vit.ac.in

40

Graphics Lab @ Korea University

Clipping to a Boundary

CGVR

Do Inside Test for Each Point in Sequence,


Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary
P2

P1

Window
Boundary

Inside
P5

P3

Outside

P4
pviswanathan@vit.ac.in

41

Graphics Lab @ Korea University

Clipping to a Boundary

CGVR

Do Inside Test for Each Point in Sequence,


Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary
P2

P1

Window
Boundary

Inside
P5

P3

Outside

P4
pviswanathan@vit.ac.in

42

Graphics Lab @ Korea University

Clipping to a Boundary

CGVR

Do Inside Test for Each Point in Sequence,


Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary
P2

P1

Window
Boundary P

Inside
P5

P3

Outside

P4
pviswanathan@vit.ac.in

43

Graphics Lab @ Korea University

Clipping to a Boundary

CGVR

Do Inside Test for Each Point in Sequence,


Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary
P2

P1

Window
Boundary P

Inside
P5

P3

Outside

P4
pviswanathan@vit.ac.in

44

Graphics Lab @ Korea University

Clipping to a Boundary

CGVR

Do Inside Test for Each Point in Sequence,


Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary
P2

P1

Window
Boundary P

Inside
P5

P3

Outside

P4
pviswanathan@vit.ac.in

45

Graphics Lab @ Korea University

Clipping to a Boundary

CGVR

Do Inside Test for Each Point in Sequence,


Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary
P2

P1

Window
Boundary P

P
P5

P3

Inside
Outside

P4
pviswanathan@vit.ac.in

46

Graphics Lab @ Korea University

Clipping to a Boundary

CGVR

Do Inside Test for Each Point in Sequence,


Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary
P2
Window
Boundary P

P1

Inside
Outside

pviswanathan@vit.ac.in

47

Graphics Lab @ Korea University

2D Rendering Pipeline

CGVR

3D Primitives
2D Primitives

Clipping

Viewport Transformation

Scan Conversion

Clip portions of geometric primitives


residing outside window

Transform the clipped primitives


from screen to image coordinates
Fill pixel representing primitives
in screen coordinates

Image
pviswanathan@vit.ac.in

48

Graphics Lab @ Korea University

Viewport Transformation

CGVR

Transform 2D Geometric Primitives from


Screen Coordinate System (Projection
Coordinates) to Image Coordinate System
(Device Coordinates)
Screen

Image

Viewport

pviswanathan@vit.ac.in

49

Graphics Lab @ Korea University

Window vs. Viewport

Window

CGVR

World-coordinate area selected for display


What is to be viewed

Viewport

Area on the display device to which a window is


mapped
Where it is to be displayed

pviswanathan@vit.ac.in

50

Graphics Lab @ Korea University

Viewport Transformation

CGVR

Window-to-Viewport Mapping
Window

wy2

Viewport

vy2

(wx, wy)
wy1
wx1

(vx, vy)
wx2

Screen Coordinates

vy1
vx1

vx2

Image Coordinates

vx = vx1 + (wx wx1) * (vx2 vx1) / (wx2 wx1);


vy = vy1 + (wy wy1) * (vy2 vy1) / (wy2 wy1);
pviswanathan@vit.ac.in

51

Graphics Lab @ Korea University

2D Rendering Pipeline

CGVR

3D Primitives
2D Primitives

Clipping

Viewport Transformation

Scan Conversion

Clip portions of geometric primitives


residing outside window

Transform the clipped primitives


from screen to image coordinates
Fill pixel representing primitives
in screen coordinates

Image
pviswanathan@vit.ac.in

52

Graphics Lab @ Korea University

Scan Conversion

Definition

CGVR

Figure out which pixels to fill

Example

Filling the inside of a triangle

P1

P2
pviswanathan@vit.ac.in

53

P3
Graphics Lab @ Korea University

Triangle Scan Conversion

CGVR

Simple Algorithm

Color all pixels inside a triangle


Inside triangle test

A point is inside a triangle if it is in the positive halfspace of


all three boundary lines

L1

L3

L2
pviswanathan@vit.ac.in

54

Graphics Lab @ Korea University

Triangle Scan Conversion

CGVR

Triangle Sweep-Line Algorithm

Take advantage of spatial coherence

Compute which pixels are inside using horizontal spans


Process horizontal spans in scan-line order

Take advantage of edge linearity

Use edge slopes to update coordinates incrementally

dx

dy

pviswanathan@vit.ac.in

55

Graphics Lab @ Korea University

Polygon Scan Conversion

CGVR

Fill Pixels Inside a Polygon

Triangle
Quadrilateral
Convex
Star-Shaped
Concave
Self-Intersecting
Holes

pviswanathan@vit.ac.in

56

Graphics Lab @ Korea University

Inside Polygon Rule

CGVR

Need Better Test for Points Inside a Polygon

Inside triangle test works only for convex polygon

L2

L5

L2

L5B

L5A
L3

L3
L4

Convex Polygon
pviswanathan@vit.ac.in

57

L4
Concave Polygon
Graphics Lab @ Korea University

Inside Polygon Rule

CGVR

Odd-Parity Rule

Any ray from P to infinity crosses odd number of


edges

Concave
pviswanathan@vit.ac.in

Self-Intersecting
58

With Holes
Graphics Lab @ Korea University

Polygon Scan Conversion

CGVR

Polygon Line-Sweep Algorithm

Incremental algorithm to find spans, and determine


insideness with odd-parity rule

Triangle
pviswanathan@vit.ac.in

59

Polygon
Graphics Lab @ Korea University

Polygon Scan Conversion

CGVR

Hardware Scan Conversion

Convert everything into Triangles

pviswanathan@vit.ac.in

60

Graphics Lab @ Korea University

Summary of Transformation

CGVR

P(x, y, z)
3D Object Coordinates

Modeling
Transformation
3D World Coordinates

Viewing
Transformation
3D Viewing Coordinates

Projection
Transformation
2D Projection Coordinates

Window-to-Viewport
Transformation
2D Device Coordinates

P(x, y)
pviswanathan@vit.ac.in

61

Graphics Lab @ Korea University

Anda mungkin juga menyukai