资源描述:
《图形学种子填充算法.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、/种子填充算法voidCZhztchView::boundaryfill4(intx,inty,intboundarycolor,intnewcolor){intcolor;CClientDCdc(this);//获取客户区设备描述表color=dc.GetPixel(x,y);if(color!=newcolor&&color!=boundarycolor){dc.SetPixel(x,y,newcolor);boundaryfill4(x,y+1,boundarycolor,newcolor);bounda
2、ryfill4(x,y-1,boundarycolor,newcolor);boundaryfill4(x-1,y,boundarycolor,newcolor);boundaryfill4(x+1,y,boundarycolor,newcolor);}}//////////////////////////////////////////////////////////////////////////////////扫描线填充算法voidCZhztchView::OnScanfill(){RedrawWindo
3、w();CDC*pDC=GetDC();CPennewpen(PS_SOLID,3,RGB(255,0,0));CPen*old=pDC->SelectObject(&newpen);spt[0]=CPoint(100,100);//绘制多边形区域spt[1]=CPoint(300,100);spt[2]=CPoint(250,250);spt[3]=CPoint(100,250);spt[4]=CPoint(150,200);spt[5]=CPoint(90,180);spt[6]=CPoint(150,15
4、0);spt[7]=CPoint(100,100);pDC->Polyline(spt,8);//pDC->SelectObject(old);//ReleaseDC(pDC);//TODO:Addyourcommandhandlercodehere//CDC*pDC=GetDC();CPennewpen2(PS_SOLID,1,RGB(0,255,0));CPen*old2=pDC->SelectObject(&newpen2);intj,k,s=0;intp[5];//每根扫描线交点intpmin=0,pm
5、ax=0;for(inti=0;i<=6;i++)//建立边表{edge[i].dx=(float)(spt[i+1].x-spt[i].x)/(spt[i+1].y-spt[i].y);if(spt[i].y<=spt[i+1].y){edge[i].num=i;edge[i].ymin=spt[i].y;edge[i].ymax=spt[i+1].y;edge[i].xmin=(float)spt[i].x;edge[i].xmax=(float)spt[i+1].x;if(spt[i+1].y>pmax)
6、pmax=spt[i+1].y;if(spt[i].ypmax)pmax=spt[i].y;if(spt[i+1].y7、++)//排序edge(yUpper,xIntersect),结果为从大到小{for(intq=0;q<=6-r;q++){if(edge[q].yminedge[j].ymin;if(scan==edge[j].ymax);if
8、(spt[edge[j].num+1].y&;b++;;p[b]=(int)edge[j].xmax;;elseif(spt[edge[j].for(intscan=pmax-1;scan>=pmin+1;scan--){intb=0;k=s;for(j=k;j<=6;j++){if((scan>edge[j].ymin)&&(scan<=edge[j].ymax))//判断与线段相交