168 471 Computer Graphics

advertisement
Clipping on a Raster Display
168 471 Computer Graphics, KKU. Lecture 8
1
Approaches to Clipping
168 471 Computer Graphics, KKU. Lecture 8
2
Analytical Clipping
168 471 Computer Graphics, KKU. Lecture 8
3
Clipping Lines Against Rectangles
168 471 Computer Graphics, KKU. Lecture 8
4
Clipping Rules
168 471 Computer Graphics, KKU. Lecture 8
5
Computing Intersections
168 471 Computer Graphics, KKU. Lecture 8
6
Cohen-Sutherland Algorithm
168 471 Computer Graphics, KKU. Lecture 8
7
Outcodes
168 471 Computer Graphics, KKU. Lecture 8
8
Outcode Computation
typedef unsigned int outcode;
enum {TOP = 0x1, BOTTOM = 0x2, RIGHT = 0x4, LEFT = 0x8}
outcode CompOutCode(
double x, double y, double xmin, double xmax, double ymin, double ymax)
{
outcode code = 0;
if ( y > ymax )
code |= TOP;
else if ( y < ymin )
code |= BOTTOM;
if ( x > xmax )
code |= RIGHT;
else if ( x < xmin )
code |= LEFT;
return code;
}
168 471 Computer Graphics, KKU. Lecture 8
9
Cohen-Sutherland Procedures
168 471 Computer Graphics, KKU. Lecture 8
10
Cohen-Sutherland Procedures
168 471 Computer Graphics, KKU. Lecture 8
11
Cohen-Sutherland Algorithm
168 471 Computer Graphics, KKU. Lecture 8
12
Cohen-Sutherland Algorithm (cont.)
168 471 Computer Graphics, KKU. Lecture 8
13
Cohen-Sutherland Procedures
168 471 Computer Graphics, KKU. Lecture 8
14
Parametric Line-Clipping Algorithm
• Introduced by Cyrud and Beck in 1978
• Efficiently improved by Liang and Barsky
• Essentially find the parameter t from P(t) = P0 + (P1-P0)t
N i [ P (t )  PEi ]  0
N i [ P0  ( P1  P0 )t  PEi ]  0
N i [ P0  PEi ]  N i [ P1  P0 ]t  0
t
N i [ P0  PEi ]
Ni D
where D  ( P1  P0 )
168 471 Computer Graphics, KKU. Lecture 8
15
Parametric Line-Clipping Algorithm
(cont.)
Ni D  0  PE (angle  90)
Ni D  0  PL(angle  90)
• Formally, intersections can be classified as PE (potentially entering)
and PL (potentially leaving) on the basis of the angle between P0P1
and Ni
• Determine tE or tL for each intersection
• Select the line segment that has maximum tE and minimum tL
• If tE > tL, then trivially rejected
168 471 Computer Graphics, KKU. Lecture 8
16
Parametric Line-Clipping Algorithm
(cont.)
168 471 Computer Graphics, KKU. Lecture 8
17
Cyrus-Beck Algorithm (Pseudocode)
168 471 Computer Graphics, KKU. Lecture 8
18
Clipping Circles and Ellipses
• Firstly, do a trivial accept/reject test by intersecting
the circle’s/elleipse’s extent with the clip rectengle.
• If intersection occurs, divide it into and do the trivial
accept/reject test for each.
• If scan conversion is fast or if the circle is not too
large, scissoring on a pixel-by-pixel basis would be
more efficient.
168 471 Computer Graphics, KKU. Lecture 8
19
Clipping Polygons
Example of polygon clipping, (a) Multiple components.
(b) Simple convex case. (c) Concave case.
168 471 Computer Graphics, KKU. Lecture 8
20
Clipping Polygons (cont.)
Polygon clipping, edge by edge. (a) Before clipping. (b) Clip on right.
(c) Clip on bottom. (d) Clip on left. (e) Clip on top; polygon is fully
clipped
168 471 Computer Graphics, KKU. Lecture 8
21
Download