多边形填充算法的实现-计算机图形学

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

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

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

资源描述

《计算机图形学基础》实验报告实验序号:03实验项目名称:多边形填充算法的实现学号姓名专业、班级软件工程实验地点计-201指导教师时间2016.4.05一、实验目的及要求多边形的填充算法有很多种,比如说边缘填充算法,栅栏填充算法,还有种子填充算法。种子填充算法和其他几种的算法采用的是完全不同的方法。二、实验设备(环境)及要求1、了解MATLAB软件基本操作,熟悉基本计算和绘图功能。2、环境要求:配有WindowsXP及以上操作系统,安装MATLAB软件的完整版。3、实验过程中,务必仔细观察上机现象,记录必要信息,分析实验结果,按要求写出实验报告。三、实验内容与步骤题目:多边形填充算法的实现四、实验结果与数据处理classCDrawView:publicCView{protected://createfromserializationonlyCDrawView();DECLARE_DYNCREATE(CDrawView)public:CDrawDoc*GetDocument();public:CPointspt[7],s_point;......}voidCDrawView::OnDraw(CDC*pDC){CDrawDoc*pDoc=GetDocument();ASSERT_VALID(pDoc);CPennewpen(PS_SOLID,1,RGB(0,0,255));CPen*old=pDC-SelectObject(&newpen);pDC-TextOut(20,20,双击鼠标左键,生成多边形);pDC-TextOut(20,50,先在多边形内部单击鼠标右键,选择种子点,然后单击功能菜单实现填充);pDC-SelectObject(old);}voidCDrawView::OnSeedfill(){CclientDCdc(this);intfill=RGB(0,255,0);intboundary=RGB(0,0,255);intx,y,p0,pmin,pmax;for(intm=1;m7;m++){for(intn=0;n7-m;n++){if(spt[n].yspt[n+1].y){p0=spt[n].y;spt[n]=spt[n+1];spt[n+1]=p0;}}}pmax=spt[0].y;pmin=spt[6].y;x=s_point.x;y=s_point.y;for(;y=pmax;y++){intcurrent=dc.GetPixel(x,y);while((current!=boundary)&&(current!=fill)){dc.SetPixel(x,y,fill);x++;current=dc,GetPixel(x,y);}x=s-point.x;x--;current=dc.GetPixel(x,y);while((current!=boundary)&&(current!=fill)){dc.SetPixel(x,y,fill);x--;current=dc,GetPixel(x,y);}x=s-point.x;}x=s_point.x;y=s_point.y-1;for(;y=pmin;y--){intcurrent=dc.GetPixel(x,y);while((current!=boundary)&&(current!=fill)){dc.SetPixel(x,y,fill);x++;current=dc,GetPixel(x,y);}x=s-point.x;x--;current=dc.GetPixel(x,y);while((current!=boundary)&&(current!=fill)){dc.SetPixel(x,y,fill);x--;current=dc,GetPixel(x,y);}x=s-point.x;}}voidCDrawView::OnLButtonDblClk(UINTnFlags,CPointpoint){RedrawWindow();CDC*pDC=GetDC();CPennewpen(PS_SOLID,1,RGB(0,0,255));CPen*old=pDC-SelectObject(&newpen);spt[0]=CPoint(100,100);spt[1]=CPoint(250,100);spt[2]=CPoint(250,250);spt[3]=CPoint(100,250);spt[4]=CPoint(150,200);spt[5]=CPoint(90,150);spt[6]=CPoint(160,150);spt[7]=CPoint(100,100);pDC-SelectObject(old);CView::OnLButtonDblClk(nFlags,point);}voidCDrawView::OnLButtonDown(UINTnFlags,CPointpoint){s_point=pont;CView::OnRButtonDown(nFlags,point);}CView::OnLButtonDblClk(nFlags,point);}voidCMy2dcadView::makeet()(){intp1=0,p2=1;intsmally,bigy,smallx,bigx;Edge*ep1;for(;p1npoint;p1++,p2=(++p2)%npoint){if(lhpoint[p1][1]==lhpoint[p2][1])continue;elseif(lhpoint[p1][1]lhpoint[p2][1]){smally=lhpoint[p1][1];bigy=lhpoint[p2][1];smallx=lhpoint[p1][0];bigx=lhpoint[p2][0];}else{smally=lhpoint[p2][1];bigy=lhpoint[p1][1];smallx=lhpoint[p2][0];bigx=lhpoint[p1][0];}ep1=newEdge;ep1-ymax=bigy;ep1-x=(float)smallx;ep1-deltax=(float)(smallx-bigx)/(smally-bigy);ep1-nextEdge=et[smally];et[smally]=ep1;}}voidCMy2dcadView::OnRButtonDown(UINTnFlags,CPintpoint){//TODO:Addyourmessagehandlercodehereand/orcalldefaultCView::OnRButtonDown(nFlag,point);CClientDCdc(this);COLORREFColor;intscany=-1;inti=0,j=0;intk;intr,g,b;Edge*etp;makeet();while(et[++scany]==NULL);While(scany600){if(et[scany]!=NULL){etp=et[scany];while(etp){i=scany;while(ietp-ymax){j=(int)etp-x;j++;while(i600){Color=dc.GetPixel(j,i);r=255--GetRValue(Color);G=255--GetGValue(Color);B=255--GetBValue(Color);dc.GetPixel(j,i),RGB(r,g,b));j++;}etp-x+=etp-deltax;i++;}etp-x+=etp-nextEdge;}et[scany]=NULL;}scany++;}npoint=20;}运行结果:五、分析与讨论六、教师评语成绩签名:日期:

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

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

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

×
保存成功