www.pudn.com > VRGIS-2005.rar > dem_testDoc.cpp, change:2001-04-06,size:3142b
// dem_testDoc.cpp : implementation of the CDem_testDoc class
//
#include "stdafx.h"
#include "dem_test.h"
#include "math.h"
#include "dem_testDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDem_testDoc
IMPLEMENT_DYNCREATE(CDem_testDoc, CDocument)
BEGIN_MESSAGE_MAP(CDem_testDoc, CDocument)
//{{AFX_MSG_MAP(CDem_testDoc)
ON_COMMAND(ID_readfile, Onreadfile)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDem_testDoc construction/destruction
CDem_testDoc::CDem_testDoc()
{
// TODO: add one-time construction code here
}
CDem_testDoc::~CDem_testDoc()
{
}
BOOL CDem_testDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
int i,j,dat;
float dz;
FILE *fp;
fp=fopen("dem231.txt","r");
if(fp==NULL)
ASSERT(FALSE);//若打开文件出错,则报告出错!
else
{
fscanf(fp,"%d%d",&m,&n);
for(i=0;i<m;i++)
{ for(j=0;j<n;j++)
{
// 用于读取整形的高程点数据
// fscanf(fp,"%d",&dat);
// dix[i][j]=dat/50+0.10;
// 用于读取浮点型的高程点数据
fscanf(fp,"%f",&dz);
dix[i][j]=dz*8;
}
}
}
UpdateAllViews(NULL);
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CDem_testDoc serialization
void CDem_testDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CDem_testDoc diagnostics
#ifdef _DEBUG
void CDem_testDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CDem_testDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDem_testDoc commands
void CDem_testDoc::Onreadfile()
{
// TODO: Add your command handler code here
static char BASED_CODE szFilter[] = "地形数据文件 (*.den)|*.den|All Files (*.*)|*.*||";
CFileDialog cf(TRUE,".den",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter,NULL);
if(cf. DoModal()==IDOK)
{
FILE *fp,* fpW;
unsigned char *data = new unsigned char [1851392];
int huiche=0;
int hd2=0;
int hang=1;
int lie=1;
fp=fopen(cf.GetFileName(),"r");
if((fp!=NULL)&&(fpW =fopen("data.txt","w"))!=NULL)
{
fseek(fp,44,0);
fread(data,1851392,1,fp);
for(int i=0;i<113;i++)
{
for(lie=0;lie<128;lie++)
{
fprintf(fpW,"%d %d\n", i+1,lie+1);
for(hang=0;hang<128;hang++)
{
fprintf(fpW,"%d ",int(*(data++)));
// tou[hang][lie][i]=int(*(data++));
}
fprintf(fpW,"\n");
}
}
fclose(fp);
fclose(fpW);
AfxMessageBox("The Problem is OK!\n");
}
else
AfxMessageBox( "Problem opening the file failed!\n" );
}
UpdateAllViews(NULL);
}
void CDem_testDoc::readdata()
{
AfxMessageBox("读取数据OK!");
}