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.

Slides:



Advertisements
Similar presentations
CS 376 Introduction to Computer Graphics 02 / 02 / 2007 Instructor: Michael Eckmann.
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 , )
Computer Graphics 4: Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling By:Kanwarjeet Singh.
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.
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.
Computer Graphics Viewing.
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.
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.
Implementation Dr. Amy Zhang. Reading 2  Hill, Chapters  Hill, Chapter 10.
Vertices and Fragments I CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
1 CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai.
CS 376 Introduction to Computer Graphics 02 / 26 / 2007 Instructor: Michael Eckmann.
1 Clipping and Hidden Surfaces CS-184: Computer Graphics Prof. James O’Brien.
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.
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.
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.
Scan Conversion Line and Circle
CS 376 Introduction to Computer Graphics 02 / 12 / 2007 Instructor: Michael Eckmann.
Two-Dimensional Viewing
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)
College of Computer and Information Science, Northeastern UniversityOctober 12, CS G140 Graduate Computer Graphics Prof. Harriet Fell Spring 2006.
CS 480/680 Computer Graphics Shading in OpenGL Dr. Frederick C Harris, Jr. Fall 2013.
10/26/04© University of Wisconsin, CS559 Fall 2004 Last Time Drawing lines Polygon fill rules Midterm Oct 28.
10/15/02 (c) 2002 University of Wisconsin, CS559 Last Time Clipping.
CSE Real Time Rendering Week 9. Post Geometry Shaders Courtesy: E. Angel and D. Shreiner – Interactive Computer Graphics 6E © Addison-Wesley 2012.
Windows, Viewports, and 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.
EEL Introduction to Computer Graphics
CS 325 Introduction to Computer Graphics 02 / 03 / 2010 Instructor: Michael Eckmann.
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 CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014.
Computer Graphics Viewing. 2 of 30 Viewing in 2D Window in world coordinates. 45  250  Viewport in Device coords 250 x 250 Pixels.
Two-Dimensional Viewing Hearn & Baker Chapter 6
CS 551 / 645: Introductory Computer Graphics
Concepts, Algorithms for line clipping
(c) 2002 University of Wisconsin, CS559
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
Concepts, algorithms for clipping
Graphics Pipeline Clipping
© University of Wisconsin, CS559 Fall 2004
Computer Graphics : Viewing In 2D
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
Lecture 13 Clipping & Scan Conversion
© University of Wisconsin, CS559 Fall 2004
(c) 2002 University of Wisconsin, CS559
© University of Wisconsin, CS559 Fall 2004
Clipping Clipping Sutherland-Hodgman Clipping
Where We Stand At this point we know how to: Next thing:
COMPUTER GRAPHICS Clipping
Presentation transcript:

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 of view and aspect ratio –Near and Far clip planes and depth resolution Sutherland-Hodgman Clipping –For clipping points, lines or polygons against convex clip regions –Clip against each clip plane in turn –Rewrite vertex lists

3/2/04© University of Wisconsin, CS559 Spring 2004 Today More clipping –Cohen-Sutherland –Liang-Barsky –Project 2 clipping –Weiler-Atherton –Weiler Drawing lines

3/2/04© University of Wisconsin, CS559 Spring 2004 Clipping Lines Lines can 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)

3/2/04© University of Wisconsin, CS559 Spring 2004 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

3/2/04© University of Wisconsin, CS559 Spring 2004 Cohen-Sutherland (2)

3/2/04© University of Wisconsin, CS559 Spring 2004 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

3/2/04© University of Wisconsin, CS559 Spring 2004 Cohen-Sutherland - Details Only need to clip line against edges where one endpoint is out Use outcode to record endpoint in/out of each edge. One bit per edge, 1 if out, 0 if in –Codes can be computed very quickly – they are not independent for rectangular clip regions Trivial reject: –outcode(x1) & outcode(x2)!=0 Trivial accept: –outcode(x1) | outcode(x2)==0 Which edges to clip against? –outcode(x1) ^ outcode(x2)

3/2/04© University of Wisconsin, CS559 Spring 2004 Liang-Barsky Clipping Parametric clipping - view line in parametric form and reason about the parameter values –Parametric form: x = x 1 +(x 2 -x 1 )t –t  [0,1] are points between x 1 and x 2 Liang-Barsky is more efficient than Cohen-Sutherland –Computing intersection vertices is most expensive part of clipping –Cohen-Sutherland may compute intersection vertices that are later clipped off, and hence don’t contribute to the final answer Works for convex clip regions in 2D or 3D

3/2/04© University of Wisconsin, CS559 Spring 2004 Paramteric Clipping Recall, points inside a convex region are inside all clip planes Parametric clipping finds the values of t, the parameter, that correspond to points inside the clip region Consider a rectangular clip region Line is inside clip region for values of t such that (for 2D): x min x max y min y max

3/2/04© University of Wisconsin, CS559 Spring 2004 Parametric Intersection Infinite line intersects clip region edges when: where

3/2/04© University of Wisconsin, CS559 Spring 2004 Parametric Intersection t bottom t left t top t right

3/2/04© University of Wisconsin, CS559 Spring 2004 Entering or Leaving? When p k <0, as t increases line goes from outside to inside - entering When p k >0, line goes from inside to outside – leaving When p k =0, line is parallel to an edge (clipping is easy) Major Insight: The infinite line must not move outside a clip plane (leave) before it moves inside another (enters) –If it does leave before it enters, it cannot be inside all the planes For rectangular, if there is a segment of the line inside the clip region, sequence of infinite line intersections must go: enter, enter, leave, leave

3/2/04© University of Wisconsin, CS559 Spring 2004 Entering and Leaving Enter Leave Enter Leave Enter Leave

3/2/04© University of Wisconsin, CS559 Spring 2004 Liang-Barsky - Algorithm Compute entering t values, which are q k /p k for each p k <0 –There will always be two for 2D rectangular clip region, three in 3D Compute leaving t values, which are q k /p k for each p k >0 Parameter value for small t end of line is: t small = max(0, entering t’s) Parameter value for large t end of line is: t large =min(1, leaving t’s) If t small <t large, 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)

3/2/04© University of Wisconsin, CS559 Spring 2004 General Liang-Barsky Liang-Barsky works for any convex clip region –Compute intersection t for all clip lines/planes and label them as entering or exiting –Parameter value for small t end of line is:t small = max(0, entering t’s) –Parameter value for large t end of line is: t large =min(1, leaving t’s) –if t small <t large, there is a line segment - compute endpoints by substituting t values

3/2/04© University of Wisconsin, CS559 Spring 2004 In View Space For Project 2, you need to clip edges to a view frustum in world space Situation is: eye, e frustum x right x left x1x1 x2x2

3/2/04© University of Wisconsin, CS559 Spring 2004 First Step Determine which side of each clip plane the segment endpoints lie –Use the cross product –What do we know if (x 1 - e)  (x left - e) > 0 ? –Other cross products give other information What can we say if both segment endpoints are outside one clip plane? –Stop here if we can, otherwise…

3/2/04© University of Wisconsin, CS559 Spring 2004 Finding Parametric Intersection Left clip edge: x = e + (x left - e) t Line: x = x 1 + (x 2 - x 1 ) s Solve simultaneous equations in t and s: Use endpoint inside/outside information to label as entering or leaving Now we have general Liang-Barsky case

3/2/04© University of Wisconsin, CS559 Spring 2004 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

3/2/04© University of Wisconsin, CS559 Spring 2004 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

3/2/04© University of Wisconsin, CS559 Spring 2004 Weiler Algorithm (1)

3/2/04© University of Wisconsin, CS559 Spring 2004 Changes to Rearranging pointers makes it possible to enumerate all components of the intersection

3/2/04© University of Wisconsin, CS559 Spring 2004 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

3/2/04© University of Wisconsin, CS559 Spring 2004 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

3/2/04© University of Wisconsin, CS559 Spring 2004 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 What function are we sampling with?

3/2/04© University of Wisconsin, CS559 Spring 2004 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”) –Sampling theory?

3/2/04© University of Wisconsin, CS559 Spring 2004 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:

3/2/04© University of Wisconsin, CS559 Spring 2004 Bresenham’s Algorithm Overview Aim: For each x, plot the pixel whose y-value is closest to the line Given (x i,y i ), must choose from either (x i +1,y i +1) or (x i +1,y i ) Idea: compute a decision variable –Value that will determine which pixel to draw –Easy to update from one pixel to the next Bresenham’s algorithm is the midpoint algorithm for lines –Other midpoint algorithms for conic sections (circles, ellipses)

3/2/04© University of Wisconsin, CS559 Spring 2004 yiyi y i +1 x i +1 Midpoint Methods Consider the midpoint between (x i +1,y i +1) and (x i +1,y i ) If it’s above the line, we choose (x i +1,y i ), otherwise we choose (x i +1,y i +1) xixi Choose (x i +1,y i ) yiyi y i +1 x i +1xixi Choose (x i +1,y i +1)

3/2/04© University of Wisconsin, CS559 Spring 2004 Midpoint Decision Variable Write the line in implicit form: The value of F(x,y) tells us where points are with respect to the line –F(x,y)=0: the point is on the line –F(x,y)<0: The point is above the line –F(x,y)>0: The point is below the line The decision variable is the value of d i = 2F(x i +1,y i +0.5) –The factor of two makes the math easier

3/2/04© University of Wisconsin, CS559 Spring 2004 What Can We Decide? d i negative => next point at (x i +1,y i ) d i positive => next point at (x i +1,y i +1) At each point, we compute d i and decide which pixel to draw How do we update it? What is d i+1 ?

3/2/04© University of Wisconsin, CS559 Spring 2004 Updating The Decision Variable d k+1 is the old value, d k, plus an increment: If we chose y i+1 =y i +1: If we chose y i+1 =y i : What is d 1 (assuming integer endpoints)? Notice that we don’t need c any more

3/2/04© University of Wisconsin, CS559 Spring 2004 Bresenham’s Algorithm For integers, slope between 0 and 1: –x=x 1, y=y 1, d=2dy - dx, draw (x, y) –until x=x 2 x=x+1 If d>0 then { y=y+1, draw (x, y), d=d+2  y - 2  x } If d<0 then { y=y, draw (x, y), d=d+2  y } Compute the constants (2  y-2  x and 2  y ) once at the start –Inner loop does only adds and comparisons Floating point has slightly more difficult initialization, but is otherwise the same Care must be taken to ensure that it doesn’t matter which order the endpoints are specified in (make a uniform decision if d==0)

3/2/04© University of Wisconsin, CS559 Spring 2004 Midterm Info March 11 in class All material up to exam time –Topics list will be posted online –Look at summary at start of each lecture Allowed: –Pencil/pen, ruler –One sheet of letter (standard) sized paper, with anything on it, both sides Nothing to increase the surface area Not allowed: –Calculator, anything else