【vc++精品源码栏目提醒】:网学会员--在 vc++精品源码编辑为广大网友搜集整理了:(计算机图形学)多边形区域扫描线填充或种子填充 - 其它资料绩等信息,祝愿广大网友取得需要的信息,参考学习。
实验 2:多边形区域扫描线填充或种子填充实验类型:验证、设计所需时间:3 学时主要实验内容及要求: 实现多边形区域扫描线填充的有序边表算法, 并将实现的算法应用于任意多边形的填充,要求多边形的顶点由键盘输入或鼠标拾取,填充要准确,不能多填也不能少填。
要求掌握边形区域扫描线填充的有序边表算法的基本原理和算法设计, 画出算法实现的程序流程图,使用 C 或者 VC实现算法,并演示。
参考试验步骤:1)分析多边形区域扫描线填充算法的原理,确定算法流程 ① 初始化:构造边表,AET 表置空 ② 将第一个不空的 ET 表中的边插入 AET 表 ③ 由 AET 表取出交点进行配对(奇偶)获得填充区间,依次对这些填充区 间着色 ④ yyi1 时, 根据 xxi1/k 修改 AET 表所有结点中交点的 x 坐标。
同时如 果相应的 ET 表不空,则将其中的结点插入 AET 表,形成新的 AET 表 ⑤ AET 表不空,则转(3) ,否则结束。
2)编程实现 ① 首先确定多边形顶点和 ET/AET 表中结点的结构 ② 编写链表相关操作(如链表结点插入、删除和排序等) ③ 根据 1)中的算法结合上述已有的链表操作函数实现多边形区域扫描线 填充的主体功能 ④ 编写主函数,测试该算法源代码:includeincludeusing namespace stdtypedef struct dePtint xint ydePtvoid fillGLint x1GLint y1GLint z1 glBeginGL_POINTS glVertex3fx1y10.0f glEndtypedef struct Edgeint yUpperfloat xIntersect dxPerScanstruct Edge nextEdgevoid insertEdgeEdge list Edge edgeEdge pqlistpq-nextwhilepNULLifedge-xIntersectxIntersectpNULLelseqppp-nextedge-nextq-nextq-nextedgeint yNextint k int cnt dePtptsint jifk1cnt-1j0elsejk1whileptsk.yptsj.yifj1cnt-1j0else jreturn ptsj.yvoid makeEdgeRecdePt lower dePt upperint yCompEdge edgeEdge edgesedge-dxPerScanfloatupper.x-lower.x/upper.y-lower.yedge-xIntersectlower.xifupper.yyUpperupper.y-1elseedge-yUpperupper.yinsertEdgeedgeslower.yedgevoid buildEdgeListint cntdePt ptsEdge edgesEdge edgedePt v1v2int iyPrevptscnt-2.yv1.xptscnt-1.xv1.yptscnt-1.yfori0inextinsertEdgeactiveppqvoid fillScanint scanEdge activeEdge p1p2int ip1active-nextwhilep1p2p1-nextforip1-xIntersectixIntersectifillintiscan3p1p2-nextvoid deleteAfterEdge qEdge pq-nextq-nextp-nextfreepvoid updateActiveListint scanEdge activeEdge qactive pactive-nextwhilepifscanp-yUpperpp-nextdeleteAfterqelsep-xIntersectp-xIntersectp-dxPerScanqppp-nextvoid resortActiveListEdge activeEdge qpactive-nextactive-nextNULLwhilepqp-nextinsertEdgeactiveppqvoid scanFillint cntdePt ptsEdge edges1024activeint iscanfori0inextNULLbuildEdgeListcntptsedgesactiveEdge mallocsizeofEdgeactive-nextNULLforscan0scannextfillScanscanactiveupdateActiveListscanactiveresortActiveListactivevoid ChangeSizeGLsizei wGLsizei hGLfloat nRange400.0fifh0 h1 glViewport00whglMatrixModeGL_PROJECTIONglLoadIdentityifw
上一篇:
力控pLerine
下一篇:
2016年江苏国考职位表下载——江苏地区