Computer Graphics - PowerPoint PPT Presentation

1 / 24
About This Presentation
Title:

Computer Graphics

Description:

Edge data can be explicitly or implicitly represented in a data structure ... Cyrus-Beck (1978) Somewhat different from Cohen-Sutherland ... – PowerPoint PPT presentation

Number of Views:106
Avg rating:3.0/5.0
Slides: 25
Provided by: billj2
Category:

less

Transcript and Presenter's Notes

Title: Computer Graphics


1
Computer Graphics
  • 2D GraphicsPolygons

2
Polygons
  • Generally represented as vertex and edge data
  • Edge data can be explicitly or implicitly
    represented in a data structure
  • Explicit - list of vertices (x,y) and a list of
    edges (v1,v2) no order required
  • Implicit - list of vertices in either clockwise
    or counter-clockwise order

3
PolygonsExplicit data structure
  • Edges
  • 1, 4
  • 4, 3
  • 3, 2
  • 2, 5
  • 5, 1

V3
  • Vertices
  • 4, 3
  • -2, -4
  • -4, 4
  • 0, 2
  • 2, -4

V1
V4
V2
V5
4
PolygonsImplicit data structure
V3
  • Vertices
  • 4, 3
  • 0, 2
  • -4, 4
  • -2, -4
  • 2, -4

V1
V2
V4
V5
5
Filling shapes
  • Shapes are generally filled by setting each
    pixel, for a given scan-line, from xmin to xmax
  • Spans reflect spatial coherence - primitives
    often do not change from pixel to pixel or from
    scan line to scan line

6
Filling shapes
Span coherence - all pixels on a span are set to
the same value
Edge coherence - all pixels on an edge are set to
the same value
7
Filling polygons
  • Scanline algorithm - How to ...
  • Find the intersections between each scan lines
    and all of the edges
  • Sort the intersections by Y, and then by X
  • Set all pixels between pairs of intersections
    that lie interior to the polygon

8
Filling polygons
  • In order to insure that pixels on shared edges
    are not often set twice
  • Only choose pixels which are found inside a
    polygon

9
Filling polygons
  • Horizontal edges
  • Ignored as they are automatically drawn due to
    the fact that there are included via other edges

10
Filling polygons
  • A vertex shared by two edges, where the dY does
    not change direction from edge to edge,
  • Need to be addressed only once

11
Filling polygons
  • To accomplish this, one of the two edges needs to
    be foreshortened before being added to the Edge
    Table

12
Edge table
y min
y max
A
x min
6
1/m
5
DA
4
D
3
BA
2
B
1
CD
CB
0
C
  • For each edge, create an edge record consisting
    of ymax, xmin (value for x corresponding to ymin)
    and 1/m
  • Place the each edge record into the sublist
    (bucket) corresponding to the edges ymin

13
Active edge table
y max
x
1/m
  • Set y to the smallest y coordinate with a list in
    the ET
  • Initialize the AET to be empty
  • Repeat until AET and ET are both empty
  • Move edge records from ET to AET where yminy
  • Draw spans using two edge records at a time
  • Remove from AET all edges where ymax y
  • Increment y
  • Increment each x by 1/m

14
Clipping
  • Simultaneous equations
  • Cohen-Sutherland Line-Clipping Algorithm
  • Parametric Line-Clipping Algorithm
  • Circles
  • Sutherland-Hodgman Polygon-Clipping Algorithm

15
Clipping
  • Lines within the clipping rectangle are trivially
    accepted
  • Lines outside the rectangle with respect to one
    halfplane are trivially rejected

Accepted
Rejected
16
Clipping
  • Lines that are neither accepted nor rejected
  • are clipped against the extended edges of the
    clipping rectangle
  • thus creating new endpoints

Accepted
Rejected
17
Simultaneous equations
  • For a given line segment (x0,y0,x1,y1), each
    point in the edge can be described by...
  • x x0 t (x1 - x0)
  • y y0 t (y1 - y0)
  • ...where 0 ? t ? 1

18
Simultaneous equations
  • First, the intersection of the extended clipping
    rectangle edge and the extended line segment is
    determined.
  • Then, this point (x,y) is placed into two pairs
    of simultaneous equations to compute tedge and
    tline
  • If tedge and tline and both in the range 0,1,
    then this is an intersection we wish to clip to

19
Cohen-SutherlandLine-Clipping Algorithm
  • Uses a four-bit code for each of the nine regions
  • 1 0 0 1top-bottom-left-right
  • 1 outside0 inside

1001
1000
1010
0001
0000
0010
0101
0100
0110
20
Cohen-SutherlandLine-Clipping Algorithm
if outCode.top 1 then clip against
top else if outCode.bottom 1 then clip
against bottom else if outCode.right 1
then clip against right else if outCode.left
1 then clip against left code endpoint
p0 if (accept) then draw P0 to P1
  • accept ? false
  • done ? false
  • code endpoints P0 and P1
  • while (not done)
  • if (outCode0 0) and (outCode1 0) then
  • accept ? true
  • done ? true
  • else if (outCode 0 and outCode1) ? 0 then
  • done ? true
  • else if outCode0 0 then
  • swap points and codes

21
ParametricLine-Clipping Algorithm
  • Cyrus-Beck (1978)
  • Somewhat different from Cohen-Sutherland
  • First, pick a point PE somewhere on the edge
    being tested

N? P(t) - PE lt 0
N? P(t) - PE 0
N? P(t) - PE gt 0
Ni
22
ParametricLine-Clipping Algorithm
  • Next, since the dot product of the edges normal
    with P(t)-PE is zero when P(t) is on the edge
  • with some rearrangement and substitution we get

N? P(t) - PE lt 0
N? P(t) - PE 0
N? P(t) - PE gt 0
Ni
23
ParametricLine-Clipping Algorithm
  • If t is in the range 0,1
  • then the edge intersects our line segment (P0,P1)
  • And so, we clip against the edge using t to
    compute the new endpoint

N? P(t) - PE lt 0
N? P(t) - PE 0
N? P(t) - PE gt 0
Ni
24
Antialiasing
  • Increasing resolution
  • Area sampling
Write a Comment
User Comments (0)
About PowerShow.com