Download presentation
Presentation is loading. Please wait.
Published byJade Simon Modified over 9 years ago
1
10/15/02 (c) 2002 University of Wisconsin, CS559 Last Time Clipping
2
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
3
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
4
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
5
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
6
10/15/02 (c) 2002 University of Wisconsin, CS559 Weiler Algorithm (1)
7
10/15/02 (c) 2002 University of Wisconsin, CS559 Changes to Rearranging pointers makes it possible to enumerate all components of the intersection
8
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
9
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
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
11
10/15/02 (c) 2002 University of Wisconsin, CS559 Weiler Algorithm (1)
12
10/15/02 (c) 2002 University of Wisconsin, CS559 Changes to Rearranging pointers makes it possible to enumerate all components of the intersection
13
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
14
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?
15
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?
16
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:
17
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)
18
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)
19
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
20
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 ?
21
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
22
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)
23
10/15/02 (c) 2002 University of Wisconsin, CS559 Example: (2,2) to (7,6) x=5, y=4 xyd 1 23456781 2 3 4 5 6 7
24
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
25
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
26
10/15/02 (c) 2002 University of Wisconsin, CS559 Polygon ParityNon-zero Winding No. Non-exterior Inside/Outside Rules
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.