- 17
- 0
- 约2.86千字
- 约 7页
- 2017-01-09 发布于重庆
- 举报
实验2:多边形区域扫描线填充或种子填充
实验2:多边形区域扫描线填充或种子填充
一、、void CZhztchView::boundaryfill4(int x, int y, int boundarycolor, int newcolor)
{
int color;
CClientDC dc(this); //获取客户区设备描述表
color=dc.GetPixel(x,y);
if(color!=newcolorcolor!=boundarycolor)
{
dc.SetPixel(x,y,newcolor);
boundaryfill4(x,y+1,boundarycolor,newcolor);
boundaryfill4(x,y-1,boundarycolor,newcolor);
boundaryfill4(x-1,y,boundarycolor,newcolor);
boundaryfill4(x+1,y,boundarycolor,newcolor);
}
}
////////////////////////////////////////////////////////////////////////////////
//扫描线填充算法
void CZhztchView::OnScanfill()
{
RedrawWindow();
CDC* pDC=GetDC();
CPen newpen(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,150);
spt[7]=CPoint(100,100);
pDC-Polyline(spt,8);
//pDC-SelectObject(old);
//ReleaseDC(pDC);
// TODO: Add your command handler code here
//CDC* pDC=GetDC();
CPen newpen2(PS_SOLID,1,RGB(0,255,0));
CPen *old2=pDC-SelectObject(newpen2);
int j,k,s = 0;
int p[5]; //每根扫描线交点
int pmin = 0,pmax = 0;
for(int i=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)
pmax = spt[i+1].y;
if(spt[i].y pmin)
pmin = spt[i].y;
}
else{
edge[i].num=i;
edge[i].ymin=spt[i+1].y;
edge[i].ymax=spt[i].y;
edge[i].xmax=(float)spt[i].x;
edge[i].xmin=(float)spt[i+1].x;
if(spt[i].y pmax)
pmax = spt[i].y;
if(spt[i+1].y pmin)
pmin = spt[i+1].y;
}
}
for(int r=1;r=6;r++) //排序edge(yUpper,xIntersect),结果为从大到小
{
for(int q=0;q=6-r;q++)
{
if(edge[q].yminedge[q+1].ymin)
{
newedge[0]=edge[q]; edge[q]=edge[q+1];
edge[q+1]=newedge[0];
}
}
您可能关注的文档
- 《慢性乙型肝炎防治指南》(2015年版)..doc
- 《慢性乙型肝炎防治指南》..doc
- 《成长的烦恼》_教案..doc
- 《我是演说家》第2季演讲稿1..doc
- 《房地产案例与分析》指错题答题通关宝典..doc
- 《打击乐》课程教学大纲..doc
- 《托幼机构消毒卫生标准》..doc
- 不同浸种时间对种子萌发生长的影响.doc
- 《技能大赛背景下计算机网络技术专业建设的优化研究》结题报告.doc
- 《投资项目调查与可行性研究》..doc
- 小区绿化施工协议书.docx
- 墙面施工协议书.docx
- 1 古诗二首(课件)--2025-2026学年统编版语文二年级下册.pptx
- (2026春新版)部编版八年级道德与法治下册《3.1《公民基本权利》PPT课件.pptx
- (2026春新版)部编版八年级道德与法治下册《4.3《依法履行义务》PPT课件.pptx
- (2026春新版)部编版八年级道德与法治下册《6.2《按劳分配为主体、多种分配方式并存》PPT课件.pptx
- (2026春新版)部编版八年级道德与法治下册《6.1《公有制为主体、多种所有制经济共同发展》PPT课件.pptx
- 初三教学管理交流发言稿.docx
- 小学生课外阅读总结.docx
- 餐饮门店夜经济运营的社会责任报告(夜间贡献)撰写流程试题库及答案.doc
原创力文档

文档评论(0)