10/15/02 (c) 2002 University of Wisconsin, CS559 Last Time Clipping.

Slides:



Advertisements
Similar presentations
CS 376 Introduction to Computer Graphics 02 / 02 / 2007 Instructor: Michael Eckmann.
Advertisements

Computer Graphics 4: Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling By:Kanwarjeet Singh.
CS 450: COMPUTER GRAPHICS REVIEW: DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
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.
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.
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)
Viewing & Clipping In 2D. 2 of 44 Contents Windowing Concepts Clipping –Introduction –Brute Force –Cohen-Sutherland Clipping Algorithm Area Clipping –Sutherland-Hodgman.
Introduction to Computer Graphics Chapter 6 – 2D Viewing Pt 2 1.
Different types of Polygons Simple Convex Simple Concave Non-simple : self-intersecting With holes ConvexConcaveSelf-intersecting.
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.
CS5500 Computer Graphics © Chun-Fa Chang, Spring 2007 CS5500 Computer Graphics May 3, 2007.
Implementation III Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
1 CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai.
Rasterization Foley, Ch: 3. Pixels are represented as disjoint circles centered on uniform grid Each (x,y) of the grid has a pixel Y X (1,1) (1,2) (0,0)
Graphics Pipeline Rasterization CMSC 435/634. Drawing Terms Primitive – Basic shape, drawn directly – Compare to building from simpler shapes Rasterization.
TOPIC 4 PART III FILL AREA PRIMITIVES POLYGON FILL AREAS CGMB214: Introduction to Computer Graphics.
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.
CGMB 314 Intro to Computer Graphics Fill Area Primitives.
Dr. Scott Schaefer Scan Conversion of Lines. 2/78 Displays – Cathode Ray Tube.
1 CS 430/536 Computer Graphics I Circle Drawing and Clipping Week 3, Lecture 6 David Breen, William Regli and Maxim Peysakhov Geometric and Intelligent.
Jehee Lee Seoul National University
WHERE TO DRAW A LINE?? Line drawing is accomplished by calculating intermediate positions along the line path between specified end points. Precise definition.
Scan Conversion Line and Circle
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:
Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 121 Today’s class Drawing lines Bresenham’s algorithm Compositing Polygon filling.
Triangle Scan Conversion. 2 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Rasterization Rasterization (scan conversion) –Determine which.
College of Computer and Information Science, Northeastern UniversityOctober 12, CS G140 Graduate Computer Graphics Prof. Harriet Fell Spring 2006.
1Computer Graphics Implementation III Lecture 17 John Shearer Culture Lab – space 2
Introduction to Computer Graphics with WebGL
CS 480/680 Computer Graphics Implementation III Dr. Frederick C Harris, Jr. Fall 2011.
10/26/04© University of Wisconsin, CS559 Fall 2004 Last Time Drawing lines Polygon fill rules Midterm Oct 28.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
MIDPOINT CIRCLE & ELLIPSE GENERARTING ALGORITHMS
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.
CS 325 Introduction to Computer Graphics 02 / 03 / 2010 Instructor: Michael Eckmann.
1 CSCE 441 Lecture 2: Scan Conversion of Lines Jinxiang Chai.
Scan Conversion.
Computer Graphics CC416 Week 14 Filling Algorithms.
Computer Graphics Lecture 08 Taqdees A. Siddiqi Computer Graphics Filled Area Primitives I Lecture 08 Taqdees A. Siddiqi
Computer Graphics CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014.
Computer Graphics I, Fall 2010 Scan conversion algorithms.
Rasterization, or “What is glBegin(GL_LINES) really doing?” Course web page: February 23, 2012  Lecture 4.
CS G140 Graduate Computer Graphics
(c) 2002 University of Wisconsin, CS559
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
University of New Mexico
Implementation III.
Chapter Three Part I Output Primitives CS 380.
Introduction to Computer Graphics with WebGL
© University of Wisconsin, CS559 Fall 2004
Scan Conversion of Circles
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
Lecture 13 Clipping & Scan Conversion
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
Computer Graphics Implementation III
© University of Wisconsin, CS559 Fall 2004
(c) 2002 University of Wisconsin, CS559
(c) 2002 University of Wisconsin, CS559
© University of Wisconsin, CS559 Fall 2004
Clipping Polygons Dr. Scott Schaefer.
Chapter 3 Graphics Output Primitives
Where We Stand At this point we know how to: Next thing:
Implementation III Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

10/15/02 (c) 2002 University of Wisconsin, CS559 Last Time Clipping

10/15/02 (c) 2002 University of Wisconsin, CS559 Today Homework 3 due Line drawing Polygon filling Next time: Midterm –Web page has details –Note that you are allowed one page (double sided) of anything

10/15/02 (c) 2002 University of Wisconsin, CS559 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

10/15/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

10/15/02 (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

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

10/15/02 (c) 2002 University of Wisconsin, CS559 Changes to Rearranging pointers makes it possible to enumerate all components of the intersection

10/15/02 (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

10/15/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

10/15/02 (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

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

10/15/02 (c) 2002 University of Wisconsin, CS559 Changes to Rearranging pointers makes it possible to enumerate all components of the intersection

10/15/02 (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

10/15/02 (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 What function are we sampling with?

10/15/02 (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”) –Sampling theory?

10/15/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:

10/15/02 (c) 2002 University of Wisconsin, CS559 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)

10/15/02 (c) 2002 University of Wisconsin, CS559 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)

10/15/02 (c) 2002 University of Wisconsin, CS559 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

10/15/02 (c) 2002 University of Wisconsin, CS559 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 ?

10/15/02 (c) 2002 University of Wisconsin, CS559 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

10/15/02 (c) 2002 University of Wisconsin, CS559 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)

10/15/02 (c) 2002 University of Wisconsin, CS559 Example: (2,2) to (7,6)  x=5,  y=4 xyd

10/15/02 (c) 2002 University of Wisconsin, CS559 Filling polygons Sampling polygons: –When is a pixel inside a polygon? –Given a pixel, which polygon does it lie in? Point location Polygon representation: –Polygon defined by a list of edges - each is a pair of vertices –All vertices are inside the view volume and map to valid pixels. (Clipping gave us this.) Also, assume integers in window coordinates to simplify things for now

10/15/02 (c) 2002 University of Wisconsin, CS559 What is inside - 1? Easy for simple polygons - no self intersections or holes –OpenGL requires these. Undefined for other cases –OpenGL also requires convex polygons For general polygons, three rules are possible: –Non-exterior rule: A point is inside if every ray to infinity intersects the polygon –Non-zero winding number rule: Draw a ray to infinity that does not hit a vertex, if the number of edges crossing in one direction is not equal to the number crossing the other way, the point is inside –Parity rule: Draw a ray to infinity and count the number or edges that cross it. If even, the point is outside, if odd, it’s inside

10/15/02 (c) 2002 University of Wisconsin, CS559 Polygon ParityNon-zero Winding No. Non-exterior Inside/Outside Rules