已阅读5页,还剩4页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
二维区域扫描线填充算法的实现这个程序从一放暑假就开始做,直做到今天,花了1个星期的时间,真是不应该啊,唉,谁让咱编程技术不太好呢,得,闲话少说。关于区域填充,我们常用的算法有扫描线填充算法以及种子填充算法,我现在只完成了前一种,后一种等过两天实现之,扫描算法的理解不难,可是实现起来有许多细节问题还是有点烦琐,下面这个是非常粗糙的一个版本,只能说是实现了所需,代码一点也不好,到处充斥着各种命名模糊的变量,又不很多注释,谁要是想看,那肯定费很大劲,不过整体结构是正确的。我本来想把整个算法详细地一步一步列出来,可是要讲解算法的话,还要画很多图,还要贴上来,就此做罢,如果谁也在做这个程序,就在下面留下评论即可,我一定在最短时间内给你回复。下面是我的代码,直接CTRL+V到VC6中就可以看到效果了:(通过这个程序我还发现,当代码一上500行,变量就开始混淆了,尤其是用来控制循环的那些小变量,还有就是在这个程序中我初步使用了VC6的调试功能 ,确实非常方便,但还有些功能不清楚,唉,慢慢来吧)下面是一个简单的填充效果: /#include #include #define FILLING 1#define RESET 2typedef struct int xStart,yStart; int xEnd,yEnd; LINE,*PLINE;LINE lines100;LINE line;static int j=0;POINT draw_refresh1000;static int l=0;LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE prevInstance,PSTR szCmdLine,int iCmdShow)static TCHAR szAppName=2D Region Filling; HWND hwnd; MSG msg; WNDCLASS wndclass;for(int i=0;i100;i+)linesi.xStart=0;linesi.yStart=0;linesi.xEnd=0;linesi.yEnd=0;wndclass.style=CS_HREDRAW | CS_VREDRAW |CS_DBLCLKS; wndclass.lpfnWndProc=WndProc; wndclass.cbClsExtra=0; wndclass.cbWndExtra=0; wndclass.hInstance=hInstance; wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION); wndclass.hCursor=LoadCursor(NULL,IDC_CROSS); wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);wndclass.lpszMenuName=NULL; wndclass.lpszClassName=szAppName; if(!RegisterClass(&wndclass)MessageBox(NULL,Regist window class failed!,Error,MB_OK);hwnd=CreateWindow(szAppName,2D Region Filling,WS_OVERLAPPED | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);ShowWindow(hwnd,iCmdShow); UpdateWindow(hwnd); while(GetMessage(&msg,NULL,0,0) TranslateMessage(&msg); DispatchMessage(&msg); return msg.wParam; LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam) HWND hButtonFilling;HWND hButtonReset;int cxChar=0;int cyChar=0;static PLINE head=lines;int i=0;HDC hdc; PAINTSTRUCT ps; RECT clientrect;POINT need_draw=0,0;POINT draw100;int b=0;static int filled=0;for(int e=0;ehInstance,NULL);hButtonReset =CreateWindow(TEXT(BUTTON),Reset, WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,70*cxChar,28*cyChar,20*cxChar,7*cyChar/4,hwnd,(HMENU)RESET, (LPCREATESTRUCT)lParam)-hInstance,NULL);return 0;case WM_LBUTTONDOWN:/ SetCapture(hwnd);line.xStart=(int)LOWORD(lParam);line.yStart=(int)HIWORD(lParam);for(i=0;j=1 & ilinesi.xStart-30) & (line.xStartlinesi.yStart-30) & (line.yStartlinesi.xEnd-30) & (line.xStartlinesi.yEnd-30) & (line.yStart=1 & ilinesi.xStart-30) & (line.xEndlinesi.yStart-30) & (line.yEndlinesi.xEnd-30) & (line.xEndlinesi.yEnd-30) & (line.yEndlinesi.yEnd+30)hdc=GetDC(hwnd);SelectObject(hdc,GetStockObject(WHITE_PEN);/clear the last black line if find a adjacent vetexMoveToEx(hdc,line.xStart,line.yStart,NULL);LineTo(hdc,line.xEnd,line.yEnd);line.xEnd=linesi.xEnd;line.yEnd=linesi.yEnd;SelectObject(hdc,GetStockObject(BLACK_PEN);MoveToEx(hdc,line.xStart,line.yStart,NULL);LineTo(hdc,line.xEnd,line.yEnd);ReleaseDC(hwnd,hdc);linesj.xStart=line.xStart;linesj.yStart=line.yStart;linesj.xEnd=line.xEnd;linesj.yEnd=line.yEnd;j+;line.xStart=0;line.yStart=0;line.xEnd=0;line.yEnd=0;/ ReleaseCapture();return 0;case WM_COMMAND:switch(LOWORD(wParam)case FILLING:smallest_y=lines0.yStart;lardgest_y=lines0.yStart;for(h=0;h=100;h+)drawh.x=0;drawh.y=0;filled=1;for(h=0;hj;h+)/find the smallest y coordinate of the edgesif(linesh.yStartsmallest_y)smallest_y=linesh.yStart;if(linesh.yEndsmallest_y)smallest_y=linesh.yEnd;for(h=0;hlardgest_y)lardgest_y=linesh.yStart;if(linesh.yEndlardgest_y)lardgest_y=linesh.yEnd;for(k=smallest_y;k=lardgest_y;k+)/check every scan line to filling the regionfor(m=0;mlinesm.yEnd ? linesm.yStart:linesm.yEnd ;c=linesm.yStarta)continue; else if(kc)continue; else if(linesm.yStart=linesm.yEnd & k=linesm.yStart)continue;elsex=0;if(linesm.yStart=k)for(n=0;nlinesm.yStart & linesn.yEndlinesm.yStart) | (linesm.yEndlinesm.yStart & linesn.yEndlinesm.yStart)x=linesm.xStart;drawb.x=x;drawb.y=k;b+;drawb.x=x;drawb.y=k;b+;else/ MessageBox(hwnd,error2,error2,MB_OK);x=linesm.xStart;flag=0;for(h=0;hlinesm.yStart & linesn.yStartlinesm.yStart) | (linesm.yEndlinesm.yStart & linesn.yStartlinesm.yStart)/ MessageBox(hwnd,error3,error3,MB_OK);x=linesm.xStart;drawb.x=x;drawb.y=k;b+;drawb.x=x;drawb.y=k;b+;else/ MessageBox(hwnd,error4,error4,MB_OK);x=linesm.xStart;flag=0;for(h=0;hb;h+)if(x=drawh.x & k=drawh.y)flag=1;break;if(flag!=1)drawb.x=x;drawb.y=k;b+;else if(linesm.yEnd=k)for(n=0;nlinesm.yEnd & linesn.yEndlinesm.yEnd) | (linesm.yStartlinesm.yEnd & linesn.yEndlinesm.yEnd)/ MessageBox(hwnd,error,error,MB_OK);x=linesm.xEnd;drawb.x=x;drawb.y=k;b+;drawb.x=x;drawb.y=k;b+;elsex=linesm.xEnd;flag=0;for(h=0;hlinesm.yEnd & linesn.yStartlinesm.yEnd) | (linesm.yStartlinesm.yEnd & linesn.yStartlinesm.yEnd)x=linesm.xEnd;drawb.x=x;drawb.y=k;b+;drawb.x=x;drawb.y=k;b+;elsex=linesm.xEnd;flag=0;for(h=0;hlinesm.yEnd)x1=linesm.xEnd;y1=linesm.yEnd;x2=linesm.xStart;y2=linesm.yStart;else if(linesm.yStartlinesm.yEnd)x1=linesm.xStart;y1=linesm.yStart;x2=linesm.xEnd;y2=linesm.yEnd;x=x2+(x1-x2)*(y2-k)/(y2-y1);drawb.x=x;drawb.y=k;b+;/check complete,then draw them/sorting first!for(h=0;hb;h+)for(m=h+1;mdrawm.x)x=drawh.x;drawh.x=drawm.x;drawm.x=x;x=drawh.y;drawh.y=drawm.y;drawm.y=x;hdc=GetDC(hwnd); /real filling for(h=0;hb;h+=2) MoveToEx(hdc,drawh.x,drawh.y,NULL);LineTo(hdc,drawh+1.x,drawh+1.y);ReleaseDC(hwnd,hdc);for(h=0;hb;h+)draw_refreshl.x=drawh.x;dr
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025-2026学年江苏省盐城市科创城初中等校八年级(下)月考英语试卷(5月份)(含答案)
- 初中八年级地理《交通运输:区域发展的血脉》教学设计
- 北师大版小学数学六年级下册“探索规律(二)”教学设计
- 八年级英语上册 Unit 7 Will people have robots 写作课导学案
- 初中八年级科学期中素能测评与单元整合教学教案
- 建筑工地安全地面沉降预案
- 初中八年级历史教学设计:教育文化事业的近代转型-从科举之变到思想启蒙的互动共生
- 八年级生物上学期期末知识清单:第17章 传染病与免疫
- 爱上吃蔬菜:小学四年级综合实践活动项目化教学设计
- 初二生地会考百日冲刺知识清单与备考策略
- 水电维修维护方案(3篇)
- 村级组织公章管理制度
- 【8生 会考】2022-2024年安徽省初中(八年级)中考初二会考生物试卷(3年真题)
- 《中医骨伤科学》课件-脑震荡
- 苏州大学《模拟电子技术基础》2022-2023学年第一学期期末试卷
- 幼儿园融入本土资源 课程走向园本教育课件
- (正式版)CB∕T 4550-2024 船舶行业企业安全设备设施管理规定
- DL-T-1878-2018燃煤电厂储煤场盘点导则
- JT-T-1202-2018城市公共汽电车场站配置规范
- 2025届河南省郑州市外国语高中物理高一第二学期期末统考试题含解析
- 文艺复兴经典名著选读智慧树知到期末考试答案章节答案2024年北京大学
评论
0/150
提交评论