Computer Graphics
Si Lu
Fall 2017
http://web.cecs.pdx.edu/~lusi/CS447/CS447_547_Comp uter_Graphics.htm 10/23/2017
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
http://web.cecs.pdx.edu/~lusi/CS447/CS447_547_Comp uter_Graphics.htm 10/23/2017
2
3
n Before dividing out the homogeneous coordinate
4
n Only those parts of the geometry that lie inside the clip region will be output
n Frequently, one edge or face of the clip region
5
Clip region Geometry
Output
n Before dividing out the homogeneous coordinate
n Building BSP trees for visibility and spatial data structures n Hidden surface removal algorithms n Removing hidden lines in line drawings n Finding intersection/union/difference of polygonal regions n 2D drawing programs: cropping, arbitrary clipping
n Assumption depend on the algorithm
6
n Many algorithms for this task, depending on the clip region
n Sutherland-Hodgman n Weiler that we will not talk about in our class
7
n The normals to the clip planes are considered to point inward, toward the visible region
n For instance, to check against the left plane: n X coordinate in 3D must be > -1 n In homogeneous screen space, same as: xscreen> -wscreen
n You represent the plane as nxx+nyy+nzz+d=0, with (nx,ny,nz) pointing inward n And nxpx+nypy+nzpz+d>0
8
9
0 1 1
(0.4, 0.4)
10
n Clip polygon each time to line containing edge n Only works for convex clip regions (Why? Example that breaks?)
11
n Consider the polygon as a list of vertices n One side of the line/plane is considered inside the clip region, the other side is
n We are going to rewrite the polygon one vertex at a time – the rewritten polygon will be the polygon clipped to the line/plane n Check start vertex: if “inside”, emit it,
n Continue processing vertices as follows… p0 p4 p3 p2 p1 p0 p4 p3 p2 p1 Clipper point s in point s out
12
Inside Outside
s p Output p
Inside Outside
s p Output i
Inside Outside
s p No output
Inside Outside
s p Output i and p i i
n polygon edge crosses the clip line/plane going from out to in: 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
pointing toward the inside of the clip region – the inward pointing normal
n Could re-define for outward pointing
inside/outside information
point on the clip line/plane
Outside Inside n s f i x
1 2 1
1 1 2 1 2 1 1 1 2 1 2 1
i
16
s s s s s s s s s
n Slower than necessary, unless you already have hardware
n Cohen-Sutherland n Liang-Barsky n Nicholl-Lee-Nicholl (we won’t cover this one – only good for 2D)
17
n Was developed earlier
n If both endpoints outside, discard line and stop n If both endpoints in, continue to next edge (or finish) n If one in, one out, chop line at crossing pt and continue
18
19
1 2 3 4 1 2 3 4 3 4 1 2 3 4 1 2
edge, 1 if out, 0 if in.
n
n
n
1 2 3 4 0010 0101
n Parametric form: x = x1+(x2-x1)t n t[0,1] are points between x1 and x2
n Computing intersection vertices is most expensive part of clipping n Cohen-Sutherland may compute intersection vertices that are later clipped off, and hence don’t contribute to the final answer
21
correspond to points inside the clip region
22
Left, x=xmin Right, x=xmax Bottom, y=ymin Top, y =ymax
tbottom tleft ttop tright
it is on the inside of every clip edge/plane
n t<tleft is inside, t>tleft is outside leaving n t<tleft is outside, t>tleft is inside entering
n Started inside, and have not left yet n Started outside, and have entered
24
Clip edge inside entering leaving
25
Enter Enter Leave Leave Enter Leave Enter Leave
edge before you have left any clip edge
n First parameter value to leave is the end of the visible segment
entered n Last parameter value to enter is the start of the visible segment
see any part of the line
26
n Parameter values where line crosses each clip edge/plane
n For every clip edge/plane, are either entering or leaving
n Check that enter before leave
27
28
1 2 1 2
k k k
1 max min 1 1 max min 1
top top bottom bottom right right left left
where
29
top bottom right left
30
n E.g. Perspective view volume in world or view coordinates
31
Near Far Left Right
32
n Determine which side of each clip plane the segment endpoints lie n Use the cross product n What do we know if (x1 - e) (xleft - e) > 0 ? n Other cross products give other information
n Stop here if we can, otherwise…
33
34
y y y y y left y x x x x x left x
, 1 , 2 , 1 , , 1 , 2 , 1 ,
n Consider clip edges as non-infinite segments n Look at all intersecting ts between 0 and 1
35