Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
PREPARED BY:
Mr.S.Vimal M.E.,
Asst.Prof/IT,
NEC 1
UNIT I OUTPUT PRIMITIVES
SYLLABUS
2
Output Primitives
Introduction
Advantages of Interactive Graphics
Natural means of communicating with a
computer
Creating & reproducing pictures- easy
4
Output Primitives
Definition
A scene has been represented by basic geometric
structure which map into rectangular grid of pixel
Keyword
Pixel : little rectangles with same size and
shape at each screen points
5
Output Primitives
Points
Straight Lines
6
Points
Accomplished by converting a single coordinate
position by an application program into
appropriate operations for output device in use
(i.e. monitor)
7
Point
type
8
Output Primitives
9
Why Lines?
Lines
most common 2D primitive - done 100s or 1000s of
times each frame
even 3D wireframes are eventually 2D lines!
optimized algorithms contain numerous
tricks/techniques that help in designing more
advanced algorithms
10
Lines?
11
Lines?
12
Line Requirements
Must compute integer coordinates of pixels which lie on or near a line or circle.
Pixel level algorithms are invoked hundreds or thousands of times when an image is
created or modified must be fast!
Lines must create visually satisfactory images.
Lines should appear straight
Lines should terminate accurately
Lines should have constant density
Line algorithm should always be defined.
13
Basic Line Equation
line: P = (X,Y) 2
1 P1 = (X1,Y1)
Y = [(Y2-Y1)/(X2-X1)]*(X-
X1)+ Y1 1 2 3 4 5 6
RISE Y2-Y1
or SLOPE =
RUN
=
X2-X1
Y = mx + b
14
Other Helpful Formulas
L ( x 2 x 1 ) ( y 2 y1 )
2 2
15
Parametric Form
16
Basic Line Equation y=mx+b
. Equation for straight line
. y = mx + b
. m = slope
. m is the changes in y divided by changes of x
. m = y / x
. b = the point where the line intercepts of y axis.
. y axis Intercept
. b = y1 m.x1
17
Simple DDA Line Algorithm
18
DDA Code
#include device.h
#define ROUND (a) ((int) (a+0.5))
void lineDDA( int xa, int ya, int xb, int yb) DDA create good lines but
{ int dx = xb-xa, dy = yb ya, steps, k; it is too time consuming
float xinc, yinc, x = xa, y = ya;
due to the round function
if (abs(dx) > abs(dy)) steps = abs(dx); and long operation on real
else steps = abs(dy); values
xinc = dx/(float) steps;
yinc = dy/(float) steps;
setPixel(ROUND(x), ROUND(y));
for (k=0; k<steps; k++) {
x += xinc; y+= yinc;
setPixel(ROUND(x), ROUND(y));
}
19
DDA Example
step = ?
xinc = ?
yinc = ?
13
12
11
10
6 7 8 9 10 11 12 13
20
DDA Example
Line from (6,9) to (11,12).
12
(6,9), (7,9.6),
11
(8,10.2), (9,10.8), 10
(10,11.4), (11,12) 9
6 7 8 9 10 11 12 13
21
DDA
. Advantages:
. Faster than using y = mx +b
. Eliminates multiplication (mx) by using screen
characteristics, i.e. incrementing pixel.
. Disadvantages:
. Floating point arithmetic is slower than
integer arithmetic.
. Rounding down take time.
. Long line s can drift from the true line due to
floating point round-off errors.
22
DDA
23
Bresenhams Line Drawing Algorithm
1. Input the two line endpoints and store the left endpoint in (X0,Y0)
2. Load (X0,Y0) into the frame buffer; that is, plot the first point.
3. Calculate constants X, Y, 2Y, and 2Y - 2X, and obtain the
starting value for the decision parameter as
P0 = 2Y - X
4. At each Xk along the line, starting at k = 0, perform the following test:
If Pk < 0, the next point to plot is (Xk + 1, Yk) and
Pk+1 = Pk + 2Y
Otherwise, the next point to plot is (Xk + 1, Yk + 1) and
Pk+1 = Pk + 2Y - 2X
5. Repeat step 4, X times.
24
Bresenhams Line Drawing Algorithm
25
Bresenhams Line Algorithm
#include device.h
void lineBres( int xa, int ya, int xb, int yb)
{ int dx = abs(xb-xa), dy = abs(yb ya);
int p = 2*dy-dx;
int twoDy = 2*dy, twoDyDx = 2* (dy-dx);
int x,y,xEnd;
/* Determine which point to use as start, which as end */
if (xa > xb){
x = xb; y = yb; xEnd = xa; }
else { x = xa; y = ya; xEnd = xb; }
setPixel(x,y);
while (x < xEnd){
x++;
if (p < 0) p += twoDy;
else { y++; p += twoDyDx;}
setPixel(x,y); }
}
26
Example
We digitize the line with endpoints (20,10) and
(30,18)
X= 10, Y = 8, 2Y = 16, 2Y - 2X = -4
p0 = 2Y - X = 6
k pk (xk+1,yk+1) k pk (xk+1,yk+1)
0 6 (21,11) 5 6 (26,15)
1 2 (22,12) 6 2 (27,16)
2 -2 (23,12) 7 -2 (28,16)
3 14 (24,13) 8 14 (29,17)
4 10 (25,14) 9 10 (30,18)
27
Bresenham
. Advantages
. Accurate and efficient incremental
integer calculations
. Can be adapted to draw circles and
curves.
Generalization:
Increment (x or y) depending on slope (m)
starting endpoints (left or right)
special case (Y=0 or X =0)
28
Optimizations
15
14
13
12
11
10
6 7 8 9 10 11 12 13 14 15 16 17
di= 2 -6 6 -2 10 2 -6 6 -2 10
29
Output Primitives
1. Circles
2. Ellipses
3. Curves
30
Circles
1. Circles
Properties:
Is a set of points from a given distance of r from center
position (xC, yC).
31
Circles
34
Circles
. Based on the upper octant (between y axis and 45o line), circles increases
faster along x axis compared to y axis. Since we are stepping along x axis,
pixels with successive x co-ordinate positions can have the same y co-ordinate
reduce or no gap.
. In the lower octant , the circle increases faster along the y axis compared to x
axis. Pixels with successive y co-ordinates need to have the same x co-
ordinates to avoid gaps. Since , we are using x axis in unit of intervals, so each
pixel has a unique y-coordinates bigger gap.
35
Circles
. Solutions:
- to change the logic or formula whether to y
or x depending on the upper or lower octant.
- use polar co-ordinates
x = xc + r.cos
y = yc + r.sin
37
Circles
38
Circles
. A step size of = 1/r will produce a continuous circle with the pixel
is approximately 1 unit a apart.
. The larger of the step size will cause the straight lineconnection.
Disadvantages:
a. Trigonometric calculations (sin and cos) are computationally
expensive. 39
Circles
40
Circle Drawing Algorithm
3. Bresenham Algorithm (Mid Point)
. To avoid rounding where incrementing integer for
calculation is faster and more efficient.
P = fcircle(xk+1,yk 0.5)
42
Circle Drawing Algorithm
Bresenham Algorithm (Mid Point)
. If P < 0
The mid-point is inside the boundary, so the pixel at
(xk+1,yk) is closer to the circle boundary and should be
plotted.
. If P= 0 or P > 0
The mid-point is outside or on the circle boundary. So
the pixel at (xk+1,yk-1) is closer to the circle boundary
and need to be plotted.
43
Circle Drawing Algorithm
(-b,a) (b,a)
Procedure Circle_Points(x,y :Integer);
Begin
Plot(x,y);
Plot(y,x); (-a,b) (a,b)
Plot(y,-x);
Plot(x,-y); (-a,-b) (a,-b)
Plot(-x,-y);
Plot(-y,-x);
Plot(-y,x);
Plot(-x,y) (-b,-a) (b,-a)
End;
44
Fast Circles
Consider only the first octant of a circle of radius r centered on
the origin. We begin by plotting point (r,0) and end when x
< y. 2
2 2
x +y -r =0 x=y
45
Fast Circles - The Decision Variable
T = (x ,y
i +1)
i
f(xi - 1/2 + e, yi + 1)
= (xi - 1/2 + e)2 + (yi + 1)2 - r2 e
= (xi- 1/2)2 + (yi+1)2 - r2 + 2(xi-1/2)e + e2 S = (x i-1,y +1)i
= f(xi - 1/2, yi + 1) + 2(xi - 1/2)e + e2 = 0
Let di = f(xi - 1/2, yi+1) = -2(xi - 1/2)e - e2
P = (x ,y
i )i
If e < 0 then di > 0 so choose point S = (xi - 1, yi + 1).
di+1 = f(xi - 1 - 1/2, yi + 1 + 1) = ((xi - 1/2) - 1)2 + ((yi + 1) +
1)2 - r2
= di - 2(xi -1) + 2(yi + 1) + 1 = di + 2(yi+1- xi+1) + 1
46
Fast Circles - Decision Variable (cont.)
47
Fast Circle Algorithm
Void circleMidpoint (int xcenter, int ycenter, int radius)
{ int x=0;
int y=radius;
int p=1-radius;
void circlePlotPoints (int , int, int, int);
/* Plot first set of points */
circlePlotPoints (xCenter, yCenter, x,y);
while (x<y) { x++;
if (p<0)
p +=2* x + 1;
else {
y--;
p += 2 * (x-y) + 1;}
circlePlotPoints (xCenter, yCenter, x, y); }
}
void circlePlotPoints (int xCenter, int yCenter, int x, int y)
{ setPixel (xCenter + x, yCenter + y);
setPixel (xCenter - x, yCenter + y);
setPixel (xCenter + x, yCenter - y);
setPixel (xCenter - x, yCenter - y);
setPixel (xCenter + y, yCenter + x);
setPixel (xCenter - y, yCenter + x);
setPixel (xCenter + y, yCenter - x);
setPixel (xCenter - y, yCenter -x); } 48
Fast Circle Algorithm
49
Ellipses
. An ellipse has set of fixed points (foci) that will have a constant
total of distance from all the points on the boundary.
50
Ellipses
.Ellipse symmetry
. Ellipses are symmetrical between the four quadrants.
51
Ellipses
Mid-Point Ellipses Algorithm
. A modification of the mid-point circle algorithm
.. Incremental integer calculations.
. Calculations are easier if:
1. the circle is centered on the origin (0,0)
. points are placed in the correct position by
adding xc to the x co-ordinates and y, to the y
co-ordinates. ie performing a translation
2. the major and minor axes are aligned to be
parallel with x and y axes.
. ellipses are drawn at the correct angle by
rotating the points to their correct position.
52
Ellipses
53
Ellipses
. Region 1:
. Step along the x axis in unit intervals (k) until the
boundary between region 1 and region 2.
P=fellipse(xk+1 , yk 0.5)
55
Ellipses
56
Ellipses
. If Pk < 0
. The mid-point is inside the ellipse boundary so the
pixel at (xk + 1, yk) ) is closer to the ellipse boundary
and should be plotted.
. If Pk=0 or Pk>0;
. The mid-point is outside or on the ellipse boundary
pixel at (xk+1,yk-1) is closer to the ellipse boundary
and should be plotted.
. Region 2:
. Step along the y axis in unit intervals (k) for the
remainder of the curve until y = 0
.If we have just plotted pixel (xk,yk), the choices for the
next pixel to plot are (xk,yk-1) and (xk+1,yk-1)
58
Fast Ellipses
The circle algorithm can be generalized to work for an ellipse
but only four way symmetry can be used.
59
Other Curves
Xo
60
Speed Improvement
Xk = Xo +kdXp
dYp = m dXp
Yk = Yo +round(kdYp)
61
Speed Improvement
. Plot point if the distance of the pixel from the line is less
than or equal to the line thickness.
62
Speed Improvement
. Curve segmentation
. Circle
. Divide the circular arc the upper octant
into sub-arc segments.
. Ellipse
. Divide the elliptical arc in the first quadrant
into sub-arc segment.
64
Filled-Area Primitives
65
Filled-Area Primitives
. Polygon
- Concave
- Convex
66
Polygon Classifications
67
Identifying Concave/Convex
Vm
V6 E5 V5
Ej = (Vnx Vmx , Vny Vmy)
E4
(E1 X E2) > 0
V4 (E2 X E3) > 0
E6 E3 (E3 X E4) < 0
(E4 X E5) > 0
V3 (E5 X E6) > 0
(E6 X E1) > 0
E2
E1 V2 EJ X EK = EJXEKY - EJYEKX
V1
69
Example
Given 6 vertices:
V1 = (1,1)
V2 = (5,1)
V3 = (7,3)
V4 = (4,5)
V5 = (4,10)
V6 = (1,10)
71
Angle Between Edges
Example:
Given 2 vectors a = (2,3) and b = (6,3). Determine
the angle between these two vectors
Determine the angle between E3 and E4 (refer to
previous example)
72
Inside-Outside Tests
Inside-Outside Tests.
. Filling means coloring a region
. How to identify interior or exterior region.
- Once determined only then interior to be filled accordingly.
. Two well known rules which decide the interior or exterior.
. Odd-even rule
. Non-zero winding rule.
73
Inside-Outside Tests
Odd-Even Rule
. Also known as odd-parity and even-odd rule.
. How its work?
. Pick a point of P in the region of interest.
. Draw a line from P to a distant point which lower than the
smallest x.
. Move from P along the line to the distant point.
. Count the number of region edges the line crosses.
. If the number of crossed is odd then P is inside the interior region
. If the number of crossed is even then P is inside the exterior
region. 74
Inside-Outside Tests
76
Character Generation
77
Character Generation
Bitmapped Fonts:
Outline Fonts
79
Character Generation
80
Summary
Output primitives
(points, straight-line, circle, ellipse, curves)
DDA vs Bresenham
Inside-Outside Test
Odd-even rule / even-odd rule
Non zero winding rule
Character Generation
serif vs san serif
Outline vs Bitmap
81
Summary
Inside-Outside Test
Odd-even rule / even-odd rule
Non zero winding rule
Character Generation
serif vs san serif
Outline vs Bitmap
82
Attributes of Graphics
Primitives
83
Agenda
84
Learning Objectives
Understand what are the main attributes
of graphic primitives
color, antialiasing,
point attributes,
line attributes,
curve attributes,
character attributes
85
Line Attributes and Functions
Line attributes
Basic attributes: color, width, style
Width
can be set in the line drawing algorithm as well as
the length and point spacing.
Raster algorithms display line attributes by plotting
pixel spans, like plotting multiple pixels along the
line either horizontally (m<1)of vertically (m>1).
Produces lines of slightly different width according
to the slope, and also abrupt ends (horizontal or
vertical).
Add line caps at the end (butt cap, round cap,
projecting square cap).
86
Line Attributes and Functions
Line attributes
Width
thick polylines with previous method do not
connect smoothly
miter join: extend the outer boundaries of each
segment until they join
round join: cap connection with circular
boundary
bevel join: display line segments with butt caps
and fill-in triangular gap between the two butts.
87
Line Attributes and
Functions
Line attributes
Style
Solid lines, dashed lines, dotted lines can be
generated by modifying the line drawing
algorithm spacing between drawn pixels
Can be also generated from the raster by using
a pixel mask, for example 11111000 will display
a dashed line with dash length of 5 and inter-
dash length of 3.
88
Line Attributes and
Functions
Line attributes
Pen and brush options
Select several pen and brush styles
Shape, size, pattern
Can be implemented in a pixel mask
Change the mask to change the pen/brush
89
Line Attributes and
Functions
Line attribute functions
gl.glLineWidth (width); // width is the width of the line
90
Display
91
Color and Gray Scale
92
Color and Gray Scale
Color tables
Color map (color look-up table)
Each pixel in the frame buffer contains a
value (Ex. 196) corresponding to an entry
in the color table (Ex. 2081), which has 256
entries.
Color table contains a 3-byte color code
that represents an RGB color 1-byte for
the Red, 1-byte for the Green, 1-byte for
the Blue.
Pick 256 colors from a total of 17 million,
and save storage: 1024 * 1024 = 1MB 93
Color and Gray Scale
94
Color and Gray Scale
Gray scale
Shades of gray
0 dark gray, 1 light gray
Other color parameters
Intensity (amount of light energy)
Luminance (perceived brightness)
95
Color Functions
97
Color Functions
98
Color Functions
Point center = new Point(100, 75);
float [][] CLUT ={{1.0f,0.0f,0.0f}, {1.0f,0.5f,0.0f},
{1.0f,1.0f,0.0f},{0.0f,1.0f,0.0f},{0.0f,0.0f,1.0f},
{1.0f,0.0f,1.0f}, {0.5f,0.0f,0.5f}, {1.0f,0.0f,0.5f}};
99
Color Functions
100
Point Attributes and Functions
102
Character Attributes
Character attributes
Font (typeface)
Helvetica, Courier, Times Roman,
Underlining style
solid, dotted, double
Style
boldface, italics, outline, shadow
Size
10-point, 12-point,
Color.
103
Character Attributes
104
Character Attributes
Character attributes
Font (typeface)
Helvetica, Courier, Times Roman,
Underlining style
solid, dotted, double
Style
boldface, italics, outline, shadow
Size
10-point, 12-point,
Color
Direction (up vector)
105
Character Attributes
Two methods
With bitmap functions
create images of each character
With GLUT character generating routines
available in OpenGL from GLUT class
BITMAP_HELVETICA_10
BITMAP_HELVETICA_12
BITMAP_HELVETICA_18
BITMAP_TIMES_ROMAN_10
BITMAP_TIMES_ROMAN_24
glutBitmapCharacter, glutBitmapString,
glutBitmapLength, glutBitmapWidth
106
Antialiasing
107
2D Transformations with Matrices
The element on the ith row and jth column is denoted by ai,j. Note
that we start indexing at 1, whereas C indexes arrays from 0.
108
Matrices Addition
Ci , j Ai , j Bi , j
1 2 5 6 1 5 2 6 6 8
3 4 7 8 3 7 4 8 10 12
109
Matrices Multiplication
110
Matrices Multiplication (Examples)
2 6 7 6 8 44 76
4 5 8 3 3 55 95
9 2 3 2 6 66 96
6 8
2 6
4 5 3 3
Undefined!
2 6 2x2 x 3x2 2!=3
2x2 x 2x4 x 4x4 is allowed. Result is 2x4 matrix
111
Matrices -- Basics
a1,1 a2,1
a1,1 a1, 2 a1,3
A A' a1, 2 a2, 2
a2,1 a2, 2 a2 , 3
a1,3 a2,3
112
2D Geometrical Transformations
Translate
Shear
Rotate Scale
113
Scale Points
To double the size of an object we use a scale factor of 2, to half the size of
an obejct we use a scale factor of 0.5
x' s x x
y P(x,y) y' s y y
sy y
P(x,y) x' s x 0 x
y' 0 s y y
sx x x
sx 0
If we define S , then we have P =SP
0 s y
114
Rotate Points (cont.)
115
Review
Translate: P = P+T
Scale: P = SP
Rotate: P = RP
Spot the odd one out
Multiplying versus adding matrix
Ideally, all transformations would be the
same..
easier to code
Solution: Homogeneous Coordinates
116
Homogeneous Coordinates
[x, y, 1]
[x, y, W]
117
Homogeneous Transformations
x' 1 0 dx x
x' x d x y ' 0
y ' y d 1 d y y
y 1 0 0 1 1
P' T P
Similarly, we have:
Scaling Rotation
P = S P P = R P
118
Composition of 2D Transformations
119
Examples of Composite 2D Transformations
(1,3)
T(-1,2) T(1,-1)
(2,2)
(2,1)
1 0 1 1 0 1
T21 0 1 1 0 1 2
0 0 1 0 0 1
1 0 0
0 1 1
0 0 1
120
Composition of 2D Transformations (cont.)
121
Composition of 2D Transformations (cont.)
where R21 R ( 2 ) R (1 )
cos 2 sin 2 0 cos 1 sin 1 0
sin 2 cos 2 0 sin 1 cos 1 0
0 0 1 0 0 1
cos( 2 1 ) sin( 2 1 ) 0
sin( 2 1 ) cos( 2 1 ) 0
0 0 1
122
Composition of 2D Transformations (cont.)
where M R( )T (d x , d y )
123
Consider the following two questions:
P2
P1(1,2)
P1(1,2) P1
124
Rigid-Body vs. Affine Transformations
A transformation matrix of the form
r11 r12 tx
r r22 t y
21
0 0 1
where the upper 22 sub-matrix is orthogonal, preserves angles
and lengths. Such transforms are called rigid-body
transformations, because the body or object being transformed is
not distorted in any way. An arbitrary sequence of rotation and
translation matrices creates a matrix of this form.
125
Rigid-Body vs. Affine Transformations (cont.)
45
Unit cube Scale in x, not in y
1 a 0 1 0 0
SH x 0 1 0 SH y b 1 0
0 0 1 0 0 1
126
2D Viewing
3D Rendering Pipeline
2D Rendering Pipeline
Clipping
Cohen-Sutherland Line Clipping
Sutherland-Hodgeman Polygon Clipping
Viewport Transformation
Scan Conversion
Summary of Transformation
127
3D Rendering Pipeline
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
3D Primitives
2D Primitives
Image
130
2D Rendering Pipeline
3D Primitives
2D Primitives
Image
131
Clipping
World
Coordinates
132
Clipping
133
Clipping
134
Types of Clipping algorithms
Point clipping
Line clipping
(a) Cohen sutherland
(b) Liang barsky line clipping
(c) Nicholl lee nicholl line clipping
(d) Nonrectangular line clipping
Polygon clipping
(a) Sutherland hodgeman polygon
(b) Weiler atherton polygon
Curve clipping
Text clipping
Exterior clipping
135
Point Clipping
wy2
Inside =
(x>=wx1) &&
wy1
wx1 wx2
136
Line Clipping
P1
P4 P8
P3
P2
P6
P10
P5 P9
Before Clipping
137
Line Clipping
P7
P4 P8
P3
P6
P5
After Clipping
138
Cohen-Sutherland Line Clipping
P7
P1
P4 P8
P3
P2
P6
P10
P5 P9
139
Cohen-Sutherland Line Clipping
P4 P8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P5 0010 P9 0110
Bit 1 Bit 2
142
Cohen-Sutherland Line Clipping
P4 P8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P5 0010 P9 0110
Bit 1 Bit 2
143
Cohen-Sutherland Line Clipping
P4 P8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P5 0010 P9 0110
Bit 1 Bit 2
144
Cohen-Sutherland Line Clipping
P4 P8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P5 0010 0110
P9
Bit 1 Bit 2
145
Cohen-Sutherland Line Clipping
P4 P8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P5 0010 0110
P9
Bit 1 Bit 2
146
Cohen-Sutherland Line Clipping
P4 P8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P5 0010 0110
P9
Bit 1 Bit 2
147
Cohen-Sutherland Line Clipping
P4 P8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P5 0010 0110
P9
Bit 1 Bit 2
148
Cohen-Sutherland Line Clipping
P4 P8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P5 0010 0110
P9
Bit 1 Bit 2
149
Cohen-Sutherland Line Clipping
Compute Intersections with Window Boundary for
Lines That Cant be Classified Quickly
1001 0001
P7 0101
Bit 4
P4 P8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P5 0010 0110
P9
Bit 1 Bit 2
150
Cohen-Sutherland Line Clipping
Compute Intersections with Window Boundary for
Lines That Cant be Classified Quickly
1001 0001
P7 0101
Bit 4
P4 P8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P5 0010 0110
P9
Bit 1 Bit 2
151
Cohen-Sutherland Line Clipping
P4 P8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P5 0010 0110
P9
Bit 1 Bit 2
152
Cohen-Sutherland Line Clipping
P4 P8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P5 0010 0110
P9
Bit 1 Bit 2
153
Cohen-Sutherland Line Clipping
P4 P8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P5 0010 0110
P9
Bit 1 Bit 2
154
Cohen-Sutherland Line Clipping
P4 P8
1000 P3 0000 0100
P6
P10
P9 Bit 3
1010 P5 0010 0110
Bit 1 Bit 2
155
Cohen-Sutherland Line Clipping
P4 P8
1000 P3 0000 0100
P6
P10
P9 Bit 3
1010 P5 0010 0110
Bit 1 Bit 2
156
Cohen-Sutherland Line Clipping
P4 P8
1000 P3 0000 0100
P6
Bit 3
1010 P5 0010 0110
Bit 1 Bit 2
157
Polygon Clipping
Find the Part of a Polygon Inside the Clip
Window?
Before Clipping
158
Polygon Clipping
After Clipping
159
Sutherland-Hodgeman Polygon Clipping
160
Sutherland-Hodgeman Polygon Clipping
161
Sutherland-Hodgeman Polygon
Clipping
Clip to Each Window Boundary One at a Time
162
Sutherland-Hodgeman Polygon
Clipping
Clip to Each Window Boundary One at a Time
163
Sutherland-Hodgeman Polygon Clipping
164
Clipping to a Boundary
P2 P1
Window
Boundary Inside
Outside
P3 P5
P4
165
Clipping to a Boundary
P2 P1
Window
Boundary Inside
Outside
P3 P5
P4
166
Clipping to a Boundary
P2 P1
Window
Boundary Inside
Outside
P3 P5
P4
167
Clipping to a Boundary
P2 P1
Window
Boundary Inside
Outside
P3 P5
P4
168
Clipping to a Boundary
P2 P1
Window
Boundary P Inside
Outside
P3 P5
P4
169
Clipping to a Boundary
P2 P1
Window
Boundary P Inside
Outside
P3 P5
P4
170
Clipping to a Boundary
P2 P1
Window
Boundary P Inside
Outside
P3 P5
P4
171
Clipping to a Boundary
P2 P1
Window
Boundary P P Inside
Outside
P3 P5
P4
172
Clipping to a Boundary
P2 P1
Window
Boundary P P Inside
Outside
173
2D Rendering Pipeline
3D Primitives
2D Primitives
Image
174
Viewport Transformation
Viewport
175
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
176
Viewport Transformation
Window-to-Viewport Mapping
Window Viewport
wy2 vy2
177
2D Rendering Pipeline
3D Primitives
2D Primitives
Image
178
Scan Conversion
Definition
Figure out which pixels to fill
Example
Filling the inside of a triangle
P1
P2
P3
179
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 L3
P
L2
180
Triangle Scan Conversion
dx
dy
181
Polygon Scan Conversion
182
Inside Polygon Rule
L L
1 1
L2 L5 L2 L5B
L5A
L3 L3
L4 L4