(c) 2002 University of Wisconsin, CS559

Slides:



Advertisements
Similar presentations
Computer Graphics - Rasterization -
Advertisements

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Clipping Concepts, Algorithms for line clipping 1 of 16 Clipping - 10/16/12.
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 , )
CS 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE.
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
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.
3/2/04© University of Wisconsin, CS559 Spring 2004 Last Time General Perspective –Methods for specifying the view volume As a set of clip planes As a field.
David Breen, William Regli and Maxim Peysakhov
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.
Computer Graphics Viewing.
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 Clipping and Hidden Surfaces CS-184: Computer Graphics Prof. James O’Brien.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Clipping.
2/26/04© University of Wisconsin, CS559 Spring 2004 Last Time General Orthographic Viewing –Specifying cameras in world coordinates –Building world  view.
CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.
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.
3/4/04© University of Wisconsin, CS559 Spring 2004 Last Time Clipping Lines –Cohen-Sutherland: The use of outcodes and early reject/accept tests –Liang-Barsky:
02/26/02 (c) 2002 University of Wisconsin, CS 559 Last Time Canonical view pipeline Orthographic projection –There was an error in the matrix for taking.
CS 325 Introduction to Computer Graphics 03 / 08 / 2010 Instructor: Michael Eckmann.
Objectives Introduce basic implementation strategies Clipping Scan conversion.
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.
10/15/02 (c) 2002 University of Wisconsin, CS559 Last Time Clipping.
10/15/02 (c) 2002 University of Wisconsin, CS559 Who Am I? Prof Stephen Chenney These notes will be online after the lecture – in fact they’re online already.
Basic Perspective Projection Watt Section 5.2, some typos Define a focal distance, d, and shift the origin to be at that distance (note d is negative)
10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.
Graphics Graphics & Graphical Programming Lecture 23 - Viewing & Clipping.
Lecture 9 From Vertices to Fragments. Objectives Introduce basic implementation strategies Clipping Rasterization hidden-surface removal.
Two-Dimensional Viewing Hearn & Baker Chapter 6
Computer Graphics Lecture 14 CLIPPING I Taqdees A. Siddiqi
Computer Graphic 2 D Viewing.
Computer Graphics Clipping.
Computer Graphics CC416 Week 13 Clipping.
Transformations contd.
CS 551 / 645: Introductory Computer Graphics
Computer Graphics Shading in OpenGL
Concepts, Algorithms for line clipping
(c) 2002 University of Wisconsin, CS559
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
© University of Wisconsin, CS559 Fall 2004
3D Rendering Pipeline Hidden Surface Removal 3D Primitives
OpenGL 2D Viewing Pipeline
Computer Graphics : Viewing In 2D
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
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
Joshua Barczak CMSC 435 UMBC
Last Time 2D and 3D Transformations
© University of Wisconsin, CS559 Fall 2004
© University of Wisconsin, CS559 Fall 2004
3D rezanje 3D Clipping view frustrum clipping planes clipped.
Clipping Clipping Sutherland-Hodgman Clipping
Computer Graphics Viewing. 2 of 30 Viewing in 2D Window in world coordinates. 45  250  Viewport in Device coords 250 x 250 Pixels.
Where We Stand At this point we know how to: Next thing:
Clipping University of British Columbia CPSC 314 Computer Graphics
Implementation I Ed Angel Professor Emeritus of Computer Science
COMPUTER GRAPHICS Clipping
Presentation transcript:

(c) 2002 University of Wisconsin, CS559 Last Time Finished viewing: Now you know how to: Define a region of space that you wish to view – the view volume Transform it into a generic view volume – canonical view volume Using orthographic or perspective projection Very brief intro to clipping 02/28/02 (c) 2002 University of Wisconsin, CS559

(c) 2002 University of Wisconsin, CS559 Today Clipping in all its detail 02/28/02 (c) 2002 University of Wisconsin, CS559

Sutherland-Hodgman Clip Clip the polygon against each edge of the clip region in turn Clip polygon each time to line containing edge Only works for convex clip regions (Why?) 02/28/02 (c) 2002 University of Wisconsin, CS559

Sutherland-Hodgman Clip To clip a polygon to a line/plane: Consider the polygon as a list of vertices One side of the line/plane is considered inside the clip region, the other side is outside We are going to rewrite the polygon one vertex at a time – the rewritten polygon will be the polygon clipped to the line/plane Check start vertex: if “inside”, emit it, otherwise ignore it Continue processing vertices as follows… 02/28/02 (c) 2002 University of Wisconsin, CS559

Sutherland-Hodgman (3) Look at the next vertex in the list, and the edge from the last vertex to the next. If the polygon edge crosses the clip line/plane going from out to in: emit crossing point, next vertex polygon edge crosses clip line/plane going from in to out: emit crossing polygon edge goes from out to out: emit nothing polygon edge goes from in to in: emit next vertex 02/28/02 (c) 2002 University of Wisconsin, CS559

Sutherland-Hodgman (4) Inside Outside Inside Outside Inside Outside Inside Outside s p i s p p s i p s Output p Output i No output Output i and p 02/28/02 (c) 2002 University of Wisconsin, CS559

Inside-Outside Testing Lines/planes store a vector pointing toward the outside of the clip region – the outward pointing normal Could re-define for inward pointing Dot products give inside/outside information Note that x is any point on the clip line/plane Outside Inside x n f i s 02/28/02 (c) 2002 University of Wisconsin, CS559

Finding Intersection Pts Use the parametric form for the edge between two points, x1 and x2: For planes of the form x=a: Similar forms for y=a, z=a Solution for general plane can also be found 02/28/02 (c) 2002 University of Wisconsin, CS559

Inside/Outside in Screen Space In canonical screen space, clip planes are xs=±1, ys=±1, zs=±1 Inside/Outside reduces to comparisons before perspective divide 02/28/02 (c) 2002 University of Wisconsin, CS559

Hardware Sutherland-Hodgman Suitable for hardware implementation Only need the clip edge, the endpoints of the current edge, and the last output point Polygon edges are output as they are found, and passed right on to the next clip region edge Clip Top Clip Right Clip Bottom Vertices in Clip Far Clip Near Clip Left Clipped vertices out 02/28/02 (c) 2002 University of Wisconsin, CS559

(c) 2002 University of Wisconsin, CS559 Other Ways to Reject If a polygonal object is closed, then no back-facing face is visible Front-facing faces must occlude all back-facing ones Reject back-facing polygons in view space Transform face normal and check OpenGL supports optional back-face culling (and front-face culling too) Bounding volumes enclosing many polygons can be checked against the view volume Done in software in world or view space Visibility can reject whole chunks of geometry without even looking at them 02/28/02 (c) 2002 University of Wisconsin, CS559

(c) 2002 University of Wisconsin, CS559 Clipping In General Apart from clipping to the view volume, clipping is a basic operation in many other algorithms Breaking space up into chunks 2D drawing and windowing Modeling May require more complex geometry than rectangular boxes 02/28/02 (c) 2002 University of Wisconsin, CS559

Additional Clipping Planes Useful for doing things like cut-away views Use a clip plane to cut off part of the object Only works if piece to be left behind is convex OpenGL allows you to do it Also one way to use OpenGL to identify objects in a region of space (uses the selection mechanism) 02/28/02 (c) 2002 University of Wisconsin, CS559

(c) 2002 University of Wisconsin, CS559 Clipping Lines Lines can also be clipped by Sutherland-Hodgman Slower than necessary, unless you already have hardware Better algorithms exist Cohen-Sutherland Liang-Barsky Nicholl-Lee-Nicholl (we won’t cover this one – only good for 2D) 02/28/02 (c) 2002 University of Wisconsin, CS559

(c) 2002 University of Wisconsin, CS559 Cohen-Sutherland (1) Works basically the same as Sutherland-Hodgman Was developed earlier Clip line against each edge of clip region in turn If both endpoints outside, discard line and stop If both endpoints in, continue to next edge (or finish) If one in, one out, chop line at crossing pt and continue Works in both 2D and 3D for convex clipping regions 02/28/02 (c) 2002 University of Wisconsin, CS559

(c) 2002 University of Wisconsin, CS559 Cohen-Sutherland (2) 1 2 1 2 3 3 4 4 3 3 4 4 1 2 1 2 02/28/02 (c) 2002 University of Wisconsin, CS559

(c) 2002 University of Wisconsin, CS559 Cohen-Sutherland (3) Some cases lead to premature acceptance or rejection If both endpoints are inside all edges If both endpoints are outside one edge General rule of clipping – if a fast test can cover many cases, do it first 02/28/02 (c) 2002 University of Wisconsin, CS559

Cohen-Sutherland - Details Only need to clip line against edges where one endpoint is out Use outcode to record endpoint in/out wrt each edge. One bit per edge, 1 if out, 0 if in. Trivial reject: outcode(x1)&outcode(x2)!=0 Trivial accept: outcode(x1)|outcode(x2)==0 Which edges to clip against? outcode(x1)^outcode(x2) 1 2 0010 3 4 0101 02/28/02 (c) 2002 University of Wisconsin, CS559

Liang-Barsky Clipping Parametric clipping - view line in parametric form and reason about the parameter values More efficient, as not computing the coordinate values at irrelevant vertices Works for rectilinear clip regions in 2D or 3D Clipping conditions on parameter: Line is inside clip region for values of t such that (for 2D): 02/28/02 (c) 2002 University of Wisconsin, CS559

(c) 2002 University of Wisconsin, CS559 Liang-Barsky (2) Infinite line intersects clip region edges when: where Note: Left edge is 1, right edge is 2, top edge is 3, bottom is 4 02/28/02 (c) 2002 University of Wisconsin, CS559

(c) 2002 University of Wisconsin, CS559 Liang-Barsky (3) When pk<0, as t increases line goes from outside to inside - entering When pk>0, line goes from inside to outside – leaving When pk=0, line is parallel to an edge (clipping is easy) If there is a segment of the line inside the clip region, sequence of infinite line intersections must go: enter, enter, leave, leave 02/28/02 (c) 2002 University of Wisconsin, CS559

(c) 2002 University of Wisconsin, CS559 Liang-Barsky (4) Leave Enter Leave Leave Leave Enter Enter Enter 02/28/02 (c) 2002 University of Wisconsin, CS559

Liang-Barsky - Algorithm Compute entering t values, which are qk/pk for each pk<0 Compute leaving t values, which are qk/pk for each pk>0 Parameter value for small t end of line is:tsmall= max(0, entering t’s) parameter value for large t end of line is: tlarge=min(1, leaving t’s) if tsmall<tlarge, there is a line segment - compute endpoints by substituting t values Improvement (and actual Liang-Barsky): compute t’s for each edge in turn (some rejects occur earlier like this) 02/28/02 (c) 2002 University of Wisconsin, CS559

Weiler Atherton Polygon Clipping Faster than Sutherland-Hodgman for complex polygons For clockwise polygon: for out-to-in pair, follow usual rule for in-to-out pair, follow clip edge Easiest to start outside 02/28/02 (c) 2002 University of Wisconsin, CS559

(c) 2002 University of Wisconsin, CS559 General Clipping Clipping general against general polygons is quite hard Outline of Weiler algorithm: Replace crossing points with vertices Double all edges and form linked lists of edges Change links at vertices Enumerate polygon patches Can use clipping to break concave polygon into convex pieces; main issue is inside-outside for edges 02/28/02 (c) 2002 University of Wisconsin, CS559

(c) 2002 University of Wisconsin, CS559 Weiler Algorithm (1) 02/28/02 (c) 2002 University of Wisconsin, CS559

(c) 2002 University of Wisconsin, CS559 Rearranging pointers makes it possible to enumerate all components of the intersection C h a n g e s t o 02/28/02 (c) 2002 University of Wisconsin, CS559

(c) 2002 University of Wisconsin, CS559 Where We Stand At this point we know how to: Convert points from local to screen coordinates Clip polygons and lines to the view volume Next thing: Determine which pixels are covered by any given point, line or polygon 02/28/02 (c) 2002 University of Wisconsin, CS559

(c) 2002 University of Wisconsin, CS559 Drawing Points When points are mapped into window coordinates, they could land anywhere – not just at a pixel center Solution is the simple, obvious one Map to window space Fill the closest pixel Can also specify a radius – fill a square of that size, or fill a circle Square is faster 02/28/02 (c) 2002 University of Wisconsin, CS559

(c) 2002 University of Wisconsin, CS559 Drawing Lines Task: Decide which pixels to fill (samples to use) to represent a line We know that all of the line lies inside the visible region (clipping gave us this!) Issues: If slope between -1 and 1, one pixel per column. Otherwise, one pixel per row Constant brightness? Lines of the same length should light the same number of pixels (we normally ignore this) Anti-aliasing? (Getting rid of the “jaggies”) 02/28/02 (c) 2002 University of Wisconsin, CS559

Line Drawing Algorithms Consider lines of the form y=m x + c, where m=y/x, 0<m<1, integer coordinates All others follow by symmetry Variety of slow algorithms (Why slow?): step x, compute new y at each step by equation, rounding: step x, compute new y at each step by adding m to old y, rounding: 02/28/02 (c) 2002 University of Wisconsin, CS559

Bresenham’s Algorithm Overview Plot the pixel whose y-value is closest to the line Given (xi,yi), must choose from either (xi+1,yi+1) or (xi+1,yi) Idea: compute a decision variable Value that will determine which pixel to draw Easy to update from one pixel to the next 02/28/02 (c) 2002 University of Wisconsin, CS559

(c) 2002 University of Wisconsin, CS559 Decision Variable Decision variable is: yi+1 d2 d1 yi xi xi+1 02/28/02 (c) 2002 University of Wisconsin, CS559

(c) 2002 University of Wisconsin, CS559 What Can We Decide? d1<d2 => pi negative => next point at (xi+1,yi) d1>d2 => pi positive => next point at (xi+1,yi+1) So, we know what to draw based on the decision variable How do we update it? What is pk+1? 02/28/02 (c) 2002 University of Wisconsin, CS559

Updating The Decision Variable If yi+1=yi+1: If yi+1=yi: What is p1 (assuming integer endpoints)? 02/28/02 (c) 2002 University of Wisconsin, CS559

Bresenham’s Algorithm For integers, slope between 0 and 1: x=x1, y=y1, p=2 dy - dx, draw (x, y) until x=x2 x=x+1 p>0 ? y=y+1, draw (x, y), p=p+2 y - 2 x p<0? y=y, draw (x, y), p=p+2 y Compute the constants once at the start Only does add and comparisons Floating point has slightly more difficult initialization 02/28/02 (c) 2002 University of Wisconsin, CS559

(c) 2002 University of Wisconsin, CS559 Example: (2,2) to (7,6) x=5, y=4 i x y p 1 2 2 3 2 3 3 1 3 4 4 -1 4 5 4 7 5 6 5 5 6 7 6 3 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 02/28/02 (c) 2002 University of Wisconsin, CS559