www.pudn.com > hmmPlatform.rar > ClusterDlg.cpp


// ClusterDlg.cpp : 实现文件 
// 
 
#include "stdafx.h" 
#include "Platform.h" 
#include "ClusterDlg.h" 
#include ".\clusterdlg.h" 
 
 
// CClusterDlg 对话框 
 
IMPLEMENT_DYNAMIC(CClusterDlg, CDialog) 
CClusterDlg::CClusterDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CClusterDlg::IDD, pParent) 
	, m_nCodeNums(0) 
	, m_nRawLen(0) 
	, m_strCode(_T("")) 
{ 
	this->m_pRawData = NULL; 
} 
 
CClusterDlg::~CClusterDlg() 
{ 
} 
 
void CClusterDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	DDX_Text(pDX, IDC_EDIT_CODELEN, m_nCodeNums); 
	DDX_Text(pDX, IDC_STATIC_RAWLEN, m_nRawLen); 
	DDX_Text(pDX, IDC_EDIT_CODE, m_strCode); 
} 
 
 
BEGIN_MESSAGE_MAP(CClusterDlg, CDialog) 
	ON_BN_CLICKED(IDC_BTNCODE, OnBnClickedBtncode) 
END_MESSAGE_MAP() 
 
 
// 设定原始数据 
void CClusterDlg::LoadRawData(double* pRawData, UINT nRawLen) 
{ 
	this->m_pRawData = pRawData; 
	this->m_nRawLen = nRawLen; 
	this->m_strCode = ""; 
} 
 
////////////////////////////////////////////////////////////////////////// 
// 计算码本 
void CClusterDlg::OnBnClickedBtncode() 
{ 
	// TODO: 在此添加控件通知处理程序代码 
	double* pCodeBook = NULL; 
	CString strFormat; 
 
	CWnd::UpdateData(TRUE); 
 
	if (this->m_pRawData != NULL) 
	{ 
		// 码本长度是否合法 
		if (this->m_nCodeNums <= 0) 
		{ 
			AfxMessageBox("码本长度不能小于0"); 
 
			return; 
		} 
 
		pCodeBook = new double[this->m_nCodeNums]; 
 
		// 计算码本 
		CVQ::KMeansCluster(this->m_pRawData, this->m_nRawLen, pCodeBook, this->m_nCodeNums); 
 
		// 组合显示数据 
		this->m_strCode = ""; 
		for (unsigned int i = 0; i < this->m_nCodeNums; i++) 
		{ 
			strFormat.Format("%f\r\n", pCodeBook[i]); 
 
			this->m_strCode += strFormat; 
		} 
 
		CWnd::UpdateData(FALSE); 
		delete[] pCodeBook; 
	} 
}