Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 61

Graphics

2D Viewing

cgvr.korea.ac.kr 1 Graphics Lab @ Korea University


Contents
CGVR

 3D Rendering Pipeline
 2D Rendering Pipeline
 Clipping
 Cohen-Sutherland Line Clipping
 Sutherland-Hodgeman Polygon Clipping
 Viewport Transformation
 Scan Conversion
 Summary of Transformation

cgvr.korea.ac.kr 2 Graphics Lab @ Korea University


3D Rendering Pipeline
CGVR
3D Primitives
3D Modeling Coordinates
Model
Model Transformation
Transformation
3D World Coordinates
Lighting
Lighting
3D World Coordinates
Viewing
Viewing Transformation
Transformation
3D Viewing Coordinates
Projection
Projection Transformation
Transformation
2D Projection Coordinates
Clipping
Clipping
2D Projection Coordinates
Viewport
Viewport Transformation
Transformation
2D Device Coordinates
Scan
Scan Conversion
Conversion
Image 2D Device Coordinates
cgvr.korea.ac.kr 3 Graphics Lab @ Korea University
3D Rendering Pipeline
CGVR
3D Primitives
3D Modeling Coordinates
Model
Model Transformation
Transformation
3D World Coordinates
Lighting
Lighting
3D World Coordinates
Viewing
Viewing Transformation
Transformation
3D Viewing Coordinates
Projection
Projection Transformation
Transformation
2D Projection Coordinates
Clipping
Clipping
2D Projection Coordinates
Viewport
Viewport Transformation
Transformation
2D Device Coordinates
Scan
Scan Conversion
Conversion
Image 2D Device Coordinates
cgvr.korea.ac.kr 4 Graphics Lab @ Korea University
2D Rendering Pipeline
CGVR
3D Primitives

2D Primitives

Clip portions of geometric primitives


Clipping
Clipping residing outside window

Transform the clipped primitives


Viewport
Viewport Transformation
Transformation from screen to image coordinates

Fill pixel representing primitives


Scan
Scan Conversion
Conversion in screen coordinates

Image
cgvr.korea.ac.kr 5 Graphics Lab @ Korea University
2D Rendering Pipeline
CGVR
3D Primitives

2D Primitives

Clip portions of geometric primitives


Clipping
Clipping residing outside window

Transform the clipped primitives


Viewport
Viewport Transformation
Transformation from screen to image coordinates

Fill pixel representing primitives


Scan
Scan Conversion
Conversion in screen coordinates

Image
cgvr.korea.ac.kr 6 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
cgvr.korea.ac.kr 7 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

cgvr.korea.ac.kr 8 Graphics Lab @ Korea University


Clipping
CGVR

 Avoid Drawing Parts of Primitives Outside


Window
 Points
 Lines
 Polygons
 Circles
 etc.

cgvr.korea.ac.kr 9 Graphics Lab @ Korea University


Point Clipping
CGVR

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

wy2
Inside
Inside ==
(x>=wx1)
(x>=wx1) &&
&&
(x, y) (x<=wx2)
(x<=wx2) &&
&&
(y>=wy1)
(y>=wy1) &&
&&
(y<=wy2);
(y<=wy2);

wy1
wx1 wx2

cgvr.korea.ac.kr 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
P10

P5 P9
Before Clipping
cgvr.korea.ac.kr 11 Graphics Lab @ Korea University
Line Clipping
CGVR

 Find the Part of a Line Inside the Clip


Window
P’7

P4 P’8
P3

P6

P’5
After Clipping
cgvr.korea.ac.kr 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
P10

P5 P9

cgvr.korea.ac.kr 13 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 0001 0101
Bit 4
P1
P4 P8
1000 P3 0000 0100
P2
P6
P10
Bit 3
1010 P5 0010 P9 0110
Bit 1 Bit 2
cgvr.korea.ac.kr 14 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 0001 0101
Bit 4
P1
P4 P8
1000 P3 0000 0100
P2
P6
P10
Bit 3
1010 P5 0010 P9 0110
Bit 1 Bit 2
cgvr.korea.ac.kr 15 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 0001 0101
Bit 4

P4 P8
1000 P3 0000 0100

P6
P10
Bit 3
1010 P5 0010 P9 0110
Bit 1 Bit 2
cgvr.korea.ac.kr 16 Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Compute Intersections with Window Boundary for


Lines That Can’t be Classified Quickly
1001 P7 0001 0101
Bit 4

P4 P8
1000 P3 0000 0100

P6
P10
Bit 3
1010 P5 0010 P9 0110
Bit 1 Bit 2
cgvr.korea.ac.kr 17 Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Compute Intersections with Window Boundary for


Lines That Can’t be Classified Quickly
1001 P7 0001 0101
Bit 4

P4 P8
1000 P3 0000 0100

P6
P10
Bit 3
1010 P5 0010 P9 0110
Bit 1 Bit 2
cgvr.korea.ac.kr 18 Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Compute Intersections with Window Boundary for


Lines That Can’t be Classified Quickly
1001 P7 0001 0101
Bit 4

P4 P8
1000 P3 0000 0100

P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
cgvr.korea.ac.kr 19 Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Compute Intersections with Window Boundary for


Lines That Can’t be Classified Quickly
1001 P7 0001 0101
Bit 4

P4 P8
1000 P3 0000 0100

P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
cgvr.korea.ac.kr 20 Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Compute Intersections with Window Boundary for


Lines That Can’t be Classified Quickly
1001 P7 0001 0101
Bit 4

P4 P8
1000 P3 0000 0100

P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
cgvr.korea.ac.kr 21 Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Compute Intersections with Window Boundary for


Lines That Can’t be Classified Quickly
1001 P7 0001 0101
Bit 4

P4 P8
1000 P3 0000 0100

P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
cgvr.korea.ac.kr 22 Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Compute Intersections with Window Boundary for


Lines That Can’t be Classified Quickly
1001 0001
P’7 0101
Bit 4

P4 P8
1000 P3 0000 0100

P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
cgvr.korea.ac.kr 23 Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Compute Intersections with Window Boundary for


Lines That Can’t be Classified Quickly
1001 0001
P’7 0101
Bit 4

P4 P8
1000 P3 0000 0100

P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
cgvr.korea.ac.kr 24 Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Compute Intersections with Window Boundary for


Lines That Can’t be Classified Quickly
1001 0001
P’7 0101
Bit 4

P4 P’8
1000 P3 0000 0100

P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
cgvr.korea.ac.kr 25 Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Compute Intersections with Window Boundary for


Lines That Can’t be Classified Quickly
1001 0001
P’7 0101
Bit 4

P4 P’8
1000 P3 0000 0100

P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
cgvr.korea.ac.kr 26 Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Compute Intersections with Window Boundary for


Lines That Can’t be Classified Quickly
1001 0001
P’7 0101
Bit 4

P4 P’8
1000 P3 0000 0100

P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
cgvr.korea.ac.kr 27 Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Compute Intersections with Window Boundary for


Lines That Can’t be Classified Quickly
1001 0001
P’7 0101
Bit 4

P4 P’8
1000 P3 0000 0100

P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
cgvr.korea.ac.kr 28 Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Compute Intersections with Window Boundary for


Lines That Can’t be Classified Quickly
1001 0001
P’7 0101
Bit 4

P4 P’8
1000 P3 0000 0100

P6
P10
Bit 3
1010 P’5 0010 P’90110
Bit 1 Bit 2
cgvr.korea.ac.kr 29 Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Compute Intersections with Window Boundary for


Lines That Can’t be Classified Quickly
1001 0001
P’7 0101
Bit 4

P4 P’8
1000 P3 0000 0100

P6
P10
Bit 3
1010 P’5 0010 P’90110
Bit 1 Bit 2
cgvr.korea.ac.kr 30 Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Compute Intersections with Window Boundary for


Lines That Can’t be Classified Quickly
1001 0001
P’7 0101
Bit 4

P4 P’8
1000 P3 0000 0100

P6
Bit 3
1010 P’5 0010 0110
Bit 1 Bit 2
cgvr.korea.ac.kr 31 Graphics Lab @ Korea University
Polygon Clipping
CGVR

 Find the Part of a Polygon Inside the Clip


Window?

Before Clipping
cgvr.korea.ac.kr 32 Graphics Lab @ Korea University
Polygon Clipping
CGVR

 Find the Part of a Polygon Inside the Clip


Window?

After Clipping
cgvr.korea.ac.kr 33 Graphics Lab @ Korea University
Sutherland-Hodgeman Polygon
Clipping CGVR

 Clip to Each Window Boundary One at a


Time

cgvr.korea.ac.kr 34 Graphics Lab @ Korea University


Sutherland-Hodgeman Polygon
Clipping CGVR

 Clip to Each Window Boundary One at a


Time

cgvr.korea.ac.kr 35 Graphics Lab @ Korea University


Sutherland-Hodgeman Polygon
Clipping CGVR

 Clip to Each Window Boundary One at a


Time

cgvr.korea.ac.kr 36 Graphics Lab @ Korea University


Sutherland-Hodgeman Polygon
Clipping CGVR

 Clip to Each Window Boundary One at a


Time

cgvr.korea.ac.kr 37 Graphics Lab @ Korea University


Sutherland-Hodgeman Polygon
Clipping CGVR

 Clip to Each Window Boundary One at a


Time

cgvr.korea.ac.kr 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
Outside
P3 P5

P4
cgvr.korea.ac.kr 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
Outside
P3 P5

P4
cgvr.korea.ac.kr 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
Outside
P3 P5

P4
cgvr.korea.ac.kr 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
Outside
P3 P5

P4
cgvr.korea.ac.kr 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
Outside
P3 P5

P4
cgvr.korea.ac.kr 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
Outside
P3 P5

P4
cgvr.korea.ac.kr 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
Outside
P3 P5

P4
cgvr.korea.ac.kr 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” Inside
Outside
P3 P5

P4
cgvr.korea.ac.kr 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 P1
Window
Boundary P’ P” Inside
Outside

cgvr.korea.ac.kr 47 Graphics Lab @ Korea University


2D Rendering Pipeline
CGVR
3D Primitives

2D Primitives

Clip portions of geometric primitives


Clipping
Clipping residing outside window

Transform the clipped primitives


Viewport
Viewport Transformation
Transformation from screen to image coordinates

Fill pixel representing primitives


Scan
Scan Conversion
Conversion in screen coordinates

Image
cgvr.korea.ac.kr 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

cgvr.korea.ac.kr 49 Graphics Lab @ Korea University


Window vs. Viewport
CGVR

 Window
 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

cgvr.korea.ac.kr 50 Graphics Lab @ Korea University


Viewport Transformation
CGVR

 Window-to-Viewport Mapping
Window Viewport
wy2 vy2

(wx, wy) (vx, vy)


wy1 vy1
wx1 wx2 vx1 vx2
Screen Coordinates Image Coordinates

vx
vx == vx1
vx1 ++ (wx
(wx –– wx1)
wx1) ** (vx2
(vx2 –– vx1)
vx1) // (wx2
(wx2 –– wx1);
wx1);
vy
vy == vy1
vy1 ++ (wy
(wy –– wy1)
wy1) ** (vy2
(vy2 –– vy1)
vy1) // (wy2
(wy2 –– wy1);
wy1);

cgvr.korea.ac.kr 51 Graphics Lab @ Korea University


2D Rendering Pipeline
CGVR
3D Primitives

2D Primitives

Clip portions of geometric primitives


Clipping
Clipping residing outside window

Transform the clipped primitives


Viewport
Viewport Transformation
Transformation from screen to image coordinates

Fill pixel representing primitives


Scan
Scan Conversion
Conversion in screen coordinates

Image
cgvr.korea.ac.kr 52 Graphics Lab @ Korea University
Scan Conversion
CGVR

 Definition
 Figure out which pixels to fill

 Example
 Filling the inside of a triangle

P1

P2
P3
cgvr.korea.ac.kr 53 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
P

L2
cgvr.korea.ac.kr 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

cgvr.korea.ac.kr 55 Graphics Lab @ Korea University


Polygon Scan Conversion
CGVR

 Fill Pixels Inside a Polygon


 Triangle
 Quadrilateral
 Convex
 Star-Shaped
 Concave
 Self-Intersecting
 Holes

cgvr.korea.ac.kr 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

L L
1 1
L2 L5 L2 L5B
L5A

L3 L3
L4 L4

Convex Polygon Concave Polygon


cgvr.korea.ac.kr 57 Graphics Lab @ Korea University
Inside Polygon Rule
CGVR

 Odd-Parity Rule
 Any ray from P to infinity crosses odd number of
edges

Concave Self-Intersecting With Holes


cgvr.korea.ac.kr 58 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 Polygon
cgvr.korea.ac.kr 59 Graphics Lab @ Korea University
Polygon Scan Conversion
CGVR

 Hardware Scan Conversion


 Convert everything into Triangles

cgvr.korea.ac.kr 60 Graphics Lab @ Korea University


Summary of Transformation
CGVR
P(x, y, z)
3D Object Coordinates
Modeling
Modeling
Transformation
Transformation
3D World Coordinates
Viewing
Viewing
Transformation
Transformation
3D Viewing Coordinates
Projection
Projection
Transformation
Transformation
2D Projection Coordinates
Window-to-Viewport
Window-to-Viewport
Transformation
Transformation
2D Device Coordinates
P(x, y)
cgvr.korea.ac.kr 61 Graphics Lab @ Korea University

You might also like