Presentation is loading. Please wait.

Presentation is loading. Please wait.

10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.

Similar presentations


Presentation on theme: "10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework."— Presentation transcript:

1 10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework 4, due Oct 26 in class

2 10/19/04© University of Wisconsin, CS559 Fall 2004 Midterm Info October 28 in class All material listed in online “to-know” list 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

3 10/19/04© University of Wisconsin, CS559 Fall 2004 Today Liang-Barsky Details Weiler-Atherton clipping algorithm Drawing points and lines

4 10/19/04© University of Wisconsin, CS559 Fall 2004 Liang-Barsky Intuition To be inside the clip region, you must have entered every clip edge before you have left any clip edge Enter Leave Enter Leave Enter Leave

5 10/19/04© University of Wisconsin, CS559 Fall 2004 When are we Inside? We want parameter values that are inside all the clip 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 –First to leave will be before last to enter All this leads to an algorithm – Liang-Barsky

6 10/19/04© University of Wisconsin, CS559 Fall 2004 Liang-Barsky Sub-Tasks 1.Find parametric intersection points –Parameter values where line crosses each clip edge/plane 2.Find entering/leaving flags –For every clip edge/plane, are either entering or leaving 3.Find last parameter to enter, and first one to leave –Check that enter before leave 4.Convert these into endpoints of clipped segment

7 10/19/04© University of Wisconsin, CS559 Fall 2004 1. Parametric Intersection Segment goes from (x 1,y 1 ) to (x 2,y 2 ): Rectangular clip region with x min, x max, y min, y max Infinite line intersects rectangular clip region edges when: where

8 10/19/04© University of Wisconsin, CS559 Fall 2004 2. 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 –Special case: one endpoint outside, no part of segment visible, otherwise, ignore this clip edge and continue

9 10/19/04© University of Wisconsin, CS559 Fall 2004 Find Visible Segment ts Last parameter is enter is t small =max(0, entering t’s) First parameter is leave is t large =min(1, leaving t’s) If t small >t large, there is no visible segment If t small <t large, there is a line segment –Compute endpoints by substituting t values into parametric equation for the line segment Improvement (and actual Liang-Barsky): –compute t’s for each edge in turn (some rejects occur earlier like this)

10 10/19/04© University of Wisconsin, CS559 Fall 2004 General Liang-Barsky Liang-Barsky works for any convex clip region –E.g. Perspective view volume in world or view coordinates Require a way to perform steps 1 and 2 1.Compute intersection t for all clip lines/planes 2.Label them as entering or exiting Near Far Left Right

11 10/19/04© University of Wisconsin, CS559 Fall 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

12 10/19/04© University of Wisconsin, CS559 Fall 2004 First Step Compute inside/outside for endpoints of the line segment –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…

13 10/19/04© University of Wisconsin, CS559 Fall 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

14 10/19/04© University of Wisconsin, CS559 Fall 2004 General Clipping Liang-Barsky can be generalized to clip line segments to arbitrary polygonal clip regions –Consider clip edges as non-infinite segments –Look at all intersecting ts between 0 and 1 Clipping general polygons against general clip regions is quite hard: Weiler-Atherton algorithm –Start with polygons as lists of vertices –Replace crossing points with vertices –Double all edges and form linked lists of edges –Adjust links at crossing vertices –Enumerate polygon patches

15 10/19/04© University of Wisconsin, CS559 Fall 2004 Weiler-Atherton – Form Lists Original Polygons Double Linked Lists - outside and inside lists

16 10/19/04© University of Wisconsin, CS559 Fall 2004 Weiler-Atherton – Find Crossings Crossing vertices added – links re-written

17 10/19/04© University of Wisconsin, CS559 Fall 2004 Weiler-Atherton – Enumerate “Not clip not poly”“Clip not Poly” “Clip and Poly” Every link used once “Poly not Clip”

18 10/19/04© University of Wisconsin, CS559 Fall 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 to fill for any given point, line or polygon

19 10/19/04© University of Wisconsin, CS559 Fall 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?

20 10/19/04© University of Wisconsin, CS559 Fall 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?

21 10/19/04© University of Wisconsin, CS559 Fall 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, modify for real numbers 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:

22 10/19/04© University of Wisconsin, CS559 Fall 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)


Download ppt "10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework."

Similar presentations


Ads by Google