Scan Conversion 2

download Scan Conversion 2

of 26

Transcript of Scan Conversion 2

  • 7/30/2019 Scan Conversion 2

    1/26

    I N T R O D U C T I O N T O C O M P U T E R G R A P H I CS

    Andries van Dam September 23, 2008 ScanConversion2 #/26

    Scan Conversion 2

    (pages 81-91 in the textbook)

  • 7/30/2019 Scan Conversion 2

    2/26

    I N T R O D U C T I O N T O C O M P U T E R G R A P H I CS

    Andries van Dam September 23, 2008 ScanConversion2 #/26

    Version 1: really bad

    Forx= R to R

    y = sqrt(R * Rx*x);

    Pixel (round(x), round(y));

    Pixel (round(x), round(-y));

    Version 2: slightly less bad

    Forx= 0 to 360

    Pixel (round (R cos(x)), round(R sin(x)));

    (17, 0)

    (0, 17)

    (17, 0)

    (0, 17)

    Scan Converting Circles

  • 7/30/2019 Scan Conversion 2

    3/26

    I N T R O D U C T I O N T O C O M P U T E R G R A P H I CS

    Andries van Dam September 23, 2008 ScanConversion2 #/26

    Symmetry: If (x0 + a, y0 + b) is on circle

    also (x0 a, y0 b) and (x0 b, y0 a);hence 8-way symmetry.

    Reduce the problem to finding the pixelsfor 1/8 of the circle

    R

    (x0 + a,y0 + b)

    (x-x0)2 + (y-y0)

    2 =R2

    (x0,y0)

    Version 3 Use Symmetry

  • 7/30/2019 Scan Conversion 2

    4/26

    I N T R O D U C T I O N T O C O M P U T E R G R A P H I CS

    Andries van Dam September 23, 2008 ScanConversion2 #/26

    Scan top right 1/8 of circle of radius R

    Circle starts at (x0, y0 + R)

    Lets use another incremental algorithmwith decision variable evaluated atmidpoint

    (x0,y0)

    Using the Symmetry

  • 7/30/2019 Scan Conversion 2

    5/26

    I N T R O D U C T I O N T O C O M P U T E R G R A P H I CS

    Andries van Dam September 23, 2008 ScanConversion2 #/26

    E

    SE

    x = x0; y = y0 + R; Pixel(x, y);

    for (x = x0+1; (x

    x0) > (yy0); x++) {

    if (decision_var < 0) {

    /* move east */

    update decision_var;

    }

    else {

    /* move south east */

    update decision_var;

    y--;

    }

    Pixel(x, y);

    }

    Note: can replace all occurrences ofx0, y0 with 0, 0and Pixel (x0 + x, y0 + y) with Pixel (x, y)

    Shift coordinates by (-x0,-yo)

    Sketch of Incremental Algorithm

  • 7/30/2019 Scan Conversion 2

    6/26

    I N T R O D U C T I O N T O C O M P U T E R G R A P H I CS

    Andries van Dam September 23, 2008 ScanConversion2 #/26

    Decision variable

    negative if we move E, positive if wemove SE (or vice versa).

    Follow line strategy: Use implicit equationof circle

    f(x,y) = x2 + y2 R2 = 0

    f(x,y) is zero on circle, negative inside,

    positive outside

    If we are at pixel (x, y)

    examine (x + 1, y) and (x + 1, y1)

    Compute fat the midpoint

    What we need for Incremental

    Algorithm

  • 7/30/2019 Scan Conversion 2

    7/26

    I N T R O D U C T I O N T O C O M P U T E R G R A P H I CS

    Andries van Dam September 23, 2008 ScanConversion2 #/26

    P = (xp, yp)M ME

    MSE

    SE

    Decision Variable

    E

    Evaluate f(x,y) =x2 + y2 R2

    at the point

    We are asking: Is

    positive or negative? (it is zero on circle)

    Ifnegative, midpoint inside circle, choose E

    verticaldistance to the circle is less at

    (x + 1, y) than at (x + 1, y1).

    Ifpositive, opposite is true, choose SE

    2

    2

    2

    2

    1)1(

    2

    1,1 Ryxyxf -

    -++=

    -+

    -+

    2

    1,1 yx

  • 7/30/2019 Scan Conversion 2

    8/26

    I N T R O D U C T I O N T O C O M P U T E R G R A P H I CS

    Andries van Dam September 23, 2008 ScanConversion2 #/26

    Decision based on vertical distance Ok for lines, since dand dvertare

    proportional

    For circles, not true:

    Which dis closer to zero? (i.e. which of thetwo values below is closer to R):

    RyxCircyxd

    RyxCircyxd

    --++=-+

    -++=+

    22

    22

    )1()1()),1,1((

    )1()),,1((

    2222)1()1()1( -++++ yxoryx

    The right decision variable?

  • 7/30/2019 Scan Conversion 2

    9/26

    I N T R O D U C T I O N T O C O M P U T E R G R A P H I CS

    Andries van Dam September 23, 2008 ScanConversion2 #/26

    We could ask instead:

    Is (x+ 1)2 + y2 or (x+ 1)2 + (y 1)2closer to R2?

    The two values in equation above differ by

    12])1()1[(])1[(2222 -=-++-++ yyxyx

    fE fSE = 290 257 = 33

    (0, 17) (1, 17)

    (1, 16)

    fE = 12 + 172 = 290

    E

    SE

    fSE = 12 + 162 = 257

    2y 1 = 2(17) 1 = 33

    Alternate Phrasing (1/3)

  • 7/30/2019 Scan Conversion 2

    10/26

    I N T R O D U C T I O N T O C O M P U T E R G R A P H I CS

    Andries van Dam September 23, 2008 ScanConversion2 #/26

    The second value, which is always less,is closerif its difference from R2 is less than

    i.e., if

    then

    so

    so

    so

  • 7/30/2019 Scan Conversion 2

    11/26

  • 7/30/2019 Scan Conversion 2

    12/26

    I N T R O D U C T I O N T O C O M P U T E R G R A P H I CS

    Andries van Dam September 23, 2008 ScanConversion2 #/26

    How to compute the value of

    at successive points?

    Answer: Note that

    is just

    and that

    is just

    (1/2)

    2

    2

    2

    2

    1)1(),( Ryxyxf -

    -++=

    2232),(

    ),()1,1(

    32),(

    ),(),1(

    SE

    E

    +-+=D

    --+

    +=D

    -+

    yxyx

    yxfyxf

    xyx

    yxfyxf

    Incremental Computation, Again

  • 7/30/2019 Scan Conversion 2

    13/26

    I N T R O D U C T I O N T O C O M P U T E R G R A P H I CS

    Andries van Dam September 23, 2008 ScanConversion2 #/26

    FF

    F

    Incremental Computation(2/2)

    If we move E, update by adding 2x+ 3

    If we move SE, update by adding2x+ 3 2y+ 2.

    Forward differences of a 1st degree polynomialare constants and those of a 2nd degreepolynomial are 1st degree polynomials

    this first order forward difference, like apartial derivative, is one degree lower

  • 7/30/2019 Scan Conversion 2

    14/26

    I N T R O D U C T I O N T O C O M P U T E R G R A P H I CS

    Andries van Dam September 23, 2008 ScanConversion2 #/26

    The function is linear, henceamenable to incremental computation, viz:

    Similarly

    Second Differences(1/2)32),(E +=D xyx

    2),()1,1( EE =D--+D yxyx2),(),1( EE

    =D-+Dyxyx

    4),()1,1(SESE

    =D--+D yxyx

    2),(),1( SESE =D-+D yxyx

  • 7/30/2019 Scan Conversion 2

    15/26

    I N T R O D U C T I O N T O C O M P U T E R G R A P H I CS

    Andries van Dam September 23, 2008 ScanConversion2 #/26

    For any step, can compute new E(x, y) from oldE(x, y) by adding appropriate second constantincrement update delta terms as we move.

    This is also true ofSE(x, y)

    Having drawn pixel (a,b), decide location of newpixel at (a + 1, b) or (a + 1, b 1), usingpreviously computed d(a, b).

    Having drawn new pixel, must update d(a, b) fornext iteration; need to find either d(a + 1, b) or

    d(a + 1, b 1) depending on pixel choice

    Must add E(a, b)or SE(a, b) to d(a, b)

    So we

    Look at d(i) to decide which to draw next,updatexand y

    Update dusing E(a,b) or SE(a,b)

    Update each ofE(a,b) and SE(a,b) for futureuse

    Draw pixel

    Second Differences(2/2)

  • 7/30/2019 Scan Conversion 2

    16/26

    I N T R O D U C T I O N T O C O M P U T E R G R A P H I CS

    Andries van Dam September 23, 2008 ScanConversion2 #/26

    Midpoint Eighth Circle Algorithm

    MEC (R) /* 1/8th of a circle w/ radius R */

    {

    int x = 0, y = R;

    int delta_E, delta_SE;

    float decision;

    delta_E = 2*x + 3;

    delta_SE = 2(x-y) + 5;

    decision = (x+1)*(x+1) + (y + 0.5)*(y + 0.5) R*R;

    Pixel(x, y);

    while( y > x ) {

    if (decision > 0) {/* Move east */

    decision += delta_E;

    delta_E += 2; delta_SE += 2; /*Update delta*/}

    else {/* Move SE */

    y--;

    decision += delta_SE;

    delta_E += 2; delta_SE += 4; /*Update delta*/

    }x++;

    Pixel(x, y);

    }

    }

  • 7/30/2019 Scan Conversion 2

    17/26

    I N T R O D U C T I O N T O C O M P U T E R G R A P H I CS

    Andries van Dam September 23, 2008 ScanConversion2 #/26

    Uses floats! 1 test, 3 or 4 additions per pixel

    Initialization can be improved

    Multiply everything by 4 No Floats!

    Makes the components even, but sign of

    decision variable remains same

    Questions

    Are we getting all pixels whose distancefrom the circle is less than ?

    Why is y > xthe right stopping criterion?

    What if it were an ellipse?

    Analysis

  • 7/30/2019 Scan Conversion 2

    18/26

    I N T R O D U C T I O N T O C O M P U T E R G R A P H I CS

    Andries van Dam September 23, 2008 ScanConversion2 #/26

    Patterned primitives

    Aligned Ellipses

    Non-integerprimitives

    General conics

    Other Scan Conversion Problems

  • 7/30/2019 Scan Conversion 2

    19/26

    I N T R O D U C T I O N T O C O M P U T E R G R A P H I CS

    Andries van Dam September 23, 2008 ScanConversion2 #/26

    Patterned line from Pto Q is not sameas patterned line from Q to P.

    Patterns can be geometric or cosmetic

    Cosmetic: Texture applied aftertransformations

    Geometric: Pattern subject totransformations

    Cosmetic patterned line

    Geometric patterned line

    Patterned Lines

    P Q

    P Q

  • 7/30/2019 Scan Conversion 2

    20/26

    I N T R O D U C T I O N T O C O M P U T E R G R A P H I CS

    Andries van Dam September 23, 2008 ScanConversion2 #/26

    Geometric Pattern vs. Cosmetic Pattern

    +

    Geometric(Perspectivized/Filtered)

    Cosmetic(Contact Paper)

  • 7/30/2019 Scan Conversion 2

    21/26

    I N T R O D U C T I O N T O C O M P U T E R G R A P H I CS

    Andries van Dam September 23, 2008 ScanConversion2 #/26

    Equation is

    i.e,

    Computation of and is similar

    Only 4-fold symmetry

    When do we stop stepping horizontally andswitch to vertical?

    Aligned Ellipses

    12

    2

    2

    2

    =+b

    y

    a

    x

    222222bayaxb =+

    ED

    SED

  • 7/30/2019 Scan Conversion 2

    22/26

    I N T R O D U C T I O N T O C O M P U T E R G R A P H I CS

    Andries van Dam September 23, 2008 ScanConversion2 #/26

    When absolute value of slope of ellipse ismore than 1, viz:

    How do you check this? At a point (x,y) forwhich f(x,y) = 0, a vector perpendicular tothe level set is f(x,y) which is

    This vector points more right than up when

    Direction Changing Criterion (1/2)

    ),(),,( yx

    y

    fyx

    x

    f

    0),(),( >

    -

    yx

    y

    fyx

    x

    f

  • 7/30/2019 Scan Conversion 2

    23/26

    I N T R O D U C T I O N T O C O M P U T E R G R A P H I CS

    Andries van Dam September 23, 2008 ScanConversion2 #/26

    In our case,

    and

    so we check for

    i.e.

    This, too, can be computed incrementally

    Direction Changing Criterion (2/2)

    xayxx

    f 22),( =

    ybyxy

    f 22),( =

    02222

    >- ybxa

    022 >- ybxa

  • 7/30/2019 Scan Conversion 2

    24/26

    I N T R O D U C T I O N T O C O M P U T E R G R A P H I CS

    Andries van Dam September 23, 2008 ScanConversion2 #/26

    Now in ENE octant, not ESE octant

    This problem is artifact ofaliasing muchmore on this later

    Problems with Aligned Ellipses

  • 7/30/2019 Scan Conversion 2

    25/26

    I N T R O D U C T I O N T O C O M P U T E R G R A P H I CS

    Andries van Dam September 23, 2008 ScanConversion2 #/26

    Non-Integer Primitives

    Initialization is harder

    Endpoints are hard, too

    making Line (P,Q) and Line (Q,R)join properly is a good test

    Symmetry is lost

    Non Integer Primitives and

    General Conics

    General Conics

    Very hard--the octant-changing test istougher, the difference computationsare tougher, etc.

    do it only if you have to.

    Note that drawing gray-scale conics is

    easier than drawing B/W conics

  • 7/30/2019 Scan Conversion 2

    26/26

    I N T R O D U C T I O N T O C O M P U T E R G R A P H I CS

    Generic Polygons

    (More information and these pictures on page92-93 of textbook)