Clipping - PowerPoint PPT Presentation

1 / 41
About This Presentation
Title:

Clipping

Description:

Intersection calculation ... for x, get t, calculate corresponding y. ... The calculation of an outcode for each endpoint allows for an efficient implementation. ... – PowerPoint PPT presentation

Number of Views:37
Avg rating:3.0/5.0
Slides: 42
Provided by: chaitr
Category:

less

Transcript and Presenter's Notes

Title: Clipping


1
Clipping
  • 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

2
Clipping
  • 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

3
Cases for clipping lines
B
H
C
E
J
A
G
I
4
Cases for Clipping Lines
B
C
A
5
Clipping Targets
  • Points
  • Lines
  • Polygons
  • Text
  • Other Objects

6
Clipping
  • 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.

7
Intersection 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.

8
Clip to boundary
Clipping Edge
9
Cohen-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

10
Cohen-Sutherland Line clipping Algorithm
1001
1000
1010
y-top
0010
0001
0000
y-bottom
0110
0100
0101
X-right
X-left
11
Look at Sign Bits (neg 1)
  • Bit 1
  • Bit 2
  • Bit 3
  • Bit 4

12
Cohen-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

13
Trivial 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

14
Trivial 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

15
Example1
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
16
Clipping example1
17
Cohen-Sutherland Line ClippingExample2
D
C
I
B
H
A
G
F
E
18
Cohen-Sutherland Line ClippingExample2
D
C
1000
1001
1010
I
B
H
A
G
0000
0010
0001
F
E
0110
0101
0100
19
Initial Outcode Calculations
  • OC(D)1000 OC(A)0001
  • OC(E)0100 OC(I)1010

20
Clip and Continue
  • Clip against the top boundary (and throw gt t)
  • Calculate B. Keep AB
  • Calculate H . Keep EH

21
Cohen-Sutherland Line Clipping
B
H
A
G
F
E
22
Clip 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

23
Outcode Calculations
  • OC(H)0010 OC(E)0100
  • Since product is 0, process HE to get FH

24
Cohen-Sutherland Line Clipping
H
G
F
25
Outcode Calculations
  • OC(F)0000 OC(H)0010
  • Since product is 0, process HF to get GF

26
Clip and Continue
  • Clip against the right boundary
  • Get GF
  • Done

27
Cohen-Sutherland Line Clipping
G
F
28
Process Ends
  • Do not have to do
  • Polygon clipping convex, concave?

29
Cohen-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

32
3D Clipping against a right parallelepiped
33
Clipping for Orthographic Viewing
34
Clipping for Oblique Viewing
35
Distortion of VV by shear a) top view before
shear, b) top view after shear
36
Equations
  • 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)

37
Plane 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.

38
Line-plane Intersection
(Will also see in Ray-casting)
  • L(t) Pa t(Pb - Pa)Substituting into the
    plane equation, and solving for t

39
Graphics (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)
Write a Comment
User Comments (0)
About PowerShow.com