Line Drawing  and Generalization Sung Yong Shin Dept. of Computer Science KAIST CS580 Computer Graphics
Outline  <ul><li>overview </li></ul><ul><li>line drawing </li></ul><ul><li>circle drawing </li></ul><ul><li>curve drawing ...
1.  Overview application data structures/models application programs graphics systems display devices graphics  primitives...
Geometric Primitives <ul><li>  Building blocks for a 3D object </li></ul>Application programs must describe their service ...
<ul><li>display lists </li></ul><ul><li>evaluators </li></ul><ul><li>per-vertex operations & primitive assembly </li></ul>...
Continuity 8-connectivity (king – continuity) 4-connectivity (rook – continuity)
2.  Line Drawing f f  : L 1  => L 2  quality degradation!! Line drawing is at the heart of many graphics programs.   Smo...
Bresenham’s Line Drawing Algorithm  via  Pragram Transformation <ul><li>additions / subtractions only </li></ul><ul><li>in...
var yt : real;   x,   y, xi, yi : integer; for xi := 0 to   x do begin yt := [  y/  x]*xi; yi := trunc(yt+[1/2]); dis...
Motivation(Cont’) var ys : real;   x,   y, xi, yi : integer; ys := 1/2; for xi := 0 to dx do begin yi := trunc(ys);  dis...
Motivation(Cont’) var   x,   y, xi, ysi, r : integer; ysi := 0; for xi := 0 to   x do begin display(xi,ysi); if  then b...
Motivation(Cont’) var   x,   y, xi, ysi, r : integer; ysi := 0; r := 2*  y -   x; for xi := 0 to   x do begin display...
Line-Drawing Algorithms Assumptions
DDA(Digital Differential Analyzer) Algorithm basic idea Take unit steps with one coordinate and calculate values for the o...
DDA(Cont’) procedure dda (x1, y1, x2, y2 : integer); var  x,   y, k : integer; x, y : real begin  x := x2 - x1;  y := ...
Bresenham’s Line Algorithm <ul><li>basic idea </li></ul><ul><ul><li>Find the  closest integer coordinates  to the actual l...
Bresenham’s Line algorithm(Cont’)
Bresenham’s Line algorithm(Cont’) =1
Bresenham’s Line algorithm(Cont’) procedure bres_line (x1, y1, x2, y2 : integer); var  x,   y, x,y,p,incrE,incrNE : inte...
Midpoint Line Algorithm Van Aken, “An Efficient Ellipse - Drawing Algorithm” IEEE CG & A, 4(9), 24-35, 1984. Current  pixe...
Midpoint Line Algorithm (Cont’)
Midpoint Line Alg. (Cont’)
Midpoint Line Alg. (Cont’) Midpoint Line Algorithm(Cont’) procedure mid_point (x1, y1, x2, y2,value : integer); var  x,  ...
Geometric Interpretation any slope Bresenhams’s algorithm
Geometric Interpretation(Cont’) x y
Aliasing Effects staircases (or jaggies) intensity variation  <ul><li>line drawing </li></ul>
animation texturing popping-up
Anti-aliasing Lines <ul><li>Removing the staircase appearance of a line </li></ul><ul><ul><li>Why staircases? </li></ul></...
Increasing resolution memory cost memory bandwidth scan conversion time display device cost
Anti-aliasing Line (Cont’) <ul><li>super sampling </li></ul><ul><li>(postfiltering)  </li></ul><ul><li>area sampling </li>...
Area Sampling (Prefiltering)
Filters box filter cone filter unweighted area sampling  weighted area sampling
Table look-up for  f ( D ,  t ) The table is invariant of the slope of line!  Why? The search key for the table is D! Why? D
Intensity Functions  f ( D ,  t ) (assumption : t=1)
How to compute D (assumption : t=1)
How to compute  D , incrementally
IF (Cont’) Similarly, M D 1 -  v 1 +  v v
IF (Cont’) <ul><li> x := x2 - x1; </li></ul><ul><li> y := y2 - y1; </li></ul><ul><li>p := 2 *  y -   x; {Initial value...
3. Circle Drawing
symmetry using symmetry (0,r) r
Midpoint Circle Algorithm Current pixel Choices for next  pixel
MCA (Cont’) (0, R)
MCA (Cont’)
MCA (Cont’) procedure MidpointCircle (radius,value : integer); var x,y : integer; P: real; begin x := 0;  { initialization...
MCA (Cont’) procedure MidpointCircle (radius,value : integer); { Assumes center of circle is at origin. Integer arithmetic...
MCA (Cont’)
MCA (Cont’) procedure MidpointCircle (radius,value : integer); { This procedure uses second-order partial differences to c...
Drawing Ellipse Homework #3 Modify the midpoint circle drawing algorithm to draw ellipses.
4. Curve Drawing <ul><li>parametric equation </li></ul><ul><li>discrete data set </li></ul><ul><ul><li>curve fitting </li>...
Upcoming SlideShare
Loading in...5
×

Cs580

1,087

Published on

this is cad presentation

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,087
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
45
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Cs580

  1. 1. Line Drawing and Generalization Sung Yong Shin Dept. of Computer Science KAIST CS580 Computer Graphics
  2. 2. Outline <ul><li>overview </li></ul><ul><li>line drawing </li></ul><ul><li>circle drawing </li></ul><ul><li>curve drawing </li></ul>
  3. 3. 1. Overview application data structures/models application programs graphics systems display devices graphics primitives OpenGL pixel information
  4. 4. Geometric Primitives <ul><li> Building blocks for a 3D object </li></ul>Application programs must describe their service requests to a graphics system using geometric primitives !!! points, lines, polygons Why not providing data structures directly to the graphics system?
  5. 5. <ul><li>display lists </li></ul><ul><li>evaluators </li></ul><ul><li>per-vertex operations & primitive assembly </li></ul><ul><li>pixel operations </li></ul><ul><li>rasterization </li></ul><ul><li>texture assembly </li></ul><ul><li>per-fragment operations </li></ul>OpenGL Rendering Pipeline per-vertex operations & primitive assembly rasterization frame buffer texture assembly display lists evaluators pixel operations per-fragment operations geometric data pixel data
  6. 6. Continuity 8-connectivity (king – continuity) 4-connectivity (rook – continuity)
  7. 7. 2. Line Drawing f f : L 1 => L 2  quality degradation!! Line drawing is at the heart of many graphics programs.  Smooth, even, and continuous as much as possible !!! Simple and fast !!! ( x 1 , y 1 ) ( x 2 , y 2 )
  8. 8. Bresenham’s Line Drawing Algorithm via Pragram Transformation <ul><li>additions / subtractions only </li></ul><ul><li>integer arithmetic </li></ul><ul><li>not programmers’ point of view but system developers’ point of view </li></ul>
  9. 9. var yt : real;  x,  y, xi, yi : integer; for xi := 0 to  x do begin yt := [  y/  x]*xi; yi := trunc(yt+[1/2]); display(xi,yi); end; var yt : real;  x,  y, xi, yi : integer; yt := 0; for xi := 0 to  x do begin yi := trunc(yt + [1/2]); display(xi,yi); yt := yt+[  y/  x] end; Eliminate multiplication !!!  x  y y = mx, m = [  y/  x] * **  x ≥  y ∴ m ≤ 1  x,  y: positive integers (0,0) ( ∆x, ∆y)
  10. 10. Motivation(Cont’) var ys : real;  x,  y, xi, yi : integer; ys := 1/2; for xi := 0 to dx do begin yi := trunc(ys); display(xi,yi); ys := ys+[  y/  x] end; var ysf : real;  x,  y, xi, ysi : integer; ysi := 0; ysf := 1/2; for xi := 0 to  x do begin display(xi,ysi); if ysf+[  y/  x] < 1 then begin ysf := ysf + [  y/  x]; end else begin ysi := ysi + 1; ysf := ysf + [  y/  x-1]; end; end; integer part fractional part *** ****
  11. 11. Motivation(Cont’) var  x,  y, xi, ysi, r : integer; ysi := 0; for xi := 0 to  x do begin display(xi,ysi); if then begin end else begin ysi := ysi + 1; end; end;
  12. 12. Motivation(Cont’) var  x,  y, xi, ysi, r : integer; ysi := 0; r := 2*  y -  x; for xi := 0 to  x do begin display(xi,ysi); if r < 0 then begin r := r + [2*  y]; end else begin ysi := ysi + 1; r := r + [2*  y -2*  x ]; end; end; Bresenham’s Algorithm !!! No multiplication/ division. No floating point operations.
  13. 13. Line-Drawing Algorithms Assumptions
  14. 14. DDA(Digital Differential Analyzer) Algorithm basic idea Take unit steps with one coordinate and calculate values for the other coordinate i.e. or discontinuity !! Why?
  15. 15. DDA(Cont’) procedure dda (x1, y1, x2, y2 : integer); var  x,  y, k : integer; x, y : real begin  x := x2 - x1;  y := y2 - y1; x := x1; y := y1; display(x,y); for k := 1 to  x do begin x := x + 1; y := y + [  y/  x]; display(round(x),round(y)); end { for k } end; { dda } expensive !! no *’s Assumption : 0  m <1, x1<x2
  16. 16. Bresenham’s Line Algorithm <ul><li>basic idea </li></ul><ul><ul><li>Find the closest integer coordinates to the actual line path using only integer arithmetic </li></ul></ul><ul><ul><li>Candidates for the next pixel position </li></ul></ul>Specified Line Path Specified Line Path
  17. 17. Bresenham’s Line algorithm(Cont’)
  18. 18. Bresenham’s Line algorithm(Cont’) =1
  19. 19. Bresenham’s Line algorithm(Cont’) procedure bres_line (x1, y1, x2, y2 : integer); var  x,  y, x,y,p,incrE,incrNE : integer; begin  x := x2 – x1;  y := y2 – y1; p := 2*  y -  x; incrE := 2*  y; incrNE := 2*(  y -  x); x := x1; y := y1; display(x,y); while x < x2 do begin if p<0 then begin p := p + incrE; x := x + 1; end; { then begin } else begin p := p + incrNE; y := y + 1; x := x + 1; end; { else begin } display (x, y); end { while x < x2 } end; { bres_line} Homework #2 Extend this algorithm for general cases.
  20. 20. Midpoint Line Algorithm Van Aken, “An Efficient Ellipse - Drawing Algorithm” IEEE CG & A, 4(9), 24-35, 1984. Current pixel Choices for next pixel
  21. 21. Midpoint Line Algorithm (Cont’)
  22. 22. Midpoint Line Alg. (Cont’)
  23. 23. Midpoint Line Alg. (Cont’) Midpoint Line Algorithm(Cont’) procedure mid_point (x1, y1, x2, y2,value : integer); var  x,  y,incrE,incrNE,p,x,y : integer; begin  x := x2 – x1;  y := y2 – y1; p := 2*  y -  x; incrE := 2*  y; incrNE := 2*(  y-  x); x := x1; y := y1; display(x,y); while x  x2 do begin if p < 0 then begin p := p + incrE; x := x + 1; end; { then begin } else begin p := p + incrNE; y := y + 1; x := x + 1; end; { else begin } display(x,y); end; { while x  x2 } end; { mid_point }
  24. 24. Geometric Interpretation any slope Bresenhams’s algorithm
  25. 25. Geometric Interpretation(Cont’) x y
  26. 26. Aliasing Effects staircases (or jaggies) intensity variation <ul><li>line drawing </li></ul>
  27. 27. animation texturing popping-up
  28. 28. Anti-aliasing Lines <ul><li>Removing the staircase appearance of a line </li></ul><ul><ul><li>Why staircases? </li></ul></ul><ul><ul><ul><li>raster effect !!! </li></ul></ul></ul><ul><ul><ul><li>need some compensation in line-drawing algorithms for this raster effect? </li></ul></ul></ul><ul><ul><li>How to anti-alias? </li></ul></ul><ul><ul><li>well, … </li></ul></ul><ul><ul><li>increasing resolution . </li></ul></ul><ul><ul><li>However, ... </li></ul></ul>
  29. 29. Increasing resolution memory cost memory bandwidth scan conversion time display device cost
  30. 30. Anti-aliasing Line (Cont’) <ul><li>super sampling </li></ul><ul><li>(postfiltering) </li></ul><ul><li>area sampling </li></ul><ul><li>(prefiltering) </li></ul><ul><li>stochastic sampling </li></ul>Cook, ACM Trans. CG, 5(1), 307-316, 1986. Anti-aliasing Techniques
  31. 31. Area Sampling (Prefiltering)
  32. 32. Filters box filter cone filter unweighted area sampling weighted area sampling
  33. 33. Table look-up for f ( D , t ) The table is invariant of the slope of line! Why? The search key for the table is D! Why? D
  34. 34. Intensity Functions f ( D , t ) (assumption : t=1)
  35. 35. How to compute D (assumption : t=1)
  36. 36. How to compute D , incrementally
  37. 37. IF (Cont’) Similarly, M D 1 - v 1 + v v
  38. 38. IF (Cont’) <ul><li> x := x2 - x1; </li></ul><ul><li> y := y2 - y1; </li></ul><ul><li>p := 2 *  y -  x; {Initial value p 1 as before} </li></ul><ul><li>incrE := 2 *  y; {Increment used for move to E} </li></ul><ul><li>incrNE := 2 * (  y -  x); {Increment used for move to NE} </li></ul><ul><li>two_v_  x := 0; {Numerator; v = 0 for start pixel} </li></ul><ul><li>invDenom := 1 / (2 * Sqrt(  x *  x +  y *  y)); {Precomputed inverse denominator} </li></ul><ul><li>two_  x_invDenom := 2 *  x * invDenom; {Precomputed constant} </li></ul><ul><li>x := x1; </li></ul><ul><li>y := y1; </li></ul><ul><li>IntensifyPixel (x, y, 0); {Start pixel} </li></ul><ul><li>IntensifyPixel(x, y + 1, two_  x_invDenom); {Neighbor} </li></ul><ul><li>IntensifyPixel(x, y - 1, two_  x_invDenom); {Neighbor} </li></ul><ul><li>while x < x2 do </li></ul><ul><li> begin </li></ul><ul><li> if p < 0 then </li></ul><ul><li> begin {Choose E} </li></ul><ul><li> two_v_  x := p +  x; </li></ul><ul><li> p := p + incrE; </li></ul><ul><li> x := x + 1 </li></ul><ul><li> end </li></ul><ul><li> else </li></ul><ul><li> begin {Choose NE} </li></ul><ul><li> two_v_  x := p -  x; </li></ul><ul><li> p := p + incrNE; </li></ul><ul><li> x := x + 1; </li></ul><ul><li> y := y + 1; </li></ul><ul><li> end ; </li></ul><ul><li> {Now set chosen pixel and its neighbors} </li></ul><ul><li> IntensifyPixel (x, y, two_v_  x * invDenom); </li></ul><ul><li> IntensifyPixel (x, y + 1, two_  x_invDenom - two_v_  x * invDenom); </li></ul><ul><li> IntensifyPixel (x, y - 1, two_  x_invDenom + two_v_  x * invDenom) </li></ul><ul><li> end {while} </li></ul>
  39. 39. 3. Circle Drawing
  40. 40. symmetry using symmetry (0,r) r
  41. 41. Midpoint Circle Algorithm Current pixel Choices for next pixel
  42. 42. MCA (Cont’) (0, R)
  43. 43. MCA (Cont’)
  44. 44. MCA (Cont’) procedure MidpointCircle (radius,value : integer); var x,y : integer; P: real; begin x := 0; { initialization } y := radius; P := 5/4 - radius; CirclePoints(x,y,value); while y > x do begin if P < 0 then { select E } P : = P + 2*x + 3; x := x + 1; end else begin { select SE } P := P + 2*(x - y) + 5; x := x + 1; y := y - 1; end CirclePoints(x,y,value) end { while } end; { MidpointCircle } * ** d = P - 1/4 P = d + 1/4 * d = 1 - radius ** d < -1/4  d < 0 why? *** d := d + 2*x + 3 **** d := d + 2(x-y) + 5 *** **** (0, R) y=x
  45. 45. MCA (Cont’) procedure MidpointCircle (radius,value : integer); { Assumes center of circle is at origin. Integer arithmetic only } var x,y,d : integer; begin x := 0; { initialization } y := radius; d := 1 - radius; CirclePoints(x,y,value); while y > x do begin if d < 0 then { select E } d := d + 2*x + 3; x := x + 1; end else begin { select SE } d := d+2*(x - y) + 5; x := x + 1; y := y - 1; end CirclePoints(x,y,value) end { while } end; { MidpointCircle } Can you go further?
  46. 46. MCA (Cont’)
  47. 47. MCA (Cont’) procedure MidpointCircle (radius,value : integer); { This procedure uses second-order partial differences to compute increments in the decision variable. Assumes center of circle is origin. } var x,y,d,deltaE,deltaSE : integer; begin x := 0; { initialization } y := radius; d := 1 - radius; deltaE := 3; deltaSE := -2*radius + 5; CirclePoints(x,y,value); while y > x do begin if d < 0 then { select E } d := d + deltaE; deltaE := deltaE + 2; deltaSE := deltaSE + 2; x := x + 1; end else begin { select SE } d := d + deltaSE; deltaE := deltaE + 2; deltaSE := deltaSE + 4; x := x + 1; y := y - 1 end CirclePoints(x,y,value) end { while } end; { MidpointCircle }
  48. 48. Drawing Ellipse Homework #3 Modify the midpoint circle drawing algorithm to draw ellipses.
  49. 49. 4. Curve Drawing <ul><li>parametric equation </li></ul><ul><li>discrete data set </li></ul><ul><ul><li>curve fitting </li></ul></ul><ul><ul><li>piecewise linear </li></ul></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×