计算机图形学区域填充.docVIP

  • 89
  • 0
  • 约5.46千字
  • 约 12页
  • 2017-02-08 发布于重庆
  • 举报
计算机图形学区域填充

实验目的与要求 用扫描线转换填充算法实现区域填充 程序完成基本过程: 给定多边形的顶点坐标(x ,y) 以dy为增量的扫描线 对每条扫描线与边的交点按y递增排序 将同一扫描线上的交点配对存储 以扫描线从Ymin开始进行扫描填充颜色 数据结构算法 #ifndef SWEEP_H #define SWEEP_H struct Edge { int nxty; int curx; int dx, dy; // 所在扫描线的增量 Edge *nxt; }; //扫描线主算法 void sweep(int p[][2], int n, void (*setPixel)(int, int)); #endif 1)图形的生成(定义坐标点) struct point { int x; int y; }p[10]={100,100,200,100,200,200,300,200,400,100,400,400,100,400,100,100,-1}; point stack[1024000]; int top; void push(int x,int y) //对选择的种子点进出栈 { if(top1024000)exit(0); stack[top].x=x; stack[top].y=y; top++; } void pop(int x,int y) { if(top==0) exit(0); x=stack[top-1].x; y=stack[top-1].y; top--; } void gettop(int x,int y) { if(top==0) exit(0); x=stack[top-1].x; y=stack[top-1].y; } 2)种子填充算法的主实现代码 void Ciew::Ontianchong() { // TODO: Add your command handler code here RedrawWindow(); CClientDC dc(this); dc.TextOut(1,5,用鼠标在各个区域中选种子点); Coc* pDoc = GetDocument(); ASSERT_VALID(pDoc); int i; for(i=0;p[i+1].x!=-1;i++) { dc.MoveTo(p[i].x,p[i].y); dc.LineTo(p[i+1].x,p[i+1].y); } dc.MoveTo(p[i].x,p[i].y); dc.LineTo(p[0].x,p[0].y); // TODO: add draw code for native } void Ciew::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default int x,y; CClientDC dc(this); // TODO: Add your message handler code here and/or call default origin=point; push(origin.x,origin.y); while(top!=0) { pop(x,y); if(dc.GetPixel(x-1,y)!=0)//不等于边界色 { dc.SetPixel(x-1,y,0);//染成黑色 push(x-1,y); //加入栈 } if(dc.GetPixel(x+1,y)!=0) { dc.SetPixel(x+1,y,0); push(x+1,y); } if(dc.GetPixel(x,y-1)!=0) { dc.SetPixel(x,y-1,0); push(x,y-1); } if(dc.GetPixel(x,y+1)!=0) { dc.SetPixel(x,y+1,0); push(x,y+1); } } CView::OnLButtonDown(nFlags, point); } 实验结果: 区域填充的原始图形 区域填充后图形 实验收获 通过本次实验本人掌握Visual C++ 6.0图形设备接口和常用图形程序设计、菜单设

文档评论(0)

1亿VIP精品文档

相关文档