aliasing and anti aliasing1.pdf

download aliasing and anti aliasing1.pdf

of 5

Transcript of aliasing and anti aliasing1.pdf

  • 7/30/2019 aliasing and anti aliasing1.pdf

    1/5

    1

    Computer Graphics & Visualization

    Lecture 4Anti-Aliasing

    Line and Polygon Clipping

    PedherJohanssonDepartmentofComputingScience,UmeUniversityComputer Graphics & Visualization

    Anti-Aliasing

    OverviewSuper SamplingArea Sampling (prefiltering)Weighting (postfiltering)

    PedherJohanssonDepartmentofComputingScience,UmeUniversityComputer Graphics & Visualization

    Antialiasing

    Aliasing, jagged edges or staircasingcan be reduced by:

    Higherscreenresolution

    - Needahugeframebuffer

    Antialiasingtechniques

    - Varypixelintensitiesalongboundariestosmooththeedge.

    PedherJohanssonDepartmentofComputingScience,UmeUniversityComputer Graphics & Visualization

    Antialiasing Techniques

    Super Sampling

    Computeintensitiesatsub-pixelgridpositionsandcombinetheresultstoobtainthepixelintensity.

    Area Sampling

    Findpixelintensitybycalculatingtheareasofoverlapofeachpixelwithintheobjectstobedisplayed.

    PedherJohanssonDepartmentofComputingScience,UmeUniversityComputer Graphics & Visualization

    Supersampling

    (zero line width)

    Example:astraightlineonagrayscaledisplay

    Divideeachpixelintosub-pixels.

    Thenumberofintensitiesarethemaxnumberofsub-pixelsselectedonthelinesegmentwithinapixel.

    PedherJohanssonDepartmentofComputingScience,UmeUniversityComputer Graphics & Visualization

    Supersampling

    (finite line width)

    Theintensitylevelforeachpixelisproportionaltothenumberofsub-pixelsinsidethepolygonrepresentingthelinearea.

    Lineintensityisdistributedovermorepixels.

  • 7/30/2019 aliasing and anti aliasing1.pdf

    2/5

    2

    PedherJohanssonDepartmentofComputingScience,UmeUniversityComputer Graphics & Visualization

    Postfiltering

    Equalareascancontributetounequalintensity.Aweightedavarage.

    WeigtingMasks

    Predefinedtablevaluesforeachsubpixel

    Filtering Techniques

    Includesneighbouringpixels

    PedherJohanssonDepartmentofComputingScience,UmeUniversityComputer Graphics & Visualization

    Filter Functions

    Optimalfiltersarecomputationallymoreexpensive.

    Conefiltersareaveryreasonablecompromisebetweencostandquality.

    PedherJohanssonDepartmentofComputingScience,UmeUniversityComputer Graphics & Visualization

    Anti-Aliasing

    Line Intensity Differences:

    Thediagonallineappearslessbrightthanthehorizontal.

    Totalintensityisproportionaltotheirlength.

    PedherJohanssonDepartmentofComputingScience,UmeUniversityComputer Graphics & Visualization

    Line and PolygonClipping

    Overview Cohen-Sutherland line clipping algorithm Liang-Barsky line clipping algorithm

    Sutherland-Hogeman polygon clipping

    PedherJohanssonDepartmentofComputingScience,UmeUniversityComputer Graphics & Visualization

    Clipping Algorithms

    Line Clipping:

    Cohen-Suterland(encoding)

    - Oldestandmostcommonlyused

    Nicholl-Lee-Nicholl(encoding)(moreefficient)

    Liang-Barsky (parametric)(moreefficient)

    Polygon Clipping:

    Sutherland-Hodgeman

    - Divideandconquerstrategy

    Weiler-Atherton(modifiedforconcavepolygons)

    PedherJohanssonDepartmentofComputingScience,UmeUniversityComputer Graphics & Visualization

    1001 1000 1010

    0101 0100 0110

    0001 0000 0010

    C0 = Bit code of P0Cend = Bit code of Pend

    Cohen-Sutherland Line-Clipping

    1. EncodeendpointsBit0=pointisleftofwindowBit1=pointisrightofwindowBit2=pointisbelowwindowBit3=pointisabovewindow

    2. IfC0 Cend 0 thenP0Pend istriviallyrejected

    3. IfC0 Cend = 0 thenP0Pend istriviallyaccepted

    4. Otherwisesubdivideandgotostep1withnewsegment.

  • 7/30/2019 aliasing and anti aliasing1.pdf

    3/5

    3

    PedherJohanssonDepartmentofComputingScience,UmeUniversityComputer Graphics & Visualization

    1001 1000 1010

    0101 0100 0110

    0001 0000 0010

    Clip order: Left, Right, Bottom, Top

    A1

    A3

    B3

    C3

    D3

    E2

    D2

    C2

    B2

    A2

    B1

    C11) A1C1 1) A2E2

    2) B1C1 2) B2E2

    3) reject 3) B2D2

    4) B2C2

    5) accept

    1) A3D3

    2) A3C3

    3) A3B3

    4) accept

    Cohen-Sutherland Line-Clipping

    PedherJohanssonDepartmentofComputingScience,UmeUniversityComputer Graphics & Visualization

    Cohen-Sutherland Line-Clipping

    Willdounnecessaryclipping.

    Efficientwhenmostofthelinestobeclippedareeitherrejectedoraccepted(notsomanysubdivisions).

    Easytoprogram

    PedherJohanssonDepartmentofComputingScience,UmeUniversityComputer Graphics & Visualization

    Parametric form

    Alinesegmentwithendpoints

    (x0, y0) and(xend, yend)

    wecandescribeintheparametricform

    x = x0 + uxy = x

    0

    + uy 0 u 1

    where

    x = xend x0y = yend y0

    PedherJohanssonDepartmentofComputingScience,UmeUniversityComputer Graphics & Visualization

    Liang-Barsky Line-Clipping

    MoreefficientthanCohen-Sutherland

    Alineisinsidetheclippingregionforvaluesofu suchthat:

    xwmin x0 + ux xwmax x = xend x0

    ywmin y0 + uy ywmax y = yend y0

    Canbedescribedas

    u pk qk, k = 1, 2, 3, 4

    PedherJohanssonDepartmentofComputingScience,UmeUniversityComputer Graphics & Visualization

    k

    kk

    p

    qu =

    0max44

    min033

    0max22

    min011

    yywqyp

    ywyqyp

    xxwqxp

    xwxqxp

    ==

    ==

    ==

    ==

    where

    Leftboundary

    Rightboundary

    Bottomboundary

    Topboundary

    Liang-Barsky Line-Clipping

    The infinitely line intersects the clipregion edges when:

    PedherJohanssonDepartmentofComputingScience,UmeUniversityComputer Graphics & Visualization

    Liang-Barsky Line-Clipping

    Whenpk< 0,asu increases

    - linegoesfromoutsidetoinside- entering

    Whenpk> 0,

    - linegoesfrominsidetooutside- exiting

    Whenpk= 0,

    - lineisparalleltoanedge

    Ifthereisasegmentofthelineinsidetheclipregion,asequenceofinfinitelineintersectionsmustgo:entering,entering,exiting,exiting

  • 7/30/2019 aliasing and anti aliasing1.pdf

    4/5

    4

    PedherJohanssonDepartmentofComputingScience,UmeUniversityComputer Graphics & Visualization

    Liang-Barsky Line-Clipping

    EnterEnter

    ExitExit

    Enter

    Exit

    EnterExit

    Clipregion

    PedherJohanssonDepartmentofComputingScience,UmeUniversityComputer Graphics & Visualization

    Liang-Barsky Line-Clipping

    1. Setumin = 0 andumax = 1.

    2. Calculatetheu values:

    3. Ifu < umin oru > umax ignoreit.Otherwiseclassifytheu valuesasenteringorexiting.

    4. Ifumin < umax thendrawalinefrom:

    ( x0 + x umin, y0 + y umin ) to( x0 + x umax, y0 + y umax )

    PedherJohanssonDepartmentofComputingScience,UmeUniversityComputer Graphics & Visualization

    0,10

    0,0 10,0

    10,10

    P0(-5,3)

    Pend(15,9)

    6

    7

    39

    310

    2

    1

    )39(

    03

    4

    3

    )5(15

    )5(10

    4

    1

    ))5(15(

    05

    0max

    4

    4

    min0

    3

    3

    0max

    2

    2

    min0

    1

    1

    =

    =

    ==

    =

    =

    ==

    =

    =

    ==

    =

    =

    ==

    y

    yyw

    p

    qu

    y

    ywy

    p

    qu

    x

    xxw

    p

    qu

    x

    xwx

    p

    qu

    top

    bottom

    right

    left

    u < 0 thenignore

    u > 1 thenignore

    Entering uenter = 1/4

    Exiting uleave = 3/4

    ExampleLiang-Barsky

    PedherJohanssonDepartmentofComputingScience,UmeUniversityComputer Graphics & Visualization

    Liang-Barsky Line-Clipping

    Wehaveuenter= 1/4 anduleave = 3/4

    Pend - P0 = (15+5,9-3) = (20,6)

    Ifuenter< uleave ,thereisalinesegment

    - computeendpointsbysubstitutingu values Drawalinefrom

    (-5+(20)(1/4), 3+(6)(1/4))to

    (-5+(20)(3/4), 3+(6)(3/4))

    x y

    PedherJohanssonDepartmentofComputingScience,UmeUniversityComputer Graphics & Visualization

    0,10

    0,0 10,0

    10,10

    P0(-8,2)

    Pend(2,14)

    3

    2

    214

    210

    6

    1

    )214(

    02

    5

    9

    )8(2

    )8(10

    5

    4

    ))8(2(

    08

    0max

    4

    4

    min0

    3

    3

    0max

    2

    2

    min0

    1

    1

    =

    =

    ==

    =

    =

    ==

    =

    =

    ==

    =

    =

    ==

    y

    yyw

    p

    qu

    y

    ywy

    p

    qu

    x

    xxw

    p

    qu

    x

    xwx

    p

    qu

    top

    bottom

    right

    left

    u < 0 thenignore

    u > 1 thenignore

    Entering uenter= 4/5

    Exiting uleave = 2/3

    Example

    Liang-Barsky

    PedherJohanssonDepartmentofComputingScience,UmeUniversityComputer Graphics & Visualization

    Liang-Barsky Line-Clipping

    Wehaveuenter= 4/5 anduleave = 2/3

    Pend - P0 = (2+8, 14-2) = (10, 12)

    uenter> uleave ,thereisnolinesegmentdodraw

  • 7/30/2019 aliasing and anti aliasing1.pdf

    5/5

    5

    PedherJohanssonDepartmentofComputingScience,UmeUniversityComputer Graphics & Visualization

    Nicholl-Lee-Nicholl Line Clipping

    Avoidsmultipleclippingofanindividuallinebycreatingmoreregions.

    Onlythreeregionsneedtobeconsidered.

    FindpositionofPend relativetoP0.

    P0

    P0

    P0

    inside edgeregion cornerregion

    PedherJohanssonDepartmentofComputingScience,UmeUniversityComputer Graphics & Visualization

    Nicholl-Lee-Nicholl Line Clipping

    IfP0 insideandPend outside:

    IfP0 istotheleft:

    B

    RL

    T

    P0

    LB

    LR

    LT

    P0L

    L

    L

    LB

    TRT

    P0

    LT

    TB

    IfP0 istotheleftandabove:

    PedherJohanssonDepartmentofComputingScience,UmeUniversityComputer Graphics & Visualization

    Nicholl-Lee-Nicholl Line Clipping

    To determine region

    compareslopes,and

    boundariesoftheNLNregion.

    PedherJohanssonDepartmentofComputingScience,UmeUniversityComputer Graphics & Visualization

    Sutherland-HodgemanPolygon Clipping

    Four test cases:1. Firstvertexinsideandthesecondoutside(in-outpair)

    2. Bothverticesinsideclipwindow

    3. Firstvertexoutsideandthesecondinside(out-inpair)

    4. Bothverticesoutsidetheclipwindow

    Concavepolygonsmaybedisplayedwithextralines.

    PedherJohanssonDepartmentofComputingScience,UmeUniversityComputer Graphics & Visualization

    Weiler-Atherton

    Polygon Clipping

    Clipsconcavepolygonscorrectly.

    Insteadofalwaysgoingaroundthepolygonedges,wealso,wanttofollowwindowboundaries.

    Foranoutside-to-insidepairofvertices,followthepolygonboundary.

    Foraninside-to-outsidepairofvertices,followthewindowboundaryinaclockwisedirection.