www.pudn.com > Depthimage.rar > DepthimageDoc.cpp
// DepthimageDoc.cpp : implementation of the CDepthimageDoc class
//
#include "stdafx.h"
#include "Depthimage.h"
#include "iostream.h"
#include "DepthimageDoc.h"
#include "MainFrm.h"
#include "DepthimageView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDepthimageDoc
IMPLEMENT_DYNCREATE(CDepthimageDoc, CDocument)
BEGIN_MESSAGE_MAP(CDepthimageDoc, CDocument)
//{{AFX_MSG_MAP(CDepthimageDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
ON_COMMAND(IDC_MYSAVE, OnMysave)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDepthimageDoc construction/destruction
CDepthimageDoc::CDepthimageDoc()
{
// TODO: add one-time construction code here
this->a=0;
this->b=0;
this->c=0;
this->f=0;
this->r=0;
this->mdepth=NULL;
}
CDepthimageDoc::~CDepthimageDoc()
{
}
BOOL CDepthimageDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CDepthimageDoc serialization
void CDepthimageDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CDepthimageDoc diagnostics
#ifdef _DEBUG
void CDepthimageDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CDepthimageDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDepthimageDoc commands
void CDepthimageDoc::OnMysave()
{
// TODO: Add your command handler code here
if(mdepth==NULL)
{::AfxMessageBox("还没有生成深度数据");
return;
}
CFile file;
if(!file.Open("D:\\DepthFile.txt", CFile::modeWrite | CFile::modeCreate))
::AfxMessageBox("无法保存数据到D:\\DepthFile.txt");
CString ss;
CMainFrame *shty=(CMainFrame *)::AfxGetMainWnd();
CDepthimageView *shty1=(CDepthimageView *)shty->GetActiveView();
char b=' ';
char c='\n';
double x,y;
float xmin,xmax,ymin,ymax;
xmin=shty1->xmin;
xmax=shty1->xmax;
ymin=shty1->ymin;
ymax=shty1->ymax;
for(x=2*xmin;x<2*xmax;x++)
{ for(y=2*ymin;y<2*ymax;y++)
{
if( mdepth[(int(x)+int(2*xmax))*int(2*xmax-2*xmin)+int(y)+int(2*ymax)]!=0)
{ss.Format("%d",int(mdepth[(int(x)+int(2*xmax))*int(2*xmax-2*xmin)+int(y)+int(2*ymax)]));
file.Write(ss,ss.GetLength());
file.Write(&b,1);}
}
}
file.Close();
int i,j,mm;
if(!file.Open("D:\\DepthFile0.txt", CFile::modeWrite | CFile::modeCreate))
::AfxMessageBox("无法保存数据到D:\\DepthFile0.txt");
for(i=0;i<511;i++)
{ for(j=0;j<511;j++)
{mm=mdepth[i*510+j];
file.Write(&mm,1);
}
}
file.Close();
::AfxMessageBox("数据以txt方式存于D:\\DepthFile.txt\n同时以二进制形式保存到D:\\DepthFile0.txt\n实验二数据将直接从DepthFile0.txt读取");
}