Click here to load reader

Computer Graphics : Viewing In 2D

  • Upload
    kovit

  • View
    79

  • Download
    0

Embed Size (px)

DESCRIPTION

Computer Graphics : Viewing In 2D. UNIT-3. Contents. Windowing Concepts Clipping Introduction Brute Force Cohen-Sutherland Clipping Algorithm Area Clipping Sutherland-Hodgman Area Clipping Algorithm. Windowing I. - PowerPoint PPT Presentation

Citation preview

Windowing & Clipping

UNIT-3Computer Graphics :Viewing In 2D1ContentsWindowing ConceptsClippingIntroduction Brute ForceCohen-Sutherland Clipping AlgorithmArea ClippingSutherland-Hodgman Area Clipping Algorithm2Windowing IA scene is made up of a collection of objects specified in world coordinatesWorld Coordinates3Windowing IIWhen we display a scene only those objects within a particular window are displayedwymaxwyminwxminwxmaxWindowWorld Coordinates4Windowing IIIBecause drawing things to a display takes time we clip everything outside the windowwymaxwyminwxminwxmaxWorld CoordinatesWindow5ClippingFor the image below consider which lines and points should be kept and which ones should be clippedwymaxwyminwxminwxmaxWindowP1P2P3P6P5P7P10P9P4P86Point ClippingEasy - a point (x,y) is not clipped if:wxmin x wxmax AND wymin y wymaxotherwise it is clippedwymaxwyminwxminwxmaxWindowP1P2P5P7P10P9P4P8ClippedPoints Within the Window are Not ClippedClippedClippedClipped7Line ClippingHarder - examine the end-points of each line to see if they are in the window or notSituationSolutionExampleBoth end-points inside the windowDont clipOne end-point inside the window, one outsideMust clipBoth end-points outside the windowDont know!89Cohen-Sutherland AlgorithmIdea: eliminate as many cases as possible without computing intersectionsStart with four lines that determine the sides of the clipping window

x = xmaxx = xminy = ymaxy = ymin10The CasesCase 1: both endpoints of line segment inside all four linesDraw (accept) line segment as is

Case 2: both endpoints outside all lines and on same side of a lineDiscard (reject) the line segment

x = xmaxx = xminy = ymaxy = ymin11The CasesCase 3: One endpoint inside, one outsideMust do at least one intersectionCase 4: Both outsideMay have part insideMust do at least one intersectionx = xmaxx = xminy = ymax12Defining OutcodesFor each endpoint, define an outcode

Outcodes divide space into 9 regionsComputation of outcode requires at most 4 subtractionsb0b1b2b3b0 = 1 if y > ymax, 0 otherwiseb1 = 1 if y < ymin, 0 otherwiseb2 = 1 if x > xmax, 0 otherwiseb3 = 1 if x < xmin, 0 otherwise

13Using OutcodesConsider the 5 cases belowAB: outcode(A) = outcode(B) = 0Accept line segment

14Using OutcodesCD: outcode (C) = 0, outcode(D) 0Compute intersectionLocation of 1 in outcode(D) determines which edge to intersect withNote if there were a segment from A to a point in a region with 2 ones in outcode, we might have to do two interesections

15Using OutcodesEF: outcode(E) logically ANDed with outcode(F) (bitwise) 0Both outcodes have a 1 bit in the same placeLine segment is outside of corresponding side of clipping windowreject

16Using OutcodesGH and IJ: same outcodes, neither zero but logical AND yields zeroShorten line segment by intersecting with one of sides of windowCompute outcode of intersection (new endpoint of shortened line segment)Reexecute algorithm

17EfficiencyIn many applications, the clipping window is small relative to the size of the entire data baseMost line segments are outside one or more side of the window and can be eliminated based on their outcodesInefficiency when code has to be reexecuted for line segments that must be shortened in more than one stepLiang Barsky clipping Incomputer graphics, theLiangBarsky algorithm(named afterYou-Dong LiangandBrian A. Barsky) is aline clippingalgorithm. The LiangBarsky 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. This algorithm is significantly more efficient thanCohenSutherland.The idea of the Liang-Barsky clipping algorithm is to do as much testing as possible before computing line intersections. Consider first the usual parametric form of a straight line:

A point is in the clip window, if

To compute the final line segment:A line parallel to a clipping window edge has for that boundary.If for that the line is completely outside and can be eliminated.When the line proceeds outside to inside the clip window and when, the line proceeds inside to outside.For nonzero ,gives the intersection point.

Here

Liang-BarskyEnterEnterLeaveLeaveEnterLeaveEnterLeaveLiang-Barsky - AlgorithmCompute entering u values, which are qk/pk for each pk0Parameter value for small u end of line is:usmall= max(0, entering us)parameter value for large t end of line is: ularge=min(1, leaving us)If usmall