Download presentation
Presentation is loading. Please wait.
Published byDaniel Francis Modified over 9 years ago
1
Institute for Visualization and Perception Research 1 © Copyright 2000 Haim Levkowitz Primitives Points … Lines … Circles, ellipses, conics, curves, disks … Polygons, triangles, fill areas … Characters, special symbols … Pixel addressing & object geometry...
2
Institute for Visualization and Perception Research 2 © Copyright 2000 Haim Levkowitz Points (x, y) WritePixel(round(x), round(y)) Clip: if x > Max(x) | y > Max(y) For real coo’s must distribute point’s intensity over neighboring pixels Crow's alg.
3
Institute for Visualization and Perception Research 3 © Copyright 2000 Haim Levkowitz Lines Appear straight, smooth Constant density independent of Length Orientation Draw rapidly (e.g., 1M pixels/sec.) Terminate accurately Line-drawing algorithms...
4
Institute for Visualization and Perception Research 4 © Copyright 2000 Haim Levkowitz Line-drawing algorithms Line equations … DDA … Bresenham’s … Midpoint line...
5
Institute for Visualization and Perception Research 5 © Copyright 2000 Haim Levkowitz Line equations Slope-intercept y = mx + b Implicit ax + by + c = 0
6
Institute for Visualization and Perception Research 6 © Copyright 2000 Haim Levkowitz DDA Idea … Algorithm … Advantages … Disadvantages...
7
Institute for Visualization and Perception Research 7 © Copyright 2000 Haim Levkowitz Idea Slope: Increment x, y by constants proportional to Dx, Dy e.g, s.t., one of them = 1 Round to closest position Cases...
8
Institute for Visualization and Perception Research 8 © Copyright 2000 Haim Levkowitz Cases
9
Institute for Visualization and Perception Research 9 © Copyright 2000 Haim Levkowitz Algorithm procedure simpleDDA(xa, ya, xb, yb: integer); var dx, dy, steps, k: integer; xInc, yInc, x, y: real; begin dx = xb - xa; dy = yb - ya; if abs(dx) > abs(dy) then steps = abs(dx) else steps = abs(dy); xInc = dx/steps; yInc = dy/steps; {one of these = 1} x = xa; y = ya; for k = 1 to steps do begin setPixel(round(x), round(y)); x = x + xInc; y = y + yInc; end end;
10
Institute for Visualization and Perception Research 10 © Copyright 2000 Haim Levkowitz Advantages Faster than direct slope-intercept computation No mult’s Use raster characteristics
11
Institute for Visualization and Perception Research 11 © Copyright 2000 Haim Levkowitz Disadvantages Round-off error accumulation Long lines ==> drift Round + floating point op’s ==> Time
12
Institute for Visualization and Perception Research 12 © Copyright 2000 Haim Levkowitz Bresenham's Only integer arithmetic Avoid round Generalize to circles & other curves Idea … Algorithm...
13
Institute for Visualization and Perception Research 13 © Copyright 2000 Haim Levkowitz Idea
14
Institute for Visualization and Perception Research 14 © Copyright 2000 Haim Levkowitz Idea (cont.) d p + 1 = 2 y x p + 1 – 2 x y p + 1 + c d p + 1 – d p = 2 y (x p + 1 – x p ) – 2 x (y p + 1 – y p ) = 1 d p + 1 = d p + 2 y – 2 x (y p + 1 – y p ) = 1, if d p > 0 = 0, if d p < 0 d 0 = 2 y – x
15
Institute for Visualization and Perception Research 15 © Copyright 2000 Haim Levkowitz Algorithm procedure lineBres(xa, ya, xb, yb: integer); var dx, dy, xEnd, dp: integer; begin dx = abs(xa - xb); dy = abs(ya - yb); dp = 2 * dy - dx; {detemine which point to use as start, which as end} if xa > xb then begin x = xb; y = yb; xEnd = xa; end {xa > xb}
16
Institute for Visualization and Perception Research 16 © Copyright 2000 Haim Levkowitz Algorithm (cont.) else begin x = xa; y = ya; xEnd = xb; end; setPixel(x, y, 1); while x < xEnd do begin x = x + 1; if dp < 0 then dp = dp + 2 * dy else begin y = y + 1; dp = dp+ 2 * (dy - dx) end; setPixel(x, y, 1); end {while} end;
17
Institute for Visualization and Perception Research 17 © Copyright 2000 Haim Levkowitz Midpoint line M above line ==> E M below line ==> NE Incremental decision variable … Algorithm … Other issues...
18
Institute for Visualization and Perception Research 18 © Copyright 2000 Haim Levkowitz Incremental decision variable Implicit form: F(x, y) = ax + by + c = 0 dy = y 1 – y 0 ; dx = x 1 – x 0 Slope-intercept: y = (dy/dx) x + B ==> F(x, y) = dy x – dx y + B dx = 0 ==> a = dy, b = –dx, c = B dx Cont....
19
Institute for Visualization and Perception Research 19 © Copyright 2000 Haim Levkowitz Incremental decision variable (cont.) Point above line: F(x, y) < 0 Point on line: F(x, y) = 0 Point below line: F(x, y) > 0 F(M) = F(x p + 1, y p + 1/2) = d (decision variable) Test sign For next point...
20
Institute for Visualization and Perception Research 20 © Copyright 2000 Haim Levkowitz For next point E case … NE case...
21
Institute for Visualization and Perception Research 21 © Copyright 2000 Haim Levkowitz E case M incremented 1 step along x only d new = F(x p + 2, y p + 1/2) = a(x p + 2) + b(y p + 1/2) + c d old = a(x p + 1) + b(y p + 1/2) + c d new = d old + a The incremental decision variable: E = dy
22
Institute for Visualization and Perception Research 22 © Copyright 2000 Haim Levkowitz NE case M incremented 1 step along both x and y d new = F(x p + 2, y p + 3/2) = a(x p + 2) + b(y p + 3/2) + c d new = d old + a + b The incremental decision variable: E = a + b = dy – dx
23
Institute for Visualization and Perception Research 23 © Copyright 2000 Haim Levkowitz Algorithm... procedure MidpointLine(xa, ya, xb, yb, value: integer); var dx, dy,, incE, incNE, d, x, y: integer; begin dx = xa - xb; dy = ya - yb; d = 2 * dy - dx; incE = 2 * dy; incNE = 2 * (dy – dx); x = xb; y = yb; writePixel(x, y, value); {start pixel} while (x < xa) do begin if d<= 0 then begin d = d + incE; x = x + 1 end else begin d = d + incNE; x = x + 1; y = y + 1 end; writePixel(x, y, value); end; {while} end;
24
Institute for Visualization and Perception Research 24 © Copyright 2000 Haim Levkowitz Other issues Varying intensity as function of slope B is 2 1/2 longer than A Same number of pixels ==> intensity / unit length A: = I B: = I/2 1/2 If n-bits, can vary I to be funct. of slope How?
25
Institute for Visualization and Perception Research 25 © Copyright 2000 Haim Levkowitz Circles, ellipses, conics, curves, disks Circle-drawing algorithms … Ellipse-drawing algorithms … Conic sections … Curves...
26
Institute for Visualization and Perception Research 26 © Copyright 2000 Haim Levkowitz Circle-drawing algorithms Properties of circles … Midpoint circle...
27
Institute for Visualization and Perception Research 27 © Copyright 2000 Haim Levkowitz Properties of circles (x – x c ) 2 + (y – y c ) 2 = r 2 ==> y = y c ± (r 2 – (x c – x) 2 ) 1/2 (Fig. 3-13) x = x c + r cos ; y = y c + r sin Equally spaced, but Expensive Eight point symmetry...
28
Institute for Visualization and Perception Research 28 © Copyright 2000 Haim Levkowitz Eight point symmetry
29
Institute for Visualization and Perception Research 29 © Copyright 2000 Haim Levkowitz Midpoint circle Similar to line Use circle equation Use 8-pt symmetry
30
Institute for Visualization and Perception Research 30 © Copyright 2000 Haim Levkowitz Ellipse-drawing algorithms Properties of ellipses … Midpoint ellipse...
31
Institute for Visualization and Perception Research 31 © Copyright 2000 Haim Levkowitz Properties of ellipses F(x,y) = (x – x c ) 2 /r x + (y – y c ) 2 /r y = 1 x = x c + r x cos ; y = y c + r y sin
32
Institute for Visualization and Perception Research 32 © Copyright 2000 Haim Levkowitz Midpoint ellipse...
33
Institute for Visualization and Perception Research 33 © Copyright 2000 Haim Levkowitz Conic sections Ax2 + By2 + Cxy + Dx + Ey + F = 0 B2 - 4AC < 0: ellipse (circle) = 0: parabola > 0: hyperbola Examples...
34
Institute for Visualization and Perception Research 34 © Copyright 2000 Haim Levkowitz Examples
35
Institute for Visualization and Perception Research 35 © Copyright 2000 Haim Levkowitz Curves Polynomials and spline curves...
36
Institute for Visualization and Perception Research 36 © Copyright 2000 Haim Levkowitz Polynomials and spline curves
37
Institute for Visualization and Perception Research 37 © Copyright 2000 Haim Levkowitz Polygon, triangles, fill areas Filling rectangles … Disks … Scan-line fill: polygons … Inside-outside tests … Scan-line fill: curved boundary areas … Thick primitives … Neighborhood connectivity … Boundary fill … Flood fill...
38
Institute for Visualization and Perception Research 38 © Copyright 2000 Haim Levkowitz Filling rectangles
39
Institute for Visualization and Perception Research 39 © Copyright 2000 Haim Levkowitz Disks Eight-way symmetry
40
Institute for Visualization and Perception Research 40 © Copyright 2000 Haim Levkowitz Scan-line fill: polygons
41
Institute for Visualization and Perception Research 41 © Copyright 2000 Haim Levkowitz Special handling Scanline through vertex Intersects 2 polygon edges Adds 2 points to list of intersections y’: correct interior spans y: add’l processing to determine correctly … Spans...
42
Institute for Visualization and Perception Research 42 © Copyright 2000 Haim Levkowitz y: add’l processing to determine correctly y: 2 Intersecting edges on opposite side y’: both above ==> Add’l processing: opposite sides...
43
Institute for Visualization and Perception Research 43 © Copyright 2000 Haim Levkowitz ==> Add’l processing: opposite sides Trace around polygon boundary (cw/ccw) consistently Relative change in vertex y coo as change edges If 2 consecutive edges monotonically increase/decrease Count middle vertex as 1 for any scan line passing Otherwise, local extremum Add 2 edges Can resolve by shortening...
44
Institute for Visualization and Perception Research 44 © Copyright 2000 Haim Levkowitz Can resolve by shortening
45
Institute for Visualization and Perception Research 45 © Copyright 2000 Haim Levkowitz Spans Extrema by midpoint alg on edges Some outside Extrema interior to polygon
46
Institute for Visualization and Perception Research 46 © Copyright 2000 Haim Levkowitz Horizontal Edges...
47
Institute for Visualization and Perception Research 47 © Copyright 2000 Haim Levkowitz Slivers Only pixels Interior On left edge On bottom edge Slivers Aliasing: missing pixels on scanline Antialising
48
Institute for Visualization and Perception Research 48 © Copyright 2000 Haim Levkowitz Using coherence
49
Institute for Visualization and Perception Research 49 © Copyright 2000 Haim Levkowitz Polygon & sorted edge table Bucket sort non horizontal edges cw/ccw Smallest y value for each edge L-R along scan line Shorten edges to resolve vertex- intersection Table...
50
Institute for Visualization and Perception Research 50 © Copyright 2000 Haim Levkowitz Table Max y for edge X-intercept at lower vertex Inverse slope of edge
51
Institute for Visualization and Perception Research 51 © Copyright 2000 Haim Levkowitz Inside-outside tests Standard polygons: usually straightforward General fill area: more complex Odd-even … Nonzero winding number...
52
Institute for Visualization and Perception Research 52 © Copyright 2000 Haim Levkowitz Odd-even Line from point P Not intersect vertices Count number of crossings Odd: P inside Even: P outside How to do...
53
Institute for Visualization and Perception Research 53 © Copyright 2000 Haim Levkowitz How to do More details ….
54
Institute for Visualization and Perception Research 54 © Copyright 2000 Haim Levkowitz 1. Project polygon onto 2D plane (u, v) (x, y, z) --> (u, v) Preserve topology E.g., rotate till normal coincides w/ say, Z axis … Can just project on plane defined, e.g., by (x, y)...
55
Institute for Visualization and Perception Research 55 © Copyright 2000 Haim Levkowitz E.g., rotate till normal coincides w/ say, Z axis ==> (X, Y) = (U, V) – generate + store R matrix for ea. polyg. – matrix mult. for ea. coo.
56
Institute for Visualization and Perception Research 56 © Copyright 2000 Haim Levkowitz Can just project on plane defined, e.g., by (x, y) Throw away z ==> area NOT preserved But topology YES Which coo to throw away? Plane eq. value w/ greatest magnitude E.g: P n = (0, –5, 3) ==> throw away y u = x, v = z (or vice versa)
57
Institute for Visualization and Perception Research 57 © Copyright 2000 Haim Levkowitz Algorithm for NV vertices (Xn, Yn, Zn), n = 0 to NV – 1 project onto dominant coo's plane --> (Un, Vn) translate (U, V) polyg. s.t. Pi is at origin --> (U'n, V'n) NC = 0{# of crossings} if V'0 < 0 then SH = -1 else SH = 1 {sign holder} for each edge ((U'a, V'a), (U'b, V'b)), a = 0,..., NV - 1, b = (a + 1) mod NV begin if V'b < 0 NSH = – 1 else NSH = 1 {next sign holder} if SH ≠ NSH begin if U'a > 0 & U'b > 0 then NC = NC + 1 {must cross +U'} else if U'a > 0 or U'b > 0 {might cross, compute intersection w/U'} if U'a – V'a (U'b – U'a )/(V'b – V'a ) > 0 then NC = NC + 1 end {SH ≠ NSH} SH = NSH; next edge end {for edges} if NC is odd then in else out
58
Institute for Visualization and Perception Research 58 © Copyright 2000 Haim Levkowitz Algorithm (cases)
59
Institute for Visualization and Perception Research 59 © Copyright 2000 Haim Levkowitz Nonzero winding number Line P to distant point Line crosses edge R-L: winding number +1 L-R: winding number –1 If winding number non 0: in L-R/R-L? x product /. product
60
Institute for Visualization and Perception Research 60 © Copyright 2000 Haim Levkowitz Scan-line fill: curved boundary areas Intersection: nonlinear boundaries Circles/ellipses: 2 scan line intersection points
61
Institute for Visualization and Perception Research 61 © Copyright 2000 Haim Levkowitz Thick primitives Replicating Moving pen Filling areas between boundaries Approximation by thick polylines
62
Institute for Visualization and Perception Research 62 © Copyright 2000 Haim Levkowitz Neighborhood connectivity 4-connected 8-connected
63
Institute for Visualization and Perception Research 63 © Copyright 2000 Haim Levkowitz Boundary fill “Wall around courtyard” Inner/outer Algorithm... Example: 4-connected partial fill...
64
Institute for Visualization and Perception Research 64 © Copyright 2000 Haim Levkowitz Algorithm procedure boundaryFill4(x, y, fill, boundary: integer); var current: integer; begin current = getPixel(x, y); if (current <> boundary) and (current <> fill) then begin setPixel(x, y, fill); boundaryFill4(x + 1, y, fill, boundary); boundaryFill4(x – 1, y, fill, boundary); boundaryFill4(x, y + 1, fill, boundary); boundaryFill4(x, y – 1, fill, boundary); end end;{boundaryFill}
65
Institute for Visualization and Perception Research 65 © Copyright 2000 Haim Levkowitz Example: 4-connected partial fill Also if pixel already in fill color, recursive branch terminate First change all fill color pixels Stacking: space hog Alternative: spans across scan lines...
66
Institute for Visualization and Perception Research 66 © Copyright 2000 Haim Levkowitz Alternative: spans across scan lines
67
Institute for Visualization and Perception Research 67 © Copyright 2000 Haim Levkowitz Flood fill “Plateau by the cliff” Algorithm...
68
Institute for Visualization and Perception Research 68 © Copyright 2000 Haim Levkowitz Algorithm procedure floodFill4(x, y, fillColor, oldColor: integer); begin current = ; if getPixel(x, y) = oldColor then begin setPixel(x, y, fillColor); floodFill4(x + 1, y, fillColor, oldColor); floodFill4(x – 1, y, fillColor, oldColor); floodFill4(x, y + 1, fillColor, oldColor); floodFill4(x, y – 1, fillColor, oldColor); end end;{floodFill}
69
Institute for Visualization and Perception Research 69 © Copyright 2000 Haim Levkowitz Characters, special symbols Typeface (font) Serif/sans serif Bitmap/outline Marker symbol (polymarker)...
70
Institute for Visualization and Perception Research 70 © Copyright 2000 Haim Levkowitz Marker symbol (polymarker)
71
Institute for Visualization and Perception Research 71 © Copyright 2000 Haim Levkowitz Pixel addressing & object geometry Screen grid coordinates … Maintaining geometric properties...
72
Institute for Visualization and Perception Research 72 © Copyright 2000 Haim Levkowitz Screen grid coordinates Pixels center Screen grid
73
Institute for Visualization and Perception Research 73 © Copyright 2000 Haim Levkowitz Maintaining geometric properties Line too long Area too large
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.