45
Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

Embed Size (px)

Citation preview

Page 1: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

Presented by:Yerrapati Raviteja (U41011820)

EEL 5771-001Introduction to Computer Graphics

PPT5: Two-dimensional viewing

Page 2: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

OUTLINE•2D VIEWING PIPELINE•CLIPPING•TYPES OF CLIPPING

1) Line clipping Cohen-Sutherland Clipping Liang-Barsky Clipping NLN Clipping Algorithm

2) Point clipping3) Area clipping

Sutherland-Hodgman Area Clipping Algorithm4) Curve clipping5) Text clipping

All-or-none string clipping All-or-none character clipping Individual character clipping or component clipping

6) Exterior clipping7) Polygon Clipping

Weiler-Atherton Polygon Clipping

Page 3: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

CLIPPINGClipping is a process of extracting a portion of a data base or identifying elements of a scene or picture inside or outside a specified region, called the clipping region.

In the below figure, which lines and points should be kept and which ones should be clipped??

Page 4: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

A 2D viewing pipeline is made up of a bunch of objects specified in space of coordinates

Windowing I

World Coordinates

Page 5: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

While we display a scene, only those objects within a particular clipping window are seen

Windowing II

wymax

wymin

wxmin wxmax

Window

World Coordinates

Page 6: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

As it takes lots of time to draw things, we simply clip everything which is outside the window.

Windowing III

wymax

wymin

wxmin wxmax

World Coordinates

Window

Page 7: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

TYPES OF CLIPPINGSBased on different output primitives. Further presentation deals with these clipping types with examples:

1) Line clipping2) Point clipping3) Area clipping4) Curve clipping5) Text clipping6) Exterior clipping

Page 8: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

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

Clipping is not needed

One end-point inside the window, one outside

Clipping is needed

Both end-points outside the window

Clipping decision should be made accordingly

Page 9: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

LINE CLIPPING (cont..)

How line clipping works:

Before

After

Let us discuss about the following Line clipping algorithms in the coming slides:

1. Cohen-Sutherland Clipping2. Liang-Barsky Clipping3. NLN Clipping Algorithm

Page 10: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

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 11: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

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

0001 0000Window

0010

0101 0100 0110

above below right left

3 2 1 0

Region Code

Page 12: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

Cohen-Sutherland: LabellingEvery 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 13: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

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 14: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

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 15: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

Cohen-Sutherland: Other Lines

Lines that cannot be identified as completely inside or outside the window may or may not cross the window interiorThese 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 16: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

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 17: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

Cohen-Sutherland ExamplesConsider 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 18: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

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 19: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

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 20: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

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 21: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

Liang-Barsky Line Clipping Algorithm:-

• The Liang–Barsky algorithm uses the parametric equation of a line and inequalities describing the range of the clipping window to determine the intersections between the line and the clipping window. With these intersections it knows which portion of the line should be drawn.

• Consider first the usual parametric form of a straight line:

X= x0+u(x1-x0)= x0+uΔx, Y= y0+u(y1-y0)= y0+uΔy,

where 0<=u<=1.

Page 22: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

Liang-Barsky line clipping (cont..)

• Faster line clipper algorithm• Based on the analysis of parametric equation of a line

segment of the form x=x0+u Δxy=y0+u Δy, // 0<=u<=1

Δx=x1-x0 & Δy=y1-y0• More efficient• Both Cohen-Sutherland and Liang-Barsky algorithm

can be extended to 3-D clipping

Page 23: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

Liang-Barsky line clipping (cont..)

Algorithm:-

1. Set umin = 0 and umax = 1.2. Calculate the u values:3. If u < umin or u > umax ignore it. Otherwise classify the u values as entering or

exiting.4. If umin < umax then draw a line from:

( x0 + Δx · umin, y0 + Δy · umin ) to ( x0 + Δx · umax, y0 + Δy · umax ).

Page 24: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

Liang-Barsky line clipping (cont..)

Example:-

Let P1 (-1, -2), P2 (2, 4) => XL = 0, XR = 1, YB = 0, YT = 1 => dx = 2 - (-1) = 3; dy = 4 - (-2) = 6

P1 = -dx = -3; Q1 = x1 - XL = -1 - 0 = -1; So, Q1 / P1 = 1/3P2 = dx = 3; Q2 = XR - x1 = 1 - (-1) = 2; So, Q2 / P2 = 2/3P3 = -dy = -6; Q3 = y1 - YR = -2; So, Q3 / P3 = 1/3P4 = dy = 6; Q4 = YT - y1 = 3; So, Q4 / P4 = 1/2

• for (Pi < 0) t1="MAX" ( 1 / 3, 1 / 3, 0 )= 1 / 3• for (Pi > 0) t2 = MIN ( 2 / 3, 1 / 2, 1 ) = 1 / 2• Since t1 < t2 there is a visible section

Page 25: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

Liang-Barsky line clipping (cont..)

Example cont.. :-Now, Compute new endpoints:• t1 = 1 / 3 x1' = x1 + dx . t1 = -1 + (3 * 1 / 3) = 0• y1' = y1 + dy . t1 = -2 + (6 * 1 / 3) = 0• t2 = 1 / 2 x2' = x1 + dx . t2 = -1 + (3 * 1 / 2) = 1 / 2• y2' = y1 + dy . t2 = -1 + (6 * 1 / 2) = 1

These are the new end point after performingclipping using Liang-Barsky line clipping algorithm.

Page 26: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

NLN clipping Algorithm

NLN method uses more regions testing in the xy plane to reduce intersection calculations. The extra intersection calculation eliminated in the NLN algorithm by carrying out more region testing before intersection position is calculated.

It uses symmetry to categorize endpoints into one of 3 regions (in the clip window, edge & corner).

Then according to end point category it checks several clip cases.

Page 27: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

NLN clipping Algorithm (cont..)

Fig: NLN clipping window. Totally, we can see 9 regions in each image. Only the three region pointed above need be

considered If P1 lies in any one of the other six region, we can

move it to one of the three regions using a symmetry transformation.

Page 28: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

Clipping against Concave Clipping Windows

If the clipping polygon is of concave topology, then if the line to be clipped intersects the clipping polygon then it does so at even number of pointsIn this case, in order to find the clipped line, it is necessary to sort the points of intersection, pair the intersection points and then join each pair by a line segment. Sorting can be performed based on either x or y coordinates

Page 29: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

POINT CLIPPINGConsider a point (x,y) If wxmin ≤ x ≤ wxmax AND wymin ≤ y ≤ wymax

It is not clipped! Otherwise

It is clipped!

Page 30: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

AREA CLIPPING

Similarly to lines, areas must be clipped to a window boundaryConsideration must be taken as to which portions of the area must be clippedBelow are few examples:

Page 31: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

Sutherland-Hodgman Area Clipping Algorithm:A technique for clipping areas developed by Sutherland & HodgmanPut simply the polygon is clipped by comparing it against each boundary in turn

AREA CLIPPING (cont..)

Page 32: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

Sutherland-Hodgman Area Clipping Algorithm (cont…)To clip an area against an individual boundary:

– Consider each vertex in turn against the boundary– Vertices inside the boundary are saved for clipping

against the next boundary– Vertices outside the boundary are clipped– If we proceed from a point inside the boundary to one

outside, the intersection of the line with the boundary is saved

– If we cross from the outside to the inside intersection point and the vertex are saved

AREA CLIPPING (cont..)

Page 33: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

CURVE CLIPPINGCurve clipping procedures will involve non-linear equations (so requires more processing than for objects with linear boundaries In general, methods depend on how characters are represented).Clipping curves requires more work

For circles we must find the two intersection points on the window boundary

Page 34: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

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 intersectionsEllipse – coordinate extents of individual quadrants are used.If 2 regions overlap, solve the simultaneous line-curve equations to obtain the clipping intersection points.

Page 35: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

TEXT CLIPPINGIt is used to clip character strings.In general, methods depend on how characters are represented.Based on the method used to generate the original characters, three strategies can be followed:

1) All-or-none string clipping use a bounding rectangle for the string

2) All-or-none character clipping use a bounding rectangle for the character

3) Individual character clipping or component clipping like line/curve clipping (outlined char’s) compare individual pixels (bit-mapped)

Page 36: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

TEXT CLIPPING (cont..)All-or-none string clipping : It is used to clip the strings relative to the window boundary. Just consider a bounding rectangle around the string.

If all of the string is inside the windowSave it!

Otherwise discard it!

Example:

Page 37: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

TEXT CLIPPING (cont..)All-or-none character clipping: It is used to clip the characters relative to the window boundary.

If all of the character is inside the windowSave it!

Otherwise discard it!

Example:

Page 38: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

TEXT CLIPPING (cont..)Component clipping : Clip the components of individual characters.

If an individual character crosses or overlaps clip window boundary

Discard that component of the character!Otherwise saveit!

Example:

Page 39: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

EXTERIOR CLIPPING

Clip a picture to the exterior of a specified regionThe picture parts to be saved are those that are outside the region.Ex: Multiple window systems, applications that require overlapping pictures.

Page 40: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

A polygon boundary processed with a line clipper may be displayed as a series of unconnected line segments, depending on the orientation of the polygon to the clipping window.

What we really want to display is a bounded area after clipping. For polygon clipping, we require an algorithm that will generate one or more closed areas that are then scan converted for the appropriate area fill.

The output of a polygon clipper should be a sequence of vertices that defines the clipped polygon boundaries.

Polygon Clipping

Page 41: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

Polygon Fill-Area Clipping

Page 42: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

Steps involved in Polygon Clipping

STEP 1: Original polygon

STEP 2: After clipping RIGHT Boundary

STEP 3: After clipping RIGHT & BOTTOM Boundaries

STEP 4: After clipping RIGHT & BOTTOM & LEFT Boundaries

STEP 5: After clipping ALL Boundaries

Page 43: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

In this algorithm, the vertex –processing procedures for window boundaries are modified so that concave polygons are displayed correctly. This clipping procedure was developed as a method for identifying visible surfaces, and so it can be applied with arbitrary polygon-clipping regions.

The basic idea in this algorithm is that instead of always proceeding around the polygon edges as vertices are processed,we sometimes want to follow the window boundaries .Which path we follow depend on the polygon-processing direction(clockwise or counterclockwise)

Weiler- Atherton Polygon Clipping

Page 44: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

Weiler-Atherton Polygon Clipping

Weiler-Atherton

Page 45: Presented by: Yerrapati Raviteja (U41011820) EEL 5771-001 Introduction to Computer Graphics PPT5: Two-dimensional viewing

REFERENCES1. http://www.cs.mun.ca/av/old/teaching/cg/notes/raster_clip2_inclas

s.pdf2. http://www.cc.gatech.edu/grads/h/Hao-wei.Hsieh/Haowei.Hsieh/m

m.html3. http://myweb.lmu.edu/dondi/share/cg/clipping.pdf4. http://www.tutorialspoint.com/computer_graphics/viewing_and_cli

pping.htm5. https://www.google.com/search?q=Text+clipping&rlz=1C1CHWA_en

US622US622&es_sm=122&source=lnms&tbm=isch&sa=X&ved=0CAcQ_AUoAWoVChMI08Cvga-byAIVytceCh2d1Ql2&biw=1242&bih=545

6. http://www.sersc.org/journals/IJCG/vol6_no1/1.pdf