Upcoming SlideShare
×

# Lecture 2d point,curve,text,line clipping

20,527 views
20,138 views

Published on

Published in: Education
19 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• i like the way of explanation...good job

Are you sure you want to  Yes  No
• its truly awesome

Are you sure you want to  Yes  No
Views
Total views
20,527
On SlideShare
0
From Embeds
0
Number of Embeds
12
Actions
Shares
0
941
2
Likes
19
Embeds 0
No embeds

No notes for slide

### Lecture 2d point,curve,text,line clipping

1. 1. 2D CLIPPING <ul><li>Clipping is a procedure that identifies those portions of a picture that are either inside or outside of a specified region of space. </li></ul><ul><li>Clip Window is the region against which an object is to be clipped. </li></ul><ul><li>It may be a polygon or curved boundaries. But rectangular clip regions are preferred. </li></ul><ul><li>For viewing transformations, picture parts within window area are displayed. Everything outside window area is discarded. </li></ul>
2. 2. CLIPPING (Cont…) <ul><li>Clipping algorithm – 2 methods </li></ul><ul><ul><li>Clipping applied in world coordinates & contents of window interior are mapped to device coordinates </li></ul></ul><ul><ul><ul><ul><li>Eliminates processing necessary to transform those primitives outside window to device space </li></ul></ul></ul></ul><ul><ul><li>Map complete world coordinate picture to device coordinate or normalized device coordinate, then clip against view port boundaries. </li></ul></ul><ul><ul><ul><ul><li>Reduce calculations by allowing concatenation of viewing & geometric transformation matrices. </li></ul></ul></ul></ul>
3. 3. Types of clipping <ul><li>Based on different output primitives </li></ul><ul><ul><li>Point clipping </li></ul></ul><ul><ul><li>Curve clipping </li></ul></ul><ul><ul><li>Text clipping </li></ul></ul><ul><ul><li>Exterior clipping </li></ul></ul><ul><ul><li>Line clipping (Straight line segments) </li></ul></ul><ul><ul><li>Area clipping (Polygons) </li></ul></ul>
4. 4. 1.POINT CLIPPING <ul><li>Clip window is a rectangle in standard position. </li></ul><ul><li>A point p=(x,y) is saved for display, if the following inequalities are satisfied, </li></ul><ul><ul><ul><ul><li>xw min < x < xw max </li></ul></ul></ul></ul><ul><ul><ul><ul><li>yw min < y < yw max where xw min, xw max , yw min & yw max are edges of clip window (WC window or view port boundaries) </li></ul></ul></ul></ul><ul><li>If any one of these 4 inequalities is not satisfied, the point is clipped i.e, not saved for display. </li></ul><ul><ul><li>Can be applied to scenes involving explosions or sea foam that are modeled with particles (points) distributed in some region of the scene. </li></ul></ul>
5. 5. 2.Curve clipping <ul><li>Curve clipping procedures </li></ul><ul><li>will involve non-linear </li></ul><ul><li>equations (so requires more </li></ul><ul><li>processing than for objects </li></ul><ul><li>with linear boundaries) </li></ul>
6. 6. Curve clipping (cont) <ul><li>Preliminary test (Test for overlapping) </li></ul><ul><ul><li>The bounding rectangle for a circle or other curved object is used to test for overlap with a rectangular clip window. </li></ul></ul><ul><ul><li>If the bounding rectangle is completely inside (save object), completely outside (discard the object) </li></ul></ul><ul><ul><li>Both cases- no computation is necessary. </li></ul></ul><ul><ul><li>If bounding rectangle test fails, use computation-saving approaches </li></ul></ul><ul><li>Circle – coordinate extents of individual quadrants & then octants are used for preliminary testing before calculating curve–window intersections </li></ul><ul><li>Ellipse – coordinate extents of individual quadrants are used. </li></ul><ul><li>If 2 regions overlap, solve the simultaneous line-curve equations to obtain the clipping intersection points. </li></ul>
7. 7. 3.TEXT CLIPPING <ul><li>Depends on methods used to generate characters & the requirements of a particular application </li></ul><ul><li>Methods for processing character strings relative to a window boundary, </li></ul><ul><ul><ul><li>All-or-none string clipping strategy </li></ul></ul></ul><ul><ul><ul><li>All or none character clipping strategy </li></ul></ul></ul><ul><ul><ul><li>Clip the components of individual characters </li></ul></ul></ul>
8. 8. TEXT CLIPPING (cont) <ul><ul><ul><li>All-or-none string clipping strategy </li></ul></ul></ul><ul><ul><ul><ul><li>Simplest method, fastest text clipping </li></ul></ul></ul></ul><ul><ul><ul><ul><li>All string - inside clip window, keep it, otherwise discard. </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Bounding rectangle considered around the text pattern </li></ul></ul></ul></ul><ul><ul><ul><ul><li>If bounding position of rectangle overlap with window boundaries, string is rejected. </li></ul></ul></ul></ul><ul><ul><ul><li>All or none character clipping strategy </li></ul></ul></ul><ul><ul><ul><ul><li>Discard or reject an entire character string that overlaps a window boundary i.e, discard those characters that are not completely inside the window. </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Compare boundary limits of individual characters with the window. </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Any character which is outside or overlapping the window boundary are clipped. </li></ul></ul></ul></ul>
9. 9. TEXT CLIPPING (cont)
10. 10. TEXT CLIPPING (cont) <ul><ul><li>Clip the components of individual characters </li></ul></ul><ul><ul><li>Treat characters same as lines </li></ul></ul><ul><ul><li>If individual char overlaps a clip window boundary, clip off the parts of the character that are outside the window. </li></ul></ul>TEXT CLIPPING (cont)
11. 11. 4.EXTERIOR CLIPPING <ul><li>Clip a picture to the exterior of a specified region </li></ul><ul><li>The picture parts to be saved are those that are outside the region. </li></ul><ul><li>Eg. Multiple window systems, applications that require overlapping pictures. </li></ul>
12. 12. 5.Line Clipping <ul><li>For the image below consider which lines and points should be kept and which ones should be clipped </li></ul>wy max wy min wx min wx max Window P 1 P 2 P 3 P 6 P 5 P 7 P 10 P 9 P 4 P 8
13. 13. Line clipping procedure <ul><li>A line clipping procedure involves several parts: </li></ul><ul><ul><li>Test a given line segment to determine whether it lies completely inside the clipping window. </li></ul></ul><ul><ul><li>Determine whether it lies completely outside the window </li></ul></ul><ul><ul><li>If not 1 & 2, perform intersection calculations with one or more clipping boundaries. </li></ul></ul><ul><li>A line with both endpoints inside all clipping boundaries is saved </li></ul><ul><li>A line with both endpoints outside any one of the clip boundaries is discarded </li></ul><ul><li>Other lines cross one or more clipping boundaries & require calculation of multiple intersection points </li></ul>
14. 14. Point Clipping <ul><li>A point ( x,y ) is not clipped if: </li></ul><ul><li>wx min ≤ x ≤ wx max AND wy min ≤ y ≤ wy max </li></ul><ul><li>otherwise it is clipped </li></ul>wy max wy min wx min wx max Window P 1 P 2 P 5 P 7 P 10 P 9 P 4 P 8 Clipped Points Within the Window are Not Clipped Clipped Clipped Clipped
15. 15. Line Clipping <ul><li>Examine the end-points of each line to see if they are in the window or not </li></ul>Situation Solution Example Both end-points inside the window Don’t clip One end-point inside the window, one outside Must clip Both end-points outside the window Clipping decision should be made appropriately
16. 16. Line clipping – parametric test <ul><li>Performed if one or both endpoints of line segment are outside the clipping rectangle </li></ul><ul><li>The parametric representation for line segment with endpoints (x1,y1) and (x2,y2) is given by </li></ul><ul><ul><ul><ul><li>X=x1+u (x2-x1) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Y=y1+u (y2-y1), 0 < u < 1 </li></ul></ul></ul></ul><ul><li>Used to determine values for parameter u for intersections with the clipping boundary </li></ul><ul><li>If u value (for intersection with a rectangle boundary edge) is outside the range 0 to 1, the line does not enter the interior of window boundary. </li></ul><ul><li>If u is within the range o to 1, the line segment does indeed cross into the clipping area. </li></ul><ul><li>This method is applied to each clipping boundary edge in turn to determine whether any part of the line segment is to be displayed. </li></ul><ul><li>Clipping line segments with these parametric tests require a good deal of computation & faster approaches to clipping are possible. </li></ul>
17. 17. Cohen-Sutherland Clipping Algorithm <ul><li>Oldest, most popular & efficient line clipping algorithm </li></ul><ul><li>It reduces the number of line intersections that must be calculated by performing initial tests & speeds up processing </li></ul><ul><li>Every line endpoint in a picture is assigned a 4-digit binary code called a region code </li></ul><ul><li>Region code identifies the location of a point relative to the boundaries of the clipping rectangle </li></ul>
18. 18. Cohen-Sutherland: World Division <ul><li>World space is divided into regions based on the window boundaries </li></ul><ul><ul><li>Each region has a unique four bit region code </li></ul></ul><ul><ul><li>Region codes indicate the position of the regions with respect to the window </li></ul></ul>1001 1000 1010 0001 0000 Window 0010 0101 0100 0110 above below right left 3 2 1 0 Region Code
19. 19. Cohen-Sutherland: Labelling <ul><li>Every end-point is labelled with the appropriate region code </li></ul>wy max wy min wx min wx max Window P 3 [0001] P 6 [0000] P 5 [0000] P 7 [0001] P 10 [0100] P 9 [0000] P 4 [1000] P 8 [0010] P 12 [0010] P 11 [1010] P 13 [0101] P 14 [0110]
20. 20. Cohen-Sutherland: Lines In The Window Lines completely contained within the window boundaries have region code [0000] for both end-points so are not clipped wy max wy min wx min wx max Window P 3 [0001] P 6 [0000] P 5 [0000] P 7 [0001] P 10 [0100] P 9 [0000] P 4 [1000] P 8 [0010] P 12 [0010] P 11 [1010] P 13 [0101] P 14 [0110]
21. 21. Cohen-Sutherland: Lines Outside The Window <ul><li>Any lines with a common set bit in the region codes of both end-points can be clipped </li></ul><ul><ul><li>The AND operation (result – not 0000) can efficiently check this </li></ul></ul>wy max wy min wx min wx max Window P 3 [0001] P 6 [0000] P 5 [0000] P 7 [0001] P 10 [0100] P 9 [0000] P 4 [1000] P 8 [0010] P 12 [0010] P 11 [1010] P 13 [0101] P 14 [0110]
22. 22. Cohen-Sutherland: Other Lines <ul><li>Lines that cannot be identified as completely inside or outside the window may or may not cross the window interior </li></ul><ul><li>These lines are processed as follows: </li></ul><ul><ul><li>Compare an end-point outside the window to a boundary (choose any order in which to consider boundaries e.g. left, right, bottom, top) and determine how much can be discarded </li></ul></ul><ul><ul><li>If the remainder of the line is entirely inside or outside the window, retain it or clip it respectively </li></ul></ul>
23. 23. Cohen-Sutherland: Other Lines (cont…) <ul><ul><li>Otherwise, compare the remainder of the line against the other window boundaries </li></ul></ul><ul><ul><li>Continue until the line is either discarded or a segment inside the window is found </li></ul></ul><ul><li>We can use the region codes to determine which window boundaries should be considered for intersection </li></ul><ul><ul><li>To check if a line crosses a particular boundary we compare the appropriate bits in the region codes of its end-points </li></ul></ul><ul><ul><li>If one of these is a 1 and the other is a 0 then the line crosses the boundary </li></ul></ul>
24. 24. Cohen-Sutherland Examples <ul><li>Consider the line P 9 to P 10 below </li></ul><ul><ul><li>Start at P 10 </li></ul></ul><ul><ul><li>From the region codes of the two end-points we know the line doesn’t cross the left or right boundary </li></ul></ul><ul><ul><li>Calculate the intersection of the line with the bottom boundary to generate point P 10 ’ </li></ul></ul><ul><ul><li>The line P 9 to P 10 ’ is completely inside the window so is retained </li></ul></ul>wy max wy min wx min wx max Window P 10 [0100] P 9 [0000] P 10 ’ [0000] P 9 [0000]
25. 25. Cohen-Sutherland Examples (cont…) <ul><li>Consider the line P 3 to P 4 below </li></ul><ul><ul><li>Start at P 4 </li></ul></ul><ul><ul><li>From the region codes of the two end-points we know the line crosses the left boundary so calculate the intersection point to generate P 4 ’ </li></ul></ul><ul><ul><li>The line P 3 to P 4 ’ is completely outside the window so is clipped </li></ul></ul>wy max wy min wx min wx max Window P 4 ’ [1001] P 3 [0001] P 4 [1000] P 3 [0001]
26. 26. Cohen-Sutherland Examples (cont…) <ul><li>Consider the line P 7 to P 8 below </li></ul><ul><ul><li>Start at P 7 </li></ul></ul><ul><ul><li>From the two region codes of the two end-points we know the line crosses the left boundary so calculate the intersection point to generate P 7 ’ </li></ul></ul>wy max wy min wx min wx max Window P 7 ’ [0000] P 7 [0001] P 8 [0010] P 8 ’ [0000]
27. 27. Cohen-Sutherland Examples (cont…) <ul><li>Consider the line P 7 ’ to P 8 </li></ul><ul><ul><li>Start at P 8 </li></ul></ul><ul><ul><li>Calculate the intersection with the right boundary to generate P 8 ’ </li></ul></ul><ul><ul><li>P 7 ’ to P 8 ’ is inside the window so is retained </li></ul></ul>wy max wy min wx min wx max Window P 7 ’ [0000] P 7 [0001] P 8 [0010] P 8 ’ [0000]
28. 28. Calculating Line Intersections <ul><li>Intersection points with the window boundaries are calculated using the line-equation parameters </li></ul><ul><ul><li>Consider a line with the end-points ( x 1 , y 1 ) and ( x 2 , y 2 ) </li></ul></ul><ul><ul><li>The y-coordinate of an intersection with a vertical window boundary can be calculated using: </li></ul></ul><ul><ul><li>y = y 1 + m ( x boundary - x 1 ) </li></ul></ul><ul><ul><li>where x boundary can be set to either wx min or wx max </li></ul></ul>
29. 29. Calculating Line Intersections (cont…) <ul><ul><li>The x-coordinate of an intersection with a horizontal window boundary can be calculated using: </li></ul></ul><ul><ul><li>x = x 1 + ( y boundary - y 1 ) / m </li></ul></ul><ul><ul><li>where y boundary can be set to either wy min or wy max </li></ul></ul><ul><ul><li>m is the slope of the line in question and can be calculated as m = ( y 2 - y 1 ) / ( x 2 - x 1 ) </li></ul></ul>
30. 30. Liang-Barsky line clipping <ul><li>Faster line clipper </li></ul><ul><li>Based on the analysis of parametric equation of a line segment of the form </li></ul><ul><li>x=x1+u Δ x </li></ul><ul><li>y=y1+u Δ y , 0<=u<=1 </li></ul><ul><li> Δ x=x2-x1 & Δ y=y2-y1 </li></ul><ul><li>More efficient </li></ul><ul><li>Both Cohen-Sutherland and Liang-Barsky algorithm can be extended to 3-D clipping </li></ul>