CG2014-052DViewing-gb

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

授课教师:郭芬红Email:guofenhong@163.com办公室:四教西204北方工业大学理学院数学系20132-DViewing二维观察2Outline(Hearn&Baker,Chapter6,p296)1.Clippingwindowandviewport裁剪窗口与视区2.Clippingofpoints,lines,polygonsandtexts点、直线、多边形、文本的裁剪算法3.2DviewinginOpenGLOpenGL中的二维观察函数1.ClippingWindowandViewport裁剪窗口与视区452DViewing-TransformationPipelineconstructionofobjectsandscenesdefinitionofviewingareaandorientationtransformationtonormalizedviewingframemappingtodevicedependentvaluesmodelingcoordinatesworldcoordinatesviewingcoordinatesnormalizedcoordinatesdevicecoordinatesMCWCVCNCDC67Clippingwindowandviewportclippingwindow:whattodisplayviewport:wheretobeviewedtranslation,rotation,scaling,clipping,...8裁剪窗口与视区Clippingwindow&Viewport9WytWybOWxlWxrxVytVybOVxrVxlXxyy窗口与视区示意图10yWytWybOWxlWxrxVytVybOVxrVxlxy边与坐标轴不平行的窗口及其视区11窗口——视区12窗口与视区窗口与视区的形状相似,即二者的长与宽之比相同,变换后在视区产生均匀缩小或均匀放大的图形。窗口与视区的形状不相似,即二者的长与宽之比不相等,变换后在视区产生畸变的图形。图形将沿水平及垂直方向以不同比例发生变化——畸变。窗口斜置,即窗口绕坐标原点旋转一个角度,变换后视区的图形也相应地旋转一个角度。13窗口(a)(b)(c)视区1—缩小视区2—放大窗口与视区形状相似14(a)视区1水平畸变(b)(c)视区2垂直畸变窗口2窗口1窗口与视区形状不相似15窗口视区(a)(b)窗口斜置162.2DClippingAlgorithms二维裁剪算法clippingofpoint,line,polygon,text18ClippingOperationsremoveobjectsoutsideaclipwindowclipwindow:rectangle,polygon,curvedboundariesappliedinworldorviewingcoordinatescombinedwithscanconversionobjectstoclip:points,lines,polygons,curves,text,...192DClipping裁剪窗口Clipwindow:物体被裁剪的区域.裁剪算法Clippingalgorithm:用于确定物体哪部分位于裁剪窗口内,哪部分位于裁剪窗口外.下面讨论裁剪窗口为与坐标轴平行的矩形PointClipping21ClippingpointsClippingapoint(x,y)iseasyassumingthattheclippingwindowisanaxisalignedrectangledefinedby(xwmin,ywmin)and(xwmax,ywmax):Ifxwmin≤x≤xwmaxandywmin≤y≤ywmaxKeeppoint(x,y)OtherwiseClipthepointLineClipping23LineClippinglineclippingagainstarectangularclipwindowbeforeclippingafterclippingNote:entirelyvisible(p1p2),entirelyinvisible(p3p4),partiallyvisible(p5p6),...24LineClipping:Thesimplebutslow(brute-force)approachFindintersectionswiththerectangleboundariesusingtheparametricline:010010()()xxxxyyyy0011where(,)and(,)arethetwoendpoints.xyxyExample:minIntersectionwiththeboundary:xwmin0min01010()()xwxxwxxxxxminIf01,intersectionatandxwmin001010()()xwxyyyyxxmin01100Checkforintersectionswiththeotherboundariesbasedonthenewlinegivenby(,y)and(,y)(assuming(,y)wasoutside).xwxx25LineClippingGoals:Eliminatesimplecasesfast(entirelyvisible/invisible)Avoidintersectioncalculations(partiallyvisible)Cohen-SutherlandLiang-BaskyNicholl-Lee-Nicholl(NLN)……26Cohen-SutherlandLineClipping(1974,DanCohen,IvanSutherland)assignmentofregioncodestolineendpoints4-bitcode:CTopCBottomCRrightCLeft(注:按上下右左的顺序)binaryregioncodesassignedtolineendpointsaccordingtorelativepositionwithrespecttotheclippingrectangleelseyyCT0max1当elsexxCR0max1当elsexxCL0min1当elseyyCB0min1当clippingwindow27编码裁剪法端点编码规则第1位为1,位于窗口左侧第2位为1,位于窗口右侧第3位为1,位于窗口下方第4位为1,位于窗口上方否则,相应的位置取028Cohen-SutherlandLineClippingcode1=code2=0000⇒entirelyvisible(code1ANDcode2)≠0000⇒entirelyinvisibleallothers⇒intersect!NOTE:CD,C:0000D:1000differentCtintersectwithtopclippingboundary29编码裁剪法编码判断规则线段两端点编码均为0000,则该线段完全位于窗口内,完全可见。线段两端点编码在相同的bit位同为1,表明该线段完全位于窗外,完全不可见。端点编码的逻辑与操作可用于测试线段是否被完全裁剪.如果结果0,则线段完全位于窗口之外.30IntersectionCase:Cohen-SutherlandLineClippingclippingwindow3P4P3P2P2P2P1P1Ppassthroughtheclipwindowintersectclippingboundarieswithoutenteringthewindow31Cohen-SutherlandLineClippingProcedureofprocessingtheintersectioncase:1)intersectiontestwithboundinglinesofclippingwindow2)left,right,bottom,top(ortop,bottom,right,left)3)discardanoutsidepart3)repeatintersectiontestuptofourtimes32Cohen-SutherlandLineClipping:ExampleDKMABCEFGHJINLAB:与窗口左边相交,求交点H,AH和BH显然不可见EF:与窗口上边交点I,弃EI与窗口下边交点K,弃KF与窗口右边交点J,弃KJ保留IJCD:与窗口上边交点L,弃CL与窗口下边交点G,弃GD与窗口右边交点M,弃LM与窗口左边交点N,弃NO保留MN最坏情形:最多求交4次clippingorder:-L-R-B-T33编码裁剪法编码判断规则如果线段不是完全位于窗内或窗外,则可通过与窗口的边界求交来检测线段的裁剪性。裁剪过程:窗口外端点到窗口边界的区域需要被裁剪。假定窗口边界的处理次序:左、右、下、上。34编码裁剪法端点编程思路已知线段两端点p1,p2及剪裁窗口边界winMin和winMax;循环依次判断线段与剪裁窗口交点的区域可见性,可见就画,不可见不画,直到所有区域判断完毕:35编码裁剪法端点编程思路(续)1.首先求线段2端点p1,p2的编码code1,code2;2.如果线段完全在剪裁窗口内,画线退出3.如果线段完全在剪裁窗口外,退出4.如果p1在窗口内,则交换2个点及其编码5.计算线段的斜率6.求p1p2是否与剪裁窗口的4条边相交7.如果相交,则用交点替换p1点返回步骤1,继续判断36编码裁剪法端点编程思路(续)求端点编码函数encode(p,winMin,winMax);交换点函数swapPts(p1,p2);交换编码函数swapCodes(code1,code2);点是否在剪裁窗口内函数inside(code);线段是否完全在剪裁窗口内函数accept(code1,code2);返回布尔值判断线段是否完全在剪裁窗口外函数reject(code1,code2);返回布尔值45Cohen-SutherlandLineClippingSummaryWorksbestwhentherearemanylinesegments,butfewareactuallydisplayedespeciallysuitableforextralarge/smallclippingwindowCanbeeasilyextendedto3DclippingCanbeextendtoconvex-polygonclippingwindowcomplicatedregioncodingschemeFloating-pointarithmeticrequired46ParametricLineClippingToachievefasterclipping,domoretestingbeforeweactuallycomputetheintersection.Liang-BaskyClipping(textbookSec.6-7,p322)47Liang-Barsky算法算法是基于直线的参数化方程分析:x=x1+uxy=y1+uy0=u=1x=x2–x1,y=y2–y1根据点剪裁的条件,有xwmin=x1+ux=xwmaxywmin=y1+uy=ywmaxPolygonClipping56PolygonClippingClippingpolygonsismorecomplexthanclippingtheindividuallinesInput:polygonOutput:originalpolygon,newpolygon,o

1 / 56
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功