计算机图形学 种子填充算法 MFC、VC

时间:2013-07-04 07:11:53
【文件属性】:
文件名称:计算机图形学 种子填充算法 MFC、VC
文件大小:3.21MB
文件格式:RAR
更新时间:2013-07-04 07:11:53
计算机图形学 图形填充 种子填充算法 种子填充算法,自己写的,希望对大家有用 // 种子法View.cpp : implementation of the CMyView class // #include "stdafx.h" #include "种子法.h" #include "种子法Doc.h" #include "种子法View.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif struct point { int x; int y; }p[10]={200,100,100,200,150,100,200,300,250,100,300,200,-1}; point stack[1024000]; int top; void push(int x,int y) { if(top>1024000)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; } ///////////////////////////////////////////////////////////////////////////// // CMyView IMPLEMENT_DYNCREATE(CMyView, CView) BEGIN_MESSAGE_MAP(CMyView, CView) //{{AFX_MSG_MAP(CMyView) ON_WM_LBUTTONDOWN() //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMyView construction/destruction CMyView::CMyView() { // TODO: add construction code here } CMyView::~CMyView() { } BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CMyView drawing void CMyView::OnLButtonDown(UINT nFlags, CPoint point) { 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); } void CMyView::OnDraw(CDC* pDC) { CClientDC dc(this); dc.TextOut(1,5,"请为每个区选种子,务必在图形内"); CMyDoc* 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 data here } ///////////////////////////////////////////////////////////////////////////// // CMyView printing BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void CMyView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CMyView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } ///////////////////////////////////////////////////////////////////////////// // CMyView diagnostics #ifdef _DEBUG void CMyView::AssertValid() const { CView::AssertValid(); } void CMyView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CMyDoc* CMyView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc))); return (CMyDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CMyView message handlers
【文件预览】:
种子法
----种子法.clw(2KB)
----种子法.h(1KB)
----种子法Doc.h(1KB)
----StdAfx.cpp(208B)
----种子法View.cpp(4KB)
----种子法.ncb(105KB)
----种子法.dsp(4KB)
----MainFrm.h(2KB)
----种子法.opt(53KB)
----种子法.plg(1KB)
----Debug()
--------种子法Doc.obj(15KB)
--------vc60.pdb(356KB)
--------APPMODUL.sbr(0B)
--------MainFrm.sbr(0B)
--------种子法.res(7KB)
--------种子法.obj(23KB)
--------vc60.idb(209KB)
--------种子法.exe(124KB)
--------种子法.pdb(473KB)
--------种子法.pch(5.24MB)
--------种子法View.obj(26KB)
--------APPMODUL.obj(5KB)
--------MainFrm.obj(20KB)
--------StdAfx.obj(103KB)
--------种子法.bsc(5.09MB)
--------种子法.ilk(435KB)
--------种子法Doc.sbr(0B)
--------种子法.sbr(0B)
--------StdAfx.sbr(1.3MB)
--------种子法View.sbr(0B)
----ReadMe.txt(4KB)
----StdAfx.h(1KB)
----MainFrm.cpp(2KB)
----种子法.cpp(4KB)
----Resource.h(490B)
----种子法Doc.cpp(2KB)
----res()
--------种子法Doc.ico(1KB)
--------种子法.ico(1KB)
--------Toolbar.bmp(1KB)
--------种子法.rc2(398B)
----种子法.aps(28KB)
----种子法View.h(2KB)
----种子法.dsw(537B)
----种子法.rc(10KB)

网友评论

  • 代码逻辑很好,可读性很强,非常实用
  • 挺好的,解决了我很多疑问
  • 堆栈太小,动不动就崩溃
  • 非常棒的程序,在图形区域很大的时候都能进行填充,思路非常好,很推荐
  • 可以运行,对于图形学实验很有帮助~!
  • 感觉太简单了。。。
  • 很有参考价值,如果要是有个解说的文档就好了。
  • 写的不错经过更改基本符合我的要求!
  • 代码挺好的,适合基础入门,但是为毛不能修改填充的颜色TT
  • 挺全的 很有帮助!
  • 可以运行 并且注释很详细 有参考价值
  • 不错,就是简单了,不能自己画图
  • 不能运行!不过写的很详细!不过是我要得,谢谢