Graphics
cgvr.korea.ac.kr 1 Graphics Lab @ Korea University
2D Viewing
고려대학교 컴퓨터 그래픽스 연구실
cgvr.korea.ac.kr
CGVR
2 Graphics Lab @ Korea University
Contents
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
CGVR
3 Graphics Lab @ Korea University
3D Rendering Pipeline
Model TransformationModel Transformation
LightingLighting
Viewing TransformationViewing Transformation
Projection TransformationProjection Transformation
ClippingClipping
Viewport TransformationViewport Transformation
Scan ConversionScan Conversion
3D Primitives
Image
3D Modeling Coordinates
3D World Coordinates
3D World Coordinates
3D Viewing Coordinates
2D Projection Coordinates
2D Projection Coordinates
2D Device Coordinates
2D Device Coordinates
cgvr.korea.ac.kr
CGVR
4 Graphics Lab @ Korea University
3D Rendering Pipeline
Model TransformationModel Transformation
LightingLighting
Viewing TransformationViewing Transformation
Projection TransformationProjection Transformation
ClippingClipping
Viewport TransformationViewport Transformation
Scan ConversionScan Conversion
3D Primitives
Image
3D Modeling Coordinates
3D World Coordinates
3D World Coordinates
3D Viewing Coordinates
2D Projection Coordinates
2D Projection Coordinates
2D Device Coordinates
2D Device Coordinates
cgvr.korea.ac.kr
CGVR
5 Graphics Lab @ Korea University
2D Rendering Pipeline
3D Primitives
ClippingClipping
Viewport TransformationViewport Transformation
Scan ConversionScan Conversion
Image
Clip portions of geometric primitives residing outside window
Transform the clipped primitives from screen to image coordinates
Fill pixel representing primitives in screen coordinates
2D Primitives
cgvr.korea.ac.kr
CGVR
6 Graphics Lab @ Korea University
2D Rendering Pipeline
3D Primitives
ClippingClipping
Viewport TransformationViewport Transformation
Scan ConversionScan Conversion
Image
Clip portions of geometric primitives residing outside window
Transform the clipped primitives from screen to image coordinates
Fill pixel representing primitives in screen coordinates
2D Primitives
cgvr.korea.ac.kr
CGVR
7 Graphics Lab @ Korea University
Clipping
Avoid Drawing Parts of Primitives Outside Window Window defines part of scene being viewed Must draw geometric primitives only inside window
WorldCoordinates
cgvr.korea.ac.kr
CGVR
8 Graphics Lab @ Korea University
Clipping
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
CGVR
9 Graphics Lab @ Korea University
Clipping
Avoid Drawing Parts of Primitives Outside Window Points Lines Polygons Circles etc.
cgvr.korea.ac.kr
CGVR
10 Graphics Lab @ Korea University
Point Clipping
Is Point(x,y) Inside the Clip Window?
(x, y)
wx2wx1wy1
wy2Inside =
(x>=wx1) &&
(x<=wx2) &&
(y>=wy1) &&
(y<=wy2);
Inside =
(x>=wx1) &&
(x<=wx2) &&
(y>=wy1) &&
(y<=wy2);
cgvr.korea.ac.kr
CGVR
11 Graphics Lab @ Korea University
Line Clipping
Find the Part of a Line Inside the Clip Window
P7
P8
P10
P9
P1
P2
P5
P4P3
P6
Before Clipping
cgvr.korea.ac.kr
CGVR
12 Graphics Lab @ Korea University
Line Clipping
Find the Part of a Line Inside the Clip Window
After Clipping
P4P3
P6
P’8
P’7
P’5
cgvr.korea.ac.kr
CGVR
13 Graphics Lab @ Korea University
Cohen-Sutherland Line Clipping
Use Simple Tests to Classify Easy Cases First
P7
P8
P10
P9
P1
P2
P5
P4P3
P6
cgvr.korea.ac.kr
CGVR
14 Graphics Lab @ Korea University
Cohen-Sutherland Line Clipping
Classify Some Lines Quickly by AND of Bit Codes Representing Regions of Two Endpoints (Must Be 0)
P10
P5
P6
P9
0001P7
P8
0101
0100
01100010
0000
1010
1000
P1
P2
1001
P4P3
Bit 4
Bit 3
Bit 2Bit 1
cgvr.korea.ac.kr
CGVR
15 Graphics Lab @ Korea University
Cohen-Sutherland Line Clipping
Classify Some Lines Quickly by AND of Bit Codes Representing Regions of Two Endpoints (Must Be 0)
P10
P5
P6
P9
0001P7
P8
0101
0100
01100010
0000
1010
1000
P1
P2
1001
P4P3
Bit 4
Bit 3
Bit 2Bit 1
cgvr.korea.ac.kr
CGVR
16 Graphics Lab @ Korea University
Cohen-Sutherland Line Clipping
Classify Some Lines Quickly by AND of Bit Codes Representing Regions of Two Endpoints (Must Be 0)
P10
P5
P6
P9
0001P7
P8
0101
0100
01100010
0000
1010
1000
1001
P4P3
Bit 4
Bit 3
Bit 2Bit 1
cgvr.korea.ac.kr
CGVR
17 Graphics Lab @ Korea University
Cohen-Sutherland Line Clipping
Compute Intersections with Window Boundary for Lines That Can’t be Classified Quickly
P10
P5
P6
P9
0001P7
P8
0101
0100
01100010
0000
1010
1000
1001
P4P3
Bit 4
Bit 3
Bit 2Bit 1
cgvr.korea.ac.kr
CGVR
18 Graphics Lab @ Korea University
Cohen-Sutherland Line Clipping
Compute Intersections with Window Boundary for Lines That Can’t be Classified Quickly
P10
P5
P6
P9
0001P7
P8
0101
0100
01100010
0000
1010
1000
1001
P4P3
Bit 4
Bit 3
Bit 2Bit 1
cgvr.korea.ac.kr
CGVR
19 Graphics Lab @ Korea University
Cohen-Sutherland Line Clipping
Compute Intersections with Window Boundary for Lines That Can’t be Classified Quickly
P10P6
P9
0001P7
P8
0101
0100
01100010
0000
1010
1000
1001
P4P3
Bit 4
Bit 3
Bit 2Bit 1
P’5
cgvr.korea.ac.kr
CGVR
20 Graphics Lab @ Korea University
Cohen-Sutherland Line Clipping
Compute Intersections with Window Boundary for Lines That Can’t be Classified Quickly
P10P6
P9
0001P7
P8
0101
0100
01100010
0000
1010
1000
1001
P4P3
Bit 4
Bit 3
Bit 2Bit 1
P’5
cgvr.korea.ac.kr
CGVR
21 Graphics Lab @ Korea University
Cohen-Sutherland Line Clipping
Compute Intersections with Window Boundary for Lines That Can’t be Classified Quickly
P10P6
P9
0001P7
P8
0101
0100
01100010
0000
1010
1000
1001
P4P3
Bit 4
Bit 3
Bit 2Bit 1
P’5
cgvr.korea.ac.kr
CGVR
22 Graphics Lab @ Korea University
Cohen-Sutherland Line Clipping
Compute Intersections with Window Boundary for Lines That Can’t be Classified Quickly
P10P6
P9
0001P7
P8
0101
0100
01100010
0000
1010
1000
1001
P4P3
Bit 4
Bit 3
Bit 2Bit 1
P’5
cgvr.korea.ac.kr
CGVR
23 Graphics Lab @ Korea University
Cohen-Sutherland Line Clipping
Compute Intersections with Window Boundary for Lines That Can’t be Classified Quickly
P10P6
P9
0001
P8
0101
0100
01100010
0000
1010
1000
1001
P4P3
Bit 4
Bit 3
Bit 2Bit 1
P’5
P’7
cgvr.korea.ac.kr
CGVR
24 Graphics Lab @ Korea University
Cohen-Sutherland Line Clipping
Compute Intersections with Window Boundary for Lines That Can’t be Classified Quickly
P10P6
P9
0001
P8
0101
0100
01100010
0000
1010
1000
1001
P4P3
Bit 4
Bit 3
Bit 2Bit 1
P’5
P’7
cgvr.korea.ac.kr
CGVR
25 Graphics Lab @ Korea University
Cohen-Sutherland Line Clipping
Compute Intersections with Window Boundary for Lines That Can’t be Classified Quickly
P10P6
P9
0001 0101
0100
01100010
0000
1010
1000
1001
P4P3
Bit 4
Bit 3
Bit 2Bit 1
P’5
P’7
P’8
cgvr.korea.ac.kr
CGVR
26 Graphics Lab @ Korea University
Cohen-Sutherland Line Clipping
Compute Intersections with Window Boundary for Lines That Can’t be Classified Quickly
P10P6
P9
0001 0101
0100
01100010
0000
1010
1000
1001
P4P3
Bit 4
Bit 3
Bit 2Bit 1
P’5
P’7
P’8
cgvr.korea.ac.kr
CGVR
27 Graphics Lab @ Korea University
Cohen-Sutherland Line Clipping
Compute Intersections with Window Boundary for Lines That Can’t be Classified Quickly
P10P6
P9
0001 0101
0100
01100010
0000
1010
1000
1001
P4P3
Bit 4
Bit 3
Bit 2Bit 1
P’5
P’7
P’8
cgvr.korea.ac.kr
CGVR
28 Graphics Lab @ Korea University
Cohen-Sutherland Line Clipping
Compute Intersections with Window Boundary for Lines That Can’t be Classified Quickly
P10P6
P9
0001 0101
0100
01100010
0000
1010
1000
1001
P4P3
Bit 4
Bit 3
Bit 2Bit 1
P’5
P’7
P’8
cgvr.korea.ac.kr
CGVR
29 Graphics Lab @ Korea University
Cohen-Sutherland Line Clipping
Compute Intersections with Window Boundary for Lines That Can’t be Classified Quickly
P10P6
0001 0101
0100
01100010
0000
1010
1000
1001
P4P3
Bit 4
Bit 3
Bit 2Bit 1
P’5
P’7
P’8
P’9
cgvr.korea.ac.kr
CGVR
30 Graphics Lab @ Korea University
Cohen-Sutherland Line Clipping
Compute Intersections with Window Boundary for Lines That Can’t be Classified Quickly
P6
0001 0101
0100
01100010
0000
1010
1000
1001
P4P3
Bit 4
Bit 3
Bit 2Bit 1
P’5
P’7
P’8
P10P’9
cgvr.korea.ac.kr
CGVR
31 Graphics Lab @ Korea University
Cohen-Sutherland Line Clipping
Compute Intersections with Window Boundary for Lines That Can’t be Classified Quickly
P6
0001 0101
0100
01100010
0000
1010
1000
1001
P4P3
Bit 4
Bit 3
Bit 2Bit 1
P’5
P’7
P’8
cgvr.korea.ac.kr
CGVR
32 Graphics Lab @ Korea University
Polygon Clipping
Find the Part of a Polygon Inside the Clip Window?
Before Clipping
cgvr.korea.ac.kr
CGVR
33 Graphics Lab @ Korea University
Polygon Clipping
Find the Part of a Polygon Inside the Clip Window?
After Clipping
cgvr.korea.ac.kr
CGVR
34 Graphics Lab @ Korea University
Sutherland-Hodgeman Polygon Clipping
Clip to Each Window Boundary One at a Time
cgvr.korea.ac.kr
CGVR
35 Graphics Lab @ Korea University
Sutherland-Hodgeman Polygon Clipping
Clip to Each Window Boundary One at a Time
cgvr.korea.ac.kr
CGVR
36 Graphics Lab @ Korea University
Sutherland-Hodgeman Polygon Clipping
Clip to Each Window Boundary One at a Time
cgvr.korea.ac.kr
CGVR
37 Graphics Lab @ Korea University
Sutherland-Hodgeman Polygon Clipping
Clip to Each Window Boundary One at a Time
cgvr.korea.ac.kr
CGVR
38 Graphics Lab @ Korea University
Sutherland-Hodgeman Polygon Clipping
Clip to Each Window Boundary One at a Time
cgvr.korea.ac.kr
CGVR
39 Graphics Lab @ Korea University
Clipping to a Boundary
Do Inside Test for Each Point in Sequence,
Insert New Points When Cross Window Boundary, Remove Points Outside Window Boundary
P1P2
P3
P4
P5
Inside
Outside
Window Boundary
cgvr.korea.ac.kr
CGVR
40 Graphics Lab @ Korea University
Clipping to a Boundary
Do Inside Test for Each Point in Sequence,
Insert New Points When Cross Window Boundary, Remove Points Outside Window Boundary
P1P2
P3
P4
P5
Inside
Outside
Window Boundary
cgvr.korea.ac.kr
CGVR
41 Graphics Lab @ Korea University
Clipping to a Boundary
Do Inside Test for Each Point in Sequence,
Insert New Points When Cross Window Boundary, Remove Points Outside Window Boundary
P1P2
P3
P4
P5
Inside
Outside
Window Boundary
cgvr.korea.ac.kr
CGVR
42 Graphics Lab @ Korea University
Clipping to a Boundary
Do Inside Test for Each Point in Sequence,
Insert New Points When Cross Window Boundary, Remove Points Outside Window Boundary
P1P2
P3
P4
P5
Inside
Outside
Window Boundary
cgvr.korea.ac.kr
CGVR
43 Graphics Lab @ Korea University
Clipping to a Boundary
Do Inside Test for Each Point in Sequence,
Insert New Points When Cross Window Boundary, Remove Points Outside Window Boundary
P1P2
P3
P4
P5
Inside
Outside
Window Boundary P’
cgvr.korea.ac.kr
CGVR
44 Graphics Lab @ Korea University
Clipping to a Boundary
Do Inside Test for Each Point in Sequence,
Insert New Points When Cross Window Boundary, Remove Points Outside Window Boundary
P1P2
P3
P4
P5
Inside
Outside
Window Boundary P’
cgvr.korea.ac.kr
CGVR
45 Graphics Lab @ Korea University
Clipping to a Boundary
Do Inside Test for Each Point in Sequence,
Insert New Points When Cross Window Boundary, Remove Points Outside Window Boundary
P1P2
P3
P4
P5
Inside
Outside
Window Boundary P’
cgvr.korea.ac.kr
CGVR
46 Graphics Lab @ Korea University
Clipping to a Boundary
Do Inside Test for Each Point in Sequence,
Insert New Points When Cross Window Boundary, Remove Points Outside Window Boundary
P1P2
P3
P4
P5
Inside
Outside
Window Boundary P’ P”
cgvr.korea.ac.kr
CGVR
47 Graphics Lab @ Korea University
Clipping to a Boundary
Do Inside Test for Each Point in Sequence,
Insert New Points When Cross Window Boundary, Remove Points Outside Window Boundary
P1P2
Inside
Outside
Window Boundary P’ P”
cgvr.korea.ac.kr
CGVR
48 Graphics Lab @ Korea University
2D Rendering Pipeline
3D Primitives
ClippingClipping
Viewport TransformationViewport Transformation
Scan ConversionScan Conversion
Image
Clip portions of geometric primitives residing outside window
Transform the clipped primitives from screen to image coordinates
Fill pixel representing primitives in screen coordinates
2D Primitives
cgvr.korea.ac.kr
CGVR
49 Graphics Lab @ Korea University
Viewport Transformation
Transform 2D Geometric Primitives from Screen Coordinate System (Projection Coordinates) to Image Coordinate System (Device Coordinates)
Screen Image
Viewport
cgvr.korea.ac.kr
CGVR
50 Graphics Lab @ Korea University
Window vs. Viewport
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
CGVR
51 Graphics Lab @ Korea University
Viewport Transformation
Window-to-Viewport Mapping
(wx, wy)
wx2wx1wy1
wy2
(vx, vy)
vx2vx1vy1
vy2Window Viewport
Screen Coordinates Image Coordinates
vx = vx1 + (wx – wx1) * (vx2 – vx1) / (wx2 – wx1);
vy = vy1 + (wy – wy1) * (vy2 – vy1) / (wy2 – wy1);
vx = vx1 + (wx – wx1) * (vx2 – vx1) / (wx2 – wx1);
vy = vy1 + (wy – wy1) * (vy2 – vy1) / (wy2 – wy1);
cgvr.korea.ac.kr
CGVR
52 Graphics Lab @ Korea University
2D Rendering Pipeline
3D Primitives
ClippingClipping
Viewport TransformationViewport Transformation
Scan ConversionScan Conversion
Image
Clip portions of geometric primitives residing outside window
Transform the clipped primitives from screen to image coordinates
Fill pixel representing primitives in screen coordinates
2D Primitives
cgvr.korea.ac.kr
CGVR
53 Graphics Lab @ Korea University
Scan Conversion
Definition Figure out which pixels to fill
Example Filling the inside of a triangle
P1
P2P3
cgvr.korea.ac.kr
CGVR
54 Graphics Lab @ Korea University
Triangle Scan Conversion
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
L2
L3P
cgvr.korea.ac.kr
CGVR
55 Graphics Lab @ Korea University
Triangle Scan Conversion
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
dxdy
cgvr.korea.ac.kr
CGVR
56 Graphics Lab @ Korea University
Polygon Scan Conversion
Fill Pixels Inside a Polygon Triangle Quadrilateral Convex Star-Shaped Concave Self-Intersecting Holes
cgvr.korea.ac.kr
CGVR
57 Graphics Lab @ Korea University
Inside Polygon Rule
Need Better Test for Points Inside a Polygon “Inside triangle test” works only for convex polygon
L
1L2
L3L4
L5
L
1L2
L3L4
L5A
L5B
Convex Polygon Concave Polygon
cgvr.korea.ac.kr
CGVR
58 Graphics Lab @ Korea University
Inside Polygon Rule
Odd-Parity Rule Any ray from P to infinity crosses odd number of
edges
Concave Self-Intersecting With Holes
cgvr.korea.ac.kr
CGVR
59 Graphics Lab @ Korea University
Polygon Scan Conversion
Polygon Line-Sweep Algorithm Incremental algorithm to find spans, and determine
insideness with odd-parity rule
Triangle Polygon
cgvr.korea.ac.kr
CGVR
60 Graphics Lab @ Korea University
Polygon Scan Conversion
Hardware Scan Conversion Convert everything into Triangles
cgvr.korea.ac.kr
CGVR
61 Graphics Lab @ Korea University
Summary of Transformation
P(x, y, z)
Viewing Transformation
Viewing Transformation
Projection Transformation
Projection Transformation
Window-to-Viewport Transformation
Window-to-Viewport Transformation
P(x, y)
Modeling Transformation
Modeling Transformation
3D Object Coordinates
3D World Coordinates
3D Viewing Coordinates
2D Projection Coordinates
2D Device Coordinates
Recommended