📄 gqk_mini2dlg.cpp
字号:
// gqk_mini2Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "gqk_mini2.h"
#include "gqk_mini2Dlg.h"
#include "isodata.h"
#include "dlgIsodataset.h"
#include "dlgKmeansset.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGqk_mini2Dlg dialog
CGqk_mini2Dlg::CGqk_mini2Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CGqk_mini2Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CGqk_mini2Dlg)
m_result = _T("");
m_data = _T("");
m_x = 0.0f;
m_y = 0.0f;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CGqk_mini2Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CGqk_mini2Dlg)
DDX_Text(pDX, IDC_result, m_result);
DDX_Text(pDX, IDC_data, m_data);
DDX_Text(pDX, IDC_x, m_x);
DDV_MinMaxFloat(pDX, m_x, 0.f, 100.f);
DDX_Text(pDX, IDC_y, m_y);
DDV_MinMaxFloat(pDX, m_y, 0.f, 100.f);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CGqk_mini2Dlg, CDialog)
//{{AFX_MSG_MAP(CGqk_mini2Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_Kmeans, OnKmeans)
ON_BN_CLICKED(IDC_Isodata, OnIsodata)
ON_BN_CLICKED(IDC_addData, OnaddData)
ON_BN_CLICKED(IDC_Isodataset, OnIsodataset)
ON_BN_CLICKED(IDC_Kmeansset, OnKmeansset)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGqk_mini2Dlg message handlers
BOOL CGqk_mini2Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
isodata = new ISODATA();
kmeans = new KMEANS();
vn = 8;
vd[0] = 0;
vd[1] = 0;
vd[2] = 10;
vd[3] = 10;
vd[4] = 20;
vd[5] = 21;
vd[6] = 0;
vd[7] = 1;
vd[8] = 11;
vd[9] = 10;
vd[10] = 21;
vd[11] = 11;
vd[12] = 20;
vd[13] = 20;
vd[14] = 21;
vd[15] = 21;
printvd();
return TRUE; // return TRUE unless you set the focus to a control
}
void CGqk_mini2Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CGqk_mini2Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CGqk_mini2Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CGqk_mini2Dlg::OnOK()
{
// TODO: Add your control notification handler code here
// CDialog::OnOK();
}
void CGqk_mini2Dlg::OnCancel()
{
// TODO: Add your control notification handler code here
//if(MessageBox("确定退出吗?","操作提示",MB_YESNO|MB_ICONWARNING)==IDNO)
//{
// return;
//}
CDialog::OnCancel();
}
void CGqk_mini2Dlg::OnIsodataset()
{
// TODO: Add your control notification handler code here
dlgIsodataset dlg;
dlg.m_Dm = isodata->Dm;
dlg.m_Ds = isodata->Ds;
dlg.m_I = isodata->I;
dlg.m_K = isodata->K;
dlg.m_L = isodata->L;
dlg.m_Nmin = isodata->Nmin;
if(dlg.DoModal()==IDOK){
isodata->Dm = dlg.m_Dm;
isodata->Ds = dlg.m_Ds;
isodata->I = dlg.m_I;
isodata->K = dlg.m_K;
isodata->L = dlg.m_L;
isodata->Nmin = dlg.m_Nmin;
}
}
void CGqk_mini2Dlg::OnKmeansset()
{
// TODO: Add your control notification handler code here
dlgKmeansset dlg;
dlg.m_K = kmeans->K;
if(dlg.DoModal()==IDOK){
kmeans->K = dlg.m_K;
}
}
void CGqk_mini2Dlg::printvd()
{
char tmp[100]={'\0'};
char data[100000]={'\0'};
for(int i = 0 ; i < vn*2 ; i=i+2){
sprintf (tmp,"(%5f , %5f)\r\n" , vd[i] , vd[i+1] );
strcat(data,tmp);
}
this->m_data = data;
UpdateData(FALSE);
}
void CGqk_mini2Dlg::OnaddData()
{
// TODO: Add your control notification handler code here
UpdateData(true);
vd[vn*2] = this->m_x;
vd[vn*2+1] = this->m_y;
vn++;
printvd();
}
void CGqk_mini2Dlg::OnIsodata()
{
// TODO: Add your control notification handler code here
// int i;
char tmp[100000]={'\0'};
isodata->start ( vn , 2 , vd , tmp);//读入数据,初始化聚类中心,参数设定默认值
this->m_result = tmp;
UpdateData(FALSE);
}
void CGqk_mini2Dlg::OnKmeans()
{
// TODO: Add your control notification handler code here
char tmp[100000]={'\0'};
kmeans->start ( vn , 2 , vd , tmp);//读入数据,初始化聚类中心,参数设定默认值
this->m_result = tmp;
UpdateData(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -