cse 403 computer graphics clipping cohen sutherland algorithm (line) cyrus-beck algorithm (line)...
Post on 17-Dec-2015
250 Views
Preview:
TRANSCRIPT
CSE 403 Computer Graphics
Clipping
• Cohen Sutherland Algorithm (Line)• Cyrus-Beck Algorithm (Line)• Sutherland-Hodgeman Algorithm (Polygon)
2
(xmin , ymin )
(xmax , ymax )
x = xmin x = xmax
y = ymin
y = ymax
(x1, y1)
cliprectangle
maxmin
maxmin
yyy
xxx
For a point For a point ((x,yx,y) ) to be inside the clip rectangleto be inside the clip rectangle::
Point Clipping
3
cliprectangle
Cases for clipping linesCases for clipping lines
Line Clipping
4
Cases for clipping linesCases for clipping lines
A
B
A
B
cliprectangle
Line Clipping
5
Cases for clipping linesCases for clipping lines
D
A
BC
D'
A
BC
D'
cliprectangle
Line Clipping
6
Cases for clipping linesCases for clipping lines
D
E
F
A
BC
D'
A
BC
D'
cliprectangle
Line Clipping
7
Cases for clipping linesCases for clipping lines
D
E
F
A
BC
D'
G
H
G'
H'A
BC
D'
G'
H'
cliprectangle
Line Clipping
8
Cases for clipping linesCases for clipping lines
D
E
F
A
BC
D'
G
H
G'
H'
I
J
I'
J'
A
BC
D'
G'
H'
cliprectangle
Line Clipping
9
Clipping Lines by Solving Simultaneous EquationsClipping Lines by Solving Simultaneous Equations
cliprectangle
(xa, ya)(xb , yb)
(xc, yc) (xd , yd)
(x0, y0)
(x1, y1)
(x , y )
cliprectangle
(xa, ya)(xb , yb)
(xc, yc) (xd , yd)
(x0, y0)
(x1, y1)
(x , y )
abedgeaabedgea
lineline
yytyyxxtxx
yytyyxxtxx
,
, 010010
Line Clipping
10
The Cohen-Sutherland Line-Clipping Algorithm performs initial tests on a line to determine whether intersection calculations can be avoided.1. First, end-point pairs are checked for Trivial
Acceptance.2. If the line cannot be trivially accepted, region
checks are done for Trivial Rejection.3. If the line segment can be neither trivially
accepted or rejected, it is divided into two segments at a clip edge, so that one segment can be trivially rejected.These three steps are performed iteratively until what remains can be trivially accepted or rejected.
Cohen-Sutherland Algorithm
11
0000
1000
0100
1001 1010
0001 0010
0101 0110clip
rectangle
Region outcodesRegion outcodes
min
max
yy
yy
:1bit
: 0bit
min
max
xx
xx
:3bit
: 2bit
Cohen-Sutherland Algorithm
12
1. A line segment can be trivially accepted if the outcodes of both the endpoints are zero.
2. A line segment can be trivially rejected if the logical and of the outcodes of the endpoints is not zero.
3. A key property of the outcode is that bits that are set in nonzero outcode correspond to edges crossed.
Cohen-Sutherland Algorithm
13
cliprectangle
AB
C
D
E
An ExampleAn Example
Cohen-Sutherland Algorithm
14An ExampleAn Example
cliprectangle
B
C
D
E
Cohen-Sutherland Algorithm
15An ExampleAn Example
cliprectangle
B
C
D
Cohen-Sutherland Algorithm
16An ExampleAn Example
cliprectangle
B
C
Cohen-Sutherland Algorithm
17
(1)(1) This fundamentally different (from Cohen-This fundamentally different (from Cohen-Sutherland algorithm) and generally more Sutherland algorithm) and generally more efficient algorithm was originally published by efficient algorithm was originally published by CyrusCyrus and and BeckBeck..
(2)(2) LiangLiang and and BarskyBarsky later independently later independently developed a more efficient algorithm that is developed a more efficient algorithm that is especially fast in the special cases of upright especially fast in the special cases of upright 2D and 3D clipping regions.They also 2D and 3D clipping regions.They also introduced more efficient trivial rejection introduced more efficient trivial rejection tests for general clip regions.tests for general clip regions.
Parametric Line-Clipping
18
Inside of clip rectangleOutside of clip region
0iEi PtPN
0iEi PtPN
0iEi PtPN
iEi PtP
iEP
0P
1P
iN
iE Edge
tPPPtPPPLine 01010 :
01
0
01
0
010
010
,
0
0
0
PPDDN
PPNt
PPN
PPNt
PtPPPN
PtPPPN
PtPN
i
Ei
i
Ei
Ei
Ei
Ei
i
i
i
i
i
The Cyrus-Beck Algorithm
19
Inside of clip rectangleOutside of clip region
0iEi PtPN
0iEi PtPN
0iEi PtPN
iEi PtP
iEP
0P
1P
iN
iE Edge
DN
PPNt
i
Ei i
0
0 3
0 2
0 1
whenexists
10
DN
PPD
N
t
i
i
The Cyrus-Beck Algorithm
20
PE
PL
P 0
P 1
t = 0
t = 1
PE
PL
P 1
t = 1
P 0
t = 0
PE
PE
PLPL
P 0
t = 0
P 1
t = 1Line 2
Line 1
Line 3
Cliprectangle
90
0
Angle
PEDNi
90
0
Angle
PLDNi
PE = Potentially Entering PL = Potentially Leaving
The Cyrus-Beck Algorithm
21
The Cyrus-Beck AlgorithmPrecalculate Ni and PEi for each edgefor (each line segment to be clipped) {
if (P1 == P0)line is degenerated, so clip as a point;
else {tE = 0; tL = 1;for (each candidate intersection with a clip edge) {
if (Ni • D != 0) { /* Ignore edges parallel to line */calculate t;use sign of Ni • D to categorize as PE or PL;if (PE) tE = max(tE , t);if (PL) tL = min(tL , t);
}}if (tE > tL) return NULL;else return P(tE) and P(tL) as true clip intersection;
} }
22
ExampleExample
Polygon Clipping
23
ExampleExample
Polygon Clipping
24
ExampleExample
Polygon Clipping
25
Initial ConditionInitial Condition
Sutherland-Hodgeman Algo.
Clip Against Right Clipping Clip Against Right Clipping BoundaryBoundary
Clip Against Top Clipping Clip Against Top Clipping BoundaryBoundary
The Clipped PolygonThe Clipped PolygonClip Against Bottom Clipping Clip Against Bottom Clipping BoundaryBoundary
Clip Against Left Clipping Clip Against Left Clipping BoundaryBoundary
26
Case 1Case 1
Inside Outside
Polygonbeingclipped
Clipboundary
s
p:output
4 Cases of Polygon Clipping
Case 2Case 2
Inside Outside
s
p
i:output
Case 3Case 3
Inside Outside
s
p
(no output)
Case 4Case 4
Inside Outside
s
i:first output
p:second output
27
Reference
FV: 3.12, 3.13, 3.14
top related