Clipping Clipping Sutherland-Hodgman 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

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.
Course Website: Computer Graphics 4: Viewing In 2D.
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.
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.
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,
CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.
Windowing and clipping
CS 376 Introduction to Computer Graphics 02 / 12 / 2007 Instructor: Michael Eckmann.
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)
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.
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.
Computer Graphics Viewing. 2 of 30 Viewing in 2D Window in world coordinates. 45  250  Viewport in Device coords 250 x 250 Pixels.
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
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
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
Lecture 13 Clipping & Scan Conversion
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
Joshua Barczak CMSC 435 UMBC
Two Dimensional Viewing and Clipping.
Last Time 2D and 3D Transformations
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
CS U540 Computer Graphics Prof. Harriet Fell Spring 2007
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.
Implementation I Ed Angel Professor Emeritus of Computer Science
CS U540 Computer Graphics Prof. Harriet Fell Spring 2007
COMPUTER GRAPHICS Clipping
Presentation transcript:

Clipping Clipping Sutherland-Hodgman Clipping Cohen-Sutherland Clipping Liang-Barsky Clipping

The Story So Far for 3D Graphics We now understand: how to model objects as a set of polygons and create a 3D world how to view the 3D world with a camera model, projecting the polygons to a 2D image plane What should come next: determine visible polygons in a scene (clipping and hidden surface removal) rasterise objects – turn 2D objects represented by edge coordinates to pixels (filling polygons) calculate lighting/texture values for pixels

Clipping Clipping removes parts of the geometry that are outside the view/clipping region Clipping edge/plane: an infinite line or plane and we want to output only the geometry on one side of it Clip region Result

Inside-Outside Testing Suppose lines/planes have a normal vector pointing toward the outside of the clip region (or towards inside) Dot products give inside/outside information x is any point on the clip line/plane Outside Inside x f n i s

Clipping Points Against a View Volume A point is inside the view volume if it is on the inside of all the clipping planes Now we see why clipping is done in canonical view space. For instance, to check against the left plane: x coordinate must be > -1 The normals to the clip planes can be considered to point inward, toward the visible region (user defined) In general, if a point p’(x’,y’,z’) is inside, then for a clipping plane nxx + nyy +nzz + d = 0, with (nx,ny,nz) pointing inward, nxx’ + nyy’ +nzz’ + d > 0

Remember the Plane Equation? Given a point A on the plane, and the plane’s normal vector n, the plane equation can be obtained using the fact that every vector on the plane should be perpendicular to n so dot product is 0 P r nxx+nyy+nzz+d=0 (d = -n.a), n= (nx,ny,nz) So

Sutherland-Hodgman p2 p3 p1 p4 p0 p0 p1 p2 p3 p4 Consider the polygon as a list of vertices Clip the polygon against each edge of the clip region in turn Rewrite the polygon one vertex at a time – the rewritten polygon will be the clipped polygon p2 p3 p1 p4 p0 p0 p1 p2 p3 p4 Clip Top Vertices in Clip Right Clip Bottom Clip Left Clipped vertices out Clip Far Clip Near

Sutherland-Hodgman Inside Outside Inside Outside Inside Outside Inside p i p s p s i p s Output p Output i No output Output i and p Case 1: Wholly inside visible region - save endpoint Case 2: Leave (from inside to outside) visible region - save the intersection Case 3: Wholly outside visible region - save nothing Case 4: Enter (from outside to inside) visible region - save intersection and endpoint

Cohen-Sutherland Clip Rectangle We extend the edges of the clip rectangle to divide the plane of the clip rectangle into nine regions Each region is assigned a 4-bit code (outcode) determined by where the region lies with respect to the clip edges Each bit in the outcode is set to either 1 (true) or 0 (false), depending on the following conditions: Bit 1: above top edge Y > Ymax Bit 2: below bottom edge Y < Ymin Bit 3: right of right edge X > Xmax Bit 4: left of left edge X < Xmin 1001 1000 1010 0001 0000 0010 0101 0100 0110 Clip Rectangle

Cohen-Sutherland Use outcode to record end point in/out against each clipping line/plane An outcode has 4 bits in 2D, 6 bits in 3D, one bit per clipping line 1st and 2nd bits for Y (>Ymax, <Ymin) clipping lines, 3rd and 4th bits for X (>Xmax,<Xmin) clipping lines, 5th and 6th for Z (>Zmin,<Zmax) clipping lines Bit is 1 if point is outside the corresponding clipping line, 0 if inside

Cohen-Sutherland Say a=outcode (P1), b=outcode(P2) If a=b=0 then both ends inside so line inside – trivial accept If (a | b) = 0, then one inside one outside – inconclusive - compute intersection point and check outcode for the intersection point If a & b != 0 (bitwise AND) then both ends on the same side of the window – trivial reject If a & b = 0 both ends are outside, but on the outside of different edges of the window - inconclusive - compute intersection point and check outcode for the intersection point

Cohen-Sutherland E a=b=0 B D A (a | b) = 0 C a & b != 0 H a & b = 0 J F G H I J a=b=0 (a | b) = 0 a & b != 0 a & b = 0 a & b = 0 End points pairs are check for trivial acceptance or trivial rejection If not accepted or rejected, divided into two segments at a clip edge Repeat the process on resulting line segments until completely inside or rejected

Example P1 P1’ P2 Clip against left, right, bottom, top boundaries in turn. P1: 1001 P2: 0100 First clip to left edge, giving P1’P2 P1’: 1000 P1’ P2 x=xmin

Example P1’ P1’’ P2’ P2 x=xmin P1’: 1000 P2 : 0100 No need to clip against right edge Clip against bottom gives P1’P2’ Clip against top gives P1’’P2’ P1’ P1’’ P2’ P2’=0000, P1’=0000 P2 x=xmin

Calculating the Intersection To calculate intersection of P1P2 with, say left edge: Left edge: x = xmin Line : y - y2 = m (x - x2) where m = (y2 - y1) / (x2 - x1) Thus intersection is (xmin, y*) where y* = y2 + m (xmin - x2) P2 P1

Liang-Barsky Clipping This uses the parametric equations for a line and solves four inequalities to find the range of the parameter for which the line is visible (within the viewport) The parametric equation of the line segment gives x values and y values for every point in terms of a parameter t that ranges from 0 to 1. The equations are We can see that when t = 0, the point computed is P(x1,y1); and when t = 1, the point computed is P(x2,y2)

Liang-Barsky Clipping We want parameter values that are inside all the clipping planes Last parameter value to enter is the start of the visible segment First parameter value to leave is the end of the visible segment If we leave some clip plane before we enter another, we cannot see any part of the line Liang-Barsky is more efficient than Cohen-Sutherland - computing intersection vertices is most expensive part of clipping

Parametric Intersection Find parametric intersections tright ttop tbottom tleft tb<tl< tt<tr tright tleft ttop tb<tt< tl<tr tbottom

Liang-Barsky Clipping Set tmin=0 and tmax=1 If t< tmin or t > tmax then ignore it and go to the next edge. Otherwise classify the t value as entering or leaving value (using inner product to classify) If t is entering value set tmin =t; if t is leaving value set tmax =t If tmin < tmax then draw a line from (x1 + Dx tmin, y1 + Dy tmin) to (x1 + Dx tmax, y1 + Dy tmax) If the line crosses over the window, you will see the two points are intersections between the line and clipping edges

Entering or Leaving We can classify if entering or leaving value by using inner product Let P(x1,y1), Q(x2,y2) be the line and n be the normal vector (outward) If the parameter t is entering If the parameter t is leaving Let P = (1,3), Q = (-4,2) while the edge equation is x+2y-4 = 0. Determine if the vector from P to Q is entering or leaving the edge. We can determine n from the equation ax + by + c = o, where n = (a,b). Therefore, n = (1,2). Q - P = (-4-1,2-3) = (-5,-1). n. (Q - P) = (1,2) * (-5,-1) = -5-2 = -7 which is less than 0. So, this line is entering the edge

T Values for Intersection with Clip Edges T value intersection with left edge: x = L With right edge: x = R With top edge: y = T With bottom edge: y = B e.g.

Line and Clipping Edge Intersection From the parametric equation and the t values, we can calculate the intersection between a line and an edge as follows Intersection with left edge Intersection with right edge Intersection with top edge Intersection with bottom edge

Example Consider if t value is entering or exiting by using inner product. (Q-P) = (15+5,9-3) = (20,6) At left edge (Q-P).nL = (20,6)(-10,0) = -200 < 0 entering so we set tmin = 1/4 At right edge (Q-P)nR = (20,6)(10,0) = 200 > 0 exiting so we set tmax = 3/4 Because tmin < tmax then we draw a line from (-5+(20)*(1/4), 3+(6)*(1/4)) to (-5+(20)*(3/4), 3+(6)*(3/4))

Example Consider if tvalue is entering or leaving by using inner product. (Q-P) = (2+8,14-2) = (10,12) At top edge (Q-P).nT = (10,12).(0,10) = 120 > 0 exiting so we set tmax = 8/12 At left edge (Q-P).nL = (10,12).(-10,0) = -100 < 0 entering so we set tmin = 8/10 Because tmin > tmax then we don't draw a line.