📄 rpc1dlg.cpp
字号:
// RPC1Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "RPC1.h"
#include "RPC1Dlg.h"
#include<iostream.h> //输入输出流
#include<fstream.h>//文件操作
#include "rc.h"
#include "math.h"
#include "Matrix.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()
/////////////////////////////////////////////////////////////////////////////
// CRPC1Dlg dialog
CRPC1Dlg::CRPC1Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CRPC1Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CRPC1Dlg)
m_Path_Left = _T("");
m_Path_Right = _T("");
m_Result = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
Read_Ok=FALSE;
}
void CRPC1Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRPC1Dlg)
DDX_Text(pDX, IDC_EDIT1, m_Path_Left);
DDX_Text(pDX, IDC_EDIT2, m_Path_Right);
DDX_Text(pDX, IDC_EDIT3, m_Result);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CRPC1Dlg, CDialog)
//{{AFX_MSG_MAP(CRPC1Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRPC1Dlg message handlers
BOOL CRPC1Dlg::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
return TRUE; // return TRUE unless you set the focus to a control
}
void CRPC1Dlg::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 CRPC1Dlg::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 CRPC1Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
//*********************************加载左影像*************************************//
void CRPC1Dlg::OnButton1()
{
CString sFilter="RPC文件(*.txt)|*.txt||";
CFileDialog m_Dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY
|OFN_OVERWRITEPROMPT,(LPCTSTR)sFilter,NULL);
if(m_Dlg.DoModal()==IDOK)
{
m_Path_Left=m_Dlg.GetPathName(); //获得左文件路径
UpdateData(FALSE);
Open_File_L=true; //设置文件已选定的标志
}
}
//*********************************加载右影像*************************************//
void CRPC1Dlg::OnButton2()
{
CString sFilter="RPC文件(*.txt)|*.txt||";
CFileDialog m_Dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY
|OFN_OVERWRITEPROMPT,(LPCTSTR)sFilter,NULL);
if(m_Dlg.DoModal()==IDOK)
{
m_Path_Right=m_Dlg.GetPathName(); //获得右文件路径
UpdateData(FALSE);
Open_File_R=true; //设置文件已选定的标志
}
}
//******************************调用计算函数,并进行迭代,最后输出满足要求的地面坐标************************//
/*
*首先读取左右影像RPC参数文件,然后调用函数comput(X0,Y0,Z0)进行相关参数的计算,利用一个循环进行迭代
*利用地面坐标的三个改正数derta_X、derta_Y、derta_Z是否满足要求进行判断,不断迭代直到得到满足要求的
*改正数,从而对地面坐标进行改正,最后得到满足要求的地面坐标
*/
void CRPC1Dlg::OnOK()
{
if (Read_Ok==FALSE)
{
if (Open_File_R==TRUE&&Open_File_L==TRUE)
{
//读取左右影像RPC参数文件
Read_left_file();
Read_right_file();
rc rc1;
if (rc1.DoModal()==IDOK)
{
row_L=rc1.m_r_l; //左影像同名点行坐标
row_R=rc1.m_r_r; //右影像同名点行坐标
col_L=rc1.m_c_l; //左影像同名点列坐标
col_R=rc1.m_c_r; //右影像同名点列坐标
X0=(X0_L+X0_R)/2;Y0=(Y0_L+Y0_R)/2;Z0=(Z0_L+Z0_R)/2; //同名点地面初始值
if(comput(X0,Y0,Z0)==TRUE)
{
CString S;
int num;
num=0;
bool flag;
flag=true;
/////////////////////进行迭代直到改正值满足要求,并对地面坐标进行修正,最后得出满足要求的地面坐标//////////
while(fabs(derta_X)>=0.0000000001||fabs(derta_Y)>=0.0000000001||fabs(derta_Z)>=0.00000001)
{
X0+=derta_X;
Y0+=derta_Y;
Z0+=derta_Z;
num++;
if (num<=100)
{
comput(X0,Y0,Z0);
CString S1;
S1.Format("第%d迭代:ok\n",num);
S1+="\r\n";
S+=S1;
m_Result=S;
UpdateData(FALSE);
flag=TRUE;
}
else
{
flag=FALSE;
S+="迭代次数过多,程序运行中止\n";
m_Result=S;
UpdateData(FALSE);
break;
}
}
////////////////////////计算结果输出///////////////////////////////////////////////////////////
if (flag==TRUE)
{
MessageBox("结算程序运行完毕\n");
S+="程序结算完毕\n";
S+="\r\n";
CString x,y,z;
x.Format("纬度:%lf",X0);
x+="\r\n";
y.Format("经度:%lf",Y0);
y+="\r\n";
z.Format("高程:%lf",Z0);
z+="\r\n";
S+=x+y+z;
m_Result=S;
UpdateData(FALSE);
}
}
}
Read_Ok=true;
}
else if (Open_File_L==TRUE)
{
MessageBox("右影像参数文件没有指定");
}
else if (Open_File_R==TRUE)
{
MessageBox("左影像参数文件没有指定");
}
else
{
MessageBox("影像参数文件没有指定");
}
}
else
{
MessageBox("文件已经读取");
}
}
//*********************************读取左影像RPC文件*****************************************//
void CRPC1Dlg::Read_left_file()
{
a_L=new double[20];
b_L=new double[20];
c_L=new double[20];
d_L=new double[20];
ifstream fin(m_Path_Left);
char *temp0,*temp01; //读取参数的临时字符串变量
temp0=new char[20];
temp01=new char[20];
fin>>temp0>>r0_L>>temp01;
fin>>temp0>>c0_L>>temp01;
fin>>temp0>>X0_L>>temp01;
fin>>temp0>>Y0_L>>temp01;
fin>>temp0>>Z0_L>>temp01;
fin>>temp0>>rs_L>>temp01;
fin>>temp0>>cs_L>>temp01;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -