30
1 of 30 2D CLIPPING Clipping is a procedure that identifies those portions of a picture that are either inside or outside of a specified region of space. Clip Window is the region against which an object is to be clipped. • It may be a polygon or curved boundaries. But rectangular clip regions are preferred. • For viewing transformations, picture parts within window area are displayed. Everything outside window area is discarded.

Lecture 2d point,curve,text,line clipping

  • Upload
    avelraj

  • View
    9.005

  • Download
    3

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Lecture   2d point,curve,text,line clipping

1of30

2D CLIPPING

• Clipping is a procedure that identifies those portions of a picture that are either inside or outside of a specified region of space.

• Clip Window is the region against which an object is to be clipped.• It may be a polygon or curved boundaries. But rectangular clip regions are preferred.

• For viewing transformations, picture parts within window area are displayed. Everything outside window area is discarded.

Page 2: Lecture   2d point,curve,text,line clipping

2of30

CLIPPING (Cont…)

•Clipping algorithm – 2 methods– Clipping applied in world coordinates &

contents of window interior are mapped to device coordinates

– Eliminates processing necessary to transform those primitives outside window to device space

– Map complete world coordinate picture to device coordinate or normalized device coordinate, then clip against view port boundaries.

– Reduce calculations by allowing concatenation of viewing & geometric transformation matrices.

Page 3: Lecture   2d point,curve,text,line clipping

3of30

Types of clipping

Based on different output primitives

– Point clipping

– Curve clipping

– Text clipping

– Exterior clipping

– Line clipping (Straight line segments)

– Area clipping (Polygons)

Page 4: Lecture   2d point,curve,text,line clipping

4of30

1.POINT CLIPPING

•Clip window is a rectangle in standard position.•A point p=(x,y) is saved for display, if the following inequalities are satisfied,

–xwmin < x < xwmax

–ywmin < y < ywmax where xwmin,xwmax ,ywmin & ywmax are edges of clip window (WC window or view port boundaries)

•If any one of these 4 inequalities is not satisfied, the point is clipped i.e, not saved for display.

– Can be applied to scenes involving explosions or sea foam that are modeled with particles (points) distributed in some region of the scene.

Page 5: Lecture   2d point,curve,text,line clipping

5of30

2.Curve clipping

• Curve clipping procedures

will involve non-linear

equations (so requires more

processing than for objects

with linear boundaries)

Page 6: Lecture   2d point,curve,text,line clipping

6of30

Curve clipping (cont)

•Preliminary test (Test for overlapping)– The bounding rectangle for a circle or other curved object

is used to test for overlap with a rectangular clip window.– If the bounding rectangle is completely inside (save

object), completely outside (discard the object)– Both cases- no computation is necessary.– If bounding rectangle test fails, use computation-saving

approaches•Circle – coordinate extents of individual quadrants & then octants are used for preliminary testing before calculating curve–window intersections•Ellipse – coordinate extents of individual quadrants are used.•If 2 regions overlap, solve the simultaneous line-curve equations to obtain the clipping intersection points.

Page 7: Lecture   2d point,curve,text,line clipping

7of30

3.TEXT CLIPPING

•Depends on methods used to generate characters & the requirements of a particular application

•Methods for processing character strings relative to a window boundary,

• All-or-none string clipping strategy• All or none character clipping strategy• Clip the components of individual characters

Page 8: Lecture   2d point,curve,text,line clipping

8of30

TEXT CLIPPING (cont)

• All-or-none string clipping strategy– Simplest method, fastest text clipping– All string - inside clip window, keep it, otherwise discard.– Bounding rectangle considered around the text pattern– If bounding position of rectangle overlap with window

boundaries, string is rejected.• All or none character clipping strategy

– Discard or reject an entire character string that overlaps a window boundary i.e, discard those characters that are not completely inside the window.

– Compare boundary limits of individual characters with the window.

– Any character which is outside or overlapping the window boundary are clipped.

Page 9: Lecture   2d point,curve,text,line clipping

9of30

TEXT CLIPPING (cont)

Page 10: Lecture   2d point,curve,text,line clipping

10of30 TEXT CLIPPING (cont)

• Clip the components of individual characters

– Treat characters same as lines

– If individual char overlaps a clip window boundary, clip off the parts of the character that are outside the window.

TEXT CLIPPING (cont)

Page 11: Lecture   2d point,curve,text,line clipping

11of30

4.EXTERIOR CLIPPING

•Clip a picture to the exterior of a specified region

•The picture parts to be saved are those that are outside the region.

•Eg. Multiple window systems, applications that require overlapping pictures.

Page 12: Lecture   2d point,curve,text,line clipping

12of30

5.Line Clipping

•For the image below consider which lines and points should be kept and which ones should be clipped

wymax

wymin

wxmin wxmax

Window

P1

P2

P3

P6

P5P7

P10

P9

P4

P8

Page 13: Lecture   2d point,curve,text,line clipping

13of30

Line clipping procedure

• A line clipping procedure involves several parts:1. Test a given line segment to determine whether it lies

completely inside the clipping window.2. Determine whether it lies completely outside the

window3. If not 1 & 2, perform intersection calculations with

one or more clipping boundaries.• A line with both endpoints inside all clipping boundaries

is saved• A line with both endpoints outside any one of the clip

boundaries is discarded• Other lines cross one or more clipping boundaries &

require calculation of multiple intersection points

Page 14: Lecture   2d point,curve,text,line clipping

14of30

Point Clipping

A point (x,y) is not clipped if:

wxmin ≤ x ≤ wxmax AND wymin ≤ y ≤ wymax

otherwise it is clipped

wymax

wymin

wxmin wxmax

Window

P1

P2

P5

P7

P10

P9

P4

P8

Clipped

Points Within the Window are Not Clipped

Clipped

Clipped

Clipped

Page 15: Lecture   2d point,curve,text,line clipping

15of30

Line Clipping

Examine the end-points of each line to see if they are in the window or not

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

Page 16: Lecture   2d point,curve,text,line clipping

16of30

Line clipping – parametric test

• Performed if one or both endpoints of line segment are outside the clipping rectangle

• The parametric representation for line segment with endpoints (x1,y1) and (x2,y2) is given by

X=x1+u (x2-x1)Y=y1+u (y2-y1), 0< u <1

• Used to determine values for parameter u for intersections with the clipping boundary

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

• If u is within the range o to 1, the line segment does indeed cross into the clipping area.

• This method is applied to each clipping boundary edge in turn to determine whether any part of the line segment is to be displayed.

• Clipping line segments with these parametric tests require a good deal of computation & faster approaches to clipping are possible.

Page 17: Lecture   2d point,curve,text,line clipping

17of30

Cohen-Sutherland Clipping Algorithm

•Oldest, most popular & efficient line clipping algorithm

•It reduces the number of line intersections that must be calculated by performing initial tests & speeds up processing

•Every line endpoint in a picture is assigned a 4-digit binary code called a region code

•Region code identifies the location of a point relative to the boundaries of the clipping rectangle

Page 18: Lecture   2d point,curve,text,line clipping

18of30

Cohen-Sutherland: World Division

World space is divided into regions based on the window boundaries

– Each region has a unique four bit region code– Region codes indicate the position of the

regions with respect to the window

1001 1000 1010

00010000

Window0010

0101 0100 0110

above below right left

3 2 1 0

Region Code

Page 19: Lecture   2d point,curve,text,line clipping

19of30

Cohen-Sutherland: Labelling

Every end-point is labelled with the appropriate region code

wymax

wymin

wxmin wxmax

Window

P3 [0001]P6 [0000]

P5 [0000]

P7 [0001]

P10 [0100]

P9 [0000]

P4 [1000]

P8 [0010]

P12 [0010]

P11 [1010]

P13 [0101] P14 [0110]

Page 20: Lecture   2d point,curve,text,line clipping

20of30

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

wymax

wymin

wxmin wxmax

Window

P3 [0001]P6 [0000]

P5 [0000]

P7 [0001]

P10 [0100]

P9 [0000]

P4 [1000]

P8 [0010]

P12 [0010]

P11 [1010]

P13 [0101] P14 [0110]

Page 21: Lecture   2d point,curve,text,line clipping

21of30

Cohen-Sutherland: Lines Outside The Window

Any lines with a common set bit in the region codes of both end-points can be clipped

– The AND operation (result – not 0000) can efficiently check this

wymax

wymin

wxmin wxmax

Window

P3 [0001]P6 [0000]

P5 [0000]

P7 [0001]

P10 [0100]

P9 [0000]

P4 [1000]

P8 [0010]

P12 [0010]

P11 [1010]

P13 [0101] P14 [0110]

Page 22: Lecture   2d point,curve,text,line clipping

22of30

Cohen-Sutherland: Other Lines

Lines that cannot be identified as completely inside or outside the window may or may not cross the window interior

These lines are processed as follows:– 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

– If the remainder of the line is entirely inside or outside the window, retain it or clip it respectively

Page 23: Lecture   2d point,curve,text,line clipping

23of30

Cohen-Sutherland: Other Lines (cont…)

– Otherwise, compare the remainder of the line against the other window boundaries

– Continue until the line is either discarded or a segment inside the window is found

We can use the region codes to determine which window boundaries should be considered for intersection

– To check if a line crosses a particular boundary we compare the appropriate bits in the region codes of its end-points

– If one of these is a 1 and the other is a 0 then the line crosses the boundary

Page 24: Lecture   2d point,curve,text,line clipping

24of30

Cohen-Sutherland Examples

Consider the line P9 to P10 below

– Start at P10

– From the region codes of the two end-points we know the line doesn’t cross the left or right boundary

– Calculate the intersection of the line with the bottom boundary to generate point P10’

– The line P9 to P10’ is completely inside the window so is retained

wymax

wymin

wxmin wxmax

Window

P10 [0100]

P9 [0000]

P10’ [0000]

P9 [0000]

Page 25: Lecture   2d point,curve,text,line clipping

25of30

Cohen-Sutherland Examples (cont…)

Consider the line P3 to P4 below

– Start at P4

– From the region codes of the two end-points we know the line crosses the left boundary so calculate the intersection point to generate P4’

– The line P3 to P4’ is completely outside the window so is clipped

wymax

wymin

wxmin wxmax

WindowP4’ [1001]

P3 [0001]

P4 [1000]

P3 [0001]

Page 26: Lecture   2d point,curve,text,line clipping

26of30

Cohen-Sutherland Examples (cont…)

Consider the line P7 to P8 below

– Start at P7

– 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 P7’

wymax

wymin

wxmin wxmax

Window

P7’ [0000]

P7 [0001] P8 [0010]P8’ [0000]

Page 27: Lecture   2d point,curve,text,line clipping

27of30

Cohen-Sutherland Examples (cont…)

Consider the line P7’ to P8

– Start at P8

– Calculate the intersection with the right boundary to generate P8’

– P7’ to P8’ is inside the window so is retained

wymax

wymin

wxmin wxmax

Window

P7’ [0000]

P7 [0001] P8 [0010]P8’ [0000]

Page 28: Lecture   2d point,curve,text,line clipping

28of30

Calculating Line Intersections

Intersection points with the window boundaries are calculated using the line-equation parameters

– Consider a line with the end-points (x1, y1) and (x2, y2)

– The y-coordinate of an intersection with a vertical window boundary can be calculated using:

y = y1 + m (xboundary - x1)

where xboundary can be set to either wxmin or wxmax

Page 29: Lecture   2d point,curve,text,line clipping

29of30

Calculating Line Intersections (cont…)

– The x-coordinate of an intersection with a horizontal window boundary can be calculated using:

x = x1 + (yboundary - y1) / m

where yboundary can be set to either wymin or wymax

– m is the slope of the line in question and can be calculated as m = (y2 - y1) / (x2 - x1)

Page 30: Lecture   2d point,curve,text,line clipping

30of30

Liang-Barsky line clipping

• Faster line clipper

• Based on the analysis of parametric equation of a line segment of the form

x=x1+u Δx

y=y1+u Δy, 0<=u<=1

Δx=x2-x1 & Δy=y2-y1

• More efficient

• Both Cohen-Sutherland and Liang-Barsky algorithm can be extended to 3-D clipping