Concepts, Algorithms for line clipping

Slides:



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

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.
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.
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:
Computer Graphics : Clipping
Computer Graphics Viewing.
Clipping CSE 403 Computer Graphics Cohen Sutherland Algorithm (Line)
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.
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,
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.
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.
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
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.
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
Computer Graphics CC416 Week 13 Clipping.
Transformations contd.
CS 551 / 645: Introductory Computer Graphics
Computer Graphics Shading in OpenGL
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
WINDOWING AND 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
WINDOWING 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.
© University of Wisconsin, CS559 Fall 2004
(c) 2002 University of Wisconsin, CS559
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
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
COMPUTER GRAPHICS Clipping
Presentation transcript:

Concepts, Algorithms for line clipping

Line Clipping in 2D Clipping endpoints Endpoint analysis for lines:   Clipping endpoints If xmin ≤ x ≤ xmax and ymin ≤ y ≤ ymax , the point is inside the clip rectangle. Endpoint analysis for lines: if both endpoints in, do “trivial acceptance” if one endpoint inside, one outside, must clip if both endpoints out, don’t know Brute force clip: solve simultaneous equations using four line and four clip edges slope-intercept formula handles infinite lines only doesn’t handle vertical lines Clipping - 10/12/17

Parametric Line Formulation For Clipping Parametric form for line segment Line is in clip rectangle if parametric variables tline and sedge both in [0,1] at intersection point between line and edge of clip rectangle Slow, must intersect lines with all edges   Clipping - 10/12/17

Cohen-Sutherland Line Clipping in 2D Divide plane into 9 regions Compute the sign bit of 4 comparisons between a vertex and an edge ymax – y; y – ymin; xmax – x; x – xmin Point lies inside only if all four sign bits are 0, otherwise exceeds edge 4 bit outcode records results of four bounds tests: First bit: above top edge Second bit: below bottom edge Third bit: to the right of right edge Fourth bit: to the left of left edge Compute outcodes for both vertices of each line (denoted OC0 and OC1) Lines with OC0 = 0 (i.e., 0000) and OC1 = 0 can be trivially accepted. Lines lying entirely in a half plane outside an edge can be trivially rejected if (OC0 AND OC1) ≠ 0 (i.e., they share an “outside” bit) Clip Rectangle Clipping - 10/12/17

Cohen-Sutherland Line Clipping in 3D Very similar to 2D Divide volume into 27 regions 6-bit outcode records results of 6 bounds tests First bit: behind back plane: Z - Zmin Second bit: in front of front plane: Zmax -Z Third bit: above top plane: Ymax - Y Fourth bit: below bottom plane: Y - Ymin Fifth bit: to the right of right plane: Xmax -X Sixth bit: to the left of left plane: X - Xmin Again, lines with OC0 = 0 and OC1 = 0 can be trivially accepted Lines lying entirely in a volume outside of a plane can be trivially rejected: OC0 AND OC1  0 (i.e., they share an “outside” bit) Back plane 000000 (in front) 100000 (behind) Front plane 010000 (in front) 000000 (behind) Bottom plane 000000 (above) 000100 (below) Left plane 000001 (to left of) 000000 (to right of) Top plane 001000 (above) 000000 (below) Right plane 000000 (to left of) 000010 (to right of) Clipping - 10/12/17

Cohen-Sutherland Algorithm (1/3) 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) Clip rectangle D C B A E F G H I Clipping - 10/12/17

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

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

Scan Conversion after Clipping   Clip rectangle Don’t round and then scan convert, because the line will have the wrong slope: calculate decision variable based on pixel chosen on left edge (remember: y = mx + B) Horizontal edge problem: Clipping/rounding produces pixel A; to get pixel B, round up x of the intersection of line with y = ymin – ½ and pick pixel above: B A x = xmin y = ymin y = ymin – 1 y = ymin – 1/2 Clipping - 10/12/17

Sutherland-Hodgman Polygon Clipping 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 BALSA demonstration: https://www.youtube.com/watch?v=ViOngYZ9-Wk Clipping - 10/12/17

Cyrus-Beck/Liang-Barsky Parametric Line Clipping (1/3)     Clipping - 10/12/17

Cyrus-Beck/Liang-Barsky Parametric Line Clipping (2/3) Now solve for the value of t at the intersection of P0 P1 with the edge Ei: First, substitute for P(t) with P0+ (P1 – P0)t: Next, group terms and distribute dot product: Let D be the vector from P0 to P1 = (P1 – P0), 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: Ni  0 (that is, the normal should not be 0; this could occur only as a mistake) D  0 (that is, P1  P0) Ni • D  0 (edge Ei and line D are not parallel; if they are, no intersection). The algorithm checks these conditions.         Clipping - 10/12/17

Cyrus-Beck/Liang-Barsky Parametric Line Clipping (3/3) Eliminate all t’s outside [0, 1] on the line Of remaining t’s which produce interior intersections? Can’t just take the innermost t values! Move from P0 to P1; for a given edge, just before crossing: If Ni • D < 0  Potentially Entering (PE); If Ni • D > 0  Potentially Leaving (PL) Pick inner PE/PL pair: tE for PPE with max t, tL for PPL with min t, and tE > 0, tL < 1 If tL < tE , no intersection Clipping - 10/12/17

Cyrus-Beck/Liang-Barsky Line Clipping Algorithm Pre-calculate Ni and select PEi for each edge; for each line segment to be clipped if P1 = P0 then line is degenerate so clip as a point; else begin tE = 0; tL = 1; for each candidate intersection with a clip edge if Ni • D  0 then {Ignore edges parallel to line} calculate t; {of line and clip edge intersection} use sign of Ni • D to categorize as PE or PL; if PE then tE = max(tE,t); if PL then tL = min(tL,t); end if tE > tL then return nil else return P(tE) and P(tL) as true clip intersections Clipping - 10/12/17

Parametric Line Clipping for Upright Clip Rectangle (1/2) D = P1 – P0 = (x1 – x0, y1 – y0) Leave PEi as an arbitrary point on clip edge: it’s a free variable and drops out Calculations for Parametric Line Clipping Algorithm (x0-x,y0- ymax) (x, ymax) (0,1) top: y = ymax (x0-x,y0- ymin) (x, ymin) (0,-1) bottom: y = ymin (x0- xmax,y0-y) (xmax,y) (1,0) right: x = xmax (x0- xmin,y0-y) (xmin, y) (-1,0) left: x = xmin P0-PEi PEi Normal Ni Clip Edgei Clipping - 10/12/17

Parametric Line Clipping for Upright Clip Rectangle (2/2) 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 P0 to P1 intersection is relative to dx or dy Clipping - 10/12/17