CS 445 / 645: Introductory Computer Graphics - PowerPoint PPT Presentation

1 / 35
About This Presentation
Title:

CS 445 / 645: Introductory Computer Graphics

Description:

CS 445 / 645: Introductory Computer Graphics Clipping Lines and Polygons Review: Polygon Rasterization Review: Active Edge Table Two data structures Edge Table Array ... – PowerPoint PPT presentation

Number of Views:127
Avg rating:3.0/5.0
Slides: 36
Provided by: virgi89
Category:

less

Transcript and Presenter's Notes

Title: CS 445 / 645: Introductory Computer Graphics


1
CS 445 / 645 Introductory Computer Graphics
  • Clipping Lines and Polygons

2
Review Polygon Rasterization
For scanline, determine all intersections of
polygon edges with scanline Sort edge
intersections in least to greatest order Use
parity count to determine when pixels are
drawn Horizontal lines do not contribute to
parity count Ymin endpoints do contribute to
parity count Ymax endpoints do not contribute to
parity count
Not drawn because H is max of AH And HG does not
contribute
Not drawn because D is min of ED And increments
counter to 2. DC doesnt contribute
Bottom edge drawn because A is min of AH. AB
does not contribute
3
Review Active Edge Table
  • Two data structures
  • Edge Table
  • Array of pointers, A, of length (screen height)
  • Ai points to linked list of all edges with ymin
    I
  • Edges in linked list are ordered according to the
    x coordinate of the ymin vertex
  • Edge in list is represented by ymax, initial x,
    slope (1/m)

4
Review Active Edge Table
  • Linked list of all edges that intersect current
    scanline
  • List must always be sorted on x intersection with
    scanline
  • First add all edges from edge table with smallest
    y
  • Use parity test to fill pixels on scanline
  • Increment scanline
  • Add all edges from edge table with ymin value
    scanline
  • Remove all edges from AET with ymax scanline
  • Update x intersection value of all edges in AET
    and re-sort

5
Review Active Edge Table
6
Review Clipping
  • Cohen-Sutherland
  • Use opcodes to quickly eliminate/include lines
  • Must compute viewport clipping of remaining lines
  • Introduced parametric equations of lines to
    perform edge/viewport intersection tests
  • Truth in advertising, Cohen-Sutherland doesnt
    use parametric equations of lines
  • Viewport intersection code
  • (x1, y1), (x2, y2) intersect with vertical edge
    at xright
  • yintersect y1 m(xright x1),
    m(y2-y1)/(x2-x1)
  • (x1, y1), (x2, y2) intersect with horizontal edge
    at ybottom
  • xintersect x1 (ybottom y1)/m,
    m(y2-y1)/(x2-x1)

7
Review Parametric Equations
  • Faster line clippers use parametric equations
  • Line 0
  • x0 x00 (x01 - x00) t0
  • y0 y00 (y01 - y00) t0
  • Viewport Edge L
  • xL xL0 (xL1 - xL0) tL
  • yL yL0 (yL1 - yL0) tL
  • x00 (x01 - x00) t0 xL0 (xL1 - xL0) tL
  • y00 (y01 - y00) t0 yL0 (yL1 - yL0) tL
  • Solve for t0 and/or tL

8
Cyrus-Beck Algorithm
  • Use parametric equations of lines
  • Optimize
  • We saw that this could be expensive
  • Start with parametric equation of line
  • P(t) P0 (P1 - P0) t
  • And a point and normal for each edge
  • PL, NL

9
Cyrus-Beck Algorithm
  • NL P(t) - PL 0
  • Substitute line equation for P(t)
  • Solve for t
  • t NL P0 - PL / -NL P1 - P0

P1
P0
10
Cyrus-Beck Algorithm
  • Compute t for line intersection with all four
    edges
  • Discard all (t lt 0) and (t gt 1)
  • Classify each remaining intersection as
  • Potentially Entering (PE)
  • Potentially Leaving (PL)
  • NL P1 - P0 gt 0 implies PL
  • NL P1 - P0 lt 0 implies PE
  • Note that we computed this term in when computing
    t

11
Cyrus-Beck Algorithm
  • Compute PE with largest t
  • Compute PL with smallest t
  • Clip to these two points

12
Cyrus-Beck Algorithm
  • Because of horizontal and vertical clip lines
  • Many computations reduce
  • Normals (-1, 0), (1, 0), (0, -1), (0, 1)
  • Pick constant points on edges
  • solution for t
  • -(x0 - xleft) / (x1 - x0)
  • (x0 - xright) / -(x1 - x0)
  • -(y0 - ybottom) / (y1 - y0)
  • (y0 - ytop) / -(y1 - y0)

13
Comparison
  • Cohen-Sutherland
  • Repeated clipping is expensive
  • Best used when trivial acceptance and rejection
    is possible for most lines
  • Cyrus-Beck
  • Computation of t-intersections is cheap
  • Computation of (x,y) clip points is only done
    once
  • Algorithm doesnt consider trivial
    accepts/rejects
  • Best when many lines must be clipped
  • Liang-Barsky Optimized Cyrus-Beck
  • Nicholl et al. Fastest, but doesnt do 3D

14
Clipping Polygons
  • Clipping polygons is more complex than clipping
    the individual lines
  • Input polygon
  • Output original polygon, new polygon, or nothing
  • When can we trivially accept/reject a polygon as
    opposed to the line segments that make up the
    polygon?

15
Why Is Clipping Hard?
  • What happens to a triangle during clipping?
  • Possible outcomes

triangle?quad
triangle?triangle
triangle?5-gon
  • How many sides can a clipped triangle have?

16
Why Is Clipping Hard?
  • A really tough case

17
Why Is Clipping Hard?
  • A really tough case

concave polygon?multiple polygons
18
Sutherland-Hodgeman Clipping
  • Basic idea
  • Consider each edge of the viewport individually
  • Clip the polygon against the edge equation

19
Sutherland-Hodgeman Clipping
  • Basic idea
  • Consider each edge of the viewport individually
  • Clip the polygon against the edge equation
  • After doing all planes, the polygon is fully
    clipped

20
Sutherland-Hodgeman Clipping
  • Basic idea
  • Consider each edge of the viewport individually
  • Clip the polygon against the edge equation
  • After doing all planes, the polygon is fully
    clipped

21
Sutherland-Hodgeman Clipping
  • Basic idea
  • Consider each edge of the viewport individually
  • Clip the polygon against the edge equation
  • After doing all planes, the polygon is fully
    clipped

22
Sutherland-Hodgeman Clipping
  • Basic idea
  • Consider each edge of the viewport individually
  • Clip the polygon against the edge equation
  • After doing all planes, the polygon is fully
    clipped

23
Sutherland-Hodgeman Clipping
  • Basic idea
  • Consider each edge of the viewport individually
  • Clip the polygon against the edge equation
  • After doing all planes, the polygon is fully
    clipped

24
Sutherland-Hodgeman Clipping
  • Basic idea
  • Consider each edge of the viewport individually
  • Clip the polygon against the edge equation
  • After doing all planes, the polygon is fully
    clipped

25
Sutherland-Hodgeman Clipping
  • Basic idea
  • Consider each edge of the viewport individually
  • Clip the polygon against the edge equation
  • After doing all planes, the polygon is fully
    clipped

26
Sutherland-Hodgeman Clipping
  • Basic idea
  • Consider each edge of the viewport individually
  • Clip the polygon against the edge equation
  • After doing all planes, the polygon is fully
    clipped

27
Sutherland-Hodgeman ClippingThe Algorithm
  • Basic idea
  • Consider each edge of the viewport individually
  • Clip the polygon against the edge equation
  • After doing all planes, the polygon is fully
    clipped

28
Sutherland-Hodgeman Clipping
  • Input/output for algorithm
  • Input list of polygon vertices in order
  • Output list of clipped poygon vertices
    consisting of old vertices (maybe) and new
    vertices (maybe)
  • Note this is exactly what we expect from the
    clipping operation against each edge

29
Sutherland-Hodgeman Clipping
  • Sutherland-Hodgman basic routine
  • Go around polygon one vertex at a time
  • Current vertex has position p
  • Previous vertex had position s, and it has been
    added to the output if appropriate

30
Sutherland-Hodgeman Clipping
  • Edge from s to p takes one of four cases
  • (Purple line can be a line or a plane)

31
Sutherland-Hodgeman Clipping
  • Four cases
  • s inside plane and p inside plane
  • Add p to output
  • Note s has already been added
  • s inside plane and p outside plane
  • Find intersection point i
  • Add i to output
  • s outside plane and p outside plane
  • Add nothing
  • s outside plane and p inside plane
  • Find intersection point i
  • Add i to output, followed by p

32
Point-to-Plane test
  • A very general test to determine if a point p is
    inside a plane P, defined by q and n
  • (p - q) n lt 0 p inside P
  • (p - q) n 0 p on P
  • (p - q) n gt 0 p outside P
  • Remember p n p n cos (q)
  • q angle between p and n

q
q
n
n
p
p
P
P
33
Finding Line-Plane Intersections
  • Use parametric definition of edge
  • L(t) L0 (L1 - L0)t
  • If t 0 then L(t) L0
  • If t 1 then L(t) L1
  • Otherwise, L(t) is part way from L0 to L1

34
Finding Line-Plane Intersections
  • Edge intersects plane P where E(t) is on P
  • q is a point on P
  • n is normal to P
  • (L(t) - q) n 0
  • t (q - L0) n / (L1 - L0) n
  • The intersection point i L(t) for this value of
    t

35
Line-Plane Intersections
  • Note that the length of n doesnt affect result
  • Again, lots of opportunity for optimization
Write a Comment
User Comments (0)
About PowerShow.com