Chapter 3 Graphics Output Primitives Computer Graphics Chapter 3 Graphics Output Primitives
Display screen과 Frame Buffer Frame buffer Display screen 2019-04-16 Computer Vision & Pattern Recognition Lab.
Computer Vision & Pattern Recognition Lab. 1. Point Point plotting : converting a single coordinate position setPixel(x,y) getPixel(x,y,color) addr(x,y) = addr(0,0) + y(xmax+1) +x addr(x+1,y) = addr(x,y) + 1 addr(x, y+1) = addr(x,y) + (xmax+1) 2019-04-16 Computer Vision & Pattern Recognition Lab.
Computer Vision & Pattern Recognition Lab. 2. Line Line drawing Calculating intermediate positions along the line path between two specified endpoint positions Output device is directed to fill in these positions between the endpoints Digital devices - Plotting discrete points between the two endpoints ⇒ jaggies - Calculate from the equation of the line 2019-04-16 Computer Vision & Pattern Recognition Lab.
3. Line-Drawing Algorithms Problem: Given start and end points, -. Find sequence of pixels (integer coor.) as close to ideal line as possible (Given point drawing software) -. Issues: Correctness(accuracy) and Effectiveness(Speed) Slope-intercept equation For each x, compute y (if m<1). or For each y, compute x (if m>1). => Floating point multiplication, addition, and rounding 2019-04-16 Computer Vision & Pattern Recognition Lab.
3. Line-Drawing Algorithms DDA Algorithm Digital Differential Analyzer Scan-conversion line algorithm Calculate either ∆x or ∆y Left endpoint → right endpoint ⇒ slope ≤ 1 ; yk+1 = yk + m (∆x=1) ⇒ slope > 1 ; xk+1 = xk + 1/m(∆y=1) Right endpoint → left endpoint ⇒ slope ≤ 1 ; yk+1 = yk - m (∆x=-1) ⇒ slope > 1 ; xk+1 = xk - 1/m(∆y=-1) Floating point addition & rounding 2019-04-16 Computer Vision & Pattern Recognition Lab.
3. Line-Drawing Algorithms Midpoint algorithm (Bresenham’s line algorithm) An accurate and efficient raster line-generating algorithm Use only incremental integer calculations that can be adapted to display circles and curves 2019-04-16 Computer Vision & Pattern Recognition Lab.
3. Line-Drawing Algorithms Assume : 0 < m < 1 Given (xk, yk), choose NE or E ⇒ Is M below the line ? Let 2019-04-16 Computer Vision & Pattern Recognition Lab.
3. Line-Drawing Algorithms Let decision variable Approach: (1) test the sign of pk (2) select E or NE (3) update pk+1 using pk 2019-04-16 Computer Vision & Pattern Recognition Lab.
3. Line-Drawing Algorithms 2019-04-16 Computer Vision & Pattern Recognition Lab.
3. Line-Drawing Algorithms To avoid , let only integer addition 2019-04-16 Computer Vision & Pattern Recognition Lab.
3. Line-Drawing Algorithms 2019-04-16 Computer Vision & Pattern Recognition Lab.
3. Line-Drawing Algorithms Note: -. Generalization -. Special case can be handled separately Horizontal lines (Δy = 0) Vertical lines (Δx = 0) Diagonal lines with |Δx| = |Δy| -. H/W dependent address generation ⇒ fast -. Additional Issues Use of symmetry ⇒ faster Independence of endpoint order Anti-aliasing Parallel algorithm 2019-04-16 Computer Vision & Pattern Recognition Lab.
4. Circle generating algorithms Problem: Given center & radius, generate a circle. Integer coordinates Accuracy and Efficiency Properties of circles Center : (xc, yc), distance : r (x - xc)2 + (y - yc)2 = r2 y = yc ± √ r2 – (x - xc)2 Multiplication, square root Problem At each step, considerable computation Unequally spacing Another way to eliminate the unequal spacing 2019-04-16 Computer Vision & Pattern Recognition Lab.
4. Circle generating algorithms Parametric polar form x = xc + r·cosθ y = yc + r·sinθ Multiplication, trigonometric calculation For a continuous boundary, set the angular step size at 1/r Considering the symmetry of circles Quadrant Octants Position (x, y) on a one-eighth circle sector is mapped into the seven circle points in the other octants of the xy plane 2019-04-16 Computer Vision & Pattern Recognition Lab.
4. Circle generating algorithms Midpoint circle algorithm Problem: Given center & radius, generate a circle. Assume: center at the origin Consider only 2nd octant and use 8-way symmetry. Given (xk, yk), choose E (xk+1, yk) or SE (xk+1, yk-1) ⇒ Is Midpoint inside the circle? fcirc(x, y) = x2 + y2 – r2 fcirc(x, y) = 0, if (x, y) is on the circle boundary < 0, if (x, y) is inside the circle boundary > 0, if (x, y) is outside the circle boundary 2019-04-16 Computer Vision & Pattern Recognition Lab.
4. Circle generating algorithms Decision function : pk = fcirc(xk+1, yk-1/2) Approach : (1) test the sign of pk (2) select E or SE (3) update pk+1 using pk pk = fcirc (xk+1, yk-1/2) = (xk+1)2 + (yk-1/2)2 – r2 If pk<0, select E (xk+1= xk +1, yk +1 = yk ) pk+1 = fcirc (xk +2, yk-1/2) = (xk+2)2 + (yk-1/2)2 – r2 = pk+ 2xk + 3 <= (xk = xk+1 -1) = pk+ 2xk +1 + 1 Otherwise, select SE (xk+1= xk +1, yk +1 = yk -1) pk+1 = fcirc (xk+2, yk-3/2) = (xk+2)2 + (yk-3/2)2 – r2 = xk2 + 4xk + 4 + yk2 – 3yk + 9/4 – r2 = pk+ 2xk – 2yk + 5 <= (xk = xk+1–1, yk = yk+1+1) = pk+ 2(xk +1 – yk +1 ) + 1 2019-04-16 Computer Vision & Pattern Recognition Lab.
4. Circle generating algorithms Initial decision function : p0 = fcirc(1, r-1/2) = 1 + (r -1/2)2 – r2 = 5/4 – r If r is specified as an integer, p0 = 1- r 2019-04-16 Computer Vision & Pattern Recognition Lab.
Computer Vision & Pattern Recognition Lab. 2019-04-16 Computer Vision & Pattern Recognition Lab.
5. Ellipse generating algorithms 2019-04-16 Computer Vision & Pattern Recognition Lab.
Computer Vision & Pattern Recognition Lab. 6. Other Curves Conic section Ax2 + By2 + Cxy + Dx + Ey + F = 0 B – 4AC < 0 : generates an ellipse = 0 : generates a parabola > 0 : generates s hyperbola Polynomials and spline curves Polynomial function of n-th degree in x y = ∑akxk Useful in a number of graphics applications 2019-04-16 Computer Vision & Pattern Recognition Lab.
7. Pixel addressing & object geometry Maintaining geometric properties of displayed objects Pixel area : referenced by the integer coordinates of its lower left corner Adjust the length of the displayed line by omitting one of the endpoint pixel 2019-04-16 Computer Vision & Pattern Recognition Lab.
7. Pixel addressing & object geometry 2019-04-16 Computer Vision & Pattern Recognition Lab.
8. Filled-Area Primitives Inside-outside tests Odd-even rule If # of crossings is odd, interior. If # of crossings is even, exterior. (Make sure there is no crossing at vertex) Nonzero winding number rule Step 1: Count directional crossing of PP' to each polygon edge (Use vector product.) If right to left, increment winding #. If left to right, decrement winding #. Step 2: If winding # is nonzero, interior (more versatile than the odd-even rule) 2019-04-16 Computer Vision & Pattern Recognition Lab.