CS 376 Introduction to Computer Graphics 02 / 12 / 2007 Instructor: Michael Eckmann.

Slides:



Advertisements
Similar presentations
Rezanje črt in poligonov. World window & viewport window viewport screen window world window.
Advertisements

Computer Graphics CLIPPING.
Objectives Define Clipping Various clipping methods. Line clipping methods.
Java ThreadsGraphics Programming Graphics Programming: Windows, Viewports & Clipping.
10/10/02 (c) 2002 University of Wisconsin, CS 559 Last Time Finished viewing: Now you know how to: –Define a region of space that you wish to view – the.
CHAPTER 12 Height Maps, Hidden Surface Removal, Clipping and Level of Detail Algorithms © 2008 Cengage Learning EMEA.
CS 551 / 645: Introductory Computer Graphics Clipping Lines and Polygons.
Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)
Course Website: Computer Graphics 4: Viewing In 2D.
1 Clipping. 2 Transformation Sequence X Y Z X Y Z X Y Z X Y Z Object Coords. Eye Coords. Clip Coords. Normalized Device Coords. Screen Coords. Implementation:
Two-Dimensional Viewing Jehee Lee Seoul National University.
Line Clipping Algorithms. A Cases for Clipping Lines E B H C G J I clip rectangle 2Prepared by Narendra V G CSE MIT.
Computer Graphics : Clipping
Computer Graphics Viewing.
Clipping CSE 403 Computer Graphics Cohen Sutherland Algorithm (Line)
Viewing & Clipping In 2D. 2 of 44 Contents Windowing Concepts Clipping –Introduction –Brute Force –Cohen-Sutherland Clipping Algorithm Area Clipping –Sutherland-Hodgman.
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.
Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 111 Today’s class Clipping Parametric and point-normal form of lines Intersecting.
CS 376 Introduction to Computer Graphics 02 / 07 / 2007 Instructor: Michael Eckmann.
1 Computer Graphics Chapter 4 2D Viewing Algorithms.
CS 325 Introduction to Computer Graphics 02 / 24 / 2010 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 02 / 09 / 2007 Instructor: Michael Eckmann.
1 King ABDUL AZIZ University Faculty Of Computing and Information Technology CS 454 Computer graphics Two Dimensional Viewing Dr. Eng. Farag Elnagahy
1 CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai.
CS 376 Introduction to Computer Graphics 02 / 26 / 2007 Instructor: Michael Eckmann.
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.
Graphics Pipeline Clipping CMSC 435/634. Graphics Pipeline Object-order approach to rendering Sequence of operations – Vertex processing – Transforms.
1 Computer Graphics Assistant Professor Dr. Sana’a Wafa Al-Sayegh 2 nd Semester ITGD3107 University of Palestine.
CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.
2-Dimension Viewing and Clipping
Clipping Apart from clipping to the view volume, clipping is a basic operation in many other algorithms –Breaking space up into chunks –2D drawing and.
Windowing and clipping
Two-Dimensional Viewing
Clipping: Clipping is a process of dividing an object into visible and invisible positions and displaying the visible portion and discarding the invisible.
CS 325 Introduction to Computer Graphics 03 / 08 / 2010 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 02 / 17 / 2010 Instructor: Michael Eckmann.
Clipping Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006 (Slide set originally by David Luebke)
CS 325 Introduction to Computer Graphics 04 / 26 / 2010 Instructor: Michael Eckmann.
CS 480/680 Computer Graphics Shading in OpenGL Dr. Frederick C Harris, Jr. Fall 2013.
Clipping Computer Graphics Cohen Sutherland Algorithm (Line)
Windows, Viewports, and Clipping
CS 376 Introduction to Computer Graphics 02 / 23 / 2007 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 02 / 26 / 2010 Instructor: Michael Eckmann.
Basic Perspective Projection Watt Section 5.2, some typos Define a focal distance, d, and shift the origin to be at that distance (note d is negative)
10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.
EEL Introduction to Computer Graphics
CS 325 Introduction to Computer Graphics 02 / 03 / 2010 Instructor: Michael Eckmann.
2D Viewing.
Clipping Primitives. Clipping line Clipping rectangle: – x min to x max – y min to y max A point (x,y) lies within a clip rectangle and thus displayed.
Graphics Graphics & Graphical Programming Lecture 23 - Viewing & Clipping.
A.Aruna/Assistant Professor/SNSCE
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.
Computer Graphics Lecture 14 CLIPPING I Taqdees A. Siddiqi
Computer Graphic 2 D Viewing.
Computer Graphics Clipping.
Computer Graphics CC416 Week 13 Clipping.
Transformations contd.
Concepts, algorithms for clipping
Graphics Pipeline Clipping
WINDOWING AND CLIPPING
Computer Graphics : Viewing In 2D
Clipping Computer Graphics Cohen Sutherland Algorithm (Line)
WINDOWING AND CLIPPING
Clipping Clipping Sutherland-Hodgman Clipping
COMPUTER GRAPHICS Clipping
Presentation transcript:

CS 376 Introduction to Computer Graphics 02 / 12 / 2007 Instructor: Michael Eckmann

Michael Eckmann - Skidmore College - CS Spring 2007 Today’s Topics Questions? World & Screen coordinates, Windows & Viewports Clipping –points –lines –polygons

Michael Eckmann - Skidmore College - CS Spring 2007 Windows and Viewports Recall that we define our objects in World coordinates and our screen shows (some part of) the world in Screen coordinates. Now that we know about transformations like translation and scaling, we can talk about how the world coordinates are transformed into screen coordinates. In the world, we define a clipping window which contains that part of the world we wish to be displayed. On the screen we create and position a display window and within that display window we create and position some viewport which can be all or part of the display window. Diagram on the board.

Michael Eckmann - Skidmore College - CS Spring 2007 Windows and Viewports

Michael Eckmann - Skidmore College - CS Spring 2007 Windows and Viewports

Michael Eckmann - Skidmore College - CS Spring 2007 Windows and Viewports clipping window in world –specified in openGL in the call to glu.gluOrtho2D(MIN_X, MAX_X, MIN_Y, MAX_Y); display window on the screen –specified in openGL in the calls testFrame = new Frame("TestFrame"); testFrame.setLocation(10, 10); // positions it on screen at 10,10 testFrame.setSize( 410, 452 ); // size in pixels by default the viewport is the entire display window to make a smaller viewport (part of that display window) use gl.glViewport(lowLeftX, lowLeftY, width, height); openGL still automatically performs the viewing transform from the clipping window in the world to the viewport in the display window.

Michael Eckmann - Skidmore College - CS Spring 2007 Windows and Viewports The transformation that converts the clipping window to the viewport is called the 2d viewing transformation, (aka window-to-viewport transformation, aka windowing transformation). So a way to do this is: –define a window in your world coordinates –clip the scene to that window (that is, “clip” or ignore everything outside the window) –translate this clipping window to the origin –scale it to the size of the viewport –translate from the origin to correct position within the display window. Diagram on board.

Michael Eckmann - Skidmore College - CS Spring 2007 Windows and Viewports Different effects can be generated when you change viewport / clipping window. –1) if we just change the viewport's position same exact objects will be shown but in a different position within the display window. –2) if we change size of viewport changes the size of the objects shown within that viewport –3) if we keep the viewport constant but change the clipping window larger clipping window will cause more of the scene to be shown but these objects will be smaller smaller clipping window will cause less of the scene to be shown but the objects will be larger if you continually make the clipping window smaller this has the effect of zooming in making the clipping window larger --- zooms out.

Michael Eckmann - Skidmore College - CS Spring 2007 Windows and Viewports Different effects can be generated when you change viewport / clipping window. –4) if we keep the viewport constant, keep the clipping window the same size but change it's position in the world what kind of effect will be displayed?

Michael Eckmann - Skidmore College - CS Spring 2007 Windows and Viewports Different effects can be generated when you change viewport / clipping window. –4) if we keep the viewport constant, keep the clipping window the same size but change it's position in the world what kind of effect will be displayed? –panning Aspect ratio: if the clipping window and viewport have the same ratio of x to y, then proportions will be correct (no stretching etc.) –but if they have different aspect ratios, for example a square in the world may not be a square in the viewport

Michael Eckmann - Skidmore College - CS Spring 2007 Windows and Viewports Example on the board of a viewing transformation –define a clipping window in our world coordinates –define a viewport in screen coordinates translate clipping window to origin scale translate to correct screen coords

Michael Eckmann - Skidmore College - CS Spring 2007 Clipping To clip our world into a window we need to determine what in the world is inside our clipping window and what is outside it. we'll talk about clipping points, lines and polygons let's say our clipping window has the following vertices in the world –(xL, yB), (xR, yB), (xR, yT), (xL, yT) –L = left, R = right, T = top, B = bottom A point (x,y) is visible if xL <= x <= xR yB <= y <= yT

Michael Eckmann - Skidmore College - CS Spring 2007 Clipping let's say our clipping window has the following vertices in the world –(xL, yB), (xR, yB), (xR, yT), (xL, yT) –L = left, R = right, T = top, B = bottom –draw clipping window on board A line segment is trickier –a line is visible if both its endpoints are in the clipping window –could solve simultaneous equations for the intersections of the window edge with the lines, but this is expensive The Cohen-Sutherland algorithm for line clipping is a more efficient way. –each vertex (endpoint) is assigned a region code (aka outcode) that defines that vertex to be in one of 9 regions

Michael Eckmann - Skidmore College - CS Spring 2007 Clipping this region code is 4 bits 1 st bit is the sign of yT-y 2 nd bit is the sign of y-yB 3 rd bit is the sign of xR-x 4 th bit is the sign of x-XL 0 = positive 1 = negative Clipping window is the center area in the right diagram with the 0000 | | 1001 | 1000 | | | | | 0001 | 0000 | | | | | 0101 | 0100 | 0110 | |

Michael Eckmann - Skidmore College - CS Spring 2007 Clipping Trivially accept if both endpoints have 0000 region codes Trivially reject if any corresponding bits in the two region codes are both 1 (and them together and if result != 0000, then reject) Example on board of trivial accepts and rejects. | | 1001 | 1000 | | | | | 0001 | 0000 | | | | | 0101 | 0100 | 0110 | |

Michael Eckmann - Skidmore College - CS Spring 2007 Clipping Example on board of several non-trivial rejects / accepts.

Michael Eckmann - Skidmore College - CS Spring 2007 Clipping If can't trivially accept or reject a line then we compute some intersections with the line boundaries Text book figure 6-14 has a mistake that shows a line that would have been trivially rejected (P3 to P4) but they consider it as not rejected until intersections are computed... | | 1001 | 1000 | | | | | 0001 | 0000 | | | | | 0101 | 0100 | 0110 | |

Michael Eckmann - Skidmore College - CS Spring 2007 Clipping Besides Cohen-Sutherland line clipping, there are several faster line clipping algorithms. Our text talks about two more: Liang-Barsky line clipping and Nicholl- Lee-Nicholl line clipping. Let's discuss how Liang-Barsky Line Clipping works.

Michael Eckmann - Skidmore College - CS Spring 2007 Clipping Liang-Barsky line clipping –based on parametric equation of a line given end points (x 0, y 0 ) and (x end, y end ) the parametric equations of a line are: x = x 0 + u (x end – x 0 ) y = y 0 + u (y end – y 0 ) 0 <= u <= 1 –recall that our clipping window has the following vertices in the world (xL, yB), (xR, yB), (xR, yT), (xL, yT) –and a point (x,y) is visible if xL <= x <= xR yB <= y <= yT –replace the parametric equations for x and y in those inequalites xL <= x 0 + u (x end – x 0 ) <= xR yB <= y 0 + u (y end – y 0 ) <= yT

Michael Eckmann - Skidmore College - CS Spring 2007 Liang-Barsky Line Clipping xL <= x 0 + u (x end – x 0 ) <= xR yB <= y 0 + u (y end – y 0 ) <= yT –which can be expressed as 4 inequalities of the form u p k <= q k, where k = 1, 2, 3, or 4 and –p 1 = (x 0 – x end ) p 2 = (x end – x 0 ) p 3 = (y 0 – y end ) p 4 = (y end – y 0 ) –q 1 = (x 0 – xL) q 2 = (xR – x 0 ) q 3 = (y 0 – yB) q 4 = (yT – y 0 ) –a line parallel to a clipping edge has p k = 0, where k represents the edge to which it is parallel: 1=Left, 2=Right, 3=Bottom, 4=Top –if (p k == 0 and q k < 0) then line completely outside boundary, done –if (p k == 0 and q k >= 0) then the line is inside the boundary –if (p k < 0) then the line goes from outside to inside of the infinite extension of a clipping window edge –if (p k > 0) then the line goes from inside to outside of the infinite extension of a clipping window edge

Michael Eckmann - Skidmore College - CS Spring 2007 Liang-Barsky Line Clipping –Recall what k's mean: 1=Left, 2=Right, 3=Bottom, 4=Top –when p k is non-zero, we find the intersection of the line with the infinite extension of the clipping window edge k recall that u p k <= q k so this intersection is simply when u = q k /p k –initialize u 1 to be 0 and u 2 to be 1 –For each of the four infinite extensions of a clipping window edge we calculate either r 1 or r 2 r 1 is the u parameter for the intersection of the line with the edge when coming from the outside of the clipping window to the inside (p < 0) r 2 is the u parameter for the intersection of the line with the edge when coming from the inside of the clipping window to the outside (p > 0) if p u1) if p>0, update u2 to be r2 if it results in a shorter line (i.e. if r2 < u2) if u1 > u2 we reject the line, and we're done. –if it makes it through all four boundary checks without rejection, then the line to be drawn is between u1 and u2.

Michael Eckmann - Skidmore College - CS Spring 2007 Liang-Barsky Line Clipping Example of Liang-Barsky line clipping algorithm in action –(x 0,y 0 ) = (10,5) –(x end,y end ) = (30,30) –Clipping window: xL = 20, xR = 35, yB = 10, yT = 20. –p 1 = (x 0 – x end ) = -20 –p 2 = (x end – x 0 ) = 20 –p 3 = (y 0 – y end ) = -25 –p 4 = (y end – y 0 ) = 25 –q 1 = (x 0 – xL) = -10 –q 2 = (xR – x 0 ) = 25 –q 3 = (y 0 – yB) = -5 –q 4 = (yT – y 0 ) = 15 –u 1 = 0 and u 2 = 1 to start, let's run the algorithm on the board

Michael Eckmann - Skidmore College - CS Spring 2007 Liang-Barsky Line Clipping Another example –(x 0,y 0 ) = (10,18) –(x end,y end ) = (25,25) –Clipping window: xL = 20, xR = 35, yB = 10, yT = 20. –p 1 = (x 0 – x end ) = -15 –p 2 = (x end – x 0 ) = 15 –p 3 = (y 0 – y end ) = -17 –p 4 = (y end – y 0 ) = 17 –q 1 = (x 0 – xL) = -10 –q 2 = (xR – x 0 ) = 25 –q 3 = (y 0 – yB) = 8 –q 4 = (yT – y 0 ) = 2 –u 1 = 0 and u 2 = 1 to start, let's run the algorithm on the board

Michael Eckmann - Skidmore College - CS Spring 2007 Line Clipping Liang-Barsky (L-B) vs. Cohen-Sutherland (C-S) –L-B in general more efficient updates of u1 & u2 require only one divide window edge intersections are computed only once when u1 & u2 are final –C-S repeatedly calcs intersections along a line path even though line may be completely outside clipping window each intersection calc requires a divide and a multiply Both line clipping algorithms can be extended to 3-d A third line clipping algorithm, Nicholl-Lee-Nicholl (N-L-N), which we will not go into is faster than both L-B & C-S but it cannot be extended to 3-d.

Michael Eckmann - Skidmore College - CS Spring 2007 Polygon Clipping Polygon clipping –Polygons can be clipped against successive infinite extensions of the clipping window edges –Keep track of new vertices (intersections with edge of clipping window) at each stage. –Notice the number of vertices increased in the example below.

Michael Eckmann - Skidmore College - CS Spring 2007 Polygon Clipping

Michael Eckmann - Skidmore College - CS Spring 2007 Polygon Clipping The text describes two polygon clipping algorithms. The Sutherland-Hodgman algorithm and the Weiler-Atherton algorithm. A major difference between the two is that the Sutherland-Hodgman algorithm produces as output one polygon. Think about a concave polygon that when clipped, really should result in two polygons. Example on board.