⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fastrbfdoc.cpp

📁 快速fft变换的c实现
💻 CPP
字号:
// FastRBFDoc.cpp : implementation of the CFastRBFDoc class
//

#include "stdafx.h"
#include "FastRBF.h"

#include "FastRBFDoc.h"
#include "FastRBFView.h"
#include <math.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CFastRBFDoc

IMPLEMENT_DYNCREATE(CFastRBFDoc, CDocument)

BEGIN_MESSAGE_MAP(CFastRBFDoc, CDocument)
	//{{AFX_MSG_MAP(CFastRBFDoc)
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
	ON_COMMAND(ID_POINTS, OnPoints)
	ON_COMMAND(ID_SHADEDPOINTS, OnShadedpoints)
	ON_COMMAND(ID_BOUNDINGBOX, OnBoundingbox)
	ON_COMMAND(ID_SMOOTHSHADING, OnSmoothshading)
	ON_COMMAND(ID_POLYGONIZE, OnPolygonize)
	ON_COMMAND(ID_DIRECTFIT, OnDirectfit)
	ON_COMMAND(ID_WIREFRAMES, OnWireframes)
	ON_COMMAND(ID_SHADEDWIREFRAMES, OnShadedwireframes)
	ON_COMMAND(ID_SOLID, OnSolid)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFastRBFDoc construction/destruction

CFastRBFDoc::CFastRBFDoc()
{
	// TODO: add one-time construction code here
	m_iDisplayMode = 0;
	m_pPointSet = 0;
	m_pMesh = 0;
	m_pRbf = 0;
	for (int i=0; i<m_pMeshArray.GetSize(); i++)
		m_pMeshArray[i] = 0;
}

CFastRBFDoc::~CFastRBFDoc()
{
	if (m_pPointSet)
	{
		delete m_pPointSet;
		m_pPointSet = 0;
	}
	if (m_pMesh)
	{
		delete m_pMesh;
		m_pMesh = 0;
	}
	for (int i=0; i<m_pMeshArray.GetSize(); i++)
	{
		if (m_pMeshArray[i])
		{
			delete m_pMeshArray[i];
			m_pMeshArray[i] = 0;
		}
	}
	if (m_pRbf)
	{
		delete m_pRbf;
		m_pRbf = 0;
	}
}

BOOL CFastRBFDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CFastRBFDoc serialization

void CFastRBFDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}

/////////////////////////////////////////////////////////////////////////////
// CFastRBFDoc diagnostics

#ifdef _DEBUG
void CFastRBFDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CFastRBFDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CFastRBFDoc commands

void CFastRBFDoc::OnFileOpen() 
{
	// TODO: Add your command handler code here
	CFileDialog dlg(TRUE, NULL, "*.pwn", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT);
	if (dlg.DoModal() != IDOK)
		return;

	BeginWaitCursor();

	CString filePath = dlg.GetPathName();
	CString fileName = dlg.GetFileName();
	CString fileExt  = dlg.GetFileExt();
	OpenFile(filePath, fileName, fileExt);
	AddToRecentFileList((LPCTSTR)filePath);

	EndWaitCursor();
}

void CFastRBFDoc::DrawObjects()
{
	switch(m_iDisplayMode)
	{
	case ID_POLYGONIZE:
		if (m_pRbf)
			m_pRbf->Draw(m_pPointSet);
	case ID_BOUNDINGBOX:
		if (m_pPointSet)
		{
			m_pPointSet->DrawShadedPoints();
			m_pPointSet->DrawBox();
		}
		break;
	case ID_POINTS:
		if (m_pPointSet)
			m_pPointSet->DrawPoints();
		break;
	case ID_SHADEDPOINTS:
		if (m_pPointSet)
			m_pPointSet->DrawShadedPoints();
		break;
	case ID_DIRECTFIT:
		if (m_pPointSet)
			m_pPointSet->DrawSolution(m_pRbf->GetSolution());
	case ID_WIREFRAMES:
		if (m_pMesh)
			m_pMesh->DrawWireframes();
		break;
	case ID_SHADEDWIREFRAMES:
		if (m_pMesh)
			m_pMesh->DrawShadedWires();
		break;
	case ID_SOLID:
		if (m_pMesh)
			m_pMesh->DrawSolid();
		break;
	case ID_SMOOTHSHADING:
/*		if (m_pPointSet)
		{
			m_pPointSet->SmoothShading();
			m_pPointSet->DrawShadedPoints();			
		}*/
		if (m_pMesh)
		{
			m_pMesh->SmoothShading();
			m_pMesh->DrawSmooth();
		}
		break;
	default:
		break;
	}
}

void CFastRBFDoc::OnPoints() 
{
	// TODO: Add your command handler code here
	m_iDisplayMode = ID_POINTS;
	UpdateAllViews(NULL);
}

void CFastRBFDoc::OnShadedpoints() 
{
	// TODO: Add your command handler code here
	m_iDisplayMode = ID_SHADEDPOINTS;
	UpdateAllViews(NULL);
}

void CFastRBFDoc::OnBoundingbox() 
{
	// TODO: Add your command handler code here
	m_iDisplayMode = ID_BOUNDINGBOX;
	UpdateAllViews(NULL);
}

void CFastRBFDoc::OpenFile(CString filePath, CString fileName, CString fileExt)
{
	m_sFileName = fileName;
	CString windowtext;
	if (fileExt == "pwn")
	{//points with normals
		if (m_pPointSet)
			delete m_pPointSet;

		m_pPointSet = new PointSet;
		m_pPointSet->OpenFile(filePath, fileExt);

		windowtext = fileName + "  #points: ";
		CString str;
		str.Format("%d", m_pPointSet->GetPointNum());
		windowtext += str;

		m_iDisplayMode = ID_SHADEDPOINTS;
	}

	CMDIChildWnd *pFrame = (CMDIChildWnd*)AfxGetApp()->GetMainWnd();
	CMDIChildWnd *pChild = (CMDIChildWnd*)pFrame->GetActiveFrame();
	pChild->SetWindowText(windowtext);

	UpdateAllViews(NULL);
}

void CFastRBFDoc::OnSmoothshading() 
{
	// TODO: Add your command handler code here
	m_iDisplayMode = ID_SMOOTHSHADING;
	UpdateAllViews(NULL);
}

BOOL CFastRBFDoc::OnOpenDocument(LPCTSTR lpszPathName) 
{
	if (!CDocument::OnOpenDocument(lpszPathName))
		return FALSE;
	
	// TODO: Add your specialized creation code here
	AddToRecentFileList(lpszPathName);
	char drive[5];
	char dir[100];
	char fname[20];
	char ext[10];
	_splitpath(lpszPathName, drive, dir, fname, ext);
	for (int i=0; i<9; i++)
		ext[i] = ext[i+1];
	BeginWaitCursor();
	OpenFile((CString)lpszPathName, (CString)fname, (CString)ext);
	EndWaitCursor();
	
	return TRUE;
}

BOOL CFastRBFDoc::OnSaveDocument(LPCTSTR lpszPathName) 
{
	// TODO: Add your specialized code here and/or call the base class
	AddToRecentFileList(lpszPathName);
	
	return CDocument::OnSaveDocument(lpszPathName);
}

void CFastRBFDoc::AddToRecentFileList(LPCTSTR lpszPathName)
{
	((CFastRBFApp*)AfxGetApp())->AddToRecentFileList(lpszPathName);
}

void CFastRBFDoc::OnPolygonize() 
{
	// TODO: Add your command handler code here
	BeginWaitCursor();
	clock_t start = clock();

	float minCoord[3];
	float maxCoord[3];
	m_pPointSet->GetBoundingBox(minCoord, maxCoord);

	float sizeX = maxCoord[0] - minCoord[0];
	float sizeY = maxCoord[1] - minCoord[1];
	float sizeZ = maxCoord[2] - minCoord[2];
	float box[] = {maxCoord[0], minCoord[0], maxCoord[1], minCoord[1], maxCoord[2], minCoord[2]};

	int N = m_pPointSet->GetPointNum();
	float boxC[] = {0.5f*(box[0]+box[1]), 0.5f*(box[2]+box[3]), 0.5f*(box[4]+box[5])};
	for(int i=0; i<N; i++)
	{
		float *p = m_pPointSet->GetPoint(i);
		if(p[0] < box[0] && p[0] > box[1] && p[1] < box[2] && p[1] > box[3] && p[2] < box[4] && p[2] > box[5])
		{
			boxC[0] = p[0];
			boxC[1] = p[1];
			boxC[2] = p[2];

			break;
		}
	}
	m_pMesh = m_pRbf->Bloomenthal(0.007*(float)sqrt(sizeX*sizeX + sizeY*sizeY + sizeZ*sizeZ), boxC, box);
	m_iDisplayMode = ID_SOLID;

	//Timing & #Evaluation
	clock_t duration = clock() - start;
	float t = (float)(duration/ CLOCKS_PER_SEC);
	EndWaitCursor();

	CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;

	// Get the active MDI child window.
	CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();

	CString str;
	str.Format("%d", m_pMesh->GetVertexCount());
    CString windowtext = m_sFileName + "  #points:" + str;
	str.Format("%d", m_pMesh->GetFaceCount());
	windowtext += "  #triangles:" + str;
    pChild->SetWindowText(windowtext);
	
	UpdateAllViews(NULL);
}

void CFastRBFDoc::OnDirectfit() 
{
	// TODO: Add your command handler code here
	m_pRbf = new RBFunc;
	m_pRbf->DirectFitGlobal(m_pPointSet);
//	m_pRbf->FMMFitGlobal(m_pPointSet, 0.01);
	m_iDisplayMode = ID_DIRECTFIT;
	UpdateAllViews(NULL);
}

void CFastRBFDoc::OnWireframes() 
{
	// TODO: Add your command handler code here
	m_iDisplayMode = ID_WIREFRAMES;
	UpdateAllViews(NULL);
}

void CFastRBFDoc::OnShadedwireframes() 
{
	// TODO: Add your command handler code here
	m_iDisplayMode = ID_SHADEDWIREFRAMES;
	UpdateAllViews(NULL);
}

void CFastRBFDoc::OnSolid() 
{
	// TODO: Add your command handler code here
	m_iDisplayMode = ID_SOLID;
	UpdateAllViews(NULL);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -