Clipping: Clipping is a process of dividing an object into visible and invisible positions and displaying the visible portion and discarding the invisible.

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

Rezanje črt in poligonov. World window & viewport window viewport screen window world window.
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.
CHAPTER 12 Height Maps, Hidden Surface Removal, Clipping and Level of Detail Algorithms © 2008 Cengage Learning EMEA.
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.
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.
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 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.
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.
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
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.
CS 376 Introduction to Computer Graphics 02 / 12 / 2007 Instructor: Michael Eckmann.
Two-Dimensional Viewing
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.
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
Unit – IV 2D Viewing. 2 of 30 Contents Windowing Concepts The viewing pipeline viewing coordinate reference frame, window to view-port coordinate transformation,
EEL Introduction to Computer Graphics
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
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
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.
Clipping.
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.
2D Viewing & Clipping 한신대 류승택
Concepts, algorithms for clipping
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
Lecture 13 Clipping & Scan Conversion
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
Computer Graphics Viewing. 2 of 30 Viewing in 2D Window in world coordinates. 45  250  Viewport in Device coords 250 x 250 Pixels.
Clipping University of British Columbia CPSC 314 Computer Graphics
CS U540 Computer Graphics Prof. Harriet Fell Spring 2007
Presentation transcript:

Clipping: Clipping is a process of dividing an object into visible and invisible positions and displaying the visible portion and discarding the invisible portion. Generally we have clipping algorithms for the following primitive types. –Point clipping –Line clipping –Area clipping (Polygon) –Curve clipping –Text clipping

Point clipping algorithm or Simple visibility algorithm: If xleft, xright, ybottom, and ytop denote the boundaries of a rectangle clipping window into a point (x, y) lies inside the window including the boundary if xleft ≤ x ≤ xright ybottom ≤ y ≤ ytop.

Point clipping algorithm or Simple visibility algorithm: where xleft, xright, ybottom and ytop are the positions of the edges of the screen. These inequalities provide us with a very simple method of clipping pictures on a point-by-point basis; we substitute the co-ordinates of each point for x and y and if the point fails to satisfy either inequality, it is invisible.

Line clipping: The below figure shows a number of different attitudes that a straight line segment may take with respected to the screen. It is an extremely useful fact that clipping to a convex boundary such as square screen never generates more than one visible segment of a straight line. This means that the visible segment of a straight line can be determined simply by computing its two endpoints.

Line clipping Algorithm: 1.If a, b are the end points of the line, 1.check if the line is totally visible by checking whether the endpoints are totally inside the boundary. 2. If both end points left, right are above and below the window then the line is trivially invisible and hence reject.

Line clipping Algorithm: If one point is inside and one point is outside then a portion of a line is invisible and a portion of a line is visible. This can be achieved by finding intersection of the line with corresponding boundaries such that the line segment outside the window is discarded, and the line segment inside the boundary is displayed.

Line clipping Algorithm: If the two points are outside such that the line is diagonally passing the window then the intersection with the two boundaries are calculated and the position of the line from one boundary to other is displayed and the remaining two portions of the line are discarded.

Cohen-Sutherland line clipping algorithm: This is one of the most popular line clipping algorithms. This was introduced by Dan Cohen and Ivan Sutherland. It was designed not only to find the endpoints very rapidly but also to reject even more rapidly any line that is clearly invisible. This makes it a very good algorithm. For clipping pictures that are much larger than the screen.

Cohen-Sutherland line clipping algorithm… Assign a four bit code to all regions as shown in the figure. Every line end point in a picture is assigned a 4-bit binary code known as region code, that identifies the location of the point relative to the boundaries of the clipping rectangle. Each bit position in the region code is used to indicate one of the 4 rectangle coordinates positions of the point with respected to clipping window to the left, right, below and top.

Cohen-Sutherland line clipping algorithm… –Bit 1 – left –Bit 2 – right –Bit 3 – below –Bit 4 – top A value of 1 in any bit position indicates that the point is in the relative position otherwise the bit position is set to zero. If a point is within the clipping the region code is 0000.

Cohen-Sutherland line clipping algorithm… If the code of both the endpoints are 0000 then the line is totally visible and hence draw the line. Bit values in the region codes are determined by comparing endpoint co- ordinate values (x, y) to the clip boundaries.

Cohen-Sutherland line clipping algorithm… Bit 1 is set to 1 if x < wmin. The other three bit values can be determined using similar comparison or calculating differences between endpoint co-ordinates and clipping boundaries. Use the resultant sign of each differences calculation to set the corresponding value in the region code.

Cohen-Sutherland line clipping algorithm… –Bit 1 is the sign bit of x-xwmin –Bit 2 is the sign bit of xwmax-x –Bit 3 is the sign bit of y-ywmin –Bit 4 is the sign bit of ywmax-y If any line have 1 in the same bit position in the region codes for each endpoint are completely outside the clipping rectangle, so we discard the line

Cohen-Sutherland line clipping algorithm… For a line with end points co-ordinates (x1, y1) and (x2, y2) then the y coordinate of the intersection point with a vertical boundary can be obtained with the calculation y=y1 + m(x-x1)  (1), where the x value is set either to xleft or xright.

Cohen-Sutherland line clipping algorithm… Similarly if we are looking for the intersection with a horizontal boundary, the x co-ordinate can be calculated as x = x1 + 1/m (y-y1)  (2) where y set either ybottom or ytop.

Cohen-Sutherland line clipping algorithm… So the points are given by left: (xleft, y=m(xleft-x1) + y1) right: (xright, y=m(xright-x1) +y1 ) top: (x=1/m (ytop-y1) + x1, ytop) bottom: (x=1/m (ybottom-y1) + x1, ybottom) where (x1, y1) and (x2, y2) are the points and xleft, xright, ytop and ybottom are the boundaries of the window and m is the slope which is given by m = y2-y1 / x2-x1  (3).

Example Display the corresponding visible portion of line leaving the outside boundary Example: Clip the line with the boundaries (-1, 1) of x and (-1, 1) of y and the points are (1/2, 1/4) and (1/2, 3/2).

Example Solution: Given xleft= -1 and xright= 1 ytop= 1 and ybottom= -1 let A=(1/2, 1/4) and B=(1/2, 3/2) i.e., A=(0.5, 0.25) and B=(0.5, 1.5). So the line is the bitwise position of A is 0000 and for B is So clearly B is not in the region. So we have to find the horizontal intercept point. i.e., (x=1/m (ytop-y1) + x1, ytop).

Example m= y2-y1 = 1.5 – 0.25 = ∞ x2-x1 0.5 – 0.5 The point is x= 1/ ∞ ( ) = 0.5 y=1 The point is (0.5, 1).

Example Example: Clip the line with the boundaries (0, 0) and (15, 15) and the points are (2, 3) and (9, 10). Solution: Given (x1, y1) = (2, 3) (x2, y2) = (9, 10) Here xwmin = 0, ywmin = 0. Xwmax = 15, ywmax = 15. Bit 1 is the sign bit of x-xwmin

Example Bit 2 is the sign bit of xwmax-x Bit 3 is the sign bit of y-ywmin Bit 4 is the sign bit of ywmax-y For (2, 3) the region code is For (9, 10) the region code is So the line should be drawn.

Example Example: Clip the line with the boundaries (0, 0) and (15, 15) and the points are (2, - 5) and (2, 18). Solution: Region code for (2, -5) is 2-0=0, 15-2=0, -5-0=1, 15+5=0. So it is in 0100 region. So (2, -5) is not in the region.

Example So we have to find the horizontal intercept point (x=1/m (ybottom-y1) + x1, ybottom); m=y2-y1 / x2-x1. m= 18-(-5) / 2-2 = 23/0 = ∞. Then x= 1/∞ (0-(-5)) + 2 = 2. y=0. The point is (2, 0). So we have to draw the line from (2, 0).

Example Region code for (2, 18) is 2-0=0, 15-2=0, 18-0=0, 15-18=1. The code is Clearly it is out of range. So we have to find the horizontal intercept point on top.

Example (x=1/m (ytop-y1) + x1, ytop) m=y2-y1 / x2-x1 = ∞. x= 1/∞ (15-2) + 2 =2. y = ytop = 15. The point is (2, 15). Then draw the line between (2, 15) and (2, 0).