⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 classifyview.cpp

📁 利用遗传算法对图像进行分类处理
💻 CPP
字号:
// classifyView.cpp : implementation of the CClassifyView class
//

#include "stdafx.h"

#include "classify.h"

#include "GaCalculate.h"

#include "classifyDoc.h"
#include "classifyView.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CClassifyView

IMPLEMENT_DYNCREATE(CClassifyView, CView)

BEGIN_MESSAGE_MAP(CClassifyView, CView)
	//{{AFX_MSG_MAP(CClassifyView)
	ON_COMMAND(ID_CLASSIFY_GA, OnClassifyGa)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CClassifyView construction/destruction

CClassifyView::CClassifyView()
{
	// TODO: add construction code here
	drawflag=0;
}

CClassifyView::~CClassifyView()
{
}

BOOL CClassifyView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CClassifyView drawing

void CClassifyView::OnDraw(CDC* pDC)
{
	CClassifyDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here

	if(ga.m_hDIB4 != NULL)
	{
		// 获取DIB
		HDIB& hDIB = ga.m_hDIB4;
		// 判断DIB是否为空
		if (hDIB != NULL)
		{
			LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) hDIB);
			
			// 获取DIB宽度
			int cxDIB = (int) ::DIBWidth(lpDIB);
			
			// 获取DIB高度
			int cyDIB = (int) ::DIBHeight(lpDIB);
			
			::GlobalUnlock((HGLOBAL) hDIB);
			
			CRect rcDIB;
			rcDIB.top = rcDIB.left = 0;
			rcDIB.right = cxDIB;
			rcDIB.bottom = cyDIB;
			
			CRect rcDest;
			
			// 非打印不必缩放图像
			rcDest = rcDIB;
			
			// 输出DIB
			::PaintDIB(pDC->m_hDC, &rcDest, hDIB,
				&rcDIB, NULL);
		}
	}




/*	int i,j;
	if (drawflag)
	{
		for (i=0;i<ga.m_width;i++)
			for (j=0;j<ga.m_height;j++)
	SetPixel
*/
}

/////////////////////////////////////////////////////////////////////////////
// CClassifyView printing

BOOL CClassifyView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CClassifyView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CClassifyView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CClassifyView diagnostics

#ifdef _DEBUG
void CClassifyView::AssertValid() const
{
	CView::AssertValid();
}

void CClassifyView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CClassifyDoc* CClassifyView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CClassifyDoc)));
	return (CClassifyDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CClassifyView message handlers


void CClassifyView::OnClassifyGa() 
{
	// TODO: Add your command handler code here

	int i;
			
	ga.FitCalculate();			//计算适应度值
	for (i=0;i<100;i++)
	{
		ga.ReFitCalculate();     //按排名修改适应度值
		ga.Cross();				//交叉
		ga.Mutate();			//变异
		ga.FitCalculate();		//重新计算适应度值
	}
	ga.SaveResult();
	drawflag=1;
	Invalidate();
}




/*	LPSTR lpDIB2 = (LPSTR) ::GlobalLock((HGLOBAL) m_hDIB2);	
	// 获取DIB宽度
	int cxDIB = (int) ::DIBWidth(lpDIB);
	int cxDIBWidthBytes = WIDTHBYTES(cxDIB*8);
	// 获取DIB高度
	int cyDIB = (int) ::DIBHeight(lpDIB);
	int temp;
	double sum=0;
	unsigned char* pImgData = (BYTE*)lpDIB + sizeof(BITMAPINFOHEADER) + 1024;
	unsigned char* pImgData2 = (BYTE*)lpDIB2 + sizeof(BITMAPINFOHEADER) + 1024;

	for(int i = 0; i < cxDIB; i++)
	{
		for(int j = 0; j < cyDIB; j++)
		{
			temp=pImgData[(cyDIB - j -1) * cxDIBWidthBytes + i]-pImgData2[(cyDIB - j -1) * cxDIBWidthBytes + i];
			temp*=temp;
			sum+=temp;
		}
	}
	sum=sum/cxDIB/cyDIB;
	CString str;
	str.Format("%f",sum);
	MessageBox(NULL,str," ",IDOK);
	::GlobalUnlock((HGLOBAL) m_hDIB1);	
	UpdateAllViews(NULL);
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -