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

📄 manifold.cpp

📁 一个非常有用的开源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		DrawPoint(pScreen, n);	// Add some border to the next rect and preserve aspect ratio	m_nextRect.x -= m_nextRect.w / 4;	m_nextRect.w += m_nextRect.w / 2;	m_nextRect.y -= m_nextRect.h / 4;	m_nextRect.h += m_nextRect.h / 2;	if(m_nextRect.h * 4 > m_nextRect.w * 3)	{		m_nextRect.x -= (m_nextRect.h * 4 / 3 - m_nextRect.w) / 2;		m_nextRect.w = m_nextRect.h * 4 / 3;	}	else	{		m_nextRect.y -= (m_nextRect.w * 3 / 4 - m_nextRect.h) / 2;		m_nextRect.h = m_nextRect.w * 3 / 4;	}}void ManifoldView::OnChar(char c){}void ManifoldView::OnMouseDown(int x, int y){	//x -= m_screenRect.x;	//y -= m_screenRect.y;}void ManifoldView::OnMouseUp(int x, int y){}bool ManifoldView::OnMousePos(int x, int y){	return false;}// -------------------------------------------------------------------------------class ManifoldController : public ControllerBase{public:	enum WhichDemo	{		MC_SWISS_ROLL,		MC_SEMI_SUPERVISED,		MC_PCA_PREPROC,		MC_LLE_PREPROC,		MC_TO_MATRIX,		MC_FROM_MATRIX,	};protected:	WhichDemo m_eDemo;	ManifoldModel* m_pModel;public:	ManifoldController(WhichDemo eDemo) : ControllerBase()	{		m_eDemo = eDemo;		m_pModel = new ManifoldModel(((eDemo == MC_TO_MATRIX) ? true : false));		m_pView = new ManifoldView(m_pModel);	}	virtual ~ManifoldController()	{		delete(m_pView);		delete(m_pModel);	}	void RunModal()	{		if(m_eDemo == MC_SWISS_ROLL)			DoSwissRollDemo();		else if(m_eDemo == MC_SEMI_SUPERVISED)			DoSemiSupervisedDemo();		else if(m_eDemo == MC_PCA_PREPROC)			DoPreProcDemo(false);		else if(m_eDemo == MC_LLE_PREPROC)			DoPreProcDemo(true);		else if(m_eDemo == MC_TO_MATRIX)			DoToMatrix();		else if(m_eDemo == MC_FROM_MATRIX)			DoFromMatrix();		else			GAssert(false, "unrecognized demo");	}	void DoSwissRollDemo()	{		double timeOld = GTime::GetTime();		double time;		m_pView->Update();		GManifoldSculpting* pSculpter = m_pModel->GetSculpter();		int nDataPoints = pSculpter->GetDataPointCount();		while(m_bKeepRunning)		{			time = GTime::GetTime();			HandleEvents(time - timeOld);			pSculpter->SquishPass(rand() % nDataPoints);			m_pView->Update();			timeOld = time;		}	}	void DoSemiSupervisedDemo()	{		// First learn the points		int nPass = 0;		double timeOld = GTime::GetTime();		double time;		m_pView->Update();		GManifoldSculpting* pSculpter = m_pModel->GetSculpter();		int nDataPoints = pSculpter->GetDataPointCount();		while(m_bKeepRunning)		{			time = GTime::GetTime();			HandleEvents(time - timeOld);			pSculpter->SquishPass(rand() % nDataPoints);			m_pView->Update();			timeOld = time;			printf("Pass %d\n", nPass++);		}		// Now do the demo with semi-supervision		nPass = 0;		m_pModel->DoSemiSupervisedThing();		pSculpter = m_pModel->GetSculpter();		nDataPoints = pSculpter->GetDataPointCount();		m_bKeepRunning = true;		while(m_bKeepRunning)		{			time = GTime::GetTime();			HandleEvents(time - timeOld);			pSculpter->SquishPass(rand() % nDataPoints);			m_pView->Update();			timeOld = time;			printf("Pass %d\n", nPass++);		}	}	void DoPreProcDemo(bool bLLE)	{		double timeOld = GTime::GetTime();		double time;		m_pModel->PreProcess(bLLE);		m_pView->Update();		GManifoldSculpting* pSculpter = m_pModel->GetSculpter();		int nDataPoints = pSculpter->GetDataPointCount();		while(m_bKeepRunning)		{			time = GTime::GetTime();			HandleEvents(time - timeOld);			pSculpter->SquishPass(rand() % nDataPoints);			m_pView->Update();			timeOld = time;		}	}	void DoToMatrix()	{		m_pModel->ToMatrix("swissroll.dat");	}	void DoFromMatrix()	{		m_pModel->FromMatrix("manifold.dat");		double timeOld = GTime::GetTime();		double time;		m_pView->Update();		GManifoldSculpting* pSculpter = m_pModel->GetSculpter();		int nDataPoints = pSculpter->GetDataPointCount();		while(m_bKeepRunning)		{			time = GTime::GetTime();			HandleEvents(time - timeOld);			m_pView->Update();			timeOld = time;		}	}};// -------------------------------------------------------------------------------#define BACKGROUND_COLOR 0xffeeee77class ManifoldMenuDialog : public GWidgetDialog{protected:	ManifoldMenuController* m_pController;	GWidgetTextButton* m_pSwissRollDemoButton;	GWidgetTextButton* m_pSemiSupervisedDemoButton;	GWidgetTextButton* m_pPCAPreProcDemoButton;	GWidgetTextButton* m_pLLEPreProcDemoButton;	GWidgetTextButton* m_pInputManifoldToMatrixButton;	GWidgetTextButton* m_pPlotPointsFromMatrixButton;	int m_nValidationTechnique;	double m_dTrainingPercent;public:	ManifoldMenuDialog(ManifoldMenuController* pController, int w, int h);	virtual ~ManifoldMenuDialog();	virtual void OnReleaseTextButton(GWidgetTextButton* pButton);};ManifoldMenuDialog::ManifoldMenuDialog(ManifoldMenuController* pController, int w, int h) : GWidgetDialog(w, h, BACKGROUND_COLOR){	m_pController = pController;	GString s;	// Left column	s.Copy(L"Swiss roll demo");	m_pSwissRollDemoButton = new GWidgetTextButton(this, 100, 100, 200, 24, &s);	s.Copy(L"Semi-supervised demo");	m_pSemiSupervisedDemoButton = new GWidgetTextButton(this, 100, 150, 200, 24, &s);//	s.Copy(L"PCA preprocessing demo");//	m_pPCAPreProcDemoButton = new GWidgetTextButton(this, 100, 200, 200, 24, &s);//	s.Copy(L"LLE preprocessing demo");//	m_pLLEPreProcDemoButton = new GWidgetTextButton(this, 100, 250, 200, 24, &s);	// Right column	s.Copy(L"Input manifold to matrix");	m_pInputManifoldToMatrixButton = new GWidgetTextButton(this, 400, 100, 200, 24, &s);	s.Copy(L"Plot points from matrix");	m_pPlotPointsFromMatrixButton = new GWidgetTextButton(this, 400, 150, 200, 24, &s);}/*virtual*/ ManifoldMenuDialog::~ManifoldMenuDialog(){}/*virtual*/ void ManifoldMenuDialog::OnReleaseTextButton(GWidgetTextButton* pButton){	ManifoldController::WhichDemo eDemo;	if(pButton == m_pSwissRollDemoButton)		eDemo = ManifoldController::MC_SWISS_ROLL;	else if(pButton == m_pSemiSupervisedDemoButton)		eDemo = ManifoldController::MC_SEMI_SUPERVISED;	else if(pButton == m_pPCAPreProcDemoButton)		eDemo = ManifoldController::MC_PCA_PREPROC;	else if(pButton == m_pLLEPreProcDemoButton)		eDemo = ManifoldController::MC_LLE_PREPROC;	else if(pButton == m_pInputManifoldToMatrixButton)		eDemo = ManifoldController::MC_TO_MATRIX;	else if(pButton == m_pPlotPointsFromMatrixButton)		eDemo = ManifoldController::MC_FROM_MATRIX;	else		GAssert(false, "unrecognized button");	ManifoldController c(eDemo);	c.RunModal();}// -------------------------------------------------------------------------------class ManifoldMenuView : public ViewBase{protected:	ManifoldMenuDialog* m_pDialog;public:	ManifoldMenuView(ManifoldMenuController* pController);	virtual ~ManifoldMenuView();	virtual void OnChar(char c);	virtual void OnMouseDown(int x, int y);	virtual void OnMouseUp(int x, int y);	virtual bool OnMousePos(int x, int y);protected:	virtual void Draw(SDL_Surface *pScreen);};ManifoldMenuView::ManifoldMenuView(ManifoldMenuController* pController): ViewBase(){	m_pDialog = new ManifoldMenuDialog(pController, 790, 590);}ManifoldMenuView::~ManifoldMenuView(){	delete(m_pDialog);}/*virtual*/ void ManifoldMenuView::Draw(SDL_Surface *pScreen){	// Clear the screen	SDL_FillRect(pScreen, NULL/*&r*/, 0x000000);	// Draw the dialog	GRect r;	BlitImage(pScreen, m_screenRect.x, m_screenRect.y, m_pDialog->GetImage(&r));}void ManifoldMenuView::OnChar(char c){	m_pDialog->HandleChar(c);}void ManifoldMenuView::OnMouseDown(int x, int y){	x -= m_screenRect.x;	y -= m_screenRect.y;	GWidgetAtomic* pNewWidget = m_pDialog->FindAtomicWidget(x, y);	m_pDialog->GrabWidget(pNewWidget, x, y);}void ManifoldMenuView::OnMouseUp(int x, int y){	m_pDialog->ReleaseWidget();}bool ManifoldMenuView::OnMousePos(int x, int y){	return m_pDialog->HandleMousePos(x - m_screenRect.x, y - m_screenRect.y);}// -------------------------------------------------------------------------------ManifoldMenuController::ManifoldMenuController(): ControllerBase(){	m_pView = new ManifoldMenuView(this);}ManifoldMenuController::~ManifoldMenuController(){	delete(m_pView);}void ManifoldMenuController::RunModal(){	double timeOld = GTime::GetTime();	double time;	m_pView->Update();	while(m_bKeepRunning)	{		time = GTime::GetTime();		if(HandleEvents(time - timeOld)) // HandleEvents returns true if it thinks the view needs to be updated		{			m_pView->Update();		}		else			GThread::sleep(10);		timeOld = time;	}}

⌨️ 快捷键说明

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