📄 cootrandlg.cpp
字号:
// CooTranDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CooTran.h"
#include "CooTranDlg.h"
#include "PointNum.h"
#include <fstream.h>
#include "Matrix.h"
#include "math.h"
#define PI 3.1415926535897932384626433
#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()
/////////////////////////////////////////////////////////////////////////////
// CCooTranDlg dialog
CCooTranDlg::CCooTranDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCooTranDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCooTranDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
// TYflag = 0;
}
void CCooTranDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCooTranDlg)
// DDX_Control(pDX, IDC_COMBO1, m_ComboBx);
DDX_Control(pDX, IDC_LIST_FINAL_RESULT, m_MyList2);
DDX_Control(pDX, IDC_LIST_UKP, m_MyList1);
DDX_Control(pDX, IDC_LIST_RESULT, m_MyList);
DDX_Control(pDX, IDC_LIST_POINT, m_ListControl);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCooTranDlg, CDialog)
//{{AFX_MSG_MAP(CCooTranDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTN_READ_K, OnButnReadK)
ON_BN_CLICKED(IDC_BUTN_DO, OnButnDo)
ON_BN_CLICKED(IDC_BUTN_READ_UK, OnButnReadUk)
ON_BN_CLICKED(IDC_BUTN_DO_Final, OnBUTNDOFinal)
ON_BN_CLICKED(IDC_BUTN_READ, OnButnRead)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCooTranDlg message handlers
BOOL CCooTranDlg::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
//读入控制点后即时显示给用户
DWORD dwStyle=::GetWindowLong(m_ListControl.m_hWnd,GWL_STYLE);
//设置为报表形式
SetWindowLong(m_ListControl.m_hWnd,GWL_STYLE,dwStyle|LVS_REPORT);
DWORD ExStyle =m_ListControl.GetExtendedStyle();
//设置为整栏选择和网格线
m_ListControl.SetExtendedStyle(ExStyle|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
//初始化列表控件标题栏
m_ListControl.InsertColumn(0,"点序号",LVCFMT_CENTER,60,0);
m_ListControl.InsertColumn(1,"X(北京54)",LVCFMT_CENTER,100,0);
m_ListControl.InsertColumn(2,"Y(北京54)",LVCFMT_CENTER,100,0);
m_ListControl.InsertColumn(3,"Z(北京54)",LVCFMT_CENTER,100,0);
m_ListControl.InsertColumn(4,"X(WGS_84)",LVCFMT_CENTER,100,0);
m_ListControl.InsertColumn(5,"Y(WGS_84)",LVCFMT_CENTER,100,0);
m_ListControl.InsertColumn(6,"Z(WGS_84)",LVCFMT_CENTER,100,0);
//计算出转换参量显示于列表框中
dwStyle=::GetWindowLong(m_MyList.m_hWnd,GWL_STYLE);
//设置为报表形式
SetWindowLong(m_MyList.m_hWnd,GWL_STYLE,dwStyle|LVS_REPORT);
ExStyle =m_MyList.GetExtendedStyle();
//设置为整栏选择和网格线
m_MyList.SetExtendedStyle(ExStyle|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
//初始化列表控件标题栏
m_MyList.InsertColumn(0,"转换参量",LVCFMT_CENTER,100,0);
m_MyList.InsertColumn(1,"所求结果",LVCFMT_CENTER,100,0);
//将待转换点坐标读入即时显示在列表框中
dwStyle=::GetWindowLong(m_MyList1.m_hWnd,GWL_STYLE);
//设置为报表形式
SetWindowLong(m_MyList1.m_hWnd,GWL_STYLE,dwStyle|LVS_REPORT);
ExStyle =m_MyList1.GetExtendedStyle();
//设置为整栏选择和网格线
m_MyList1.SetExtendedStyle(ExStyle|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
//初始化列表控件标题栏
m_MyList1.InsertColumn(0,"点序号",LVCFMT_CENTER,60,0);
m_MyList1.InsertColumn(1,"X(WGS_84)",LVCFMT_CENTER,100,0);
m_MyList1.InsertColumn(2,"Y(WGS_84)",LVCFMT_CENTER,100,0);
m_MyList1.InsertColumn(3,"Z(WGS_84)",LVCFMT_CENTER,100,0);
//将转换后点坐标即时显示在列表框中
dwStyle=::GetWindowLong(m_MyList2.m_hWnd,GWL_STYLE);
//设置为报表形式
SetWindowLong(m_MyList2.m_hWnd,GWL_STYLE,dwStyle|LVS_REPORT);
ExStyle =m_MyList1.GetExtendedStyle();
//设置为整栏选择和网格线
m_MyList2.SetExtendedStyle(ExStyle|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
//初始化列表控件标题栏
m_MyList2.InsertColumn(0,"点序号",LVCFMT_CENTER,60,0);
m_MyList2.InsertColumn(1,"X(北京54)",LVCFMT_CENTER,100,0);
m_MyList2.InsertColumn(2,"Y(北京54)",LVCFMT_CENTER,100,0);
m_MyList2.InsertColumn(3,"Z(北京54)",LVCFMT_CENTER,100,0);
return TRUE; // return TRUE unless you set the focus to a control
}
void CCooTranDlg::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 CCooTranDlg::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 CCooTranDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CCooTranDlg::OnButnReadK()
{
// TODO: Add your control notification handler code here
Count1=0;
CPointNum dlg;
if(dlg.DoModal()==IDOK)
{
Count1=dlg.m_nPointNum;
DATA=new double[Count1*6];
CFileDialog fileDlg(TRUE);
fileDlg.m_ofn.lpstrTitle="我的文件打开对话框";
fileDlg.m_ofn.lpstrFilter="Text Files(*.txt)\0*.txt\0All Files(*.*)\0*.*\0\0";
int i;
if(IDOK==fileDlg.DoModal())
{
CString filefullname=fileDlg.GetPathName();
ifstream file(filefullname);
for(i=0;i<6*Count1;i++)
{
file>>DATA[i];
}
}
CString text;
int iPos,j;
for(i=0;i<Count1;i++)
{
text.Format("%d",i+1);
iPos=m_ListControl.InsertItem(i,text);
for(j=0;j<6;j++)
{
text.Format("%f",DATA[i*6+j]);
m_ListControl.SetItemText(iPos,j+1,text);
}
}
}
}
void CCooTranDlg::OnButnDo()
{
// TODO: Add your control notification handler code here
double *A=new double[Count1*3*7]; //系数阵
double *L=new double[Count1*3]; //常数项
X=new double[7]; //结果
double *AT=new double[Count1*3*7]; //系数转置阵
double *ATA=new double[7*7];
double *ATL=new double[7];
double *invATA=new double[7*7];
int i;
for(i=0;i<Count1;i++)
{
double X_WGS84=DATA[0+i*6];
double Y_WGS84=DATA[1+i*6];
double Z_WGS84=DATA[2+i*6];
double X_54=DATA[3+i*6];
double Y_54=DATA[4+i*6];
double Z_54=DATA[5+i*6];
//系数矩阵第一行
A[7*3*i]=1;
A[7*3*i+1]=0;
A[7*3*i+2]=0;
A[7*3*i+3]=X_WGS84;
A[7*3*i+4]=0;
A[7*3*i+5]=-Z_WGS84;
A[7*3*i+6]=Y_WGS84;
//系数矩阵第二行
A[7*(3*i+1)]=0;
A[7*(3*i+1)+1]=1;
A[7*(3*i+1)+2]=0;
A[7*(3*i+1)+3]=Y_WGS84;
A[7*(3*i+1)+4]=Z_WGS84;
A[7*(3*i+1)+5]=0;
A[7*(3*i+1)+6]=-X_WGS84;
//系数矩阵第三行
A[7*(3*i+2)]=0;
A[7*(3*i+2)+1]=0;
A[7*(3*i+2)+2]=1;
A[7*(3*i+2)+3]=Z_WGS84;
A[7*(3*i+2)+4]=-Y_WGS84;
A[7*(3*i+2)+5]=X_WGS84;
A[7*(3*i+2)+6]=0;
//常数项
L[3*i]=X_54;
L[3*i+1]=Y_54;
L[3*i+2]=Z_54;
}
Trans(A,AT,3*Count1,7);
damul(AT,A,7,3*Count1,7,ATA);
damul(AT,L,7,3*Count1,1,ATL);
invATA=ATA;
dcinv(invATA,7);
damul(invATA,ATL,7,7,1,X);
CString str;
/* str.Format("X[0]=%f",X[0]);
MessageBox(str);*/
str.Format("%f",X[0]);
int iPos=m_MyList.InsertItem(0,"DeltaX");
m_MyList.SetItemText(iPos,1,str);
str.Format("%f",X[1]);
iPos=m_MyList.InsertItem(1,"DeltaY");
m_MyList.SetItemText(iPos,1,str);
iPos=m_MyList.InsertItem(2,"DeltaZ");
str.Format("%f",X[2]);
m_MyList.SetItemText(iPos,1,str);
iPos=m_MyList.InsertItem(3,"a1");
str.Format("%f",X[3]);
m_MyList.SetItemText(iPos,1,str);
iPos=m_MyList.InsertItem(4,"a2");
str.Format("%f",X[4]);
m_MyList.SetItemText(iPos,1,str);
iPos=m_MyList.InsertItem(5,"a3");
str.Format("%f",X[5]);
m_MyList.SetItemText(iPos,1,str);
iPos=m_MyList.InsertItem(6,"a4");
str.Format("%f",X[6]);
m_MyList.SetItemText(iPos,1,str);
}
void CCooTranDlg::OnButnReadUk()
{
// TODO: Add your control notification handler code here
Count2=0;
CPointNum dlg;
if(dlg.DoModal()==IDOK)
{
Count2=dlg.m_nPointNum;
DATA1=new double[Count2*3];
CFileDialog fileDlg(TRUE);
fileDlg.m_ofn.lpstrTitle="我的文件打开对话框";
fileDlg.m_ofn.lpstrFilter="Text Files(*.txt)\0*.txt\0All Files(*.*)\0*.*\0\0";
int i;
if(IDOK==fileDlg.DoModal())
{
CString filefullname=fileDlg.GetPathName();
ifstream file(filefullname);
for(i=0;i<3*Count2;i++)
{
file>>DATA1[i];
}
}
CString text;
int iPos,j;
for(i=0;i<Count2;i++)
{
text.Format("%d",i+1);
iPos=m_MyList1.InsertItem(i,text);
for(j=0;j<3;j++)
{
text.Format("%f",DATA1[i*3+j]);
m_MyList1.SetItemText(iPos,j+1,text);
}
}
}
}
void CCooTranDlg::OnBUTNDOFinal()
{
// TODO: Add your control notification handler code here
double *B=new double[Count2*3*7]; //系数阵
double *Bj_54=new double[Count2*3]; //54空间直角坐标
F_result=new double[Count2*3];
int i;
for(i=0;i<Count2;i++)
{
double X_WGS84=DATA[0+i*6];
double Y_WGS84=DATA[1+i*6];
double Z_WGS84=DATA[2+i*6];
//系数矩阵第一行
B[7*3*i]=1;
B[7*3*i+1]=0;
B[7*3*i+2]=0;
B[7*3*i+3]=X_WGS84;
B[7*3*i+4]=0;
B[7*3*i+5]=-Z_WGS84;
B[7*3*i+6]=Y_WGS84;
//系数矩阵第二行
B[7*(3*i+1)]=0;
B[7*(3*i+1)+1]=1;
B[7*(3*i+1)+2]=0;
B[7*(3*i+1)+3]=Y_WGS84;
B[7*(3*i+1)+4]=Z_WGS84;
B[7*(3*i+1)+5]=0;
B[7*(3*i+1)+6]=-X_WGS84;
//系数矩阵第三行
B[7*(3*i+2)]=0;
B[7*(3*i+2)+1]=0;
B[7*(3*i+2)+2]=1;
B[7*(3*i+2)+3]=Z_WGS84;
B[7*(3*i+2)+4]=-Y_WGS84;
B[7*(3*i+2)+5]=X_WGS84;
B[7*(3*i+2)+6]=0;
}
damul(B,X,Count2*3,7,1,Bj_54);
for(i=0;i<Count2;i++)
{
F_result[i*3+0]=Bj_54[i*3+0];
F_result[i*3+1]=Bj_54[i*3+1];
F_result[i*3+2]=Bj_54[i*3+2];
CString text;
int iPos;
text.Format("%d",i+1);
iPos=m_MyList2.InsertItem(i,text);
text.Format("%f",Bj_54[i*3+0]);
m_MyList2.SetItemText(iPos,1,text);
text.Format("%f",Bj_54[i*3+1]);
m_MyList2.SetItemText(iPos,2,text);
text.Format("%f",Bj_54[i*3+2]);
m_MyList2.SetItemText(iPos,3,text);
}
}
double CCooTranDlg::HZJ(double H) //弧度转成角度
{
double DUQ,aQ,BQ,bQ,cQ,J;
DUQ=H*180/PI;
aQ=floor(DUQ);
BQ=(DUQ-aQ)*60;
bQ=floor(BQ);
cQ=(BQ-bQ)*60;
J=aQ+bQ/100+cQ/10000;
return J;
}
void CCooTranDlg::OnButnRead()
{
// TODO: Add your control notification handler code here
CFileDialog fileDlg(FALSE);
fileDlg.m_ofn.lpstrTitle="我的文件保存对话框";
fileDlg.m_ofn.lpstrFilter="Text Files(*.txt)\0*.txt\0All Files(*.*)\0*.*\0\0";
fileDlg.m_ofn.lpstrDefExt="txt";
if(IDOK==fileDlg.DoModal())
{
CString filefullname=fileDlg.GetPathName();
ofstream file(filefullname);
MessageBox(filefullname);
int i,j;
for(i=0;i<Count2;i++)
{
for(j=0;j<3;j++)
{
//str = F_result[i*3+j];
file<<F_result[i*3+j]<<" ";
}
file<<"\n";
}
}
}
double CCooTranDlg::XYZ(double k)
{
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -