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.

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.
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 , )
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.
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
Computer Graphics, KKU. Lecture 81 Clipping on a Raster Display.
David Breen, William Regli and Maxim Peysakhov
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:
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.
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.
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.
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.
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.
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
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.
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
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 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
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
Concepts, algorithms for clipping
Implementation I Ed Angel
Graphics Pipeline Clipping
WINDOWING AND CLIPPING
Computer Graphics : Viewing In 2D
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai
WINDOWING AND CLIPPING
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
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
Implementation I Ed Angel Professor Emeritus of Computer Science
CS U540 Computer Graphics Prof. Harriet Fell Spring 2007
Presentation transcript:

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. u Doing this on a pixel-by-pixel basis would be very slow, especially if most objects in the scene are outside the window u More practical techniques are necessary to speed up the task window

University College Dublin2 Line Clipping u Lines are defined by their endpoints, so it should be possible just to examine these, and not every pixel on the line u Most applications of clipping use a window that is either very large – i.e. nearly the whole scene fits inside, or very small – i.e. most of the scene lies inside the window u Hence, most lines may be either trivially accepted or rejected window

University College Dublin3 Cohen-Sutherhland u The Cohen-Sutherland line-clipping algorithm is particularly fast for “trivial” cases – i.e. lines completely inside or outside the window u Non-trivial lines such as those that cross a boundary of the window, are clipped by computing the coordinates of the new boundary endpoint of the line where it crosses the edge of the window window

University College Dublin4 Computing intersection points (1 st case) x min y max y I y min x max AB Q P I xIxI = y I - y P x I - x P y Q - y P x Q - x P As the triangles PAI and PBQ are similar we can write xQxQ yPyP yQyQ xPxP

University College Dublin5 Computing intersection points u We have  After replacing y I with y max and multiplying both sides of this equation by y max – y P, we get = y I - y P x I - x P y Q - y P x Q - x P = y Q - y P (y max - y P )(x Q - x P ) xPxP + xIxI = y max yIyI

University College Dublin6 Computing intersection points u If segment PQ intersects one of the other sides of the rectangle, coordinates are calculated with similar considerations y max x min y min x max Q P I P’P’ Q’ I’I’ P’’ Q’’ I’’

University College Dublin7 y max Computing intersections: 2 nd case x min y min x max A B Q P I xIxI = x I - x P y I - y P x Q - x P y Q - y P As the triangles PAQ and PBI are similar we can write xQxQ yPyP yQyQ xPxP yIyI

University College Dublin8 Computing intersection points u We have  After replacing x I with x min and multiplying both sides of this equation by x min – x P, we get = x Q - x P (x min - x P )(y Q - y P ) yPyP + yIyI = x min xIxI = x I - x P y I - y P x Q - x P y Q - y P

University College Dublin9 Cohen Sutherland cont. u Having decided that a line is non-trivial, it must be clipped u We “push” each end-point of the line to its “nearest” window boundary

University College Dublin10 Cohen-Sutherhland u The window edges are assumed to be extended so that the whole picture is divided into 9 regions u Each region is assigned a four-bit code, called an outcode Left Right Below Above

University College Dublin11 Example 1. Since P lies to the left of the left rectangle edge, it is replaced with P` 2. Since P` lies below the lower rectangle edge, it is replaced with P`` 3. Since Q lies to the right of the rectangle edge, it is replaced with Q` 4. Line segment P`` Q` (the clipped segment) can now be drawn 1010 Q P` P`` Q` P Y min Y max X max X min

University College Dublin12 Example u Steps 1, 2, 3 loop terminated as follows: u If the four bit code of P and Q are equal to zero –Draw line u If the two four bit codes contain a 1 in the same bit position –P and Q are on the same side of rectangle nothing to be drawn 1010 Q P` P`` Q` P Y min Y max X max X min

University College Dublin13 Sample Java Code u Method for generating outcode for each end of the line is computed, giving codes cP and cQ int clipCode(float x, float y) { return ((x xmax ? 4 : 0) | (y ymax ? 1 : 0)); } Note: The expression: condition ? value1 : value2 evaluates value1 if condition is true value2 if condition is false

University College Dublin14 Sample Java Code u Method for generating outcode for each end of the line is computed, giving codes cP and cQ int clipCode(float x, float y) { return ((x xmax ? 4 : 0) | (y ymax ? 1 : 0)); } 1000 = = = = x < xmin Left x > xmax Right y < ymin Below y > ymax Above

University College Dublin15 Sample Java Code u The expression ((x xmax ? 4 : 0) | (y ymax ? 1 : 0)); Is an OR of boolean values (bit by bit) Example: 1000 | 0110 = st and 2 nd bits are mutually exclusive (cannot be both 1 but they can be both 0) Same for 3 rd and 4 th bits x < xmin Left x > xmax Right y < ymin Below y > ymax Above

University College Dublin16 Sample Java Code u The expression ((x xmax ? 4 : 0) | (y ymax ? 1 : 0)); Example: point P 0000 | 0100 | 0010 | 0000 == x < xmin Left x > xmax Right y < ymin Below y > ymax Above P

University College Dublin17 void clipLine (Graphics g, float xP, float yP, float xQ, float yQ, float xmin, float ymin, float xmax, float ymax) { int cP = clipCode(xP, yP); // Generate clip code for point P int cQ = clipCode(xQ, yQ); // Generate clip code for point Q float dx, dy; while ((cP | cQ) != 0) { if ((cP & cQ) != 0) return; // Both points are outside area so ignore dx = xQ - xP; dy = yQ - yP;

University College Dublin18 Trivial cases 1010 Y min Y max X max X min CP&CQ==4 (0100) CP&CQ==1 (0001) CP&CQ==2 (0010) CP&CQ==8 (1000)

University College Dublin19 More trivial cases 1010 Y min Y max X max X min CP&CQ==0 However PQ does not intersect the window: must run a few steps

University College Dublin20 More trivial cases (cont.d) 1010 Y min Y max X max X min Now: CP’&CQ’==1 P’ Q’

University College Dublin21 if (cP != 0) { if ((cP & 8) == 8) /* i.e. cP & 1000 == 1000 (x<xmin) */ { yP += (xmin-xP) * dy / dx; xP = xmin; } else if ((cP & 4) == 4) { yP += (xmax-xP) * dy / dx; xP = xmax; } else if ((cP & 2) == 2) { xP += (ymin-yP) * dx / dy; yP = ymin; } else if ((cP & 1) == 1) { xP += (ymax-yP) * dx / dy; yP = ymax; } cP = clipCode(xP, yP) } // end outer if

University College Dublin22 else if (cQ != 0) { if ((cQ & 8) == 8) { yQ += (xmin-xQ) * dy / dx; xQ = xmin; } else if ((cQ & 4) == 4) { yQ += (xmax-xQ) * dy / dx; xQ = xmax; } else if ((cQ & 2) == 2) { xQ += (ymin-yQ) * dx / dy; yQ = ymin; } else if ((cQ & 1) == 1) { xQ += (ymax-yQ) * dx / dy; yQ = ymax;} cQ = clipCode(xQ, yQ); } // end else if } //end while drawLine(g, xP, yP, xQ, yQ); } // end method

University College Dublin23 Other Clipping algorithms u The Cohen-Sutherland algorithm requires the window to be a rectangle, with edges aligned with the co-ordinate axes u It is sometimes necessary to clip to any convex polygonal window, e.g. triangular, hexagonal, or rotated. u The Cyrus-Beck, and Liang-Barsky line clippers use the concept of inside/outside half spaces generated by edges (polygons are seen as intersection of half (2D) spaces (planes)

University College Dublin24 Polygon Clipping u A polygon is usually defined by a sequence of vertices and edges u If the polygons are un-filled, line-clipping techniques are sufficient

University College Dublin25 Polygon Clipping u However, if the polygons are filled, the process in more complicated u A polygon may be fragmented into several polygons in the clipping process, and the original colour associated with each one

University College Dublin26 Polygon Clipping Algorithms u The Sutherland-Hodgeman clipping algorithm clips any polygon against a convex clip polygon. u The Weiler-Atherton clipping algorithm will clip any polygon against any clip polygon. The polygons may even have holes