www.pudn.com > MeshProcess.rar > MeshProcessDoc.cpp
// MeshProcessDoc.cpp : implementation of the CMeshProcessDoc class
//
#include "stdafx.h"
#include "MeshProcess.h"
#include "MainFrm.h"
#include "MeshProcessDoc.h"
#include "MeshProcessView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMeshProcessDoc
IMPLEMENT_DYNCREATE(CMeshProcessDoc, CDocument)
BEGIN_MESSAGE_MAP(CMeshProcessDoc, CDocument)
//{{AFX_MSG_MAP(CMeshProcessDoc)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_OPEN_TMESH, OnOpenTMesh)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMeshProcessDoc construction/destruction
CMeshProcessDoc::CMeshProcessDoc()
{
// TODO: add one-time construction code here
m_bSModel = false;
m_bTModel = false;
}
CMeshProcessDoc::~CMeshProcessDoc()
{
}
BOOL CMeshProcessDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMeshProcessDoc serialization
void CMeshProcessDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CMeshProcessDoc diagnostics
#ifdef _DEBUG
void CMeshProcessDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CMeshProcessDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMeshProcessDoc commands
void CMeshProcessDoc::OnFileOpen()
{
// TODO: Add your command handler code here
static char BASED_CODE szFilter[] = "OBJ Files (*.obj)|*.obj|TM Files (*.tm)|*.tm|All Files (*.*)|*.*||";
CFileDialog dlg( TRUE, NULL, NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, szFilter );
dlg.m_ofn.lpstrTitle = "Open Source Mesh";
if( dlg.DoModal() == IDOK)
{
CString file_ext = dlg.GetFileExt();
{
CString pat = dlg.GetPathName();
char *fl = pat.GetBuffer( 10 );
if( m_mSourceModel.ImportMesh( fl, file_ext ))
{
printf( "The number of the Vertices and Triangles is: %d and %d.\n", m_mSourceModel.m_numV, m_mSourceModel.m_numT );
printf( "The Bounding Box xmin: %f, xmax: %f.\n", m_mSourceModel.m_Box.X1, m_mSourceModel.m_Box.X2 );
printf( " ymin: %f, ymax: %f.\n", m_mSourceModel.m_Box.Y1, m_mSourceModel.m_Box.Y2 );
printf( " zmin: %f, zmax: %f.\n", m_mSourceModel.m_Box.Z1, m_mSourceModel.m_Box.Z2 );
BoundingBox winbox;
double range = 2.0*0.72;
winbox.X1 = -range; winbox.X2 = range;
winbox.Y1 = -range; winbox.Y2 = range;
// Head
m_mSourceModel.CoordinateRotate(0.0, 2.0, 1.55);
m_mSourceModel.CoordinateRotate(0.2, .0, .0);
// Pig
// m_mSourceModel.CoordinateRotate(0.0, 0.0, 3.0);
// m_mSourceModel.CoordinateRotate(0.3, 0.0, 0.0);
// m_mSourceModel.CoordinateRotate(0.0, -0.1, 0.0);
// Beeth
/* m_mSourceModel.CoordinateRotate(0.0, -2.4, 0.0);
m_mSourceModel.CoordinateRotate(0.0, 0.0, 0.2);
m_mSourceModel.CoordinateRotate(0.3, 0.0, 0.0);
m_mSourceModel.CoordinateRotate(0.0, -.2, 0.0);
m_mSourceModel.CoordinateRotate(0.0, 0.0, -0.05);
m_mSourceModel.CooridnateTranslate(0.0, .6, 0.0); */
m_mSourceModel.CoordianteTransform(winbox);
m_mSourceModel.ComputeAttribute();
CMainFrame *pFrameWnd = (CMainFrame*)AfxGetMainWnd();
char tmps[80];
sprintf( tmps, "Model: %s", dlg.GetFileName() );
pFrameWnd->m_wndStatusBar.SetPaneText( 1, tmps );
sprintf( tmps, "Triangles: %d", m_mSourceModel.m_numT );
pFrameWnd->m_wndStatusBar.SetPaneText( 2, tmps );
sprintf( tmps, "Vertices: %d", m_mSourceModel.m_numV );
pFrameWnd->m_wndStatusBar.SetPaneText( 3, tmps );
m_bSModel = true;
UpdateAllViews(NULL);
}
}
}
}
void CMeshProcessDoc::OnOpenTMesh()
{
// TODO: Add your command handler code here
static char BASED_CODE szFilter[] = "OBJ Files (*.obj)|*.obj|TM Files (*.tm)|*.tm|All Files (*.*)|*.*||";
CFileDialog dlg( TRUE, NULL, NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, szFilter );
dlg.m_ofn.lpstrTitle = "Open Target Mesh";
if( dlg.DoModal() == IDOK)
{
printf("Hello, Welcome to HappyJimmy!\n");
CString file_ext = dlg.GetFileExt();
{
CString pat = dlg.GetPathName();
char *fl = pat.GetBuffer( 10 );
if( m_mTargetModel.ImportMesh( fl, file_ext ))
{
printf( "The number of the Vertices and Triangles is: %d and %d.\n", m_mTargetModel.m_numV, m_mTargetModel.m_numT );
printf( "The Bounding Box xmin: %f, xmax: %f.\n", m_mTargetModel.m_Box.X1, m_mTargetModel.m_Box.X2 );
printf( " ymin: %f, ymax: %f.\n", m_mTargetModel.m_Box.Y1, m_mTargetModel.m_Box.Y2 );
printf( " zmin: %f, zmax: %f.\n", m_mTargetModel.m_Box.Z1, m_mTargetModel.m_Box.Z2 );
BoundingBox winbox;
double range = 2.0;
winbox.X1 = -range; winbox.X2 = range;
winbox.Y1 = -range; winbox.Y2 = range;
// Head
m_mTargetModel.CoordinateRotate(2.6, .0, .0);
// Cow
// m_mTargetModel.CoordinateRotate(0.0, -1.6, 0.0);
// m_mTargetModel.CoordinateRotate(0.3, 0.0, 0.0);
// Isis
/* m_mTargetModel.CoordinateRotate(3.1, 0.0, 0.0);
m_mTargetModel.CoordinateRotate(0.0, -.2, 0.0);
m_mTargetModel.CoordinateRotate(0.0, 0.0, 0.05);
m_mTargetModel.CoordinateRotate(0.0, -.08, 0.0);
m_mTargetModel.CoordinateRotate(.2, 0.0, 0.0); */
m_mTargetModel.CoordianteTransform(winbox);
m_mTargetModel.ComputeAttribute();
CMainFrame *pFrameWnd = (CMainFrame*)AfxGetMainWnd();
char tmps[80];
sprintf( tmps, "Model: %s", dlg.GetFileName() );
pFrameWnd->m_wndStatusBar.SetPaneText( 1, tmps );
sprintf( tmps, "Triangles: %d", m_mTargetModel.m_numT );
pFrameWnd->m_wndStatusBar.SetPaneText( 2, tmps );
sprintf( tmps, "Vertices: %d", m_mTargetModel.m_numV );
pFrameWnd->m_wndStatusBar.SetPaneText( 3, tmps );
m_bTModel = true;
}
}
POSITION pos = GetFirstViewPosition();
CMeshProcessView* pMeshView =(CMeshProcessView*)GetNextView(pos);
pMeshView->m_mModel.m_numT = m_mSourceModel.m_numT;
pMeshView->m_mModel.m_Meshes = new CTri3D[m_mSourceModel.m_numT];
pMeshView->m_mModel.m_numV = m_mSourceModel.m_numV;
pMeshView->m_mModel.m_Vertices = new CVer3D[m_mSourceModel.m_numV];
pMeshView->m_vSTDifference = new CVer3D[m_mSourceModel.m_numV];
pMeshView->m_vNormalDiffce = new CVer3D[m_mSourceModel.m_numV];
for (int i = 0; i < m_mSourceModel.m_numV; i ++)
{
pMeshView->m_vSTDifference[i].x = m_mTargetModel.m_Vertices[pMeshView->m_Correspond[i]].x - m_mSourceModel.m_Vertices[i].x;
pMeshView->m_vSTDifference[i].y = m_mTargetModel.m_Vertices[pMeshView->m_Correspond[i]].y - m_mSourceModel.m_Vertices[i].y;
pMeshView->m_vSTDifference[i].z = m_mTargetModel.m_Vertices[pMeshView->m_Correspond[i]].z - m_mSourceModel.m_Vertices[i].z;
pMeshView->m_vNormalDiffce[i].x = m_mTargetModel.m_Vertices[pMeshView->m_Correspond[i]].normale[0] - m_mSourceModel.m_Vertices[i].normale[0];
pMeshView->m_vNormalDiffce[i].y = m_mTargetModel.m_Vertices[pMeshView->m_Correspond[i]].normale[1] - m_mSourceModel.m_Vertices[i].normale[1];
pMeshView->m_vNormalDiffce[i].z = m_mTargetModel.m_Vertices[pMeshView->m_Correspond[i]].normale[2] - m_mSourceModel.m_Vertices[i].normale[2];
}
pMeshView->MorphMesh(.0);
UpdateAllViews(NULL);
}
}