Computer Graphics - Third Year Students 2023 PDF

Summary

This document contains lecture notes on Computer Graphics for third-year students at Minia University, focusing on topics such as computer graphics, viewport transformation, clipping algorithm, two and three dimensional viewing and polygon filling. The year is 2023.

Full Transcript

Computer Graphics Third Year Students Dr. Rehab Emad El-Dein Sayed Mohamed FCI- Minia University 2023 Course Outline A Survey of Computer Graphics Overview of Graphics Systems Graphics Output Primitives Attributes of Graphics Pri...

Computer Graphics Third Year Students Dr. Rehab Emad El-Dein Sayed Mohamed FCI- Minia University 2023 Course Outline A Survey of Computer Graphics Overview of Graphics Systems Graphics Output Primitives Attributes of Graphics Primitives Geometric Transformations Two-Dimensional Viewing Three-Dimensional Viewing Three-Dimensional Object Representations Visible-Surface Detection Methods Illumination Models and Surface-Rendering Methods CONTENTS Computer Graphics Window. Two-dimensional Viewing. Two-dimensional Viewing Pipeline. The Clipping Window. Normalization and Viewport Transformation. Clipping Algorithms. Two-Dimensional Point Clipping. Two-Dimensional Line Clipping. Polygon Fill Area Clipping. Two-dimensional Viewing Computer Graphics Window: ▪ The method of selecting and enlarging a portion of a drawing is called windowing. ▪ The area chosen for this display is called a window. ▪ The window is selected by world-coordinate. ▪ Sometimes we are interested in some portion of the object and not in full object. So we will decide on an imaginary box. ▪ This box will enclose desired or interested area of the object. Such an imaginary box is called a window. Viewport ▪ An area on display device to which a window is mapped [where it is to displayed]. ▪ Basically, the window is an area in object space. It encloses the object. After the user selects this, space is mapped on the whole area of the viewport. ▪ Almost all 2D and 3D graphics packages provide means of defining viewport size on the screen. ▪ It is possible to determine many viewports on different areas of display and view the same object in a different angle in each viewport. Two-dimensional Viewing Viewing Coordinates Model / Local Coordinates World Coordinates Two-dimensional Viewing ▪ Technique for not showing the part of the drawing which one is not interested is called clipping. ▪ An area on the device (ex. Screen) onto which the window will be mapped is called viewport. ▪ Clipping window defines what to be displayed. ▪ A viewport defines where it is to be displayed. Two-dimensional Viewing Window Ywmax ViewPort Ywmin Xwmin Xwmax World Coordinates Device /Screen Coordinates Window to viewport Transformation Two-dimensional Viewing So, What is window? ▪ When we are interested to display certain portion of the drawing, windowing technique is used. Yw ymax max A window defines what to be displayed Yw yminmax xXw min xmax min Xwmax World Coordinates The Clipping Window ▪ Might use any shape for clipping window (star or ellips). ▪ Easier to use a window with linear edges. (rectangular with edges aligned with x and y axes). ▪ Defined by the coordinates of two opposite corners. ▪ Specified in world-coordinates. Two-dimensional Viewing A viewport defines where the window is to be displayed on screen. ViewPort An area on the device (ex. Screen) onto which the window will be mapped is called viewport. Device /Screen Coordinates Two-dimensional Viewing So mainly window to viewport transformation is that: We need to transform from window in world coordinates to viewport in device coordinates. ywmax yvmax ywmin yvmin xwmin xwmax xvmin xvmax World Coordinates Device Coordinate The Clipping Window Viewing-Coordinate Clipping Window ▪ Genaral approach: setup viewing coordinate (VC) system with world coordinate (WC) frame. ▪ Converting WC to VC ✓ Translation ✓ Rotation ▪ View up vector is used to calculate the orientation Two-dimensional Viewing Pipeline 2001. 7. 13 View on Device /Screen Two-dimensional Viewing Pipeline Normalization and Viewport Transformation 2001. 7. 13 Normalization and Viewport Transformation ▪ Mapping a window onto a viewport involves converting from one coordinate system to another. ▪ If the window and viewport are in standard position, this just o involves translation and scaling. o if the window and/or viewport are not in standard, then extra transformation (rotation) is required. Recap Matrix Representations and Homogeneous Coordinates Recap: ▪ World coordinate – It is the Cartesian coordinate w.r.t which we define the diagram, like Xwmin, Xwmax, Ywmin, Ywmax ▪ Device Coordinate –It is the screen coordinate where the objects are to be displayed, like Xvmin, Xvmax, Yvmin, Yvmax ▪ Window –It is the area on the world coordinate selected for display. ▪ ViewPort –It is the area on the device coordinate where graphics is to be displayed. Normalization and Viewport Transformation ▪ Viewing transformation is the mapping of a part of a world-coordinate scene to device coordinates. ▪ In 2D (two dimensional) viewing transformation is simply referred as the window-to- viewport transformation or the windowing transformation. Normalization and Viewport Transformation Window-to-normalized viewport mapping ▪ A point at position (xw, yw) in a designated window is mapped to viewport coordinates (xv, yv) so that relative positions in the two areas are the same. Normalization and Viewport Transformation Window-to-normalized viewport mapping xv − xvmin xw − xwmin 150−100 = = 50/100 = 0.5 xvmax − xvmin xwmax − xwmin 200−100 (150,150) Clipping window ywmax (100,200) (200,200) (xw,yw) ywmin xwmin xwmax (100,100) (200,100) Normalization and Viewport Transformation Window-to-normalized viewport mapping xv − xvmin xw − xwmin 150−100 = = 50/100 = 0.5 xvmax − xvmin xwmax − xwmin 200−100 60−10 = 50/100 = 0.5 (60,60) 110−10 Screen viewport yvmax (10,110) (110,110) (xv,yv) 60 = 10 + 0.5* (100) yvmin xvmin xvmax 60 = 10 + 0.5* (100) (10,10) (110,10) Normalization and Viewport Transformation Window-to-normalized viewport mapping xvmax − xvmin xv − xvmin xw − xwmin sx = = xwmax − xwmin xvmax − xvmin xwmax − xwmin yvmax − yvmin sy = ywmax − ywmin xv = s x xw + t x xwmax xvmin − xwmin xvmax yv = s y yw + t y tx = xwmax − xwmin ywmax yvmin − ywmin yvmax ty = ywmax − ywmin Normalization and Viewport Transformation Window-to-normalized square-to-viewport mapping Viewing is done in three steps: ▪ Transform clipping window to normalized square ▪ Clipping normalized square ▪ Transfer the scene to viewport Normalization and Viewport Transformation Window-to-normalized square-to-viewport mapping Clipping Algorithms ▪ Procedure that eliminates a portion of a picture that inside or outside a specified region in space. ▪ Technique for not showing the part of the drawing which one is not interested is called clipping. ▪ Point Clipping ▪ Line Clipping ▪ Fill Polygon Clipping Two-Dimensional Point Clipping A point (x,y) is not clipped if: otherwise it is clipped Strategies for Clipping Strategies for clipping: a) Check (in inner loop)if each point is inside → Works, but slow b) Find intersection of line with boundary → Correct Two-Dimensional Line Clipping Examine the end-points of each line to see if they are in the window or not Two-Dimensional Line Clipping Cohen-Sutherland Line Clipping ▪ 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. ABRL Two-Dimensional Line Clipping Cohen-Sutherland Line Clipping Every end-point is labelled with the appropriate region code Two-Dimensional Line Clipping Cohen-Sutherland line clipping Algorithm Two-Dimensional Line Clipping Cohen-Sutherland Line Clipping ▪ Any line with a common set bit in the region codes of both end-points can be clipped. ▪ The AND operation can efficiently check this. Two-Dimensional Line Clipping Cohen-Sutherland Line Clipping Consider the 5 cases below ▪ AB: region code(A) = region code(B) = 0 ✓ Accept line segment ▪ CD: region code (C) = 0, region code(D)  0 ✓ Compute intersection ✓ Location of 1 in region code (D) determines which edge to intersect with ✓ Note if there were a segment from A to a point in a region with 2 ones in region code, we might have to do two intersections ▪ EF: region code(E) logically ANDed with region code(F) (bitwise)  0 ✓ Both region codes have a 1 bit in the same place ✓ Line segment is outside of corresponding side of clipping window ✓ reject Two-Dimensional Line Clipping Cohen-Sutherland Line Clipping Consider the 5 cases below ▪ GH and IJ: same region codes, neither zero but logical AND yields zero ✓ Shorten line segment by intersecting with one of sides of window. ✓ Compute region code of intersection (new endpoint of shortened line segment). ✓ Re-execute algorithm. Two-Dimensional Line Clipping 1. Both endpoints are inside the region (line AB) ✓ No clipping necessary 2. One endpoint in, one out (line CD) ✓ Clip at intersection point 3. Both endpoints outside the region: a) No intersection (lines EF, GH) b) Line intersects the region (line IJ) ✓ Clip line at both intersection points Two-Dimensional Line Clipping 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. Two-Dimensional Line Clipping 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. Two-Dimensional Line Clipping 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’. Cohen-Sutherland: Accept/Reject Tests Basic Algorithm: ▪ Accept lines that have both endpoints inside the region. ▪ Reject lines that have both endpoints less than xmin or ymin or greater than xmax or ymax. ▪ Clip the remaining lines at a region boundary and repeat the previous steps on the clipped line segments. Cohen-Sutherland: Accept/Reject Tests Accept/reject/redo all based on bit-wise Boolean ops. Two-Dimensional Line Clipping Finding the Intersection Points Given: (x1, y1) Find: (x, y) 𝒚−𝒚𝟏 Slope= m= 𝒙−𝒙𝟏 y= y1 + m (x - x1) 𝟏 x= x1 + 𝒎 (y - y1) Ymax: when line intersect with upper border Xmin: Xmax: when line Ymin: when line intersect with when line intersect with right border intersect with left border bottom border X= Y= Ymin: Xmin: when line intersect with bottom when line intersect with left border border Ymax: Xmax: when line intersect with upper when line intersect with right border border P2 (75, 45) Problem 1 (x2, y2) (xmin, ymax) (50, 40) (xmax, ymax) Find intersection of two points with rectangle i2 = (x= ?, ymax) (80, 40) Given: P1(x1, y1) = (40, 15) P2(x2,y2) = (75, 45) i1 = (xmin, y=?) 𝒚−𝒚𝟏 𝟒𝟓 −𝟏𝟓 Slope= m= = = 0.857 𝒙−𝒙𝟏 𝟕𝟓 −𝟒𝟎 (xmin, ymin) (xmax, ymin) 1. Find the 1st intersection Point P1 (40, 15) (50, 10) (80, 10) i1 = (xmin, y=?) = (50, y) (x1, y1) y = y1 + m (xmin - x1) = 15 + 0.857 (50 – 40) = 23.563 i1 = (50, 23.563) = (50, 24) 2. Find the 2nd intersection Point i2 = (x, ymax) = (x, 40) 𝟏 y = x2 + (ymax – y2) m 𝟏 = 75 + (40 – 45) = 69.2 0.857 i2 = (69.2, 40) = (69, 40) P2 (75, 45) Problem 2 (x2, y2) (xmin, ymax) D (20, 70) (xmax, ymax) C (90, 70) Let ABCD be the rectangle window with A(20,20), B(90,20), C(90,70) i2 = (x= ?, ymax) and D(20,70). Find region-codes for the endpoints and use Cohen Sutherland Algorithm to clip the line P1P2 with P1(10, 30) and P2(80, i1 = (xmin, y=?) 90). Given: P1(x1, y1) = (10, 30) P2(x2,y2) = (80, 90) (xmin, ymin) (xmax, ymin) A (20, 20) B (90, 20) 𝒚−𝒚𝟏 𝟗𝟎−𝟑𝟎 P1 (40, 15) Slope= m= = = 0.857 (x1, y1) 𝒙−𝒙𝟏 𝟖𝟎−𝟏𝟎 1. Find the 1st intersection Point i1 = (xmin, y=?) = (20, y) y = y1 + m (xmin - x1) = 30 + 0.857 (20 – 10) = 38.57 i1 = (20, 38.57) = (20, 39) 2. Find the 2nd intersection Point i2 = (x, ymax) = (x, 70) 𝟏 y = x2 + (ymax – y2) m 𝟏 = 80 + (70 – 90) = 56.67 0.857 i2 = (56.67, 70) = (57, 70) Two-Dimensional Polygon 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. Two-Dimensional Polygon Clipping 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. ▪ The Sutherland-Hodgman polygon clipping algorithm clips a polygon against each edge of the window, one at a time. ▪ Specifically for each window edge, it inputs a list of vertices and outputs a new list of vertices which is submitted to the algorithm for clipping against the next window edge. ▪ The first window edge has as input the original set of vertices. ▪ After clipping against the last edge, the output list consists of the vertices describing the clipped polygon. Two-Dimensional Polygon Clipping Sutherland-Hodgman Area Clipping Algorithm ▪ The window must be convex. ▪ Polygon to be clipped can be convex or non-convex. Two-Dimensional Polygon Clipping Sutherland-Hodgman Area Clipping Algorithm 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 inside vertex are saved. Two-Dimensional Polygon Clipping Sutherland-Hodgman Area Clipping Algorithm S S ▪ Each example shows the point being processed (P) and the previous P I point (S). P ▪ Saved points define area clipped to the boundary in question. Save Point P Save Point I P S I P S No Points Saved Save Points I & P Two-Dimensional Polygon Clipping ▪ Clip polygon to ymin and ymax: ▪ Create empty output vertex list ▪ Process input list (v0 , v1 , …, vn ) where v0 = vn ▪ For each input vertex (vi where 0 ≤ i ≤ n–1): o If vi is inside region → Add vi to output list. o If the line between vi and vi+1 intersects clipping boundaries → Add intersection point(s) to output list. ▪ Repeat: Clip to xmin and xmax ▪ Post-process: o Remove degenerate sections that have collapsed to region boundary. Other Two-Dimensional Transformations In the algorithm. ▪ For each window edge, we tack the input list of vertices for that edge, tests a pair of consecutive vertices against a window edge to produce the output list of vertices. ▪ There are four possible cases of testing as illustrated in the below figure. Where testing is performed against the left edge. Other Two-Dimensional Transformations The sample polygon has vertices {V1, V2, V3, V4}. ▪ Case 1:- Has the first and second vertices V1 and V2 inside the window, so the second vertex V2 is sent to the output list. ▪ Case2:- Has the first vertex V2 inside and the second vertex V3 outside the window. The point of intersection, I1, of the side of the polygon joining the vertices and the edge is added to the output list. ▪ Case3:- Has both vertices, V3 and V4 outside the window and no point is output. ▪ Case4:- Has the first vertex V4 outside and the second vertex V1 inside the window, the point of intersection I2 and the second vertex V1 are added to the output. The result of this left clipping is the transformation of the input list { V1, V2, V3, V4 } to the output list { V2, I1, I2, V1 }. Example 1 OUT Clipping Window 1. Clipping against the left edge V2 V1V2 (IN-IN) → V2 V2V3 (IN-OUT) → V2’ V2’ V3V1 (OUT-IN) → V3’V1 V3 Clipping Window V3’ V2 V1 V2’ V3’ V1 Other Two-Dimensional Transformations IN OUT 2. Clipping against the right edge V2 V1V2 (IN-IN) → V2 V2V2’ (IN-IN) → V2’ V2’ V2’V3’ (IN-IN) → V3’ V3’V1 (IN-IN) → V1 No change in output V3’ 3. Clipping against the Top edge V1 V1V2 (IN-IN) → V2 V2V2’ (IN-IN) → V2’ V2’V3’ (IN-IN) → V3’ V3’V1 (IN-IN) → V1 No change in output Other Two-Dimensional Transformations 4. Clipping against the bottom edge V2 V1V2 (OUT-IN) → V1’V2 V2V2’ (IN-IN) → V2’ V2’ V2’V3’ (IN-OUT) → V2’’ V3’V1 (OUT-OUT) → Nil V2’’ V1’ V3’ OUT V1 V2 V2’ V2’’ V1’ OUT Thank you

Use Quizgecko on...
Browser
Browser