Clipping - PowerPoint PPT Presentation

1 / 28
About This Presentation
Title:

Clipping

Description:

Clipping CS418 Computer Graphics John C. Hart – PowerPoint PPT presentation

Number of Views:95
Avg rating:3.0/5.0
Slides: 29
Provided by: John1698
Category:

less

Transcript and Presenter's Notes

Title: Clipping


1
Clipping
  • CS418 Computer Graphics
  • John C. Hart

2
Graphics Pipeline
ModelCoords
ModelXform
WorldCoords
ViewingXform
ViewingCoords
StillClipCoords.
Clipping
ClipCoords.
Homogeneous Divide
Window Coordinates
Window to Viewport
Viewport Coordinates
3
Why Clip?
  • Why not just transform all triangles to the
    screen and just ignore pixels off the screen?
  • Takes time to rasterize a triangle
  • Very small number of triangles fall within the
    viewing frustum
  • Output may not go directly to screen

4
Outcodes
1000
1001
1010
y top
  • Cohen-Sutherland
  • Assign segment endpoints a bitcode
  • b3b2b1b0
  • b0 x lt left
  • b1 x gt right
  • b2 y lt bottom
  • b3 y gt top
  • Let o0 outcode(x0,y0), o1 outcode(x1,y1)
  • o0 o1 0 segment visible
  • o0 0, o1 ? 0 segment must be clipped

0001
0010
0000
y bottom
0100
0101
0110
x left
x right
5
Outcodes
1000
1001
1010
y top
  • Cohen-Sutherland
  • Assign segment endpoints a bitcode
  • b3b2b1b0
  • b0 x lt left
  • b1 x gt right
  • b2 y lt bottom
  • b3 y gt top
  • Let o0 outcode(x0,y0), o1 outcode(x1,y1)
  • o0 o1 0 segment visible
  • o0 0, o1 ? 0 segment must be clipped

0001
0010
0000
y bottom
0100
0101
0110
x left
x right
6
Outcodes
1000
1001
1010
y top
  • Cohen-Sutherland
  • Assign segment endpoints a bitcode
  • b3b2b1b0
  • b0 x lt left
  • b1 x gt right
  • b2 y lt bottom
  • b3 y gt top
  • Let o0 outcode(x0,y0), o1 outcode(x1,y1)
  • o0 o1 0 segment visible
  • o0 0, o1 ? 0 segment must be clipped
  • o0 o1 ? 0 segment can be ignored

0001
0010
0000
y bottom
0100
0101
0110
x left
x right
7
Outcodes
1000
1001
1010
y top
  • Cohen-Sutherland
  • Assign segment endpoints a bitcode
  • b3b2b1b0
  • b0 x lt left
  • b1 x gt right
  • b2 y lt bottom
  • b3 y gt top
  • Let o0 outcode(x0,y0), o1 outcode(x1,y1)
  • o0 o1 0 segment visible
  • o0 0, o1 ? 0 segment must be clipped
  • o0 o1 ? 0 segment can be ignored
  • o0 o1 0 segment might need clipping

0001
0010
0000
y bottom
0100
0101
0110
x left
x right
8
Outcodes
1000
1001
1010
y top
  • Cohen-Sutherland
  • Assign segment endpoints a bitcode
  • b3b2b1b0
  • b0 x lt left
  • b1 x gt right
  • b2 y lt bottom
  • b3 y gt top
  • Let o0 outcode(x0,y0), o1 outcode(x1,y1)
  • o0 o1 0 segment visible
  • o0 0, o1 ? 0 segment must be clipped
  • o0 o1 ? 0 segment can be ignored
  • o0 o1 0 segment might need clipping

0001
0010
0000
y bottom
0100
0101
0110
x left
x right
9
Intersecting Lines
tgt1
t1
(x1,y1)
t0
(x(t),y(t))
tlt0
  • Parametric representation of a line segment
  • x(t) x0 t (x1 x0)
  • y(t) y0 t (y1 y0)

(x0,y0)
10
Intersecting Lines
(x1,y1)
y top
  • Parametric representation of a line segment
  • x(t) x0 t (x1 x0)
  • y(t) y0 t (y1 y0)
  • Plug in clipping window edge to find t
  • top y0 t (y1 y0)
  • t (top y0)/(y1 y0)

(x0,y0)
11
Serial Clipping
1000
1001
1010
y top
0001
0010
y bottom
0100
0101
0110
x left
x right
12
Serial Clipping
1000
1001
1010
y top
  • First clip 0001
  • Move (x0,y0) to (left,)

0001
0010
y bottom
0100
0101
0110
x left
x right
13
Serial Clipping
1000
1001
1010
y top
  • First clip 0001
  • Move (x0,y0) to (left,)
  • Then clip 0010
  • Move (x1,y1) to (right,)

0001
0010
y bottom
0100
0101
0110
x left
x right
14
Serial Clipping
1000
1001
1010
y top
  • First clip 0001
  • Move (x0,y0) to (left,)
  • Then clip 0010
  • Move (x1,y1) to (right,)
  • Then clip 0100
  • Move (x0,y0) again, now to (,bottom)

0001
0010
y bottom
0100
0101
0110
x left
x right
15
Serial Clipping
1000
1001
1010
y top
  • First clip 0001
  • Move (x0,y0) to (left,)
  • Then clip 0010
  • Move (x1,y1) to (right,)
  • Then clip 0100
  • Move (x0,y0) again, now to (,bottom)
  • Finally clip 1000
  • Move (x1,y1) again, now to (,top)

0001
0010
y bottom
0100
0101
0110
x left
x right
16
Parametric Clipping
tright
ttop
y top
  • Cohen-Sutherland iterates through each edge
    intersection and computes them even if they are
    later clipped
  • Liang-Barsky computes all at once postponing
    division to end
  • Unless a line is horizontal or verticalit
    intersects all four clipping planes
  • Compute all four intersections

tbottom
y bottom
tleft
x left
x right
tleft (left x0) / (x1 x0) tright (right
x0) / (x1 x0) tbottom (bottom y0) / (y1
y0) ttop (top y0) / (y1 y0)
17
Parametric Clipping
(x1,y1)
tright
ttop
y top
  • Cohen-Sutherland iterates through each edge
    intersection and computes them even if they are
    later clipped
  • Liang-Barsky computes all at once postponing
    division to end
  • Unless a line is horizontal or verticalit
    intersects all four clipping planes
  • Compute oriented numerators and denominators of
    all four intersections
  • Sign of denominator
  • positive ? entering
  • negative ? leaving

tbottom
y bottom
tleft
(x0,y0)
x left
x right
tleft (left x0) / (x1 x0) tright -(right
x0) / -(x1 x0) tbottom (bottom y0) /
(y1 y0) ttop -(top y0) / -(y1 y0)
18
Parametric Clipping
(x1,y1)
tright
ttop
y top
  • Compute ordered list of t-intersections
  • 0 lt tleft lt tbottom lt ttop lt tright lt 1

tbottom
y bottom
tleft
(x0,y0)
x left
x right
tleft (left x0) / (x1 x0) tright -(right
x0) / -(x1 x0) tbottom (bottom y0) /
(y1 y0) ttop -(top y0) / -(y1 y0)
19
Parametric Clipping
(x1,y1)
leave
leave
y top
  • Compute ordered list of t-intersections
  • 0 lt tleft lt tbottom lt ttop lt tright lt 1
  • And corresponding orientations
  • enter, enter, leave, leave

y bottom
enter
enter
(x0,y0)
x left
x right
tleft (left x0) / (x1 x0) tright -(right
x0) / -(x1 x0) tbottom (bottom y0) /
(y1 y0) ttop -(top y0) / -(y1 y0)
20
Parametric Clipping
(x1,y1)
leave
y top
  • Compute ordered list of t-intersections
  • 0 lt tleft lt tbottom lt ttop lt tright lt 1
  • And corresponding orientations
  • enter, enter, leave, leave
  • Keep only the ltenter,leavegt pair

y bottom
enter
(x0,y0)
x left
x right
tleft (left x0) / (x1 x0) tright -(right
x0) / -(x1 x0) tbottom (bottom y0) /
(y1 y0) ttop -(top y0) / -(y1 y0)
21
Polygon Clipping
C
y top
  • Sutherland-Hodgman
  • Polygon ABC

y bottom
A
B
x left
x right
22
Polygon Clipping
C
y top
  • Sutherland-Hodgman
  • Polygon ABC
  • Clip left A1BCA2

A2
y bottom
B
A
A1
x left
x right
23
Polygon Clipping
C
y top
  • Sutherland-Hodgman
  • Polygon ABC
  • Clip left A1BCA2
  • Clip right A1B1B2CA2

A2
B2
y bottom
B
B1
A1
x left
x right
24
Polygon Clipping
C
y top
  • Sutherland-Hodgman
  • Polygon ABC
  • Clip left A1BCA2
  • Clip right A1B1B2CA2
  • Clip bottom A1B1B2CA2

A2
B2
y bottom
A1
B1
B1
A1
x left
x right
25
Polygon Clipping
C
C2
C1
y top
  • Sutherland-Hodgman
  • Polygon ABC
  • Clip left A1BCA2
  • Clip right A1B1B2CA2
  • Clip bottom A1B1B2CA2
  • Clip top A1B1B2C1C2A2

A2
B2
y bottom
A1
B1
B1
A1
x left
x right
26
Concave Clipping
  • Sutherland-Hodgman
  • Clip segments even if they are trivially
    rejectible (rejectionable?)
  • Outputs a single polygon that appears as multiple
    polygons
  • Reversed edges dont get filled

27
Clipping in 3-D (4-D)
  • Need to keep depth (z-coordinate) of geometry for
    visible surface detection
  • Generalize oriented screen edge to oriented
    clipping plane C (A,B,C,D)
  • Then any homogeneous pointP (x,y,z,w)T
    classified as
  • on if C P 0
  • in if C P gt 0
  • out if C P lt 0

(A,B,C)
Ax By Cz D 0 ?? wAx wBy wCz wD 0
28
Graphics Pipeline
ModelCoords
ModelXform
WorldCoords
ViewingXform
ViewingCoords
StillClipCoords.
Clipping
ClipCoords.
Homogeneous Divide
Window Coordinates
Window to Viewport
Viewport Coordinates
Write a Comment
User Comments (0)
About PowerShow.com