Presentation is loading. Please wait.

Presentation is loading. Please wait.

EEL Introduction to Computer Graphics

Similar presentations


Presentation on theme: "EEL Introduction to Computer Graphics"— Presentation transcript:

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

2 OUTLINE 2D VIEWING PIPELINE CLIPPING TYPES OF CLIPPING Line clipping
Cohen-Sutherland Clipping Liang-Barsky Clipping NLN Clipping Algorithm Point clipping Area clipping Sutherland-Hodgman Area Clipping Algorithm Curve clipping Text clipping All-or-none string clipping All-or-none character clipping Individual character clipping or component clipping Exterior clipping Polygon Clipping Weiler-Atherton Polygon Clipping

3 CLIPPING Clipping 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??

4 Windowing I A 2D viewing pipeline is made up of a bunch of objects specified in space of coordinates World Coordinates

5 Windowing II While we display a scene, only those objects within a particular clipping window are seen Window wymax wymin wxmin wxmax World Coordinates

6 Windowing III As it takes lots of time to draw things, we simply clip everything which is outside the window. Window wymax wymin wxmin wxmax World Coordinates

7 TYPES OF CLIPPINGS Based on different output primitives. Further presentation deals with these clipping types with examples: Line clipping Point clipping Area clipping Curve clipping Text clipping Exterior clipping

8 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

9 How line clipping works:
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 Clipping 2. Liang-Barsky Clipping 3. NLN Clipping Algorithm

10 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

11 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 0000 Window 0010 0101 0100 0110 above below right left 3 2 1 Region Code

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

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

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

15 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

16 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

17 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]

18 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 Window P4’ [1001] P3 [0001] P4 [1000]

19 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]

20 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]

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

22 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 Δx y=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

23 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 ).

24 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; So, Q1 / P1 = 1/3 P2 = dx = 3; Q2 = XR - x1 = 1 - (-1) = 2; So, Q2 / P2 = 2/3 P3 = -dy = -6; Q3 = y1 - YR = -2; So, Q3 / P3 = 1/3 P4 = 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

25 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 performing clipping using Liang-Barsky line clipping algorithm.

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

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

28 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 points In 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

29 POINT CLIPPING Consider a point (x,y)
If wxmin ≤ x ≤ wxmax AND wymin ≤ y ≤ wymax It is not clipped! Otherwise It is clipped!

30 AREA CLIPPING Similarly to lines, areas must be clipped to a window boundary Consideration must be taken as to which portions of the area must be clipped Below are few examples:

31 AREA CLIPPING (cont..) Sutherland-Hodgman Area Clipping Algorithm: A technique for clipping areas developed by Sutherland & Hodgman Put simply the polygon is clipped by comparing it against each boundary in turn

32 Sutherland-Hodgman Area Clipping Algorithm (cont…)
AREA CLIPPING (cont..) 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

33 CURVE CLIPPING Curve 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

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

35 TEXT CLIPPING It 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)

36 TEXT CLIPPING (cont..) All-or-none string clipping : Example:
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 window Save it! Otherwise discard it! Example:

37 TEXT CLIPPING (cont..) Example: 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 window Save it! Otherwise discard it! Example:

38 TEXT CLIPPING (cont..) Example: 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:

39 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. Ex: Multiple window systems, applications that require overlapping pictures.

40 Polygon Clipping 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.

41 Polygon Fill-Area Clipping

42 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

43 Weiler- Atherton Polygon Clipping
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)

44 Weiler-Atherton Polygon Clipping

45 REFERENCES


Download ppt "EEL Introduction to Computer Graphics"

Similar presentations


Ads by Google