?? xddxdlg.cpp
字號:
// xddxDlg.cpp : implementation file
//
#include "stdafx.h"
#include "xddx.h"
#include "xddxDlg.h"
#include"fstream"
#include ".\xddxdlg.h"
#include"MathEx.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
using namespace std;
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CXddxDlg dialog
CXddxDlg::CXddxDlg(CWnd* pParent /*=NULL*/)
: CDialog(CXddxDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CXddxDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CXddxDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CXddxDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
DDX_Control(pDX, IDC_LIST_CoPoint, m_LstCtrl);
}
BEGIN_MESSAGE_MAP(CXddxDlg, CDialog)
//{{AFX_MSG_MAP(CXddxDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUT_CoPointFile, OnBUTCoPointFile)
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BUT_Cal, OnBnClickedButCal)
ON_BN_CLICKED(IDC_BUT_SaveData, OnBnClickedButSavedata)
ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CXddxDlg message handlers
BOOL CXddxDlg::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
m_PointNum=0;
m_LstCtrl.InsertColumn(0,"右片y",LVCFMT_CENTER,60);
m_LstCtrl.InsertColumn(0,"右片x",LVCFMT_CENTER,60);
m_LstCtrl.InsertColumn(0,"左片y",LVCFMT_CENTER,60);
m_LstCtrl.InsertColumn(0,"左片x",LVCFMT_CENTER,60);
m_LstCtrl.InsertColumn(0,"序號 ",LVCFMT_CENTER,45);
m_LstCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
CEdit *pEdit=(CEdit *)GetDlgItem(IDC_EDIT_CoPoint);
pEdit->SetWindowText("請點擊右邊的按鈕打開同名點文件^_^");
int i;
for(i=0;i<5;i++)
{
m_EleV[i]=0;
m_EleP[i]=0;
}
threshold=0.000001;
m_data=NULL;
return TRUE; // return TRUE unless you set the focus to a control
}
void CXddxDlg::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 CXddxDlg::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 CXddxDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CXddxDlg::OnBUTCoPointFile()
{
// TODO: Add your control notification handler code here
CFileDialog OpenDlg(TRUE,"*.txt","data.txt",OFN_HIDEREADONLY,"文本文件(*.txt)|*.txt|數據文件(*.dat)|*.dat||",NULL);
if(OpenDlg.DoModal()!=IDOK)
return;
CString FilePathName="";
LONG Head;
int i,j;
FilePathName=OpenDlg.GetPathName();
CEdit *pEdit=(CEdit *)GetDlgItem(IDC_EDIT_CoPoint);
pEdit->SetWindowText(FilePathName);
ifstream InFile;
InFile.open(FilePathName,ios::in);
if(!InFile)
{
MessageBox("打開文件失敗,無法讀出數據","錯誤",MB_ICONHAND|MB_OK);
return;
}
InFile>>Head;
if(Head!=9418204)
{
MessageBox("文件格式錯誤,無法讀出數據","錯誤",MB_ICONHAND|MB_OK);
return;
}
InFile>>f>>x0>>y0>>m_PointNum;
CString str1,str2;
if(m_PointNum==0)
return;
m_data=new double [m_PointNum*4];
if(m_data==NULL)
{
MessageBox("分配內存失敗,無法讀出數據","錯誤",MB_ICONHAND|MB_OK);
return;
}
for(i=0;i<m_PointNum;i++)
{
str1.Format("%d",i+1);
m_LstCtrl.InsertItem(i,str1);
for(j=0;j<4;j++)
{
InFile>>m_data[i*4+j];
str2.Format("%0.3f",m_data[i*4+j]);
m_LstCtrl.SetItemText(i,j+1,str2);
}
}
InFile.close();
m_LstCtrl.InsertItem(m_PointNum,"主距");
str2.Format("%0.3f",f);
m_LstCtrl.SetItemText(m_PointNum,1,str2);
m_LstCtrl.InsertItem(m_PointNum+1,"x0");
str2.Format("%0.3f",x0);
m_LstCtrl.SetItemText(m_PointNum+1,1,str2);
m_LstCtrl.InsertItem(m_PointNum+2,"y0");
str2.Format("%0.3f",y0);
m_LstCtrl.SetItemText(m_PointNum+2,1,str2);
CButton *pBut=(CButton *)GetDlgItem(IDC_BUT_Cal);
pBut->EnableWindow(TRUE);
}
void CXddxDlg::OnBnClickedButCal()
{
// TODO: 在此添加控件通知處理程序代碼
double R1[9],R2[9],VX[5],ATA[25],ATQ[5],X1,Y1,Z1,X2,Y2,Z2,VV;
double *A=new double [m_PointNum*5];
double *Q=new double [m_PointNum];
double *V=new double [m_PointNum];
double *AX=new double [m_PointNum];
double *AT=new double [m_PointNum*5];
int i,j=0;
for(i=0;i<5;i++)
{
VX[i]=1;
}
//--------------開始迭代求解未知數----------------//
while(fabs(Sta_Max(&VX[0],5))>threshold)
{
j++;
FormRotateMtx(R1,m_EleV[0],0 ,m_EleV[1]);
FormRotateMtx(R2,m_EleV[2],m_EleV[3],m_EleV[4]);
for(i=0;i<m_PointNum;i++)
{
X1=R1[0]*m_data[i*4] +R1[1]*m_data[i*4+1]-R1[2]*f;
Y1=R1[3]*m_data[i*4] +R1[4]*m_data[i*4+1]-R1[5]*f;
Z1=R1[6]*m_data[i*4] +R1[7]*m_data[i*4+1]-R1[8]*f;
X2=R2[0]*m_data[i*4+2]+R2[1]*m_data[i*4+3]-R2[2]*f;
Y2=R2[3]*m_data[i*4+2]+R2[4]*m_data[i*4+3]-R2[5]*f;
Z2=R2[6]*m_data[i*4+2]+R2[7]*m_data[i*4+3]-R2[8]*f;
A[i*5] = X1*Y2/Z1;
A[i*5+1]=-X1;
A[i*5+2]=-X2*Y1/Z2;
A[i*5+3]=-Z2-Y1*Y2/Z2;
A[i*5+4]= X2;
Q[i]=-f*(Y1*Z2-Y2*Z1)/(Z1*Z2);
}
Mtx_Transpose(A,AT,m_PointNum,5);
Mtx_Mult(AT,A,ATA,5,m_PointNum,5);
Mtx_Mult(AT,Q,ATQ,5,m_PointNum,1);
Mtx_Invers(ATA,5);
Mtx_Mult(ATA,ATQ,VX,5,5,1);
for(i=0;i<5;i++)
m_EleV[i]=VX[i]+m_EleV[i];
if(j>100000)
{
MessageBox("不收斂");
break;
}
}
//-----------------開始精度評定-------------------//
Mtx_Mult(A,VX,AX,m_PointNum,5,1);
Mtx_Add(AX,Q,V,m_PointNum);
Mtx_Mult(V,V,&VV,1,m_PointNum,1);
VV=VV/(m_PointNum-5);
VV=sqrt(VV);
for(i=0;i<5;i++)
m_EleP[i]=VV*sqrt(ATA[i*6]);
//----------------輸出未知數結果------------------//
CString str;
CEdit *pEdit=(CEdit *)GetDlgItem(IDC_EDIT_FaiLV);
str.Format("%0.6f",m_EleV[0]*200/PI);
pEdit->SetWindowText(str);
pEdit=(CEdit *)GetDlgItem(IDC_EDIT_KapaLV);
str.Format("%0.6f",m_EleV[1]*200/PI);
pEdit->SetWindowText(str);
pEdit=(CEdit *)GetDlgItem(IDC_EDIT_FaiRV);
str.Format("%0.6f",m_EleV[2]*200/PI);
pEdit->SetWindowText(str);
pEdit=(CEdit *)GetDlgItem(IDC_EDIT_OmigaRV);
str.Format("%0.6f",m_EleV[3]*200/PI);
pEdit->SetWindowText(str);
pEdit=(CEdit *)GetDlgItem(IDC_EDIT_KapaRV);
str.Format("%0.6f",m_EleV[4]*200/PI);
pEdit->SetWindowText(str);
//----------------輸出未知數精度------------------//
pEdit=(CEdit *)GetDlgItem(IDC_EDIT_FaiLP);
str.Format("%0.6f",VV*sqrt(ATA[0])*200000/PI);
pEdit->SetWindowText(str);
pEdit=(CEdit *)GetDlgItem(IDC_EDIT_KapaLP);
str.Format("%0.6f",VV*sqrt(ATA[6])*200000/PI);
pEdit->SetWindowText(str);
pEdit=(CEdit *)GetDlgItem(IDC_EDIT_FaiRP);
str.Format("%0.6f",VV*sqrt(ATA[12])*200000/PI);
pEdit->SetWindowText(str);
pEdit=(CEdit *)GetDlgItem(IDC_EDIT_OmigaRP);
str.Format("%0.6f",VV*sqrt(ATA[18])*200000/PI);
pEdit->SetWindowText(str);
pEdit=(CEdit *)GetDlgItem(IDC_EDIT_KapaRP);
str.Format("%0.6f",VV*sqrt(ATA[24])*200000/PI);
pEdit->SetWindowText(str);
CButton *pBut=(CButton *)GetDlgItem(IDC_BUT_SaveData);
pBut->EnableWindow(TRUE);
delete [] A;
delete [] Q;
delete [] AT;
}
void CXddxDlg::OnBnClickedButSavedata()
{
// TODO: 在此添加控件通知處理程序代碼
CFileDialog DlgOpenFile(FALSE,"*.txt","result.txt",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"文本文件(*.txt)|*.txt|數據文件(*.dat)|*.dat||",NULL);;
if(DlgOpenFile.DoModal()!=IDOK)
return;
CString StrFileName;
StrFileName=DlgOpenFile.GetPathName();
ofstream OpenFile;
OpenFile.open(StrFileName);
if(OpenFile==NULL)
{
MessageBox("創建文件失敗,無法寫入數據","錯誤",MB_ICONHAND|MB_OK);
return;
}
OpenFile.setf(ios::fixed);
OpenFile.setf(ios::showpoint);
OpenFile.precision(6);
OpenFile<<"Fai1 :"<<m_EleV[0]*200/PI<<"gon"<<" 精度:"<<m_EleP[0]*200000/PI<<" mgon"<<endl;
OpenFile<<"Kapa1 :"<<m_EleV[1]*200/PI<<"gon"<<" 精度:"<<m_EleP[1]*200000/PI<<" mgon"<<endl;
OpenFile<<"Fai2 :"<<m_EleV[2]*200/PI<<"gon"<<" 精度:"<<m_EleP[2]*200000/PI<<" mgon"<<endl;
OpenFile<<"Omiga2:"<<m_EleV[3]*200/PI<<"gon"<<" 精度:"<<m_EleP[3]*200000/PI<<" mgon"<<endl;
OpenFile<<"Kapa2 :"<<m_EleV[4]*200/PI<<"gon"<<" 精度:"<<m_EleP[4]*200000/PI<<" mgon";
OpenFile.close();
MessageBox("文件輸出成功","提示",MB_ICONINFORMATION|MB_OK);
}
void CXddxDlg::OnBnClickedCancel()
{
// TODO: 在此添加控件通知處理程序代碼
if(m_data!=NULL)
delete [] m_data;
OnOK();
}
int CXddxDlg::FormRotateMtx(double * RteMtx, double fai, double omiga, double kapa)
{
if(RteMtx==NULL)
return 0;
RteMtx[0]= cos(fai)*cos(kapa)-sin(fai)*sin(omiga)*sin(kapa);
RteMtx[1]=-cos(fai)*sin(kapa)-sin(fai)*sin(omiga)*cos(kapa);
RteMtx[2]=-sin(fai)*cos(omiga);
RteMtx[3]= cos(omiga)*sin(kapa);
RteMtx[4]= cos(omiga)*cos(kapa);
RteMtx[5]=-sin(omiga);
RteMtx[6]= sin(fai)*cos(kapa)+cos(fai)*sin(omiga)*sin(kapa);
RteMtx[7]=-sin(fai)*sin(kapa)+cos(fai)*sin(omiga)*cos(kapa);
RteMtx[8]=cos(fai)*cos(omiga);
return 1;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -