computer graphics
play

Computer Graphics Si Lu Fall 2017 - PowerPoint PPT Presentation

Computer Graphics Si Lu Fall 2017 http://web.cecs.pdx.edu/~lusi/CS447/CS447_547_Comp uter_Graphics.htm 10/23/2017 Last time o Graphics Pipeline 2 Today o Clipping o In-class Middle-Term n Wednesday, Nov. 1 n Close-book exam n Notes on 1 page


  1. Computer Graphics Si Lu Fall 2017 http://web.cecs.pdx.edu/~lusi/CS447/CS447_547_Comp uter_Graphics.htm 10/23/2017

  2. Last time o Graphics Pipeline 2

  3. Today o Clipping o In-class Middle-Term n Wednesday, Nov. 1 n Close-book exam n Notes on 1 page of A4 or Letter size paper n To-know list available online 3

  4. Clipping o Parts of the geometry to be rendered may lie outside the view volume o Clipping removes parts of the geometry that are outside the view o Best done in canonical space before perspective divide n Before dividing out the homogeneous coordinate 4

  5. Clipping Terminology Geometry o Clip region: the region we wish to Clip region restrict the output to o Geometry: the thing we are clipping n Only those parts of the geometry that lie inside the clip region will be output o Clipping edge/plane: an infinite line or plane and we want to output only the geometry on one side of it n Frequently, one edge or face of the clip region Output 5

  6. Clipping o In hardware, clipping is done in canonical space before perspective divide Before dividing out the homogeneous coordinate n o Clipping is useful in many other applications Building BSP trees for visibility and spatial data structures n n Hidden surface removal algorithms Removing hidden lines in line drawings n n Finding intersection/union/difference of polygonal regions 2D drawing programs: cropping, arbitrary clipping n o We will make explicit assumptions about the geometry and the clip region n Assumption depend on the algorithm 6

  7. Types of Geometry o Points are clipped via inside/outside tests Many algorithms for this task, depending on the clip region n o Two main algorithms for clipping polygons exist n Sutherland-Hodgman n Weiler that we will not talk about in our class 7

  8. Clipping Points to View Volume o A point is inside the view volume if it is on the “inside” of all the clipping planes The normals to the clip planes are considered to point inward, n toward the visible region o Now we see why clipping is done in canonical view space For instance, to check against the left plane: n X coordinate in 3D must be > -1 n n In homogeneous screen space, same as: x screen > - w screen o In general, a point, p , is “inside” a plane if: n You represent the plane as n x x+n y y+n z z+d=0 , with ( n x ,n y ,n z ) pointing inward n And n x p x +n y p y +n z p z +d>0 8

  9. Clipping Point to Line 1 -x-y+1=0 (0.4, 0.4) 0 1 9

  10. Sutherland-Hodgman Clip o Clip polygons to convex clip regions o Clip the polygon against each edge of the clip region in turn n Clip polygon each time to line containing edge n Only works for convex clip regions (Why? Example that breaks?) 10

  11. Sutherland-Hodgman Clip (2) p 2 o To clip a polygon to a line/plane: Consider the polygon as a list of vertices n p 3 p 1 One side of the line/plane is considered n inside the clip region, the other side is p 4 outside p 0 n We are going to rewrite the polygon one p 0 p 1 p 2 p 3 p 4 vertex at a time – the rewritten polygon will be the polygon clipped to the line/plane point point n Check start vertex: if “inside”, emit it, Clipper s in s out otherwise ignore it n Continue processing vertices as follows… 11

  12. Sutherland-Hodgman (3) Inside Outside Inside Outside Inside Outside Inside Outside p s i s p p s i p s Output p Output i No output Output i and p 12

  13. Sutherland-Hodgman (4) o Look at the next vertex in the list, p, and the edge from the last vertex, s, to p. If the… polygon edge crosses the clip line/plane going from out to in: n emit crossing point, i, next vertex, p n polygon edge crosses clip line/plane going from in to out: emit crossing, i n polygon edge goes from out to out: emit nothing n polygon edge goes from in to in: emit next vertex, p 13

  14. Inside-Outside Testing    n (s x) 0 o Lines/planes store a vector pointing toward the inside of    n (i x) 0 the clip region – the inward pointing normal    n (f x) 0 n Could re-define for outward pointing Outside Inside Dot products give o x n inside/outside information f o Note that x (a vector) is any point on the clip line/plane i s

  15. Finding Intersection Pts o Use the parametric form for the edge between two points, x 1 and x 2 :      x ( t ) x ( x x ) t 0 t 1 1 2 1 o For planes of the form x=a :   ( y y ) ( z z )      x ( a , y 2 1 ( a x ), z 2 1 ( a x )) i 1 1 1 1   ( x x ) ( x x ) 2 1 2 1 o Similar forms for y=a, z=a o Solution for general plane can also be found

  16. Inside/Outside in Screen Space o In canonical view space, clip planes are x s =± 1 , y s =± 1 , z s =± 1 o Inside/Outside reduces to comparisons before perspective divide    w x w s s s    w y w s s s    w z w s s s 16

  17. Clipping Lines o Lines can also be clipped by Sutherland-Hodgman Slower than necessary, unless you already have hardware n o Better algorithms exist n Cohen-Sutherland n Liang-Barsky Nicholl-Lee-Nicholl (we won’t cover this one – only good for n 2D) 17

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

  19. Cohen-Sutherland (2) 1 2 1 2 3 3 4 4 3 3 4 4 1 2 1 2 19

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

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

  22. Parametric Clipping o Recall, points inside a convex region are inside all clip planes o Parametric clipping finds the values of t , the parameter, that correspond to points inside the clip region Consider a rectangular clip region o Top, y =y max Left, x=x min Right, x=x max Bottom, y=y min 22

  23. Parametric Intersection o Consider line to be infinite o Find parametric intersections t right t top t left t bottom

  24. Entering and Leaving entering o Recall, a point is inside a view volume if it is on the inside of every clip edge/plane o Consider the left clip edge and the infinite line. Two cases: t<t left is inside, t>t left is outside  n leaving inside t<t left is outside, t>t left is inside  n entering o To be inside a clip plane we either: n Started inside, and have not left yet leaving n Started outside, and have entered Clip edge 24

  25. Entering/Leaving Example o To be inside the clip region, you must have entered every clip edge before you have left any clip edge Leave Enter Leave Leave Leave Enter Enter Enter 25

  26. When are we Inside? o We want parameter values that are inside all the clip planes o Any clip plane that we started inside we must not have left yet First parameter value to leave is the end of the visible n segment o Any clip plane that we started outside we must have already entered Last parameter value to enter is the start of the visible n segment o If we leave some clip plane before we enter another, we cannot see any part of the line o All this leads to an algorithm – Liang-Barsky 26

  27. Liang-Barsky Sub-Tasks 1. Find parametric intersection points n Parameter values where line crosses each clip edge/plane 2. Find entering/leaving flags n For every clip edge/plane, are either entering or leaving 3. Find last parameter to enter, and first one to leave n Check that enter before leave 4. Convert these into endpoints of clipped segment 27

  28. 1. Parametric Intersection    o Segment goes from ( x 1 , y 1 ) to ( x 2 , y 2 ): x x x 2 1    y y y 2 1 o Rectangular clip region with x min , x max , y min , y max o Infinite line intersects rectangular clip region edges when:      p x q x x left left 1 min q     p x q x x t  k where right right max 1 k p      p y q y y k bottom bottom 1 min     p y q y y top top max 1 28

  29. 2. Entering or Leaving?    p x o When p k <0, as t increases line goes from left outside to inside – entering   p x right o When p k >0, line goes from inside to    p y bottom outside – leaving   p y top o When p k =0, line is parallel to an edge n Special case: one endpoint outside, no part of segment visible, otherwise, ignore this clip edge and continue 29

Recommend


More recommend