Chi-Cheng Lin, Winona State University CS430 Computer Graphics Cohen-Sutherland Line Clipping Algorithm.

Slides:



Advertisements
Similar presentations
Computer Graphics Inf4/MSc 1 Computer Graphics Lecture 7 Scanline algorithm and polygon clipping Taku Komura.
Advertisements

Rezanje črt in poligonov. World window & viewport window viewport screen window world window.
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.
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.
CS 551 / 645: Introductory Computer Graphics Clipping Lines and Polygons.
Computer Graphics, KKU. Lecture 81 Clipping on a Raster Display.
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)
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:
Clipping Lines Lecture 7 Wed, Sep 10, The Graphics Pipeline From time to time we will discuss the graphics pipeline. The graphics pipeline is the.
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)
CS 4731: Computer Graphics Lecture 4: 2D Graphic Systems
CMPE 466 COMPUTER GRAPHICS Chapter 8 2D Viewing Instructor: D. Arifler Material based on - Computer Graphics with OpenGL ®, Fourth Edition by Donald Hearn,
Introduction to Computer Graphics Chapter 6 – 2D Viewing Pt 2 1.
Chi-Cheng Lin, Winona State University CS430 Computer Graphics Vectors Part IV Polygon Intersection.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Interpolation Clipping.
CS 4731: Computer Graphics Lecture 14: 3D Clipping and Viewport Transformation Emmanuel Agu.
Vertices and Fragments I CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
1 Computer Graphics Chapter 4 2D Viewing Algorithms.
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.
University College Dublin1 Clipping u Clipping is the removal of all objects or part of objects in a modelled scene that are outside the real-world window.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Implementation I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Graphics Pipeline Clipping CMSC 435/634. Graphics Pipeline Object-order approach to rendering Sequence of operations – Vertex processing – Transforms.
CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.
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
CS 376 Introduction to Computer Graphics 02 / 12 / 2007 Instructor: Michael Eckmann.
2003CS Hons RW778 Graphics1 Chapter 3: Windows, viewports World coordinates rather than screen coordinates. World coordinates rather than screen coordinates.
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.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CS 480/680 Computer Graphics Shading in OpenGL Dr. Frederick C Harris, Jr. Fall 2013.
Clipping CSCI 440 textbook section Starter Question How do we clip these lines? X=-5 Y=-5 Y=5 X=5 [0,0] [3,3] [7,-3] [0,-3] formula from wikipedia.
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
Implementation of a Renderer Consider Programs are processd by the system line & polygon, outside the view volume Efficiently Understanding of the implementation.
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
Chi-Cheng Lin, Winona State University CS430 Computer Graphics Rendering Pipeline and Primitive Rasterization.
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.
Chapter #03 More Drawing Tools 1. Viewport 2 Do not have use the entire window for the image: glViewport(x,y,w,h) Values in pixels (screen coordinates)
Computer Graphics Viewing. 2 of 30 Viewing in 2D Window in world coordinates. 45  250  Viewport in Device coords 250 x 250 Pixels.
Lecture 9 From Vertices to Fragments. Objectives Introduce basic implementation strategies Clipping Rasterization hidden-surface removal.
Computer Graphics Lecture 14 CLIPPING I Taqdees A. Siddiqi
Computer Graphic 2 D Viewing.
Introduction to Computer Graphics with WebGL
Computer Graphics CC416 Week 13 Clipping.
Transformations contd.
Computer Graphics Shading in OpenGL
2D Viewing & Clipping 한신대 류승택
Chapter #03 More Drawing Tools.
Graphics Pipeline Clipping
Computer Graphics : Viewing In 2D
Clipping Computer Graphics Cohen Sutherland Algorithm (Line)
Lecture 13 Clipping & Scan Conversion
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
Clipping Clipping Sutherland-Hodgman Clipping
CS U540 Computer Graphics Prof. Harriet Fell Spring 2007
Clipping University of British Columbia CPSC 314 Computer Graphics
CS U540 Computer Graphics Prof. Harriet Fell Spring 2007
Presentation transcript:

Chi-Cheng Lin, Winona State University CS430 Computer Graphics Cohen-Sutherland Line Clipping Algorithm

2 Topics l Clipping l Cohen-Sutherland Line Clipping Algorithm

3 Clipping l Why clipping? zNot everything defined in the world coordinates is inside the world window l Where does clipping take place? l OpenGL does it for you zBUT, as a CS major, you should know how it is done. Model Viewport Transformation Clipping …

4 Line Clipping l int clipSegment(p1, p2, window) zInput parameters: p1, p2, window p1, p2: 2D endpoints that define a line window: aligned rectangle zReturned value: 1, if part of the line is inside the window 0, otherwise zOutput parameters: p1, p2 p1 and/or p2’s value might be changed so that both p1 and p2 are inside the window

5 Line Clipping l Example zLine RetVal Output AB BC CD DE EA o P1 o P2 o P3 o P4o P1 o P2 o P3 o P4

6 Cohen-Sutherland Line Clipping Algorithm l Trivial accept and trivial reject zIf both endpoints within window  trivial accept zIf both endpoints outside of same boundary of window  trivial reject l Otherwise zClip against each edge in turn Throw away “clipped off” part of line each time l How can we do it efficiently (elegantly)?

7 Cohen-Sutherland Line Clipping Algorithm l Examples: ztrivial accept? ztrivial reject? window L1 L2 L3 L4 L5 L6

8 Cohen-Sutherland Line Clipping Algorithm l Use “region outcode”

9 Cohen-Sutherland Line Clipping Algorithm l outcode[1]  (x < Window.left) outcode[2]  (y > Window.top) outcode[3]  (x > Window.right) outcode[4]  (y < Window.bottom)

10 Cohen-Sutherland Line Clipping Algorithm l Both outcodes are FFFF zTrivial accept l Logical AND of two outcodes  FFFF zTrivial reject l Logical AND of two outcodes = FFFF zCan’t tell zClip against each edge in turn Throw away “clipped off” part of line each time

11 Cohen-Sutherland Line Clipping Algorithm l Examples: zoutcodes? ztrivial accept? ztrivial reject? window L1 L2 L3 L4 L5 L6

12 Cohen-Sutherland Line Clipping Algorithm int clipSegment(Point2& p1, Point2& p2, RealRect W) do if(trivial accept) return 1; else if(trivial reject) return 0; else if(p1 is inside) swap(p1, p2) if(p1 is to the left) chop against the left else if(p1 is to the right) chop against the right else if(p1 is below) chop against the bottom else if(p1 is above) chop against the top while(1);

13 Cohen-Sutherland Line Clipping Algorithm l A segment that requires 4 clips

14 Cohen-Sutherland Line Clipping Algorithm l How do we chop against each boundary?  Given P1 (outside) and P2, (A.x,A.y)=?

15 Cohen-Sutherland Line Clipping Algorithm l Let dx = p1.x - p2.xdy = p1.y - p2.y A.x = w.r d = p1.y - A.y e = p1.x - w.r d/dy = e/dx  p1.y - A.y = (dy/dx)(p1.x - w.r)  A.y = p1.y - (dy/dx)(p1.x - w.r) = p1.y + (dy/dx)(w.r - p1.x) As A is the new P1  p1.y += (dy/dx)(w.r - p1.x) p1.x = w.r Q: Will we have divided-by-zero problem?