OVERVIEW OF GRAPHICS SYSTEMS L7 Clipping Plan Review of rendering pipeline Clipping The Graphics Pipeline Modeling Transformations Illumination (Shading) Viewing Transformation (Perspective / Orthographic) Clipping Projection (to Screen Space) Scan Conversion (Rasterization) Visibility / Display Clipping Clipping is the process of extracting identifying element of a scene or picture inside or outside a special region, called the clipping region. عملية استخراج اجزاء معينة من مشهد او صورة Clipping: Remove points outside a region of interest – clip حذف النقاط اللي تكون خارج املنطقة اللي نبيها window. Clipping is useful for copying, moving or deleting a portion : استعماالته of a scene or picture Windowing I A scene is made up of a collection of objects specified in world coordinates يتكون املشهد من مجموعة من الكائنات املحددة في إحداثيات العالم World Coordinates Windowing II . يتم عرض تلك الكائنات فقط داخل نافذة معينة، عندما نعرض مشهًدا When we display a scene only those objects within a particular window are displayed. clipping Window wxmax ألن جميع أجزاء املشهد خارج القسم املحدد يتم قطعها A section of a two dimensional scene that is selected for display is called a clipping window, because all parts of the scene outside the selected section are clipped off wymax wymin wxmin World Coordinates Windowing III ألن رسم األشياء على شاشة العرض يستغرق وقتًا نقطع كل شيء خارج النافذة viewport wxmax Because drawing things to a display takes time we clip everything outside the window wymax wymin wxmin World Coordinates Clipping (عشان نتجنب نرسم اشياء خارج النافذة)الجزء اللي نبيه نحدد الجزء اللي نبي نعرضه١ نرسم بدائل هندسية داخل النافذة٢- Avoid Drawing Parts of Primitives Outside Window Window defines part of scene being viewed Must draw geometric primitives only inside window World Coordinates Viewport Transformation Image Transform 2D Geometric Primitives from Screen Coordinate System (Projection Coordinates) to Image Coordinate System (Device Coordinates) Screen Viewport Window إحداثيات العالم)الحقيقي( املحدد للعرض Window vs. Viewport الجزء اللي حددناه حددناه مع-الصورة الكاملة World-coordinate area selected for display What is to be viewed املساحة املوجودة على جهاز العرض الذي تم تعيني نافذة فيه Area on the display device to which a window is mapped Where it is to be displayed Viewport الجزء بعد ماسوينا له قص - على جهاز العرض- Clipping All-or-none clipping: If any part of object outside clip window then the whole object is rejected. Point clipping: Only keep the points that are inside clip window. Line clipping: Only keep segment of line inside clip window. Polygon clipping: Only keep segment of polygon inside clip window. Text clipping. Types of clipping: 1. 2. 3. 4. 5. Why Clip? Bad idea to rasterize outside of framebuffer bounds Also, don’t waste time scan converting pixels outside ما نضيع وقت بأننا نحول االشياء اللي خارج النافذة لبكسل window Clipping P3 P7 P4 P5 P9 Window P6 P10 P1 wxmax P8 P2 For the image below consider which lines and points should be kept and which ones should be clipped. wymax wymin wxmin Point Clipping P P1 P Clipped 4 Window Clipped P9 P10 P8 P2 Clipped wxmax Points Within the Window are Not Clipped 5 Easy - a point (x,y) is not clipped if: wxmin≤ x ≤ wxmaxAND wymin≤ y ≤ wymax P7 Clipped otherwise it is clipped wymax wymin wxmin ((30 ,30)) قيمة امليمنوم عندي ((110 ,130)) قيمة املاكس عندي هي: النقاط اللي مارح تنقص اللي تكون بينهم )اكبر من املن (واصغر من املاكس P1= (10,20), P2= (30,50), P3= (60,90), and P4= (130,150). Suppose that the coordinates of the two opposite corners of the clip window are (xwmin, ywmin) = (30, 30) and (xwmax, ywmax) = (130, 110). Which of the above points will be clipped? P2 and P3 will saved because: For P2: 30 ≤ 30 ≤ 130 and 30 ≤ 50 ≤ 110. For P3: 30 ≤ 60 ≤ 130 and 30 ≤ 90 ≤ 110. Line Clipping فحص نقاط نهاية كل سطر ملعرفة ما إذا كانت في النافذة أم ال- أصعب Solution Example Harder - examine the end-points of each line to see if they are in the window or not Situation Must clip Don’t clip • One end-point inside the window, one outside Don’t know! • Both end-points inside the window • Both end-points outside the window Brute Force Line Clipping Brute force line clipping can be performed as follows: ال تقم بقص الخطوط بنقطتي النهاية داخل النافذة Don’t clip lines with both endpoints within the window For lines with one end- point inside the window and one endpoint outside, calculate the intersection point (using the equation of the line) and clip from this point out. للنقاط اللي بدايتها داخل ونهايتها برا ( نحسب نقطة التقاطع )تقاطع الخط مع حدود النافذة، باستخدام معادلة الخط واللي بعد هالنقطة نحذفه Brute Force Line Clipping (cont…) For lines with both end-points outside the window test the line for intersection with all of the window boundaries, and clip appropriately. ، بالنسبة للخطوط ذات النهايتني الخارجيتني للنافذة اختبر الخط للتقاطع مع كل حدود النافذة . وقم باملقطع بشكل مناسب، However, calculating line intersections is computationally expensive Because a scene can contain so many lines, the brute force approach to clipping is much too slow يعتبر مكلف وبطيء Cohen-Sutherland Clipping Algorithm An efficient line clipping algorithm The key advantage of the algorithm is that it vastly reduces the number of line intersections that must be calculated يقلل بشكل كبير من عدد التقاطعات الخط الذي يجب حسابه 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 تشير رموز املنطقة إلى موضع املناطق فيما يتعلق بالنافذة Cohen-Sutherland: Labelling P5 [0000] P6 [0000] Window P4 [1000] يتم تمييز كل نقطة نهاية برمز املنطقة املناسب P3 [0001] P7 [0001] P9 [0000] P [0100] 10 wxmax P14 [0110] P8 [0010] P12 [0010] P11 [1010] Every end-point is labelled with the appropriate region code wymax wymin P13 [0101] wxmin 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 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 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 Cohen-Sutherland Examples Consider the line P9 to P10below ◦ 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 Window P9 [0000] P10’ [0000] P10 [0100] P8 [0010] wxmax P8’ [0000] Window P7’ [0000] wxmin P7 [0001] Cohen-Sutherland Examples (cont…) wymin wymax Consider the line P7 to P8below ◦ 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 P ’ 7 wymax wymin P7 [0001] Cohen-Sutherland Examples (cont…) Consider the line P7’ to P8 ◦ Start at P8 ◦ Calculate the intersection with the right boundary to generate P 8’ ◦ P’7 to P 8’ is inside the window so is retained P8 [0010] wxmax P8’ [0000] Window P7’ [0000] wxmin Window wxmax Cohen-Sutherland Worked Example wymax wymin wxmin 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 ◦ 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) Suppose that the coordinates of opposite corners of the clip window are (68,59) & (92,71). Use CohenSutherland clipping line algorithm to find region codes of the line (72,65)-(90,68), and the line (74,93)-(85,100), and the line (60,50)-(120, 93). Solution: 1. Calculate differences between endpoint coordinates and clipping boundaries. 2. Use the resultant sign bit of each difference calculation to set the corresponding value in the region code. (68,59) & (92,71) Line (72,65)-(90,68): the region code of (72,65) is 0000 the region code of (90,68) is 0000 The line (72-65)-(90,68) is completely inside Line (74,93)-(85,100): the region code of (74,93) is 1000 the region code of (85,100) is 1000 Since 1000 AND 1000 = 1000 (Non Zero), so the line (74,93) – (85,100) lie completely outside the clipping region. So we clip it. Line (60,50)-(120,95): the region code of (60,50) is 1010 the region code of (120,95) is 0101 The line is saved because the final region code is 0000. 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 Clip Left Clip Right Clip Top Clip Bottom A technique for clipping areas developed by Sutherland & Hodgman Put simply the polygon is clipped by comparing it against each boundary in turn Original Area 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 character نستخدم مستطيل لكل نستخدم مستطيل لكل سترينق In general, methods depend on how characters are represented However, three strategies can be followed: all-or-none string clipping use a bounding rectangle for the string all-or-none character clipping use a bounding rectangle for the character individual character clipping or component clipping like line/curve clipping (outlined char’s) compare individual pixels (bit-mapped)