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

📄 conceptiondlg.cpp

📁 模式识别的源代码
💻 CPP
字号:
// ConceptionDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Conception.h"
#include "ConceptionDlg.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()

/////////////////////////////////////////////////////////////////////////////
// CConceptionDlg dialog

CConceptionDlg::CConceptionDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CConceptionDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CConceptionDlg)
	m_k = 1;
	m_v = 1;
	m_w = _T("(1,1,1)");
	m_eq = _T("1*x1+1*x2+1=0");
	m_n = 4;
	m_m = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	Ox=100;
	Oy=110;
	scale=45;
	m_nProgress=0;
	refresh=1;
	num=0;

    x[0][0]=0; 
	x[0][1]=0;
	x[0][2]=1;
	x[1][0]=0;   
	x[1][1]=1;
	x[1][2]=1;
	x[2][0]=-1;   
	x[2][1]=0;
	x[2][2]=-1;
	x[3][0]=-1;  
	x[3][1]=-1;
	x[3][2]=-1;
    
}

void CConceptionDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CConceptionDlg)
	DDX_Text(pDX, IDC_EDIT4, m_k);
	DDX_Text(pDX, IDC_EDIT2, m_v);
	DDX_Text(pDX, IDC_EDIT3, m_w);
	DDX_Text(pDX, IDC_EDIT5, m_eq);
	DDX_Text(pDX, IDC_EDIT1, m_n);
	DDX_Text(pDX, IDC_EDIT6, m_m);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CConceptionDlg, CDialog)
	//{{AFX_MSG_MAP(CConceptionDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_OK, OnClickedOk)
	ON_WM_LBUTTONDOWN()
	ON_WM_MOUSEMOVE()
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CConceptionDlg message handlers

BOOL CConceptionDlg::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
     CProgressCtrl*pProg=(CProgressCtrl*)GetDlgItem(IDC_PROGRESS1);
	 pProg->SetRange(0,100);
	 pProg->SetPos(m_nProgress);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CConceptionDlg::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 CConceptionDlg::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();
	}
	CDC*pDC=GetDC();		
    pDC->MoveTo(30,110);
	pDC->LineTo(215,110);
	pDC->LineTo(210,105);
	pDC->MoveTo(210,115);
	pDC->LineTo(215,110);

	pDC->MoveTo(100,180);
	pDC->LineTo(100,30);
	pDC->LineTo(95,35);
	pDC->MoveTo(105,35);
	pDC->LineTo(100,30);
    if(refresh==1)
	{CPen newpen(PS_SOLID,5,RGB(255,100,50));
	 CPen*oldpen=pDC->SelectObject(&newpen);
	 pDC->MoveTo(100,110);
     pDC->LineTo(100,110);
	 pDC->MoveTo(100,110-scale);
	 pDC->LineTo(100,110-scale);
     pDC->SelectObject(oldpen); 
	
	 CPen newpen1(PS_SOLID,5,RGB(0,255,50));
	 oldpen=pDC->SelectObject(&newpen1);
	 pDC->MoveTo(100+scale,110);
	 pDC->LineTo(100+scale,110);
	 pDC->MoveTo(100+scale,110-scale);
	 pDC->LineTo(100+scale,110-scale);
	 pDC->SelectObject(oldpen);
	}
	 this->ReleaseDC(pDC); 

}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CConceptionDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CConceptionDlg::OnButton1() 
{
   int n,k=0;
   float w[3]={1,1,1};
   int tag=0,s;
   float dx;
   float p;
   num=0;
   UpdateData();
   n=m_n+m_m;
   p=m_v;
  CDC*pDC=GetDC();
  CProgressCtrl*pProg=(CProgressCtrl*)GetDlgItem(IDC_PROGRESS1);
  draw(w,pDC);
   while(tag!=1)
   {   s=0;
	   for(int i=0;i<n;i++)
	   { m_nProgress++;   
	    dx=w[0]*x[i][0]+w[1]*x[i][1]+w[2]*x[i][2];
	    if(dx<=0.0)
		{
		 draw(w,pDC);
		 w[0]=w[0]+p*x[i][0];
		 w[1]=w[1]+p*x[i][1];
		 w[2]=w[2]+p*x[i][2];
		 s=-1;
		 k++;
		m_k=k;
		UpdateData(false);
		UpdateWindow();
	     m_eq.Format("%.3f*x1+%.3f*x2+%.3f=0",w[0],w[1],w[2]);
          
		 UpdateData(false);
		 UpdateWindow();
		 draw(w,pDC);
		 ::Sleep(1000);
		
		}
		
	if(m_nProgress<100)pProg->SetPos(m_nProgress);
	else pProg->SetPos(100);
	   }
	   if(s==0)tag=1;
   }
   this->ReleaseDC(pDC);
   	pProg->SetPos(100);
	::Sleep(500);
	pProg->SetPos(0);
}

void CConceptionDlg::draw(float w[3],CDC*pDC)
{
	float x0,y0,x1,y1;
	float x,y;
	if(w[0]==0&&w[1]==0)return;
	if(w[0]==0.0)
	{y=(-w[2])/w[1];
	x0=float(30-Ox);
	y0=(-1)*scale*y;
	y1=y0;
	x1=float(210-Ox);
	}
	if(w[1]==0.0)
	{x=(-w[2])/w[0];
	x0=(scale*x);
	x1=x0;
	y0=float(160-Oy);
	y1=float(20-Oy);
	}
	if(w[0]!=0&&w[1]!=0)
	{y=float((-w[2]+2.0*w[0])/w[1]);
	 x0=float(scale*(-2.0));
	 x1=float(scale*2.0);
	 y0=-scale*y;
     y=float((-w[2]-2.0*w[0])/w[1]);
	 y1=-scale*y;
	}

  
  CPen newpen(PS_SOLID,2,RGB(0,0,255));
  CPen*oldpen=pDC->SelectObject(&newpen);

  int xx0,yy0,xx1,yy1;

  xx0=int(Ox+x0);
  xx1=int(Ox+x1); 
  if(int(Oy+y0)>=180)
  {yy0=180;
   y=float((Oy-180)/scale);
   xx0=int(scale*(-w[2]-y*w[1])/w[0]);
   xx0=int(Ox+xx0);
  }
  else
  if(int(Oy+y0)<=30)
  {yy0=30;
   y=float((Oy-30)/scale);
   xx0=int(scale*(-w[2]-y*w[1])/w[0]);
   xx0=int(Ox+xx0);
  }
   else yy0=int(Oy+y0);

   if(int(Oy+y1)>=180)
  {yy1=180;
   y=float((Oy-180)/scale);
   xx1=int(scale*(-w[2]-y*w[1])/w[0]);
   xx1=int(Ox+xx1);
  }
  else
  if(int(Oy+y1)<=30)
  {yy1=30;
   y=float((Oy-30)/scale);
   xx1=int(scale*(-w[2]-y*w[1])/w[0]);
   xx1=int(Ox+xx1);
  }
   else yy1=int(Oy+y1);
  
  pDC->SetROP2(R2_NOTXORPEN);
  pDC->MoveTo(xx0,yy0);
  pDC->LineTo(xx1,yy1);
  /*
  pDC->MoveTo(int(Ox+x0),int(Oy+y0));
  pDC->LineTo(int(Ox+x1),int(Oy+y1));*/

  pDC->SelectObject(oldpen);
  


}

void CConceptionDlg::OnOK() 
{
	// TODO: Add extra validation here

}

void CConceptionDlg::OnClickedOk() 
{
	// TODO: Add your control notification handler code here
	CDialog::OnOK();
}

void CConceptionDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
   CRect rect=CRect(30,30,215,180);
   if(rect.PtInRect(point)!=0)	
   {UpdateData();
    if(num<m_n+m_m)
	{
     CDC*pDC=GetDC();
   ::SetCursor(::LoadCursor(NULL, IDC_CROSS));
	 num++;
	 if(num==m_n)//afxMessage("",0,0);
	 MessageBox("第一类样本已输入完毕!", "系统提示" , MB_ICONINFORMATION | MB_OK);
	 x[num-1][0]=float(point.x-Ox)/scale;
     x[num-1][1]=float(Oy-point.y)/scale;
	 COLORREF color;
	 if(num<=m_n)
	 {color=RGB(255,100,50);	  
	  x[num-1][2]=1;
	 }
	 else 
	 {color=RGB(0,255,50);
	  x[num-1][0]*=-1;
      x[num-1][1]*=-1;
      x[num-1][2]=-1;
	 }
     CPen newpen(PS_SOLID,5,color);
	 CPen*oldpen=pDC->SelectObject(&newpen);
	 pDC->MoveTo(point.x,point.y);
	 pDC->LineTo(point.x,point.y);
	 pDC->SelectObject(oldpen); 
	 this->ReleaseDC(pDC); 
	}
	else MessageBox("第二类样本已输入完毕!", "系统提示" , MB_ICONINFORMATION | MB_OK);

   }
	CDialog::OnLButtonDown(nFlags, point);
}

void CConceptionDlg::OnMouseMove(UINT nFlags, CPoint point) 
{
   CRect rect=CRect(30,30,215,180);
   if(rect.PtInRect(point)!=0)	
   ::SetCursor(::LoadCursor(NULL, IDC_CROSS));	
	CDialog::OnMouseMove(nFlags, point);
}

void CConceptionDlg::OnButton2() 
{
  refresh=0;
  num=0;
  Invalidate();
}

⌨️ 快捷键说明

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