geocorpage.cpp
来自「基于小波的SAR斑点处理」· C++ 代码 · 共 480 行
CPP
480 行
// GeoCorPage.cpp : implementation file
//
#include "stdafx.h"
#include "RSIP.h"
#include "GeoCorPage.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CGeoCorPage1 CPropertyPage
IMPLEMENT_DYNCREATE(CGeoCorPage1, CPropertyPage)
CGeoCorPage1::CGeoCorPage1() : CPropertyPage(CGeoCorPage1::IDD)
{
//{{AFX_DATA_INIT(CGeoCorPage1)
m_nImageWidth = 0;
m_nImageHeight = 0;
//}}AFX_DATA_INIT
m_dHorScale = 1.0;
m_dVerScale = 1.0;
}
CGeoCorPage1::~CGeoCorPage1()
{
}
void CGeoCorPage1::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CGeoCorPage1)
DDX_Text(pDX, IDC_IMAGEWIDTH, m_nImageWidth);
DDX_Text(pDX, IDC_IMAGEHEIGHT, m_nImageHeight);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CGeoCorPage1, CDialog)
//{{AFX_MSG_MAP(CGeoCorPage1)
ON_BN_CLICKED(IDC_BROWSEFILE, OnBrowsefile)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGeoCorPage1 message handlers
void CGeoCorPage1::OnBrowsefile()
{
CFileDialog fileDlg(TRUE,"*.GCP",NULL,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"GCPs Files(*.gcp)|*.gcp||",this);
if(fileDlg.DoModal()==IDOK)
{
CFile File;
if(0 == File.Open(fileDlg.GetPathName(),CFile::modeRead))
{
MessageBox("不能打开文件!");
return;
}
int nHeightInTics;
int nWidthInTics;
File.Read(&nWidthInTics,sizeof(int));
File.Read(&nHeightInTics,sizeof(int));
if(nWidthInTics != m_nImageWidth ||
nHeightInTics != m_nImageHeight)
{
MessageBox("地面控制点文件中的尺寸与影像大小不匹配!");
File.Close();
return;
}
if(!m_Tics.ReadFrom(File))
{
MessageBox("读地面控制点文件时出错!");
File.Close();
return;
}
File.Close();
SetDlgItemText(IDC_GCPFILENAME,fileDlg.GetPathName());
}
}
BOOL CGeoCorPage1::OnKillActive()
{
// TODO: Add your specialized code here and/or call the base class
return CPropertyPage::OnKillActive();
}
void CGeoCorPage1::CalculateEdge(double &dLeft,double &dTop,double &dRight,double &dBottom)
{
if(!m_Tics.m_bCorrectionReady)
{
m_Tics.Calculate();
}
CGisPoint ptTemp = m_Tics.MapToGeo(CGisPoint(0,0));
dRight = dLeft = ptTemp.x;
dTop = dBottom = ptTemp.y;
// 坐标原点位于左下点,X轴正方向向上,Y轴正方向向右
for(int i=0; i<m_nImageWidth; i++)
{
ptTemp = m_Tics.MapToGeo(CGisPoint(i,0));
if(dLeft > ptTemp.x)
dLeft = ptTemp.x;
if(dRight < ptTemp.x)
dRight = ptTemp.x;
if(dTop < ptTemp.y)
dTop = ptTemp.y;
if(dBottom > ptTemp.y)
dBottom = ptTemp.y;
}
for(i=0; i<m_nImageWidth; i++)
{
ptTemp = m_Tics.MapToGeo(CGisPoint(i,m_nImageHeight-1));
if(dLeft > ptTemp.x)
dLeft = ptTemp.x;
if(dRight < ptTemp.x)
dRight = ptTemp.x;
if(dTop < ptTemp.y)
dTop = ptTemp.y;
if(dBottom > ptTemp.y)
dBottom = ptTemp.y;
}
for(i=0; i<m_nImageHeight; i++)
{
ptTemp = m_Tics.MapToGeo(CGisPoint(0,i));
if(dLeft > ptTemp.x)
dLeft = ptTemp.x;
if(dRight < ptTemp.x)
dRight = ptTemp.x;
if(dTop < ptTemp.y)
dTop = ptTemp.y;
if(dBottom > ptTemp.y)
dBottom = ptTemp.y;
}
for(i=0; i<m_nImageHeight; i++)
{
ptTemp = m_Tics.MapToGeo(CGisPoint(m_nImageWidth-1,i));
if(dLeft > ptTemp.x)
dLeft = ptTemp.x;
if(dRight < ptTemp.x)
dRight = ptTemp.x;
if(dTop < ptTemp.y)
dTop = ptTemp.y;
if(dBottom > ptTemp.y)
dBottom = ptTemp.y;
}
}
/////////////////////////////////////////////////////////////////////////////
// CGeoCorPage2 CPropertyPage
IMPLEMENT_DYNCREATE(CGeoCorPage2, CPropertyPage)
CGeoCorPage2::CGeoCorPage2() : CPropertyPage(CGeoCorPage2::IDD)
{
//{{AFX_DATA_INIT(CGeoCorPage2)
m_bCut = FALSE;
m_dCutBottom = 0.0;
m_dCutLeft = 0.0;
m_dCutRight = 0.0;
m_dCutTop = 0.0;
m_dOriginBottom = 0.0;
m_dOriginLeft = 0.0;
m_dOriginRight = 0.0;
m_dOriginTop = 0.0;
//}}AFX_DATA_INIT
}
CGeoCorPage2::~CGeoCorPage2()
{
}
void CGeoCorPage2::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CGeoCorPage2)
DDX_Check(pDX, IDC_CUT_CHECK, m_bCut);
DDX_Text(pDX, IDC_CUTBOTTOM, m_dCutBottom);
DDX_Text(pDX, IDC_CUTLEFT, m_dCutLeft);
DDX_Text(pDX, IDC_CUTRIGHT, m_dCutRight);
DDX_Text(pDX, IDC_CUTTOP, m_dCutTop);
DDX_Text(pDX, IDC_RESULTBOTTOM, m_dOriginBottom);
DDX_Text(pDX, IDC_RESULTLEFT, m_dOriginLeft);
DDX_Text(pDX, IDC_RESULTRIGHT, m_dOriginRight);
DDX_Text(pDX, IDC_RESULTTOP, m_dOriginTop);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CGeoCorPage2, CDialog)
//{{AFX_MSG_MAP(CGeoCorPage2)
ON_BN_CLICKED(IDC_CUT_CHECK, OnCutCheck)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGeoCorPage2 message handlers
void CGeoCorPage2::OnCutCheck()
{
m_bCut = !m_bCut;
if(m_bCut)
{
GetDlgItem(IDC_CUTLEFT)->EnableWindow(TRUE);
GetDlgItem(IDC_CUTTOP)->EnableWindow(TRUE);
GetDlgItem(IDC_CUTRIGHT)->EnableWindow(TRUE);
GetDlgItem(IDC_CUTBOTTOM)->EnableWindow(TRUE);
}
else
{
GetDlgItem(IDC_CUTLEFT)->EnableWindow(FALSE);
GetDlgItem(IDC_CUTTOP)->EnableWindow(FALSE);
GetDlgItem(IDC_CUTRIGHT)->EnableWindow(FALSE);
GetDlgItem(IDC_CUTBOTTOM)->EnableWindow(FALSE);
}
}
BOOL CGeoCorPage2::OnKillActive()
{
// TODO: Add your specialized code here and/or call the base class
UpdateData();
return CPropertyPage::OnKillActive();
}
/////////////////////////////////////////////////////////////////////////////
// CGeoCorPage3 CPropertyPage
IMPLEMENT_DYNCREATE(CGeoCorPage3, CPropertyPage)
CGeoCorPage3::CGeoCorPage3() : CPropertyPage(CGeoCorPage3::IDD)
{
//{{AFX_DATA_INIT(CGeoCorPage3)
m_dOriginHeight = 0.0;
m_dOriginWidth = 0.0;
m_nResultHeight = 0;
m_nResultWidth = 0;
//}}AFX_DATA_INIT
m_bChangeText = FALSE;
m_HScale = 1.0;
m_VScale = 1.0;
}
CGeoCorPage3::~CGeoCorPage3()
{
}
void CGeoCorPage3::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CGeoCorPage3)
DDX_Text(pDX, IDC_HEIGHT, m_dOriginHeight);
DDX_Text(pDX, IDC_WIDTH, m_dOriginWidth);
DDX_Text(pDX, IDC_RESULTHEIGHT_PIXEL, m_nResultHeight);
DDX_Text(pDX, IDC_RESULTWIDTH_PIXEL, m_nResultWidth);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CGeoCorPage3, CDialog)
//{{AFX_MSG_MAP(CGeoCorPage3)
// ON_EN_CHANGE(IDC_RESULTHEIGHT_PIXEL, OnChangeResultheightPixel)
// ON_EN_CHANGE(IDC_RESULTWIDTH_PIXEL, OnChangeResultwidthPixel)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGeoCorPage3 message handlers
/*
void CGeoCorPage3::OnChangeResultheightPixel()
{
if(m_bChangeText)
return;
m_nResultHeight = GetDlgItemInt(IDC_RESULTWIDTH_PIXEL);
if(m_nResultHeight <= 0)
return;
m_nResultWidth = (int)(m_nResultHeight*m_dOriginWidth/m_dOriginHeight);
m_bChangeText = TRUE;
SetDlgItemInt(IDC_RESULTWIDTH_PIXEL,m_nResultWidth);
m_bChangeText = FALSE;
}
void CGeoCorPage3::OnChangeResultwidthPixel()
{
if(m_bChangeText)
return;
m_nResultWidth = GetDlgItemInt(IDC_RESULTWIDTH_PIXEL);
if(m_nResultWidth <= 0)
return;
m_nResultHeight = (int)(m_nResultWidth*m_dOriginHeight/m_dOriginWidth);
m_bChangeText = TRUE;
SetDlgItemInt(IDC_RESULTHEIGHT_PIXEL,m_nResultHeight);
m_bChangeText = FALSE;
}
*/
BOOL CGeoCorPage3::OnKillActive()
{
// TODO: Add your specialized code here and/or call the base class
return CPropertyPage::OnKillActive();
}
void CGeoCorPage3::CalculateCoefficient()
{
double HDistance,VDistance;
m_Tics.m_bCorrectionReady = FALSE;
for(DWORD i=0; i<m_Tics.m_dwTicsNumber; i++)
{
HDistance = ((CGisPoint *)(m_Tics.m_aGeoPoints[i]))->x - m_dOriX;
VDistance = m_dOriY - ((CGisPoint *)(m_Tics.m_aGeoPoints[i]))->y;
((CGisPoint *)(m_Tics.m_aGeoPoints[i]))->x = HDistance / m_HScale;
((CGisPoint *)(m_Tics.m_aGeoPoints[i]))->y = VDistance / m_VScale;
}
m_Tics.Calculate();
m_Tics.m_bCorrectionReady = TRUE;
for(i=0; i<12; i++)
{
m_pdInvertCoefficient[i] = m_Tics.m_dInvertCoefficient[i];
}
}
/////////////////////////////////////////////////////////////////////////////
// CGeoCorSheet
IMPLEMENT_DYNAMIC(CGeoCorSheet, CPropertySheet)
CGeoCorSheet::CGeoCorSheet(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
{
AddPage(&m_step1Page);
AddPage(&m_step2Page);
AddPage(&m_step3Page);
}
CGeoCorSheet::CGeoCorSheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(pszCaption, pParentWnd, iSelectPage)
{
AddPage(&m_step1Page);
AddPage(&m_step2Page);
AddPage(&m_step3Page);
}
CGeoCorSheet::~CGeoCorSheet()
{
}
BEGIN_MESSAGE_MAP(CGeoCorSheet, CPropertySheet)
//{{AFX_MSG_MAP(CGeoCorSheet)
// NOTE - the ClassWizard will add and remove mapping macros here.
ON_COMMAND(ID_WIZNEXT, OnNext)
ON_COMMAND(ID_WIZBACK, OnBack)
ON_COMMAND(ID_WIZFINISH, OnFinish)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGeoCorSheet message handlers
BOOL CGeoCorSheet::OnInitDialog()
{
BOOL bResult = CPropertySheet::OnInitDialog();
// TODO: Add your specialized code here
CenterWindow();
SetWizardButtons( PSWIZB_NEXT);
return bResult;
}
void CGeoCorSheet::OnNext()
{
int nPageCount = GetPageCount();
int nActivePage = GetActiveIndex();
if(nActivePage == nPageCount-1) //The last page
return;
nActivePage++;
if(nActivePage == 1)
{
if(m_step1Page.m_Tics.m_dwTicsNumber==0)
{
MessageBox("尚未选取地面控制点文件!");
return;
}
m_step1Page.CalculateEdge(m_step2Page.m_dOriginLeft,
m_step2Page.m_dOriginTop,
m_step2Page.m_dOriginRight,
m_step2Page.m_dOriginBottom);
}
else if(nActivePage==2)
{
m_step2Page.UpdateData();
if(m_step2Page.m_bCut)
{
if(m_step2Page.m_dCutLeft >= m_step2Page.m_dCutRight ||
m_step2Page.m_dCutBottom >= m_step2Page.m_dCutTop ||
m_step2Page.m_dCutLeft < m_step2Page.m_dOriginLeft ||
m_step2Page.m_dCutTop > m_step2Page.m_dOriginTop ||
m_step2Page.m_dCutBottom < m_step2Page.m_dOriginBottom ||
m_step2Page.m_dCutRight > m_step2Page.m_dOriginRight)
{
MessageBox("剪切范围错误!");
return;
}
}
m_step3Page.m_Tics = m_step1Page.m_Tics;
if(m_step2Page.m_bCut)
{
m_step3Page.m_dOriginWidth = (m_step2Page.m_dCutRight-m_step2Page.m_dCutLeft)
/ m_step1Page.m_dHorScale + 1;
m_step3Page.m_dOriginHeight = (m_step2Page.m_dCutTop-m_step2Page.m_dCutBottom)
/ m_step1Page.m_dVerScale + 1;
m_step3Page.m_dOriX = m_step2Page.m_dCutLeft;
m_step3Page.m_dOriY = m_step2Page.m_dCutTop;
}
else
{
m_step3Page.m_dOriginWidth = (m_step2Page.m_dOriginRight-m_step2Page.m_dOriginLeft)
/m_step1Page.m_dHorScale + 1;
m_step3Page.m_dOriginHeight = (m_step2Page.m_dOriginTop-m_step2Page.m_dOriginBottom)
/m_step1Page.m_dVerScale + 1;
m_step3Page.m_dOriX = m_step2Page.m_dOriginLeft;
m_step3Page.m_dOriY = m_step2Page.m_dOriginTop;
}
m_step3Page.m_nResultWidth = (int)(m_step3Page.m_dOriginWidth + 0.5);
m_step3Page.m_nResultHeight = (int)(m_step3Page.m_dOriginHeight + 0.5);
m_step3Page.m_HScale = m_step1Page.m_dHorScale;
m_step3Page.m_VScale = m_step1Page.m_dVerScale;
}
SetActivePage(nActivePage);
if(nActivePage == nPageCount-1)
SetWizardButtons( PSWIZB_BACK | PSWIZB_FINISH );
else
SetWizardButtons( PSWIZB_NEXT | PSWIZB_BACK);
}
void CGeoCorSheet::OnBack()
{
int nActivePage = GetActiveIndex();
if(nActivePage == 0) //The first page
return;
nActivePage--;
SetActivePage(nActivePage);
if(nActivePage == 0)
SetWizardButtons( PSWIZB_NEXT );
else
SetWizardButtons( PSWIZB_NEXT | PSWIZB_BACK);
}
void CGeoCorSheet::OnFinish()
{
m_step3Page.UpdateData();
if(m_step3Page.m_nResultHeight<=0 || m_step3Page.m_nResultWidth<=0 ||
m_step3Page.m_nResultHeight>10000 || m_step3Page.m_nResultWidth>=10000)
{
MessageBox("结果图像大小错误!(1-10000)");
return;
}
m_step3Page.CalculateCoefficient();
EndDialog(IDOK);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?