Title: Clipping
1Clipping
- Clipping is a process of extracting a portion of
the database (having many polygons) - Clipping can be used to select a specific
information to display - Clipping can be 2D or 3D and implemented in
hardware or software. For real time applications,
clipping is typically implemented in hardware or
firmware - A regular clipping window is rectangular with its
edges aligned with those of the object space or
display device
2Clipping
- Points are interior if
- xl lt x lt xr and yb lt y lt yr
- (points on the boundary are included)
- A simple but inefficient method of clipping would
be to have SetPixel(x,y,color) and ignore any
requests to set a pixel outside the drawing
window - A better method is to clip the primitives
themselves so that only the visible portions are
further processed
3Cases for clipping lines
B
H
C
E
J
A
G
I
4Cases for Clipping Lines
B
C
A
5Clipping Targets
- Points
- Lines
- Polygons
- Text
- Other Objects
6Clipping
- We will study problem of Clip Line against an
axis-oriented rectangular window - Expensive part of clipping is intersection
calculations, so main goal of a clipping
algorithm is to minimize this.
7Intersection calculation
- We can find where the line segment crosses each
clipping-window edge by - assigning the coordinate value for that edge to
either x or y and solving for parameter t. - ii) For instance, substitute xl for x, get t,
calculate corresponding y. - iii) If this value of t is outside the range from
0 to 1, the line segment does not - Intersect that window border line.
- iv) Otherwise, part of the line is inside. We
process this inside portion against - the other clipping boundaries until we have
clipped the entire line.
8Clip to boundary
Clipping Edge
9Cohen-Sutherland Line clipping Algorithm
- Following algorithm considers efficiently
clipping 2D lines to a rectangle . - The motivating idea is to use inside/outside
information about the line end-points. This
generates the following possibilities - Both end points are inside the rectangular
window - Line completely inside trivial accept
- Both end points are to the right of the right
edge of the window - Line completely outside trivial reject
- None of the above
- Clip against one edge and repeat
10Cohen-Sutherland Line clipping Algorithm
1001
1000
1010
y-top
0010
0001
0000
y-bottom
0110
0100
0101
X-right
X-left
11Look at Sign Bits (neg 1)
12Cohen-Sutherland Line clipping Algorithm
- The calculation of an outcode for each endpoint
allows for an efficient implementation. An
outcode consists of 4 bits TRBL, where - T is set if y gt top
- B is set if y lt bottom
- R is set is x gt right , and
- L is set if x lt left
13Trivial accept cases
- The trivial accept case corresponds to ensuring
that no outcode bits are set for both endpoints.
This can be nicely accomplished with a bitwise OR
operation. - Out (A) 0101
- Out (B) 0100
- bitwise OR 0101 ? fails trivial accept
- Out(C) 0000
- Out (D) 0000 ? fails trivial accept
14Trivial reject cases
- The trivial reject case can be nicely
accomplished with a bitwise AND operation. We can
trivially reject a line segment which has a
result not equal to 0000 - Out (A) 0101
- Out (B) 0100
- bitwise AND 0100 ? trivial reject
- Out (E) 1000
- Out (F) 0010
- bitwise AND 0000 ?fails trivial reject
15Example1
k
h
j
i
l
g
b
e
d
a
f
c
1000
1010
1001
T
0001
0010
0000
B
0101
0100
0110
L
R
16Clipping example1
17Cohen-Sutherland Line ClippingExample2
D
C
I
B
H
A
G
F
E
18Cohen-Sutherland Line ClippingExample2
D
C
1000
1001
1010
I
B
H
A
G
0000
0010
0001
F
E
0110
0101
0100
19Initial Outcode Calculations
- OC(D)1000 OC(A)0001
- OC(E)0100 OC(I)1010
20Clip and Continue
- Clip against the top boundary (and throw gt t)
- Calculate B. Keep AB
- Calculate H . Keep EH
21Cohen-Sutherland Line Clipping
B
H
A
G
F
E
22Clip and Continue
- Now test and reject AB because
- OC(A)0001 and OC(B)0001
- Reject AB on outcode basis
-
- Clip against the bottom boundary
23Outcode Calculations
- OC(H)0010 OC(E)0100
- Since product is 0, process HE to get FH
24Cohen-Sutherland Line Clipping
H
G
F
25Outcode Calculations
- OC(F)0000 OC(H)0010
- Since product is 0, process HF to get GF
26Clip and Continue
- Clip against the right boundary
- Get GF
- Done
27Cohen-Sutherland Line Clipping
G
F
28Process Ends
- Do not have to do
- Polygon clipping convex, concave?
29Cohen-Sutherland in 3D
- The Cohen-Sutherland algorithm extends easily to
3D. - 2D is extended to the 3D clipping window
boundaries to define 27 regions. Assign a 6 bit
code to each region, that is, for each point - Left (first) bit set (1) point lies to left of
window - Right (second) bit set (1) point lies to right
of window - Bottom (third) bit set (1) point lies below
window - Top (fourth) bit set (1) point lies above
window - Near (fifth) bit set (1) point lies to in front
of window (near) - Far (sixth) bit set (1) point lies to behind of
window (far) -
30(No Transcript)
31- The Left, Right, Bottom, Top, Near, Far (LRBTNF)
outcode can be used to determine segments that
are trivially visible, trivially invisible, or
indeterminate. In the indeterminate case we
intersect the line segment with faces of clipping
cube determined by the outcode of an end-point
that is outside of the clipping cube. More
specifically, in the indeterminant case, use
parametric form of the line. - To clip against a face, say y1, compute
- and use it to evaluate the x and z intersections
323D Clipping against a right parallelepiped
33Clipping for Orthographic Viewing
34Clipping for Oblique Viewing
35Distortion of VV by shear a) top view before
shear, b) top view after shear
36Equations
- Explicit equation y f(x)
- Dependent on choice of coordinate axes
- Not defined if more than one f(x) for x, sqrt(9)
- Implicit equation f(x, y) 0
- Quick to see if (x,y) is on curve
- Difficult to generate series of f(x) for x0g10
- Parametric x f(t), y f(t)
37Plane Equations
- Implicit plane equation
- Ax By Cz D F(x,y,z)F(x,y,z)0 for points
on the plane - This can be rewritten asF(P) N.P D
- Parametric plane equation
- Plane(s,t) P0 s(P1-P0) t(P2-P0), provided
P0, P1, and P2 are non-colinear. - Plane(s,t) P0 s V1 t V2, where V1 and V2
are two basis vectors. - Explicit plane equation
- z -(A/C)x - (B/C)y - D/C , valid if C is
non-zero.
38Line-plane Intersection
(Will also see in Ray-casting)
- L(t) Pa t(Pb - Pa)Substituting into the
plane equation, and solving for t
39Graphics (rendering) pipeline
Viewing Geometry Processing World Coordinates
(floating point)
Rendering Pixel Processing Screen Coordinates
(integer)
Conservative VSD Selective traversal of object
database (or traverse scene graph to get CTM)
Transform Vertices To canonical view
volume
Light at Vertices Calculate light intensity at
vertices (lighting model of choice)
Conservative VSD Back-face Culling
Conservative VSD View Volume Clipping
Image- precision VSD Compare pixel
depth (Z-buffer)
Shading Interpolate color values (Gouraud) or
normals (Phong)
Projected!
per polygon
per pixel of polygon
avd November 9,
2004 VSD 6/48
avd November 5,
2002 VSD 5/45
40(No Transcript)
41(No Transcript)