
CS 4204 Computer Graphics ClippingClipping andand ClassClass ViewingViewing YongYong CaoCao VirginiaVirginia TechTech References: Interactive Computer Graphics, Fourth Edition, Ed Angle Objectives IntroduceIntroduceIntroduce basicbasicbasic implementationimplementationimplementation strategiesstrategiesstrategies ClippingClippingClipping Overview AtAt endend ofof thethe geometricgeometric pipipeline,peline, verticesvertices havehave beenbeen assembledassembled intointo primitivesprimitives MustMust clipclip outout primitivesprimitives thatthat areare outsideoutside thethe viewview frustumfrustum •• AlgorithmsAlgorithms basedbased onon representingrepresenting primitivesprimitives byby listslists ofof verticesvertices MustMust findfind whichwhich pixelspixels cancan bebe affectedaffected byby eacheach primitiveprimitive •• FragmentFragment generationgeneration •• RasterizationRasterization oror scanscan conversionconversion Required Tasks ClippingClippingClipping RasterizationRasterizationRasterization ororor scanscanscan conversionconversionconversion TransformationsTransformationsTransformations SomeSomeSome taskstaskstasks deferreddeferreddeferred untiluntiluntil fragementfragementfragement processingprocessingprocessing •• HiddenHidden surfacesurface removalremoval •• AntialiasingAntialiasing Clipping 2D2D againstagainst clippingclipping windowwindow 3D3D againstagainst clippingclipping volumevolume EasyEasy forfor lineline segmentssegments polygonspolygons HardHard forfor curvescurves andand texttext •• ConvertConvert toto lineslines andand polygonspolygons firstfirst Clipping 2D Line Segments BruteBruteBrute forceforceforce approach:approach:approach: computecomputecompute intersectionsintersectionsintersections withwithwith allallall sidessidessides ofofof clippingclippingclipping windowwindowwindow •••Inefficie InefficientInefficientnt Cohen-Sutherland Algorithm •••Idea:Idea:Idea: eliminateeliminateeliminate asasas manymanymany casescasescases asasas possiblepossiblepossible withoutwithoutwithout computingcomputingcomputing intersectionsintersectionsintersections •••StartStartStart withwithwith fourfourfour lineslineslines thatthatthat determinedeterminedetermine thethethe sidessidessides ofofof thethethe clippingclippingclipping windowwindowwindow y = ymax x = xmin x = xmax y = ymin The Cases CaseCase 1:1: bothboth endpointsendpoints ofof lineline segmentsegment insideinside allall fourfour lineslines •• DrawDraw (accept)(accept) lineline segmentsegment asas isis y = ymax x = xmin x = xmax y = ymin CaseCase 2:2: bothboth endpointsendpoints outsideoutside allall lineslines andand onon samesame sideside ofof aa lineline •• DiscardDiscard (reject)(reject) thethe lineline segmentsegment The Cases CaseCaseCase 3:3:3: OneOneOne endpointendpointendpoint inside,inside,inside, oneoneone outsideoutsideoutside •• MustMust dodo atat leastleast oneone intersectionintersection CaseCaseCase 4:4:4: BothBothBoth outsideoutsideoutside •• MayMay havehave partpart insideinside •• MustMust dodo atat leastleast oneone intersectionintersection y = ymax x = xmin x = xmax Defining Outcodes ForForFor eacheacheach endpoint,endpoint,endpoint, definedefinedefine ananan outcodeoutcodeoutcode b0 b1 b2b 3 b0 = 1 if y > ymax , 0 otherwise b1 = 1 if y < ymin , 0 otherwise b2 = 1 if x > xmax , 0 otherwise b3 = 1 if x < xmin , 0 otherwise OutcodesOutcodesOutcodes dividedividedivide spacespacespace intointointo 999 regionsregionsregions ComputationComputationComputation ofofof outcodeoutcodeoutcode requiresrequiresrequires atatat mostmostmost 444 subtractionssubtractionssubtractions Using Outcodes ConsiderConsiderConsider thethethe 555 casescasescases belowbelowbelow AB:AB:AB: outcode(Aoutcode(Aoutcode(A))) === outcode(Boutcode(Boutcode(B))) === 000 •• AcceptAccept lineline segmentsegment Using Outcodes CD:CD:CD: outcodeoutcodeoutcode (C)(C)(C) === 0,0,0, outcode(Doutcode(Doutcode(D))) ≠≠≠ 000 •• ComputeCompute intersectionintersection •• LocationLocation ofof 11 inin outcode(Doutcode(D)) determinesdetermines whichwhich edgeedge toto intersectintersect withwith •• NoteNote ifif therethere werewere aa segmentsegment fromfrom AA toto aa pointpoint inin aa regionregion withwith 22 onesones inin outcodeoutcode,, wewe mightmight havehave toto dodo twotwo intersectionsintersections Using Outcodes EF:EF:EF: outcode(Eoutcode(Eoutcode(E))) logicallylogicallylogically ANDedANDedANDed withwithwith outcode(Foutcode(Foutcode(F))) (bitwise)(bitwise)(bitwise) ≠≠≠ 000 ••• BothBothBoth outcodesoutcodesoutcodes havehavehave aaa 111 bitbitbit ininin thethethe samesamesame placeplaceplace ••• LineLineLine segmentsegmentsegment isisis outsideoutsideoutside ofofof correspondingcorrespondingcorresponding sidesideside ofofof clippingclippingclipping windowwindowwindow ••• rejectrejectreject Using Outcodes •••GHGHGH andandand IJ:IJ:IJ: samesamesame outcodesoutcodesoutcodes,,, neitherneitherneither zerozerozero butbutbut logicallogicallogical ANDANDAND yieldsyieldsyields zerozerozero •••ShortenShortenShorten linelineline segmentsegmentsegment bybyby intersectingintersectingintersecting withwithwith oneoneone ofofof sidessidessides ofofof windowwindowwindow •••ComputeComputeCompute outcodeoutcodeoutcode ofofof intersectionintersectionintersection (new(new(new endpointendpointendpoint ofofof shortenedshortenedshortened linelineline segment)segment)segment) •••ReexecuteReexecuteReexecute algorithmalgorithmalgorithm Efficiency InInIn manymanymany applications,applications,applications, thethethe clippingclippingclipping windowwindowwindow isisis smallsmallsmall relativerelativerelative tototo thethethe sizesizesize ofofof thethethe entireentireentire datadatadata basebasebase •• MostMost lineline segmentssegments areare outsideoutside oneone oror moremore sideside ofof thethe windowwindow andand cancan bebe eliminatedeliminated basedbased onon theirtheir outcodesoutcodes InefficiencyInefficiencyInefficiency whenwhenwhen codecodecode hashashas tototo bebebe reexecutedreexecutedreexecuted forforfor linelineline segmentssegmentssegments thatthatthat mustmustmust bebebe shortenedshortenedshortened ininin moremoremore thanthanthan oneoneone stepstepstep Cohen Sutherland in 3D UseUse 66-bit-bit outcodesoutcodes WhenWhen needed,needed, clipclip lineline segmentsegment againstagainst planesplanes Viewing and Projection CameraCamera Analogy:Analogy: 1.1. SetSet upup youryour tripodtripod andand pointingpointing thethe cameracamera atat thethe scenescene (viewing(viewing transformation).transformation). 2.2. ArrangeArrange thethe scenescene toto bebe photographedphotographed intointo thethe desireddesired compositioncomposition (modeling(modeling transformation).transformation). 3.3. ChooseChoose aa cameracamera lenslens oror adjustadjust thethe zoomzoom (projection(projection transformation).transformation). 4.4. DetermineDetermine howhow largelarge youyou wantwant thethe finalfinal photographphotograph toto bebe -- forfor example,example, youyou mightmight wantwant itit enlargedenlarged (viewport(viewport transformation).transformation). Projection transformations Introduction to Projection Transformations Mapping:Mapping: ff :: RRnn ÆÆ RRmm Projection:Projection: nn >> mm PlanarPlanar Projection:Projection: ProjectionProjection onon aa plane.plane. RR33ÆÆRR22 oror RR44ÆÆRR33 homogenoushomogenous coordinates.coordinates. Introduction to Projection Transformations Objectives IntroduceIntroduceIntroduce thethethe classicalclassicalclassical viewsviewsviews CompareCompareCompare andandand contrastcontrastcontrast imageimageimage formationformationformation bybyby computercomputercomputer withwithwith howhowhow imagesimagesimages havehavehave beenbeenbeen formedformedformed bybyby architects,architects,architects, artists,artists,artists, andandand engineersengineersengineers LearnLearnLearn thethethe benefitsbenefitsbenefits andandand drawbacksdrawbacksdrawbacks ofofof eacheacheach typetypetype ofofof viewviewview Classical Viewing ViewingViewing requiresrequires threethree basicbasic elementselements •• OneOne oror moremore objectsobjects •• AA viewerviewer withwith aa projectionprojection surfacesurface •• ProjectorsProjectors thatthat gogo fromfrom thethe objecobject(s)t(s) toto thethe projectionprojection surfacesurface ClassicalClassical viewsviews areare basedbased onon thethe relationshiprelationship amongamong thesethese elementselements •• TheThe viewerviewer pickspicks upup thethe objectobject andand orientsorients itit howhow sheshe wouldwould likelike toto seesee itit EachEach objectobject isis assumedassumed toto constructedconstructed fromfrom flatflat principalprincipal facesfaces •• Buildings,Buildings, polyhedrapolyhedra,, manufacturedmanufactured objectsobjects Planar Geometric Projections StandardStandardStandard projectionsprojectionsprojections projectprojectproject ontoontoonto aaa planeplaneplane ProjectorsProjectorsProjectors areareare lineslineslines thatthatthat eithereithereither •• convergeconverge atat aa centercenter ofof projectionprojection •• areare parallelparallel SuchSuchSuch projectionsprojectionsprojections preservepreservepreserve lineslineslines •• butbut notnot necessarilynecessarily anglesangles NonNonNon-planar--planarplanar projectionsprojectionsprojections areareare neededneededneeded forforfor applicationsapplicationsapplications suchsuchsuch asasas mapmapmap constructionconstructionconstruction Classical Projections Perspective vs Parallel ComputerComputerComputer graphicsgraphicsgraphics treatstreatstreats allallall projectionsprojectionsprojections
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages43 Page
-
File Size-