Chapter 9cs314/Vsep2005/lec_pdf/ch9.pdf · University of 4 British Columbia Analytic Solution...
Transcript of Chapter 9cs314/Vsep2005/lec_pdf/ch9.pdf · University of 4 British Columbia Analytic Solution...
![Page 1: Chapter 9cs314/Vsep2005/lec_pdf/ch9.pdf · University of 4 British Columbia Analytic Solution Intersectionof convex regions is convex Why? L& Dare convex- intersection is convex single](https://reader030.fdocuments.in/reader030/viewer/2022040416/5d14b62a88c993fd118b4dd5/html5/thumbnails/1.jpg)
Clipping - 1
University ofUniversity ofBritish ColumbiaBritish Columbia
Chapter 9Clipping
![Page 2: Chapter 9cs314/Vsep2005/lec_pdf/ch9.pdf · University of 4 British Columbia Analytic Solution Intersectionof convex regions is convex Why? L& Dare convex- intersection is convex single](https://reader030.fdocuments.in/reader030/viewer/2022040416/5d14b62a88c993fd118b4dd5/html5/thumbnails/2.jpg)
2University ofUniversity ofBritish ColumbiaBritish Columbia
The Rendering Pipeline
GeometryDatabaseGeometryGeometryDatabaseDatabase
Model/ViewTransform.Model/ViewModel/ViewTransform.Transform. LightingLightingLighting Perspective
Transform.PerspectivePerspectiveTransform.Transform. ClippingClippingClipping
ScanConversion
ScanScanConversionConversion
DepthTest
DepthDepthTestTestTexturingTexturingTexturing BlendingBlendingBlending
Frame-buffer
FrameFrame--bufferbuffer
![Page 3: Chapter 9cs314/Vsep2005/lec_pdf/ch9.pdf · University of 4 British Columbia Analytic Solution Intersectionof convex regions is convex Why? L& Dare convex- intersection is convex single](https://reader030.fdocuments.in/reader030/viewer/2022040416/5d14b62a88c993fd118b4dd5/html5/thumbnails/3.jpg)
3University ofUniversity ofBritish ColumbiaBritish Columbia
Problem:Given a 2D line/polygon and a window, clip the line/polygon to their regions that are inside the window.
Problem:Given a 2D line/polygon and a window, clip the line/polygon to their regions that are inside the window.
Line/Polygon Clipping (2D)
Objectives• Efficiency• Memory access
![Page 4: Chapter 9cs314/Vsep2005/lec_pdf/ch9.pdf · University of 4 British Columbia Analytic Solution Intersectionof convex regions is convex Why? L& Dare convex- intersection is convex single](https://reader030.fdocuments.in/reader030/viewer/2022040416/5d14b62a88c993fd118b4dd5/html5/thumbnails/4.jpg)
4University ofUniversity ofBritish ColumbiaBritish Columbia
Analytic Solution
Intersection of convex regions is convex Why?
L & D are convex - intersection is convex
single connected segment of LQuestion: Can boundary of two convex shapes intersect more than twice?Clipping - compute intersection of Lwith four boundary segments of window D
D
L
D
L
D
L
![Page 5: Chapter 9cs314/Vsep2005/lec_pdf/ch9.pdf · University of 4 British Columbia Analytic Solution Intersectionof convex regions is convex Why? L& Dare convex- intersection is convex single](https://reader030.fdocuments.in/reader030/viewer/2022040416/5d14b62a88c993fd118b4dd5/html5/thumbnails/5.jpg)
University ofUniversity ofBritish ColumbiaBritish Columbia
Line-Line Intersection
( ) ( )( ) ( )
( ) ( )( ) ( )
Gx t x x x t
y t y y y tt G
x r x x x r
y r y y y rr1
101
11
01
101
11
01 2
202
12
02
202
12
02
0 1 0 1== + −
= + −
⎧⎨⎪
⎩⎪∈ =
= + −
= + −
⎧⎨⎪
⎩⎪∈[ , ] [ , ]
( )x y11
11,
( )x y01
01,
( )x y02
02,
( )x y12
12,
Γ1 Γ2
Intersection: x & y values equal in both representations - two linear equations in two unknowns (r,t)
( ) ( )( ) ( )
x x x t x x x r
y y y t y y y r
01
11
01
02
12
02
01
11
01
02
12
02
+ − = + −
+ − = + −
![Page 6: Chapter 9cs314/Vsep2005/lec_pdf/ch9.pdf · University of 4 British Columbia Analytic Solution Intersectionof convex regions is convex Why? L& Dare convex- intersection is convex single](https://reader030.fdocuments.in/reader030/viewer/2022040416/5d14b62a88c993fd118b4dd5/html5/thumbnails/6.jpg)
University ofUniversity ofBritish ColumbiaBritish Columbia
Intersection with vertical/horizontal lines
( ) ( )( ) ( )
( )( ) ( ) ]1,0[]1,0[
20
21
20
2
20
2
210
11
10
1
10
11
10
1
1 ∈⎪⎩
⎪⎨⎧
−+=
==∈
⎪⎩
⎪⎨⎧
−+=
−+== r
ryyyry
xrxGt
tyyyty
txxxtxG
( )x y11
11,
( )x y01
01,
( )x y02
02,
( )21
20 , yx
Γ1 Γ2
Intersection: x & y values equal in both representations - two linear equations in two unknowns (r,t)
( )
( ) ( )ryyytyyy
xxxxt
xtxxx
20
21
20
10
11
10
10
11
10
20
20
10
11
10
−+=−+
−−
=
=−+
![Page 7: Chapter 9cs314/Vsep2005/lec_pdf/ch9.pdf · University of 4 British Columbia Analytic Solution Intersectionof convex regions is convex Why? L& Dare convex- intersection is convex single](https://reader030.fdocuments.in/reader030/viewer/2022040416/5d14b62a88c993fd118b4dd5/html5/thumbnails/7.jpg)
7University ofUniversity ofBritish ColumbiaBritish Columbia
Purpose:Fast treatment of line segments that are trivially inside/outside window.
Purpose:Fast treatment of line segments that are trivially inside/outside window.
Cohen-Sutherland Algorithm
P = (x,y) - point to be classified against window D
Idea: Assign to P a binary code consisting of a bit for each edge of D, using lookup table:
0000
0101
0001
1001
0100
1000 1010
0010
0110
01
1234
bit
y y< min
y y> max
x x> maxx x< min
y y≥ miny y≤ max
x x≤ maxx x≥ min
![Page 8: Chapter 9cs314/Vsep2005/lec_pdf/ch9.pdf · University of 4 British Columbia Analytic Solution Intersectionof convex regions is convex Why? L& Dare convex- intersection is convex single](https://reader030.fdocuments.in/reader030/viewer/2022040416/5d14b62a88c993fd118b4dd5/html5/thumbnails/8.jpg)
8University ofUniversity ofBritish ColumbiaBritish Columbia
Cohen-Sutherland Algorithm (cont’d)
Why?
Given L from ),( to),( 1100 yxyx
If bitwise and of the codes of ( , ) ( , )x y x y0 0 1 1 and is not zero,
& rectangle D.
then L can be trivially handled (it is either totally outside or totally inside D).
or the bitwise or is zero,
0000
0101
0001
1001
0100
1000 1010
0010
0110
![Page 9: Chapter 9cs314/Vsep2005/lec_pdf/ch9.pdf · University of 4 British Columbia Analytic Solution Intersectionof convex regions is convex Why? L& Dare convex- intersection is convex single](https://reader030.fdocuments.in/reader030/viewer/2022040416/5d14b62a88c993fd118b4dd5/html5/thumbnails/9.jpg)
9University ofUniversity ofBritish ColumbiaBritish Columbia
end); , , , , , (
;,
; ofbit zero-nonleftmost ofboundary Windowelseend
); , , , , , (;,
; ofbit zero-nonleftmost ofboundary Windowbegin
then) ) ndow((OutsideWi if else;) , draw( then ) 0 ) or ( ( if
;return then ) 0 ! ) and ( ( if);( code );( code
) , , , ),,( ),,( (
maxminmaxmin20
102
1
maxminmaxmin12
102
0
0
1010
10
1100
maxminmaxmin111000
yyxxPPEdgePPP
CEdge
yyxxPPEdgePPP
CEdge
PPPCC
CCPCPC
yyxxyxPyxP
Clip-S-C
Clip-S-C
Clip-S-C
∩⇐
⇐
∩⇐
⇐
===
⇐⇐==
0000
0101
0001
1001
0100
1000 1010
0010
0110A
B
CD
E
AB CB DB DE
Cohen-Sutherland Algorithm (cont’d)
01
1234
bit
y y< min
y y> max
x x> maxx x< min
y y≥ miny y≤ max
x x≤ maxx x≥ min
![Page 10: Chapter 9cs314/Vsep2005/lec_pdf/ch9.pdf · University of 4 British Columbia Analytic Solution Intersectionof convex regions is convex Why? L& Dare convex- intersection is convex single](https://reader030.fdocuments.in/reader030/viewer/2022040416/5d14b62a88c993fd118b4dd5/html5/thumbnails/10.jpg)
10University ofUniversity ofBritish ColumbiaBritish Columbia
3D clipping
Determine portion of line inside axis-aligned parallelpiped (viewing frustum in NDC)Simple extension to 2D algorithmsAfter perspective transform
means that clipping volume always the samexmin=ymin= -1, xmax=ymax= 1 in OpenGL
boundary lines become boundary planesbut bit-codes still work the same wayadditional front and back clipping plane
zmin = -1, zmax = 1 in OpenGL
![Page 11: Chapter 9cs314/Vsep2005/lec_pdf/ch9.pdf · University of 4 British Columbia Analytic Solution Intersectionof convex regions is convex Why? L& Dare convex- intersection is convex single](https://reader030.fdocuments.in/reader030/viewer/2022040416/5d14b62a88c993fd118b4dd5/html5/thumbnails/11.jpg)
11University ofUniversity ofBritish ColumbiaBritish Columbia
Triangle Clipping
How does intersection of rectangle & triangle looks like?
How many sides?
How to expand clipping to triangles?Hint: it is convexWill develop on the board…
![Page 12: Chapter 9cs314/Vsep2005/lec_pdf/ch9.pdf · University of 4 British Columbia Analytic Solution Intersectionof convex regions is convex Why? L& Dare convex- intersection is convex single](https://reader030.fdocuments.in/reader030/viewer/2022040416/5d14b62a88c993fd118b4dd5/html5/thumbnails/12.jpg)
12University ofUniversity ofBritish ColumbiaBritish Columbia
end); , , , ,,...,,, ,.., (
;,
;,
; ofbit zero-nonleftmost ofboundary Window begin
then) ) ndow((OutsideWi ifn to1ifor else
;)poly draw( then ) 0 )or ...or or ( ( if;return then ) 0 ! ) and ... and and ( ( if
);( code n to1ifor ) , , , , ,..,poly (
maxminmaxmin11,,110
11,
1,1
10
10
maxminmaxmin0
yyxxPPPPPPEdgePPP
EdgePPP
CEdge
P
CCCCCC
PCyyxxPP
niiiiii
iiii
iiii
i
i
n
n
ii
n
++−−
++
−−
∩⇐
∩⇐
⇐
=
===
⇐==
Clip-S-C
Clip-S-C
Cohen-Sutherland Algorithm for convex polygons
01
1234
bit
y y< min
y y> max
x x> maxx x< min
y y≥ miny y≤ max
x x≤ maxx x≥ min