CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Clipping Concepts, Algorithms for line clipping 1 of 16 Clipping - 10/16/12.

Slides:



Advertisements
Similar presentations
Clipping de linhas e polígonos. Casos de clipping de linhas.
Advertisements

9.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 9 – Clipping.
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.
Many slides are borrowed from Foley & Van Dam. Topics Viewing Transformation Pipeline in 2D Line and polygon clipping (Slow Fast) – Simultaneous Equations.
Computer Graphics Inf4/MSc 1 Computer Graphics Lecture 7 Scanline algorithm and polygon clipping Taku Komura.
Rezanje črt in poligonov. World window & viewport window viewport screen window world window.
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.
Computer Graphics Lecture 8 Arbitrary Viewing II: More Projection, Clipping and Mathematics of 3D Viewing.
CS 551 / 645: Introductory Computer Graphics Clipping Lines and Polygons.
Computer Graphics, KKU. Lecture 81 Clipping on a Raster Display.
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:
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 Viewing.
Clipping CSE 403 Computer Graphics Cohen Sutherland Algorithm (Line)
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.
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.
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.
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 CIS 736 Computer Graphics Lecture 4 of 42 Review of Basics 3 of 5: Clipping and 3-D Viewing.
CS 325 Introduction to Computer Graphics 03 / 08 / 2010 Instructor: Michael Eckmann.
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)
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.
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 50 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 50 Computer Graphics Implementation II.
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.
CIS 736 Computer Graphics Lecture 6 of 42 Viewing 4: Clipping and Culling Monday, 04 February 2008 Reading: Sections 2.4, 4.1, 4.5 Eberly 2e Adapted with.
Computer Graphics Implementation II.
CENG 538 Advanced Graphics and UIs
Computer Graphics Lecture 14 CLIPPING I Taqdees A. Siddiqi
Computer Graphic 2 D Viewing.
Computer Graphics Clipping.
Introduction to Computer Graphics with WebGL
Transformations contd.
CS 551 / 645: Introductory Computer Graphics
Computer Graphics Shading in OpenGL
Concepts, Algorithms for line clipping
Clipping Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
3D rezanje 3D Clipping view frustrum clipping planes clipped.
Concepts, algorithms for clipping
3D Clipping.
Implementation I Ed Angel
Graphics Pipeline Clipping
Computer Graphics : Viewing In 2D
Clipping Computer Graphics Cohen Sutherland Algorithm (Line)
CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai
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.
© University of Wisconsin, CS559 Fall 2004
3D rezanje 3D Clipping view frustrum clipping planes clipped.
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
COMPUTER GRAPHICS Clipping
Presentation transcript:

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Clipping Concepts, Algorithms for line clipping 1 of 16 Clipping - 10/16/12

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Line Clipping in 2D 2 of 16 Clipping - 10/16/12

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam ©  Parametric form for line segment  Line is in clip rectangle if parametric variables t line and s edge both in [0,1] at intersection point between line and edge of clip rectangle  Slow, must intersect lines with all edges Parametric Line Formulation For Clipping 3 of 16 Clipping - 10/16/12

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Clip Rectangle Cohen-Sutherland Line Clipping in 2D 4 of 16 Clipping - 10/16/12

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam ©  Very similar to 2D  Divide volume into 27 regions (Picture a Rubik’s cube)  6-bit outcode records results of 6 bounds tests  First bit: behind back plane  Second bit: in front of front plane  Third bit: above top plane  Fourth bit: below bottom plane  Fifth bit: to the right of right plane  Sixth bit: to the left of left plane  Again, lines with OC 0 = 0 and OC 1 = 0 can be trivially accepted  Lines lying entirely in a volume outside of a plane can be trivially rejected: OC 0 AND OC 1  0 (i.e., they share an “outside” bit) Cohen-Sutherland Line Clipping in 3D 5 of 16 Clipping - 10/16/12 Back plane (in front) (behind) Front plane (in front) (behind) Bottom plane (above) (below) Left plane (to left of) (to right of) Top plane (above) (below) Right plane (to left of) (to right of)

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam ©  If we can neither trivially accept/reject (T/A, T/R), divide and conquer  Subdivide line into two segments; then T/A or T/R one or both segments:  use a clip edge to cut line  use outcodes to choose the edges that are crossed  for a given clip edge, if a line’s two outcodes differ in the corresponding bit, the line has one vertex on each side of the edge, thus crosses  pick an order for checking edges: top – bottom – right – left  compute the intersection point  the clip edge fixes either x or y  can substitute into the line equation  iterate for the newly shortened line, “extra” clips may happen (e.g., E-I at H) Cohen-Sutherland Algorithm (1/3) Clip rectangle D C B A E F G H I 6 of 16 Clipping - 10/16/12

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Cohen-Sutherland Algorithm (2/3) ComputeOutCode(x0, y0, outcode0); ComputeOutCode(x1, y1, outcode1); repeat check for trivial reject or trivial accept pick the point that is outside the clip rectangle if TOP then x = x0 + (x1 – x0) * (ymax – y0) / (y1 – y0); y = ymax; else if BOTTOM then x = x0 + (x1 – x0) * (ymin – y0) / (y1 – y0); y = ymin; else if RIGHT then y = y0 + (y1 – y0) * (xmax – x0) / (x1 – x0); x = xmax; else if LEFT then y = y0 + (y1 – y0) * (xmin – x0) / (x1 – x0); x = xmin; if (x0, y0 is the outer point) then x0 = x; y0 = y; ComputeOutCode(x0, y0, outcode0) else x1 = x; y1 = y; ComputeOutCode(x1, y1, outcode1) until done 7 of 16 Clipping - 10/16/12

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam ©  Similar algorithm for using 3D outcodes to clip against canonical parallel view volume: Cohen-Sutherland Algorithm (3/3) xmin = ymin = -1; xmax = ymax = 1; zmin = -1; zmax = 0; ComputeOutCode(x0, y0, z0, outcode0); ComputeOutCode(x1, y1, z1, outcode1); repeat check for trivial reject or trivial accept pick the point that is outside the clip rectangle if TOP then x = x0 + (x1 – x0) * (ymax – y0) / (y1 – y0); z = z0 + (z1 – z0) * (ymax – y0) / (y1 – y0); y = ymax; else if BOTTOM then x = x0 + (x1 – x0) * (ymin – y0) / (y1 – y0); z = z0 + (z1 – z0) * (ymin – y0) / (y1 – y0); y = ymin; else if RIGHT then y = y0 + (y1 – y0) * (xmax – x0) / (x1 – x0); z = z0 + (z1 – z0) * (xmax – x0) / (x1 – x0); x = xmax; else if LEFT then y = y0 + (y1 – y0) * (xmin – x0) / (x1 – x0); z = z0 + (z1 – z0) * (xmin – x0) / (x1 – x0); x = xmin; else if NEAR then x = x0 + (x1 – x0) * (zmax – z0) / (z1 – z0); y = y0 + (y1 – y0) * (zmax – z0) / (z1 – z0); z = zmax; else if FAR then x = x0 + (x1 – x0) * (zmin – z0) / (z1 – z0); y = y0 + (y1 – y0) * (zmin – z0) / (z1 – z0); z = zmin; if (x0, y0, z0 is the outer point) then x0 = x; y0 = y; z0 = z; ComputeOutCode(x0, y0, z0, outcode0) else x1 = x; y1 = y; z1 = z; ComputeOutCode(x1, y1, z1, outcode1) until done 8 of 16 Clipping - 10/16/12

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Scan Conversion after Clipping BA x = x min y = y min y = y min – 1 y = y min – 1/2 Clip rectangle 9 of 16 Clipping - 10/16/12

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Sutherland-Hodgman Polygon Clipping 10 of 16  The 2D Sutherland-Hodgman algorithm generalizes to higher dimensions  We can use it to clip polygons to the 3D view volume one plane at a time  Section 36.5 in textbook

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Cyrus-Beck/Liang-Barsky Parametric Line Clipping (1/3) 11 of 16 Clipping - 10/16/12

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam ©  Now solve for the value of t at the intersection of P 0 P 1 with the edge E i :  First, substitute for P(t):  Next, group terms and distribute dot product:  Let D be the vector from P 0 to P 1 = (P 1 – P 0 ), and solve for t:  note that this gives a valid value of t only if the denominator of the expression is nonzero.  For this to be true, it must be the case that:  N i  0 (that is, the normal should not be 0; this could occur only as a mistake)  D  0 (that is, P 1  P 0 )  N i D  0 (edge E i and line D are not parallel; if they are, no intersection).  The algorithm checks these conditions. Cyrus-Beck/Liang-Barsky Parametric Line Clipping (2/3) 12 of 16 Clipping - 10/16/12

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Cyrus-Beck/Liang-Barsky Parametric Line Clipping (3/3) 13 of 16 Clipping - 10/16/12

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Cyrus-Beck/Liang-Barsky Line Clipping Algorithm Pre-calculate N i and select P E i for each edge; for each line segment to be clipped if P 1 = P 0 then line is degenerate so clip as a point; else begin t E = 0; t L = 1; for each candidate intersection with a clip edge if Ni D  0 then {Ignore edges parallel to line} begin calculate t; {of line and clip edge intersection} use sign of N i D to categorize as PE or PL; if PE then t E = max(t E,t); if PL then t L = min(t L,t); end if t E > t L then return nil else return P(t E ) and P(t L ) as true clip intersections end 14 of 16 Clipping - 10/16/12

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam ©  D = P 1 – P 0 = (x 1 – x 0, y 1 – y 0 )  Leave P E i as an arbitrary point on clip edge: it’s a free variable and drops out Parametric Line Clipping for Upright Clip Rectangle (1/2) Calculations for Parametric Line Clipping Algorithm (x 0 -x,y 0 - y max )(x, y max )(0,1)top: y = y max (x 0 -x,y 0 - y min )(x, y min )(0,-1)bottom: y = y min (x 0 - x max,y 0 -y)(x max,y)(1,0)right: x = x max (x 0 - x min,y 0 -y)(x min, y)(-1,0)left: x = x min P 0 -P E i PEiPEi Normal N i Clip Edge i 15 of 16 Clipping - 10/16/12

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam ©  Examine t:  Numerator is just the directed distance to an edge; sign corresponds to OC  Denominator is just the horizontal or vertical projection of the line, dx or dy; sign determines PE or PL for a given edge  Ratio is constant of proportionality: “how far over” from P 0 to P 1 intersection is relative to dx or dy Parametric Line Clipping for Upright Clip Rectangle (2/2) 16 of 16 Clipping - 10/16/12

Embedded Font (Hidden slide, to ensure that all characters are embedded for future editing) =~`,./;’[]{}:”>?<  ABCDEFGHIJKLMNOPQRSTUVWXYZ  a b c d e f g h i j k l m n o p q r s t u v w x y z   ABCDEFGHIJKLMNOPQRSTUVWXYZ  a b c d e f g h i j k l m n o p q r s t u v w x y z   ABCDEFGHIJKLMNOPQRSTUVWXYZ  a b c d e f g h i j k l m n o p q r s t u v w x y z 