📄 testdlg.cpp
字号:
// TestDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Test.h"
#include "TestDlg.h"
#include "math.h"
#include "Mmsystem.h"
#include "Windows.h"
#include "ProgDlg.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()
/////////////////////////////////////////////////////////////////////////////
// CTestDlg dialog
CTestDlg::CTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTestDlg)
m_nCols = 100;
m_nRows = 100;
m_nSamples = 100;
m_nLayers = 20;
m_strFileName = _T("");
m_strFileDem = _T("");
m_str3DVFile = _T("");
m_nModeOne = -1;
m_nModeTwo = 0;
m_strOrgFileDir = _T("");
m_str3doDir = _T("");
m_str3doFileName = _T("");
m_dbConeffY = 1.0;
m_dbConeffZ = 1.0;
m_dbConeffX = 1.0;
m_strSave3dvFileName = _T("");
m_nGridX = 1;
m_nGridY = 1;
m_strAreaPath = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_strCurrentPro="";
m_nScale=1;
m_bRead=FALSE;
}
void CTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestDlg)
DDX_Control(pDX, IDC_EDIT_XY_GRID2, m_editXyGrid2);
DDX_Control(pDX, IDC_STATIC_XY_GRID2, m_staticXY2);
DDX_Control(pDX, IDC_EDIT_3DV_SAVE_FILE_NAME, m_editSave3dvFileName);
DDX_Control(pDX, IDC_STATIC_3DV_SAVE_NAME, m_staticSave3dvFileName);
DDX_Control(pDX, IDC_EDIT_SAVE_3DO_FILE_NAME, m_editSave3doFileName);
DDX_Control(pDX, IDC_STATIC_SAVE_3DO_FILE_NAME, m_staticSave3doFileName);
DDX_Control(pDX, IDC_BUTTON_SAVE_3DO, m_buttonSave3do);
DDX_Control(pDX, IDC_EDIT_SAVE_3DO, m_editSave3do);
DDX_Control(pDX, IDC_STATIC_SAVE_3DO, m_staticSave3doFile);
DDX_Control(pDX, IDC_EDIT_CONEFF_Z, m_editConeffZ);
DDX_Control(pDX, IDC_EDIT_CONEFF_Y, m_editConeffY);
DDX_Control(pDX, IDC_EDIT_CONEFF_X, m_editConeffX);
DDX_Control(pDX, IDC_STATIC_CONEFF_Z, m_staticConeffZ);
DDX_Control(pDX, IDC_STATIC_CONEFF_Y, m_staticConeffY);
DDX_Control(pDX, IDC_STATIC_CONEFF_X, m_staticConeffX);
DDX_Control(pDX, IDC_EDIT_XY_GRID, m_editXyGrid);
DDX_Control(pDX, IDC_EDIT_LAYER, m_editLayer);
DDX_Control(pDX, IDC_EDIT_SAMPLE, m_editSamples);
DDX_Control(pDX, IDC_EDIT_ROW, m_editRows);
DDX_Control(pDX, IDC_EDIT_COL, m_editCols);
DDX_Control(pDX, IDC_STATIC_XY_GRID, m_staticXY);
DDX_Control(pDX, IDC_STATIC_Z_L, m_staticZL);
DDX_Control(pDX, IDC_STATIC_Z_S, m_staticZS);
DDX_Control(pDX, IDC_STATIC_Y_S, m_staticYS);
DDX_Control(pDX, IDC_STATIC_X_S, m_staticXS);
DDX_Control(pDX, IDC_STATIC_DEM_FILE, m_staticdemfile);
DDX_Control(pDX, IDC_STATIC_3DO_FILE, m_static3dofile);
DDX_Control(pDX, IDC_BUTTON_OPEN, m_button3DO);
DDX_Control(pDX, IDC_BUTTON_3DV, m_button3DV);
DDX_Control(pDX, IDC_BUTTON_DEM, m_buttonOpenDem);
DDX_Control(pDX, IDC_EDIT_3DV_FILE, m_edit3dvfile);
DDX_Control(pDX, IDC_EDIT_DEM, m_editdemfile);
DDX_Control(pDX, IDC_EDIT_FILE_NAME, m_edit3dofile);
DDX_Control(pDX, IDC_STATIC_3DV_FILE, m_static3dvfile);
DDX_Control(pDX, IDC_STATIC_PRO_SET, m_staticProSet);
DDX_Control(pDX, IDC_STATIC_FILE_PATH, m_staticFilePath);
DDX_Control(pDX, IDC_STATIC_GRID_SET, m_staticGridSet);
DDX_Control(pDX, IDCANCEL, m_buttonCancel);
DDX_Control(pDX, ID_OK, m_buttonMake3dv);
DDX_Control(pDX, IDC_BUTTON_MAKE_3DO, m_buttonMake3do);
DDX_Control(pDX, IDC_COMBO_RESET_STEP, m_comboxResetStep);
DDX_Control(pDX, IDC_STATIC_SAMPLE_STEP, m_staticSampleStep);
DDX_Control(pDX, IDC_COMBO_SAMPLE_SHEET, m_comboxSample);
DDX_Control(pDX, IDC_STATIC_SAMPLE_SHEET, m_staticSampleSheet);
DDX_Control(pDX, IDC_COMBO_PRO_SHEET, m_comboxBoxPro);
DDX_Control(pDX, IDC_STATIC_PRO_SHEET, m_staticProSheet);
DDX_Control(pDX, IDC_BUTTON_AREA_FILE, m_buttonAreaFile);
DDX_Control(pDX, IDC_EDIT_AREA_PATH, m_editAreaDir);
DDX_Control(pDX, IDC_BUTTON_AREA_DIR, m_buttonAreaDir);
DDX_Control(pDX, IDC_STATIC_AREA_DIR, m_staticAreaDir);
DDX_Control(pDX, IDC_BUTTON_READ_FILE, m_buttonReadFile);
DDX_Control(pDX, IDC_EDIT_ORG_FILE_DIR, m_editOrgDir);
DDX_Control(pDX, IDC_BUTTON_ORG_DIR, m_buttonOrgDir);
DDX_Control(pDX, IDC_STATIC_ORG_DIR_LEFT, m_staticOrgDir);
DDX_Control(pDX, IDC_STATIC_BROWSER, m_BrowserBox);
DDX_Control(pDX, IDC_STATIC_MODE_TWO, m_ModeTwoBox);
DDX_Control(pDX, IDC_STATIC_MODE_ONE, m_ModeOneBox);
DDX_Control(pDX, IDC_RADIO_MODE_TWO, m_RadioModeTwo);
DDX_Control(pDX, IDC_RADIO_MODE_ONE, m_RadioModeOne);
DDX_Control(pDX, IDC_STATIC_3DV_BOX, m_Ctrl3DVBox);
DDX_Control(pDX, IDC_STATIC_3DO_BOX, m_Ctrl3DOBox);
DDX_Text(pDX, IDC_EDIT_COL, m_nCols);
DDX_Text(pDX, IDC_EDIT_ROW, m_nRows);
DDX_Text(pDX, IDC_EDIT_SAMPLE, m_nSamples);
DDX_Text(pDX, IDC_EDIT_LAYER, m_nLayers);
DDX_Text(pDX, IDC_EDIT_FILE_NAME, m_strFileName);
DDX_Text(pDX, IDC_EDIT_DEM, m_strFileDem);
DDX_Text(pDX, IDC_EDIT_3DV_FILE, m_str3DVFile);
DDX_Radio(pDX, IDC_RADIO_MODE_ONE, m_nModeOne);
DDX_Radio(pDX, IDC_RADIO_MODE_TWO, m_nModeTwo);
DDX_Text(pDX, IDC_EDIT_ORG_FILE_DIR, m_strOrgFileDir);
DDX_Text(pDX, IDC_EDIT_SAVE_3DO, m_str3doDir);
DDX_Text(pDX, IDC_EDIT_SAVE_3DO_FILE_NAME, m_str3doFileName);
DDX_Text(pDX, IDC_EDIT_CONEFF_Y, m_dbConeffY);
DDX_Text(pDX, IDC_EDIT_CONEFF_Z, m_dbConeffZ);
DDX_Text(pDX, IDC_EDIT_CONEFF_X, m_dbConeffX);
DDX_Text(pDX, IDC_EDIT_3DV_SAVE_FILE_NAME, m_strSave3dvFileName);
DDX_Text(pDX, IDC_EDIT_XY_GRID, m_nGridX);
DDX_Text(pDX, IDC_EDIT_XY_GRID2, m_nGridY);
DDX_Text(pDX, IDC_EDIT_AREA_PATH, m_strAreaPath);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
//{{AFX_MSG_MAP(CTestDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_OPEN, OnButtonOpen)
ON_BN_CLICKED(ID_OK, OnOk)
ON_BN_CLICKED(IDC_BUTTON_DEM, OnButtonDem)
ON_BN_CLICKED(IDC_BUTTON_3DV, OnButton3dv)
ON_WM_SIZE()
ON_BN_CLICKED(IDC_RADIO_MODE_ONE, OnRadioModeOne)
ON_BN_CLICKED(IDC_RADIO_MODE_TWO, OnRadioModeTwo)
ON_BN_CLICKED(IDC_BUTTON_READ_FILE, OnButtonReadFile)
ON_BN_CLICKED(IDC_BUTTON_ORG_DIR, OnButtonOrgDir)
ON_CBN_CLOSEUP(IDC_COMBO_PRO_SHEET, OnCloseupComboProSheet)
ON_CBN_CLOSEUP(IDC_COMBO_RESET_STEP, OnCloseupComboResetStep)
ON_BN_CLICKED(IDC_BUTTON_MAKE_3DO, OnButtonMake3do)
ON_BN_CLICKED(IDC_BUTTON_SAVE_3DO, OnButtonSave3do)
ON_BN_CLICKED(IDC_BUTTON_AREA_DIR, OnButtonAreaDir)
ON_BN_CLICKED(IDC_BUTTON_AREA_FILE, OnButtonAreaFile)
ON_WM_SETCURSOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestDlg message handlers
BOOL CTestDlg::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
//ShowWindow(SW_SHOWMAXIMIZED);
m_buttonMake3do.SubclassDlgItem(IDI_ICON_MAKE_3DO, this);
m_buttonMake3do.SetIcon(IDI_ICON_MAKE_3DO);
m_buttonMake3dv.SubclassDlgItem(IDI_ICON_MAKE_3DO, this);
m_buttonMake3dv.SetIcon(IDI_ICON_MAKE_3DV);
m_buttonOrgDir.SubclassDlgItem(IDI_ICON_OPEN, this);
m_buttonOrgDir.SetIcon(IDI_ICON_OPEN);
m_buttonAreaDir.SubclassDlgItem(IDI_ICON_OPEN, this);
m_buttonAreaDir.SetIcon(IDI_ICON_OPEN);
m_buttonReadFile.SubclassDlgItem(IDI_ICON_READ,this);
m_buttonReadFile.SetIcon(IDI_ICON_READ);
m_buttonAreaFile.SubclassDlgItem(IDI_ICON_READ,this);
m_buttonAreaFile.SetIcon(IDI_ICON_READ);
m_buttonSave3do.SubclassDlgItem(IDI_ICON_OPEN, this);
m_buttonSave3do.SetIcon(IDI_ICON_OPEN);
m_button3DO.SubclassDlgItem(IDI_ICON_OPEN, this);
m_button3DO.SetIcon(IDI_ICON_OPEN);
m_buttonOpenDem.SubclassDlgItem(IDI_ICON_OPEN, this);
m_buttonOpenDem.SetIcon(IDI_ICON_OPEN);
m_button3DV.SubclassDlgItem(IDI_ICON_OPEN, this);
m_button3DV.SetIcon(IDI_ICON_OPEN);
SetControlSize();
DisableModeOne(FALSE);
m_comboxResetStep.SetCurSel(0);
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CTestDlg::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 CTestDlg::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 CTestDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CTestDlg::OnButtonOpen()
{
// TODO: Add your control notification handler code here
CFileDialog dlg( TRUE );
if( IDOK!=dlg.DoModal( ))return;
m_strFileName=dlg.GetPathName();
UpdateData(FALSE);
}
CString CTestDlg::GetFileExtName(CString strFileName)
{
CString strExtName;
int nLen = strFileName.GetLength();
int nIndex = strFileName.ReverseFind('.');
if (nIndex>=0)
strExtName = strFileName.Right(nLen-nIndex-1);
return strExtName;
}
void CTestDlg::OnOk()
{
// TODO: Add your control notification handler code here
UpdateData();
//----------------检查数据的合法性---------------
CString strExt3DO=GetFileExtName(m_strFileName);
CString strExtDem=GetFileExtName(m_strFileDem);
if(m_nCols<1||m_nRows<1||m_nSamples<1||m_nLayers<1||strExt3DO!="3do"\
||strExtDem!="xyz")
{
AfxMessageBox("参数非法!");
return;
}
if(m_strSave3dvFileName=="")
{
AfxMessageBox("三维数据文件名称未指定!");
return;
}
//---------------开始插值生成高程数据
Clear();
if(!OpenDemFile(m_strFileDem)) //打开高程离散数据文件
return;
StatisticMaxMin(); //统计出最大与最小值
InvDistancePower() ; //插值计算
// SaveDem(); //保存结果数据
//---------------开始三维插值
if(!OpenD3doFile(m_strFileName))
return;
double z,v;
CGLVertex vertex;
Init3dGroup();
DivLayer();
//DivXYGrid();
CProgressDlg *m_pProgress=new CProgressDlg(1);
m_pProgress->m_strTitle="生成三维数据进度条";
m_pProgress->Create(this);
m_pProgress->SetRange(0,99);
for(int r=0;r<m_nRows;r++)
for(int c=0;c<m_nCols;c++)
for(int s=0;s<m_nSamples;s++)
{
if(m_pProgress->m_bCancel)
{
m_pProgress->DestroyWindow();
return;
}
vertex=m_3DVGroup.GetAt((r*m_nCols+c)*m_nSamples+s);
z=vertex.z;
int n=GetPointLieLayer(c,r,z);
v=GetValue(vertex.x,vertex.y,z,n);
m_3DVGroup[(r*m_nCols+c)*m_nSamples+s].v=v;
m_pProgress->SetPos(100*((r*m_nCols+c)*m_nSamples+s)/(m_nSamples*m_nRows*m_nCols));
}
m_pProgress->DestroyWindow();
if(!Save3dv())
{
AfxMessageBox("3dv数据保存出错!");
return;
}
UpdateData(FALSE);
}
void CTestDlg::OnButtonDem()
{
// TODO: Add your control notification handler code here
CFileDialog dlg( TRUE );
if( IDOK!=dlg.DoModal( ))return;
m_strFileDem=dlg.GetPathName();
UpdateData(FALSE);
}
void CTestDlg::Clear()
{
m_DemGroup.Clear();
m_DemFullGroup.Clear();
m_LayerArray.Clear();
m_3DOGroup.Clear();
m_3DVGroup.Clear();
}
BOOL CTestDlg::OpenDemFile(CString strFileName)
{
FILE *fp;
fp=fopen(strFileName,"r");
if(fp==NULL)
{
AfxMessageBox("文件读取失败!");
return FALSE;
}
int nCount;
double x,y,z;
C3DPoint pt;
fscanf(fp,"%d",&nCount);
m_DemGroup.Init(nCount);
for(int i=0;i<nCount;i++)
{
fscanf(fp,"%lf%lf%lf",&x,&y,&z);
pt.x=x;
pt.y=y;
pt.z=z;
m_DemGroup.SetAt(i,pt);
}
fclose(fp);
return TRUE;
}
void CTestDlg::StatisticMaxMin()
{
int nCount=m_DemGroup.GetSize();
C3DPoint pt;
if(nCount<=1) //如果只有一个点将是无意义的
return;
pt=m_DemGroup.GetAt(0);
m_dbMinX=m_dbMaxX=pt.x;
m_dbMinY=m_dbMaxY=pt.y;
for(int i=1;i<nCount;i++)
{
pt=m_DemGroup.GetAt(i);
if(pt.x<m_dbMinX)
m_dbMinX=pt.x;
if(pt.x>m_dbMaxX)
m_dbMaxX=pt.x;
if(pt.y<m_dbMinY)
m_dbMinY=pt.y;
if(pt.y>m_dbMaxY)
m_dbMaxY=pt.y;
}
m_dbDeltaX=(m_dbMaxX-m_dbMinX)/(m_nCols-1);
m_dbDeltaY=(m_dbMaxY-m_dbMinY)/(m_nRows-1);
}
void CTestDlg::InvDistancePower()
{
C3DPoint pt;
m_DemFullGroup.Init(m_nRows*m_nCols);
for(int i=0;i<m_nRows;i++)
{
pt.y=m_dbMinY+i*m_dbDeltaY;
for(int j=0;j<m_nCols;j++)
{
pt.x=m_dbMinX+j*m_dbDeltaX;
pt.z=GetZ(pt.x,pt.y);
m_DemFullGroup.SetAt(i*m_nCols+j,pt);
}
}
}
double CTestDlg::GetZ(double dbX,double dbY)
{
double dbZ;
double dbNumerator=0; //分子
double dbDenominator=0; //分母
double dbDist;
C3DPoint pt;
int nCount=m_DemGroup.GetSize();
for(int i=0;i<nCount;i++)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -