CGPage: 1 東吳資訊科學 江清水 The process of clipping decides which part, if any, of a primitive lies inside the window. The algorithms used for line clipping can.

Slides:



Advertisements
Similar presentations
9.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 9 – Clipping.
Advertisements

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.
Computer Graphics Inf4/MSc 1 Computer Graphics Lecture 7 Scanline algorithm and polygon clipping Taku Komura.
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.
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.
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.
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,
2 D viewing Prepared by Elizabeth Isaac DCS, RSET.
Introduction to Computer Graphics Chapter 6 – 2D Viewing Pt 2 1.
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.
1 CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai.
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.
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.
CGPage: 1 東吳資訊科學 江清水 3.1 2D Geometry - points and polygons X Y A point in 2D is represented by two real numbers (X,Y) A line segment is represented by.
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.
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
CGPage: 1 東吳資訊管理 江清水 Computer Game : Basic 1.Computer Graphics and Its application 2.2D Coordinate Geometry 3.1 2D geometry -- points and polygons 3.2.
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
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
Clipping. Before clipping… After clipping… Point Clipping Display P = (x, y) if xw min
Computer Graphics Viewing. 2 of 30 Viewing in 2D Window in world coordinates. 45  250  Viewport in Device coords 250 x 250 Pixels.
1 U08181 Computer Graphics Clipping Transformations –Transformations and matrices –Homogeneous matrices –Transformations in SVG.
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.
Computer Graphics Clipping.
Introduction to Computer Graphics with WebGL
Computer Graphics CC416 Week 13 Clipping.
Transformations contd.
Computer Graphics Shading in OpenGL
Concepts, Algorithms for line clipping
2D Viewing & Clipping 한신대 류승택
Concepts, algorithms for clipping
Implementation I Ed Angel
Graphics Pipeline Clipping
WINDOWING AND CLIPPING
Computer Graphics : Viewing In 2D
CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai
CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai
WINDOWING AND CLIPPING
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
Clipping Clipping Sutherland-Hodgman Clipping
CS U540 Computer Graphics Prof. Harriet Fell Spring 2007
Implementation I Ed Angel Professor Emeritus of Computer Science
CS U540 Computer Graphics Prof. Harriet Fell Spring 2007
Presentation transcript:

CGPage: 1 東吳資訊科學 江清水 The process of clipping decides which part, if any, of a primitive lies inside the window. The algorithms used for line clipping can be divided into two parts: (1) Check all the line segments and separate those that intersect the window boundary. (The curve is represented by a sequence of line segment) (2) Clip the line segments obtained from step 1 by calculating their intersections with the window boundaries. Clipping 2D Clipping

CGPage: 2 東吳資訊科學 江清水 (1) How can we sure that a line segment is totally inside the window (such as A) ? Both endpoints of the segment fall within the boundaries. (2) How can we sure that a line segment is totally outside the window (such as E,F,G)? Let two endpoints are (x 1,y 1 ),(x 2,y 2 ) If ( max{x 1,x 2 } x max or max{y 1,y 2 } y max ) then the line segment is totally outside the window. We introduce an efficient procedure, the Cohen-Sutherland algorithm, to check the intersection property and further clip the line segment if necessary. X min X max Y min Y max A B C D E F G

CGPage: 3 東吳資訊科學 江清水 Cohen-Sutherland Algorithm The 2D plane is divided into 9 regions. Each region is designated by a 4-bit (base 2) integer code. Each bit of the code is set to 1 (true) or 0 (false), starting with the left most one. The bits are assigned by the follow rule: bit 1 = 1 if the region is above the window. bit 2 = 1 if the region is below the window. bit 3 = 1 if the region is on the right of the window. bit 4 = 1 if the region is on the left of the window. X min X max Y min Y max (1001) (0001)(0000)(0010) (0100)(0110) (1000)(1010) (0001)

CGPage: 4 東吳資訊科學 江清水 (1) Given a point (x,y), we would like to assign a "region code" to it by using Cohen-Suterlandalgorithm. In C this can be coded: code = 0 if (x < x min ) code = 1 if (x > x max ) code = 2 if (y < y min ) code += 4 if (y > y max ) code += 8 (2) According to the C code in (1), what code will be assigned if the point is on the boundary of the window? (0000)  0 (3) How about the point on the line X max and not on the boundary of the window? (0100) or (1000) depending on y

CGPage: 5 東吳資訊科學 江清水 (4) Draw precise picture for the partition of 2D plane according to the C code in (1). (Using solid line and dotted line) Let's consider the line clipping now. At first, the visibility of the line segment is determined as follows: (1) Visible -> Both endoint codes are (0000).

CGPage: 6 東吳資訊科學 江清水 (2) Invisible -> Bitwise logical AND of the endpoint codes is not (0000). (3) Indeterminate -> Bitwise logical AND of the endpoint codes is (0000), but at least one of the endpoint does not have a (0000) code. On the third situation, the line endpoints are "pushed" towards the boundary line until the first or the second situation occurs. (0001) (0010) (0000) Y max Y min X min X max

CGPage: 7 東吳資訊科學 江清水 The algorithm steps: 1. Calculate IC1 and IC2, the code of the two endpoints. 2. If (IC1 + IC2.eq. 0) then "Visible". 3. If ( (IC1.AND. IC2).NE. 0) then "Invisible". 4. If ( IC1.EQ. 0) then { Swap(IC1, IC2); Swap(X1,X2); Swap(Y1,Y2); } // At lease one point is outside the // viewport. Insure that point #1 is // one of the outside point. 5. Push endpoint #1 towards X min, X max, Y min, or Y max, depending on which region endpoint #1 occupies (via IC1). bit 1 = 1  toward Y max bit 2 = 1 toward Y min bit 3 = 1 toward X max bit 4 = 1 toward X min If endpoint #1 towards Y max, then { Y max = Y = X 1 + t(Y 2 - Y 1 ), find t and calculate X = X 1 + t(X 2 - X 1 ) } 6. Go To Step #1 above.

CGPage: 8 東吳資訊科學 江清水 Example: Let Xmin = 2, Xmax = 8, Ymin = 2 and Ymax = 8, check the visibility of the following segments using the Cohen-Sutherland Algorithm and, if necessary, clip them against the appropriate window boundaries. Line AB: A(3,10) B(6,12) Line CD: C(4,1) D(10,6) X min =2X max =8 Y min =2 Y max =8 A(3,10) B(6,12) C(4,1) D(10,6)

CGPage: 9 東吳資訊科學 江清水 Example: Let Xmin = 2, Xmax = 8, Ymin = 2 and Ymax = 8, check the visibility of the following segments using the Cohen-Sutherland Algorithm. Line AB: A(3,10) B(6,12) Line CD: C(4,1) D(10,6)

CGPage: 10 東吳資訊科學 江清水 How will the algorithm handle these examples? (A)(B) (C)(D)