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

📄 vision.cpp

📁 FIRA 3对3 机器人足球PC端控制程序。
💻 CPP
字号:
//////////////// ROBOT SOCCER PROGRAM //////////////////
//////////////// By Kim Heung Soo     //////////////////
//////////////// IC Lab. 98. 8. 2.    //////////////////

// Vision.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "Vision.h"

#include "MainFrm.h"
#include "VisionDoc.h"
#include "VisionView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CVisionApp

BEGIN_MESSAGE_MAP(CVisionApp, CWinApp)
	//{{AFX_MSG_MAP(CVisionApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
	// Standard file based document commands
	ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
	ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CVisionApp construction

CVisionApp::CVisionApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CVisionApp object

CVisionApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CVisionApp initialization

BOOL CVisionApp::InitInstance()
{
	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	// Change the registry key under which our settings are stored.
	// You should modify this string to be something appropriate
	// such as the name of your company or organization.
	SetRegistryKey(_T("Heung-Soo Kim"));

	LoadStdProfileSettings();  // Load standard INI file options (including MRU)

	// Allocate an application
	MappAlloc(M_DEFAULT,&MilApplication);
	// Disable MIL error message to be displayed as the usual way
	MappControl(M_ERROR,M_PRINT_DISABLE);
	// Retrieve previous hanler ptr and user handler ptr
	MappInquire(M_CURRENT_ERROR_HANDLER_PTR,&HandlerPtr);		
	MappInquire(M_CURRENT_ERROR_HANDLER_USER_PTR,&HandlerUserPtr);	
	// Hook MIL error on function DisplayError()
	MappHookFunction(M_ERROR_CURRENT,DisplayErrorExt,this);
	// Allocate a system	
 	MsysAlloc(M_SYSTEM_SETUP,M_DEF_SYSTEM_NUM,M_COMPLETE,&MilSystem);
	// Inquire number of digitizers available on the system
	MsysInquire(MilSystem,M_SYS_DIGITIZER_NUM,&NumberOfDigitizer);
	
	// Digitizer is available
	if (NumberOfDigitizer)	{
		// Allocate a digitizer
		MdigAlloc(MilSystem,M_DEFAULT,M_CAMERA_SETUP,M_DEFAULT,&MilDigitizer);
		// Stop live grab when window is disable
    	MsysControl(MilSystem,M_STOP_LIVE_GRAB_WHEN_DISABLED,M_ENABLE);
		// Inquire digitizer informations
  		MdigInquire(MilDigitizer,M_SIZE_X,&DigSizeX);
		MdigInquire(MilDigitizer,M_SIZE_Y,&DigSizeY);  	
		MdigInquire(MilDigitizer,M_SIZE_BAND,&Band);
				
		if (DigSizeX > M_DEF_IMAGE_SIZE_X_MAX)
			DigSizeX = M_DEF_IMAGE_SIZE_X_MAX;
		if (DigSizeY > M_DEF_IMAGE_SIZE_Y_MAX) 
			DigSizeY = M_DEF_IMAGE_SIZE_Y_MAX;
	}
	else {	// Digitizer is not available
		SizeX = M_DEF_IMAGE_SIZE_X_MIN; 
		SizeY = M_DEF_IMAGE_SIZE_Y_MIN;
		Band  =	M_DEF_IMAGE_NUMBANDS_MIN;
	}

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views.

	CSingleDocTemplate* pDocTemplate;
	pDocTemplate = new CSingleDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(CVisionDoc),
		RUNTIME_CLASS(CMainFrame),       // main SDI frame window
		RUNTIME_CLASS(CVisionView));
	AddDocTemplate(pDocTemplate);

	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	// Dispatch commands specified on the command line
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;

	// The one and only window has been initialized, so show and update it.
	m_pMainWnd->ShowWindow(SW_SHOW);
	m_pMainWnd->UpdateWindow();

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
		// No message handlers
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

// App command to run the dialog
void CVisionApp::OnAppAbout()
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// CVisionApp commands

int CVisionApp::ExitInstance() 
{
	// TODO: Add your specialized code here and/or call the base class
	if (MilDigitizer)
		MdigFree (MilDigitizer);	// Free the digitizer
	if (MilSystem)
		MsysFree (MilSystem);		// Free the system
	if (MilApplication)
		MappFree (MilApplication);	// Free the application
	
	return CWinApp::ExitInstance();
}

// MIL: Hook-handler function: DisplayError()
long MFTYPE DisplayErrorExt(long HookType, MIL_ID EventId, void MPTYPE *UserDataPtr)
{
	((CVisionApp*) AfxGetApp())->DisplayError(HookType,EventId, (CWinApp*) UserDataPtr);
	return M_NULL;
}

long MFTYPE CVisionApp::DisplayError(long HookType, MIL_ID EventId, void MPTYPE *UserDataPtr)
{
	char 	ErrorMessageFunction[M_ERROR_MESSAGE_SIZE] = "";
	char 	ErrorMessage[M_ERROR_MESSAGE_SIZE]         = "";
	char 	ErrorSubMessage1[M_ERROR_MESSAGE_SIZE]     = "";
	char 	ErrorSubMessage2[M_ERROR_MESSAGE_SIZE]     = "";
	char 	ErrorSubMessage3[M_ERROR_MESSAGE_SIZE]     = "";
	long 	NbSubCode;
	CString	CErrorMessage;

	MappGetHookInfo(EventId,M_MESSAGE+M_CURRENT_FCT,ErrorMessageFunction);
	MappGetHookInfo(EventId,M_MESSAGE+M_CURRENT,ErrorMessage);
	MappGetHookInfo(EventId,M_CURRENT_SUB_NB,&NbSubCode);	
	if (NbSubCode > 2)
	MappGetHookInfo(EventId,M_MESSAGE+M_CURRENT_SUB_3,ErrorSubMessage3);	
	if (NbSubCode > 1)	
		MappGetHookInfo(EventId,M_MESSAGE+M_CURRENT_SUB_2,ErrorSubMessage2);
	if (NbSubCode > 0)
		MappGetHookInfo(EventId,M_MESSAGE+M_CURRENT_SUB_1,ErrorSubMessage1);

	CErrorMessage = ErrorMessageFunction;
	CErrorMessage = CErrorMessage + "\n";
	CErrorMessage = CErrorMessage + ErrorMessage;
	
	if(NbSubCode > 0)
	{
		CErrorMessage = CErrorMessage + "\n";
		CErrorMessage = CErrorMessage + ErrorSubMessage1;
	}
	
	if(NbSubCode > 1)
	{
		CErrorMessage = CErrorMessage + "\n";
		CErrorMessage = CErrorMessage + ErrorSubMessage2;
	}
	
	if(NbSubCode > 2)
	{
		CErrorMessage = CErrorMessage + "\n";
		CErrorMessage = CErrorMessage + ErrorSubMessage3;
	}
	
	AfxMessageBox(CErrorMessage,MB_OK,0);

	// Chain hook function
 	if(HandlerPtr)
 		(*HandlerPtr)(HookType,EventId,HandlerUserPtr);
 	
	return M_NULL;
}

⌨️ 快捷键说明

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