Professional Documents
Culture Documents
2D Viewing: Prepared By: K. R. Rathod, A. K. Ranpura, A. R. Rathod
2D Viewing: Prepared By: K. R. Rathod, A. K. Ranpura, A. R. Rathod
CCET
2D Viewing
2D Primitives
Image
4 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Clipping CCET
CGVR
World
Coordinates
5 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
2-Dimensional Views CCET
CGVR
A Rasterization Issue
•Transformation
•Representa- &Normalization •Scan
tion of conversion •Color
geometric •Clipping
•Antialiasing mapping
objects •Hidden surface
removal
Real-world
screen co-ordinates
co-ordinates
{wxmax,wymax}
{vxmax,vymax}
{vx,vy}
{wx,wy}
{vxmin,vymin}
{wxmin,wymin}
For any point {wx, wy} in the real-world window, what is
the corresponding pixel position?
wy2
Inside
Inside ==
(x>=wx1)
(x>=wx1) &&
&&
(x, y) (x<=wx2)
(x<=wx2) &&
&&
(y>=wy1)
(y>=wy1) &&
&&
(y<=wy2);
(y<=wy2);
wy1
wx1 wx2
ymax
Clip Region
(Includes
Boundary)
ymin
x min x max
15 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
COHEN SUTHERLAND CLIPPING CCET
CGVR
Outcodes
y ymax x xmax
0 1 0 1
y y min x x min
ymax
ymin
x min x max
ymax
P1
P0
ymin
x min x max
ymax
P0
0001 0000 0010
ymin
P0
P1 P1
x min x max
ymax
ymin
x min x max
= “Inside”
20 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Cohen-Sutherland Clipping:
The Algorithm CCET
CGVR
B
ymax
ymin
x min x max
B
ymax
ymin
x min x max
ymin
B
A
0101 0100 0110
x min x max
ymin
B
x min x max
ymax
D
ymin
B
x min x max
ymax
ymin
B
x min x max
Before Clipping
44 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Polygon Clipping CCET
CGVR
After Clipping
45 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Sutherland-Hodgeman Polygon Clipping CCET
CGVR
(x3 , y3 )
(x 4 , y 4 )
(x 5 , y 5 )
(x 2 , y 2 )
P2 P1
Window
Boundary Inside
Outside
P3 P5
P4
53 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Clipping to a Boundary CCET
CGVR
P2 P1
Window
Boundary Inside
Outside
P3 P5
P4
54 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Clipping to a Boundary CCET
CGVR
P2 P1
Window
Boundary Inside
Outside
P3 P5
P4
55 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Clipping to a Boundary CCET
CGVR
P2 P1
Window
Boundary Inside
Outside
P3 P5
P4
56 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Clipping to a Boundary CCET
CGVR
P2 P1
Window
Boundary P’ Inside
Outside
P3 P5
P4
57 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Clipping to a Boundary CCET
CGVR
P2 P1
Window
Boundary P’ Inside
Outside
P3 P5
P4
58 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Clipping to a Boundary CCET
CGVR
P2 P1
Window
Boundary P’ Inside
Outside
P3 P5
P4
59 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Clipping to a Boundary CCET
CGVR
P2 P1
Window
Boundary P’ P” Inside
Outside
P3 P5
P4
60 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Clipping to a Boundary CCET
CGVR
P2 P1
Window
Boundary P’ P” Inside
Outside
2D Primitives
Image
62 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Viewport Transformation CCET
CGVR
Screen Image
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
Window-to-Viewport Mapping
Window Viewport
wy2 vy2
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);
0.4
0.3
-0.4 -0.2
Say we want to map this to a
640x480 viewport
640
67 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Solution CCET
CGVR
wx -0.2 vxmax 640
wy 0.3
vxmin 0 320
wxmax 0
wxmin -0.4
vymax 0
120
wy max 0.4 vymin 480
wy min 0
vxmax - vxmin
vx ( wx - wx min )* vxmin
wx max - wxmin
vymax - vymin
vy ( wy - wy min ) * vymin
wy max - wy min
(640-0)
vx (-0.2 -(-0.4)) 0 320
0 ( 0.4)
(0- 480)
vy (0.3 - 0) 480 120
0.4 (0)
Repeat this for all vertices and then rasterize.
68 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
2D Rendering Pipeline CCET
CGVR
3D Primitives
2D Primitives
Image
69 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Scan Conversion CCET
CGVR
Definition
Figure out which pixels to fill
Example
Filling the inside of a triangle
P1
P2
P3
70 Prepared By : K. R. Rathod, Graphics
A. K. Ranpura, A. R. Rathod
Lab @ Korea University
Triangle Scan Conversion CCET
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
(Odd-even parity rule, Non-zero winding rule)
Take advantage of edge linearity
Use edge slopes to update coordinates incrementally
dx
dy