Computer Graphic 2 D Viewing.

Slides:



Advertisements
Similar presentations
CGPage: 1 We can define a window as a rectangular region of the world coordinate space, and the viewport as a rectangular region of the device coordinate.
Advertisements

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Clipping Concepts, Algorithms for line clipping 1 of 16 Clipping - 10/16/12.
I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam September 30, D Clipping 1/14 Clipping (pages , )
Computer Graphics CLIPPING.
Objectives Define Clipping Various clipping methods. Line clipping methods.
Line clipping: Line clipping algorithm is method of eliminate lines of outside area of the object,so outside of object viewing is Removed. Typically, any.
Java ThreadsGraphics Programming Graphics Programming: Windows, Viewports & Clipping.
Computer Graphics : Clipping
Computer Graphics Viewing.
CMPE 466 COMPUTER GRAPHICS Chapter 8 2D Viewing Instructor: D. Arifler Material based on - Computer Graphics with OpenGL ®, Fourth Edition by Donald Hearn,
2D Viewing and Projection
2 D viewing Prepared by Elizabeth Isaac DCS, RSET.
Introduction to Computer Graphics Chapter 6 – 2D Viewing Pt 2 1.
CHAPTER 7 2D VIEWING CGMB214: Introduction to Computer Graphics.
1 Computer Graphics Chapter 4 2D Viewing Algorithms.
1 King ABDUL AZIZ University Faculty Of Computing and Information Technology CS 454 Computer graphics Two Dimensional Viewing Dr. Eng. Farag Elnagahy
Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Clipping.
2D Viewing. 2D viewing transformation is a mapping of world coordinate scene to device coordinates xw min xw max yw min yw max xv min xv max yv min yv.
Graphics Pipeline Clipping CMSC 435/634. Graphics Pipeline Object-order approach to rendering Sequence of operations – Vertex processing – Transforms.
2-Dimension Viewing and Clipping
Windowing and clipping
CS 376 Introduction to Computer Graphics 02 / 12 / 2007 Instructor: Michael Eckmann.
Clipping: Clipping is a process of dividing an object into visible and invisible positions and displaying the visible portion and discarding the invisible.
CSE Real Time Rendering Week 9. Post Geometry Shaders Courtesy: E. Angel and D. Shreiner – Interactive Computer Graphics 6E © Addison-Wesley 2012.
Clipping Computer Graphics Cohen Sutherland Algorithm (Line)
Windows, Viewports, and Clipping
EEL Introduction to Computer Graphics
1 Computer Graphics Clipping Fall FCC Line Clipping What happens when one or both endpoints of a line segment are not inside the specified drawing.
Computer Graphics Lecture 20 Fasih ur Rehman. Last Class Clipping – What is clipping – Why we do clipping – How clipping is done.
1Computer Graphics Implementation 1 Lecture 15 John Shearer Culture Lab – space 2
Graphics Graphics & Graphical Programming Lecture 23 - Viewing & Clipping.
CS 376 Introduction to Computer Graphics 02 / 14 / 2007 Instructor: Michael Eckmann.
Computer Graphics Viewing. 2 of 30 Viewing in 2D Window in world coordinates. 45  250  Viewport in Device coords 250 x 250 Pixels.
Clipping.
Two-Dimensional Viewing Hearn & Baker Chapter 6
Computer Graphics Lecture 14 CLIPPING I Taqdees A. Siddiqi
Computer Graphics Clipping.
Introduction to Computer Graphics with WebGL
Computer Graphics CC416 Week 13 Clipping.
Transformations contd.
CS 551 / 645: Introductory Computer Graphics
Computer Graphics Shading in OpenGL
Concepts, Algorithms for line clipping
Two-Dimensional Viewing
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
2D Viewing & Clipping 한신대 류승택
Concepts, algorithms for clipping
Implementation I Ed Angel
Graphics Pipeline Clipping
WINDOWING AND CLIPPING
o عَلَّمَهُ الْبَيَانَ
Computer Graphics : Viewing In 2D
CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai
WINDOWING AND CLIPPING
Lecture 13 Clipping & Scan Conversion
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
Joshua Barczak CMSC 435 UMBC
Two Dimensional Viewing and Clipping.
Segment Clipping Simple algorithm. For each segment compute the intersection with the four sides of the rectangle, and then determine which sub-segment.
CS U540 Computer Graphics Prof. Harriet Fell Spring 2007
Window to Viewport Transformations
Clipping Clipping Sutherland-Hodgman Clipping
CS U540 Computer Graphics Prof. Harriet Fell Spring 2007
Computer Graphics Viewing. 2 of 30 Viewing in 2D Window in world coordinates. 45  250  Viewport in Device coords 250 x 250 Pixels.
Implementation I Ed Angel Professor Emeritus of Computer Science
CS U540 Computer Graphics Prof. Harriet Fell Spring 2007
COMPUTER GRAPHICS Clipping
Presentation transcript:

Computer Graphic 2 D Viewing

2-Dimensional Viewing Subjects : 2D-Viewing Viewing Transformation Clipping

2D Viewing Generally, Objects are defined in world coordinate coordinates value To display these on 2D screen, We need to transform Window Coordinates ( WC) value to screen (or display device) value (VC) Viewing Transformation : transformation of world coord. value to device coord. value

2D Viewing

Viewing Transformation Window a world-coord rectangular area selected for display View point a rectangular area on display device to which window is mapped a normalized device coord. are most often used

Viewing Transformation The process of viewing transformation can be performed by using the following steps: Clip the picture against the window Translate the clipped picture together with window until the lower left corner of windows comes at the origin the picture and the window are scaled until the window has the dimensions of the viewport Translate the scaled window to the correct position on the screen (view port ) Translation Scaling Translation

Steps for window- to- viewport transformation Y Y Ymax Ymin X X Xmin Xmax Window translated to origin Window in WC v v (Umax, Vmax) (Umin, Vmin) u u Window scaled to viewport size Translated by (Umin, Vmin) to final position

Viewing Transformation For given window boundary (xwmin, xwmax, ywmin, ywmax) and viewpoint boundary (xvmin, xvmax, yvmin, yvmax) A position (xw, yw) in window mapped into position(xv, yv) in viewport Where : scale factor

For Y-coordinate

Viewing Transformation Matrix Translate Scaling

Reverse Translation The combined viewing transformation matrix is:

Example: Derive the normalization matrix that maps a window specified by coordinates (1,1) and (4,5) onto viewport specified by coordinates (2,4) and (8,10)

Clipping of Lines in 2D Point Clipping clipping is performed relative to the window boundaries in world coordinate. Point Clipping check window boundaries with point P(Px, Py) If all four inequalities are satisfied then accept the point, otherwise reject it.

Line Clipping: Parametric Lines From the parametric representation of a line from (x1,y1) to (x2,y2) x = x1 + t*(x2-x1) y = y1 + t*(y2-y1) where t Î [0,1] we check for intersection points with the four boundaries x = xmin, x = xmax, y = ymin, y = ymax (lines parallel to the edges treated separately) • Computationally easier methods exist

Line Clipping line clipping determine wholly within the window wholly outside the window partially within the window boundary Cohen-Sutherland clipping algorithm Liang-Barsky clipping algorithm

Cohen-Sutherland Clipping Basic idea: every point (x,y) is coded using four bits to denote the position of the point w.r.t the window:[above,below,right,left]. For example: 1001 above and to the left Breaking Up Space above below right left 1 2 3 Region Code Legend Each region is represented by a 4-bit outcode b0b1b2b3:

Clipping Procedures Given a line segment, let o1=outcode(x1,y1), o2=outcode(x2, y2) (o1=o2=0)  it inside clipping window (AB) (o1&o20)  it is on the same outside sides of the window (EF) (o10, o2=0; or vice versa)  one or two intersections must be computed, and the outcode of the intersection point is re-examined (CD) (o1&o2=0)  Cannot tell, find the outcode of one intersection point (GH, IJ)

For lines that cannot be identified with 1) and 2) check for intersection with boundaries. ex) P1P2, P3P4 For P1P2 : Start from P1 1. check P1 region code : below window 2. find P1’ with bottom boundary discard P1, P1’ 3. check P2 region code : above & left of window 4. find P2’ : left window 5. find P2” : above window 6. save P1’ and P2’’

Intersection point with vertical boundary. For P3P4 : Start from P3 1. check P3 : left of window. 2. calculate P3’ : discard P3P3’ 3. check P3’ and P4 : discard Intersection point with vertical boundary. For P1(x1 y1) P2(x2 y2) Intersection point with horizontal boundary

Example: Consider the line from P1(-1,1) to P2(9,3) Example: Consider the line from P1(-1,1) to P2(9,3) . Determine its visibility against the clipping window defined by vertices (0,0 ),(8,0),(8,4),(0,4) using Cohen- Sutherland algorithm D(0,4) C(8,4) P2(9,3) P1(-1,1) A(0,0) B(8,0) Ymin=0 , Ymax=4 Xmin=0 Xmax=8 For p1: the opcode is o1=0001 for p2: the opcode is o2=0010

The slop of the line is The intersections with the window boundaries are calculated as follows: For Left edge : X=Xmin=0 ,Y=m(Xmin-X1)+Y1=0.2(0+1)+1=1.2 For right edge: X=Xmax=8 , Y=m(Xmax-X1)+Y1=0.2(8+1)+1=2.8 For bottom edge: Y=Ymin=0 , =5(0-1)+1=-6 For Top Edge Y=Ymax=4 , =5(4-1)-1=14 Check whether It seen that the above conditions are satisfied by the intersections with left and right edges only: Hence , the intersection points is (0,1.2) and (8,2.8)

Line Clipping: Liang-Barsky Clipping Algorithm Basic idea: Using the parametric representation of the line we solve for the parameter to see if and where the line intersects the window boundaries. For given (x1, y1), (x2, y2) parametric equation If a point (x, y) along the line is inside a window, then

Liang-Barsky Clipping Algorithm these inequalities can be written in the form k=1, 2, 3, 4 where p and q are defined as (Left) k=1 p1 = -Dx q1= x1- xwmin (Right) k=2 p2 = Dx q2= xwmax - x1 (Bottom) k=3 p3 = -Dy q3= y1- ywmin (Top) k=4 p4 = Dy q4= ywmax - y1

Liang-Barsky Clipping Algorithm Strategy : 1. If pk = 0 for some k then the line is parallel to a clipping boundary. Now test qk : if one qk < 0 for these k then line is outside if all qk ≥ 0 then line is inside 2. For all pk < 0 calculate u1 = max (0, {qk / pk}) to determine intersection point with the possibly extended clipping boundary k and obtain a new starting point for the line at u1. 3. For all pk > 0 calculate u2 = min (1, {qk / pk}) to determine intersection points with extended clipping boundary k and obtain a new end point at u2. 4. If u1 > u2 then discard the line 5. The line is now between [u1,u2]

Example 1: p1 < 0 , p2 > 0 , p3 < 0, p4 > 0 Example 1: p1 < 0 , p2 > 0 , p3 < 0, p4 > 0. For k=1,3 calculate q1/p1 (P1) and q3/p3 (P3) and choose u1 = max (0, q1/p1, q3/p3 ) = q1/p1 • Likewise for k=2,4 calculate q2/p2 (P2) and q4/p4 (P4) and choose u2 = min (1, q2/p2, q4/p4 ) = q4/p4 Ymin Xmin Xmax Ymax (x1,y1) P3 P1 P4 P2

Example 2: Consider horizontal lines with Δy = 0, p3 = p4 = 0. • For line 1, q4 < 0 and will be discarded. • For line 2, p1 < 0, p2 > 0, q3 > 0 and q4 > 0. We proceed to calculate u1 and u2. Line: 1 Ymax Line: 2 (x1,y1) (x2,y2) Ymin Xmin Xmax

• p2 > 0, calculate q2/p2 and choose u2 = min (q2/p2, 1) = q2/p2. Example 2: p1 < 0, note that q1 > 0 hence q1/p1 < 0, and u1 = max{0,q1/p1} = 0 • p2 > 0, calculate q2/p2 and choose u2 = min (q2/p2, 1) = q2/p2. • u1 < u2 and the line is between [u1,u2] Ymin Xmin Xmax Ymax (x1,y1) Line: 2 (x2,y2)

– p1 < 0, p2 > 0 , p3 < 0 and p4 > 0. Example 3: – p1 < 0, p2 > 0 , p3 < 0 and p4 > 0. – calculate q1/p1 (P1) and q3/p3 (P3) and choose u1 = max (0, q1/p1, q3/p3 ) = q1/p1 – calculate q2/p2 (P2) and q4/p4 (P4) and choose u2 = min (1, q2/p2, q4/p4 ) = q4/p4 – u1 > u2 hence discard line (x2,y2) P2 P1 P4 Ymax P3 Ymin (x1,y1) Xmin Xmax

Example:Let P1 (-1, -2), P2 (2, 4) XL = 0, XR = 1, YB = 0, YT = 1 For u1<u2 there is visible section compute new end points

The new intersection points (0,0) and (1/2,2)

ex) (3, 9) (4, 6) (2, 2) P1(x1’,y1’) (8, 1) (3, 1)

Polygon Clipping • Polygon Clipping Algorithm Uses a divide and conquer strategy, one window boundary at a time Accepts a series of polygon vertices and output another series of vertices defining the clipped polygon

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E

Sutherland-Hodgman Algorithm Out In No output Output E Output I Output I,E Possible error for non-convex polygons