CS 551 / 645: Introductory Computer Graphics Clipping Lines and Polygons.

Slides:



Advertisements
Similar presentations
Rezanje črt in poligonov. World window & viewport window viewport screen window world window.
Advertisements

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 , )
CS 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE.
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.
CHAPTER 12 Height Maps, Hidden Surface Removal, Clipping and Level of Detail Algorithms © 2008 Cengage Learning EMEA.
CS 445 / 645 Introduction to Computer Graphics Lecture 9 Clipping Clipping.
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)
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:
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 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,
Introduction to Computer Graphics Chapter 6 – 2D Viewing Pt 2 1.
March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Clipping Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009.
Ray Polygon Interception: Cyrus Beck Algorithm Mengxia Zhu Fall 2007.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Clipping Week 8, Wed Mar.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Clipping II, Hidden Surfaces.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Interpolation Clipping.
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.
Texturing, Clipping Week 9, Mon 27 Oct 2003
1 CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai.
Visibility culling – Clipping. The visibility problem What polygons are visible? There are few visible polygons. –Avoid redundant processing Three classes.
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/26/04© University of Wisconsin, CS559 Spring 2004 Last Time General Orthographic Viewing –Specifying cameras in world coordinates –Building world  view.
UBI 516 Advanced Computer Graphics Two Dimensional Viewing ( Chapter 6 ) Aydın Öztürk Two Dimensional.
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 551 / 645: Introductory Computer Graphics
CS 376 Introduction to Computer Graphics 02 / 12 / 2007 Instructor: Michael Eckmann.
Clipping Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006 (Slide set originally by David Luebke)
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
10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.
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.
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.
CS 376 Introduction to Computer Graphics 02 / 14 / 2007 Instructor: Michael Eckmann.
Computer Graphics Viewing. 2 of 30 Viewing in 2D Window in world coordinates. 45  250  Viewport in Device coords 250 x 250 Pixels.
Lecture 9 From Vertices to Fragments. Objectives Introduce basic implementation strategies Clipping Rasterization hidden-surface removal.
Computer Graphics Clipping.
Computer Graphics CC416 Week 13 Clipping.
Transformations contd.
CS 551 / 645: Introductory Computer Graphics
Concepts, Algorithms for line clipping
Clipping Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
Concepts, algorithms for 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
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
© University of Wisconsin, CS559 Fall 2004
(c) 2002 University of Wisconsin, CS559
Clipping Polygons Dr. Scott Schaefer.
Clipping Clipping Sutherland-Hodgman Clipping
Clipping University of British Columbia CPSC 314 Computer Graphics
COMPUTER GRAPHICS Clipping
Presentation transcript:

CS 551 / 645: Introductory Computer Graphics Clipping Lines and Polygons

Know your role... l Brian talks about assignment 1 l Clipping lines to viewports l Clipping lines to arbitrary polygons l Clipping polygons

Clipping Lines To Viewport l Discard segments of lines outside viewport –Trivially accept lines with both endpoints inside all edges of the viewport –Trivially reject lines with both endpoints outside the same edge of the viewport –Otherwise, reduce to trivial cases by splitting into two segments

Solving Simultaneous Equations l Equation of a line –Slope-intercept: y = mx + b –Implicit Equation: Ax + By + C = 0 –Parametric: Line defined by two points, P 0 and P 1 n P(t) = P 0 + (P 1 - P 0 ) t n x(t) = x 0 + (x 1 - x 0 ) t n y(t) = x 0 + (y 1 - y 0 ) t

Parametric Line Equation l Describes a finite line l Works with vertical lines (like the viewport) l 0 <=t <= 1 –Defines line between P 0 and P 1 l t < 0 –Defines line before P 0 l t > 1 –Defines line after P 1

Parametric Lines and Clipping l Define each line in parametric form: –P 0 (t)…P n-1 (t) l Define each edge of viewport in parametric form: –P L (t), P R (t), P T (t), P B (t) l For each line, compute intersection with all viewport edges

Computing Intersections l Line 0: –x 0 = x (x x 0 0 ) t 0 –y 0 = y (y y 0 0 ) t 0 l Edge L: –x L = x L 0 + (x L 1 - x L 0 ) t L –y L = y L 0 + (y L 1 - y L 0 ) t L l x (x x 0 0 ) t 0 = x L 0 + (x L 1 - x L 0 ) t L l y (y y 0 0 ) t 0 = y L 0 + (y L 1 - y L 0 ) t L –Solve for t 0 and t L

What’s wrong with this?

Cohen-Sutherland Line Clipping l Divide viewplane into regions defined by viewport edges l Assign each region a 4-bit outcode:

Cohen-Sutherland Line Clipping l Set bits with simple tests x > x max y < y min etc. l Assign an outcode to each vertex of line –If both outcodes = 0, trivial accept –bitwise AND vertex outcodes together –If result  0, trivial reject

Cohen-Sutherland Line Clipping l If line cannot be trivially accepted or rejected, subdivide so that one or both segments can be discarded l Pick an edge that the line crosses A B D E C

Cohen-Sutherland Line Clipping l Intersect line with edge (how?) A B D E C

l Discard portion on wrong side of edge and assign outcode to new vertex l Apply trivial accept/reject tests and repeat if necessary Cohen-Sutherland Line Clipping A B D C

l Outcode tests and line-edge intersects are quite fast l But some lines require multiple iterations (see F&vD figure 3.40) l Fundamentally more efficient algorithms: –Cyrus-Beck uses parametric lines –Liang-Barsky optimizes this for upright volumes –F&vD for more details

Cyrus-Beck Algorithm l Use parametric equations of lines l Optimize l We saw that this could be expensive… l Start with parametric equation of line: –P(t) = P 0 + (P 1 - P 0 ) t l And a point and normal for each edge –P L, N L

Cyrus-Beck Algorithm l N L [P(t) - P L ] = 0 l Substitute line equation for P(t) l Solve for t –t = N L [P 0 - P L ] / -N L [P 1 - P 0 ] PLPL NLNL P(t) Inside P0P0 P1P1

Cyrus-Beck Algorithm l Compute t for line intersection with all four edges l Discard all (t 1) l Classify each remaining intersection as –Potentially Entering (PE) –Potentially Leaving (PL) l N L [P 1 - P 0 ] > 0 implies PL l N L [P 1 - P 0 ] < 0 implies PE –Note that we computed this term in when computing t

l Compute PE with largest t l Compute PL with smallest t l Clip to these two points Cyrus-Beck Algorithm PE PL P1P1 PE P0P0

Cyrus-Beck Algorithm l Because of horizontal and vertical clip lines: –Many computations reduce l Normals: (-1, 0), (1, 0), (0, -1), (0, 1) l Pick constant points on edges l solution for t: –-(x 0 - x left ) / (x 1 - x 0 ) –(x 0 - x right ) / -(x 1 - x 0 ) –-(y 0 - y bottom ) / (y 1 - y 0 ) –(y 0 - y top ) / -(y 1 - y 0 )

Comparison l Cohen-Sutherland –Repeated clipping is expensive –Best used when trivial acceptance and rejection is possible for most lines l Cyrus-Beck –Computation of t-intersections is cheap –Computation of (x,y) clip points is only done once –Algorithm doesn’t consider trivial accepts/rejects –Best when many lines must be clipped l Liang-Barsky: Optimized Cyrus-Beck l Nicholl et al.: Fastest, but doesn’t do 3D

Clipping Polygons l Clipping polygons is more complex than clipping the individual lines –Input: polygon –Output: polygon, or nothing l When can we trivially accept/reject a polygon as opposed to the line segments that make up the polygon?

l What happens to a triangle during clipping? l Possible outcomes: triangle  triangle Why Is Clipping Hard? triangle  quad triangle  5-gon l How many sides can a clipped triangle have?

l A really tough case: Why Is Clipping Hard?

l A really tough case: Why Is Clipping Hard? concave polygon  multiple polygons

Sutherland-Hodgman Clipping l Basic idea: –Consider each edge of the viewport individually –Clip the polygon against the edge equation

Sutherland-Hodgman Clipping l Basic idea: –Consider each edge of the viewport individually –Clip the polygon against the edge equation –After doing all planes, the polygon is fully clipped

Sutherland-Hodgman Clipping l Basic idea: –Consider each edge of the viewport individually –Clip the polygon against the edge equation –After doing all planes, the polygon is fully clipped

Sutherland-Hodgman Clipping l Basic idea: –Consider each edge of the viewport individually –Clip the polygon against the edge equation –After doing all planes, the polygon is fully clipped

Sutherland-Hodgman Clipping l Basic idea: –Consider each edge of the viewport individually –Clip the polygon against the edge equation –After doing all planes, the polygon is fully clipped

Sutherland-Hodgman Clipping l Basic idea: –Consider each edge of the viewport individually –Clip the polygon against the edge equation –After doing all planes, the polygon is fully clipped

Sutherland-Hodgman Clipping l Basic idea: –Consider each edge of the viewport individually –Clip the polygon against the edge equation –After doing all planes, the polygon is fully clipped

Sutherland-Hodgman Clipping l Basic idea: –Consider each edge of the viewport individually –Clip the polygon against the edge equation –After doing all planes, the polygon is fully clipped

Sutherland-Hodgman Clipping l Basic idea: –Consider each edge of the viewport individually –Clip the polygon against the edge equation –After doing all planes, the polygon is fully clipped

Sutherland-Hodgman Clipping: The Algorithm l Basic idea: –Consider each edge of the viewport individually –Clip the polygon against the edge equation –After doing all planes, the polygon is fully clipped l Will this work for non-rectangular clip regions? l What would 3-D clipping involve?

Sutherland-Hodgman Clipping l Input/output for algorithm: –Input: list of polygon vertices in order –Output: list of clipped poygon vertices consisting of old vertices (maybe) and new vertices (maybe) l Note: this is exactly what we expect from the clipping operation against each edge

Sutherland-Hodgman Clipping l Sutherland-Hodgman basic routine: –Go around polygon one vertex at a time –Current vertex has position p –Previous vertex had position s, and it has been added to the output if appropriate

Sutherland-Hodgman Clipping l Edge from s to p takes one of four cases: (Purple line can be a line or a plane) insideoutside s p p output insideoutside s p no output insideoutside s p i output insideoutside s p i output p output

Sutherland-Hodgman Clipping l Four cases: –s inside plane and p inside plane n Add p to output n Note: s has already been added –s inside plane and p outside plane n Find intersection point i n Add i to output –s outside plane and p outside plane n Add nothing –s outside plane and p inside plane n Find intersection point i n Add i to output, followed by p

Point-to-Plane test l A very general test to determine if a point p is “inside” a plane P, defined by q and n: (p - q) n < 0: p inside P (p - q) n = 0: p on P (p - q) n > 0: p outside P P n p q P n p q P n p q

Point-to-Plane Test l Dot product is relatively expensive –3 multiplies –5 additions –1 comparison (to 0, in this case) l Think about how you might optimize or special-case this

Finding Line-Plane Intersections l Use parametric definition of edge: L(t) = L 0 + (L 1 - L 0 )t –If t = 0 then L(t) = L 0 –If t = 1 then L(t) = L 1 –Otherwise, L(t) is part way from L 0 to L 1

Finding Line-Plane Intersections Edge intersects plane P where E(t) is on P –q is a point on P –n is normal to P (L(t) - q) n = 0 t = [(q - L 0 ) n] / [(L 1 - L 0 ) n] –The intersection point i = L(t) for this value of t

Line-Plane Intersections Note that the length of n doesn’t affect result: l Again, lots of opportunity for optimization