您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 人事档案/员工关系 > 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-TransformationPipelineconstructionofobjectsandscenesdefinitionofviewingareaandorientationtransformationtonormalizedviewingframemappingtodevicedependentvaluesmodelingcoordinatesworldcoordinatesviewingcoordinatesnormalizedcoordinatesdevicecoordinatesMCWCVCNCDC67Clippingwindowandviewportclippingwindow:whattodisplayviewport:wheretobeviewedtranslation,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,text18ClippingOperationsremoveobjectsoutsideaclipwindowclipwindow:rectangle,polygon,curvedboundariesappliedinworldorviewingcoordinatescombinedwithscanconversionobjectstoclip:points,lines,polygons,curves,text,...192DClipping裁剪窗口Clipwindow:物体被裁剪的区域.裁剪算法Clippingalgorithm:用于确定物体哪部分位于裁剪窗口内,哪部分位于裁剪窗口外.下面讨论裁剪窗口为与坐标轴平行的矩形PointClipping21ClippingpointsClippingapoint(x,y)iseasyassumingthattheclippingwindowisanaxisalignedrectangledefinedby(xwmin,ywmin)and(xwmax,ywmax):Ifxwmin≤x≤xwmaxandywmin≤y≤ywmaxKeeppoint(x,y)OtherwiseClipthepointLineClipping23LineClippinglineclippingagainstarectangularclipwindowbeforeclippingafterclippingNote:entirelyvisible(p1p2),entirelyinvisible(p3p4),partiallyvisible(p5p6),...24LineClipping:Thesimplebutslow(brute-force)approachFindintersectionswiththerectangleboundariesusingtheparametricline:010010()()xxxxyyyy0011where(,)and(,)arethetwoendpoints.xyxyExample:minIntersectionwiththeboundary:xwmin0min01010()()xwxxwxxxxxminIf01,intersectionatandxwmin001010()()xwxyyyyxxmin01100Checkforintersectionswiththeotherboundariesbasedonthenewlinegivenby(,y)and(,y)(assuming(,y)wasoutside).xwxx25LineClippingGoals:Eliminatesimplecasesfast(entirelyvisible/invisible)Avoidintersectioncalculations(partiallyvisible)Cohen-SutherlandLiang-BaskyNicholl-Lee-Nicholl(NLN)……26Cohen-SutherlandLineClipping(1974,DanCohen,IvanSutherland)assignmentofregioncodestolineendpoints4-bitcode:CTopCBottomCRrightCLeft(注:按上下右左的顺序)binaryregioncodesassignedtolineendpointsaccordingtorelativepositionwithrespecttotheclippingrectangleelseyyCT0max1当elsexxCR0max1当elsexxCL0min1当elseyyCB0min1当clippingwindow27编码裁剪法端点编码规则第1位为1,位于窗口左侧第2位为1,位于窗口右侧第3位为1,位于窗口下方第4位为1,位于窗口上方否则,相应的位置取028Cohen-SutherlandLineClippingcode1=code2=0000⇒entirelyvisible(code1ANDcode2)≠0000⇒entirelyinvisibleallothers⇒intersect!NOTE:CD,C:0000D:1000differentCtintersectwithtopclippingboundary29编码裁剪法编码判断规则线段两端点编码均为0000,则该线段完全位于窗口内,完全可见。线段两端点编码在相同的bit位同为1,表明该线段完全位于窗外,完全不可见。端点编码的逻辑与操作可用于测试线段是否被完全裁剪.如果结果0,则线段完全位于窗口之外.30IntersectionCase:Cohen-SutherlandLineClippingclippingwindow3P4P3P2P2P2P1P1Ppassthroughtheclipwindowintersectclippingboundarieswithoutenteringthewindow31Cohen-SutherlandLineClippingProcedureofprocessingtheintersectioncase:1)intersectiontestwithboundinglinesofclippingwindow2)left,right,bottom,top(ortop,bottom,right,left)3)discardanoutsidepart3)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-SutherlandLineClippingSummaryWorksbestwhentherearemanylinesegments,butfewareactuallydisplayedespeciallysuitableforextralarge/smallclippingwindowCanbeeasilyextendedto3DclippingCanbeextendtoconvex-polygonclippingwindowcomplicatedregioncodingschemeFloating-pointarithmeticrequired46ParametricLineClippingToachievefasterclipping,domoretestingbeforeweactuallycomputetheintersection.Liang-BaskyClipping(textbookSec.6-7,p322)47Liang-Barsky算法算法是基于直线的参数化方程分析:x=x1+uxy=y1+uy0=u=1x=x2–x1,y=y2–y1根据点剪裁的条件,有xwmin=x1+ux=xwmaxywmin=y1+uy=ywmaxPolygonClipping56PolygonClippingClippingpolygonsismorecomplexthanclippingtheindividuallinesInput:polygonOutput:originalpolygon,newpolygon,o
本文标题:CG2014-052DViewing-gb
链接地址:https://www.777doc.com/doc-2904595 .html