diff --git a/ECTrainer2/ECTrainer.cpp b/ECTrainer2/ECTrainer.cpp index 84c6b2c..4aae2bb 100644 --- a/ECTrainer2/ECTrainer.cpp +++ b/ECTrainer2/ECTrainer.cpp @@ -11,14 +11,6 @@ // �R���X�g���N�^ ECTrainer::ECTrainer(HINSTANCE hInstance) - //: _pGui(NULL) - //, _pSceneCam(NULL) - //, _pStimulus(NULL) - //, _pMarker(NULL) - //, _pImageProc(NULL) - //, _pEyeTrack(NULL) - //, _pTobiiREST(NULL) - //, _pBital(NULL) : _Running(true) , _HomographyOK(false) , _CalibResult(0) @@ -26,13 +18,6 @@ , _HeartBeat(0) { _pMarker = new Marker(); - //_pGui = new ECTrainerGUI(this); - //_pImageProc = new ImageProc(this, _pMarker); - //_pSceneCam = new SceneCamera(this, _pImageProc); - //_pStimulus = new Stimulus(this, _pMarker); - //_pEyeTrack = new EyeTrack(this, _pMarker); - //_pTobiiREST = new TobiiREST(this); - //_pBital = new BitalMonitor(this); _pProcs[GUI] = new ECTrainerGUI(this); _pProcs[IMGPROC] = new ImageProc(this, _pMarker); _pProcs[SCNCAM] = new SceneCamera(this, (ImageProc*)_pProcs[IMGPROC]); @@ -45,52 +30,30 @@ // �f�X�g���N�^ ECTrainer::~ECTrainer() { - for (int i = 0; i < NUM; i++) { + for (int i = 0; i < PROC::NUM; i++) { if (_pProcs[i]) delete _pProcs[i]; } - //if (_pGui) delete _pGui; - //if (_pSceneCam) delete _pSceneCam; - //if (_pStimulus) delete _pStimulus; - //if (_pMarker) delete _pMarker; - //if (_pImageProc) delete _pImageProc; - //if (_pEyeTrack) delete _pEyeTrack; - //if (_pTobiiREST) delete _pTobiiREST; - //if (_pBital) delete _pBital; } // ������ bool ECTrainer::Process() { + // �v���Z�X������ if (!((ECTrainerGUI*)_pProcs[GUI])->Init(_hInstance)) return false; - for (int i = 0; i < NUM; i++) { + for (int i = 0; i < PROC::NUM; i++) { if (!_pProcs[i]->Init()) return false; } - //if (!_pGui->Init(_hInstance)) return false; - //if (!_pSceneCam->Init()) return false; - //if (!_pStimulus->Init()) return false; - //if (!_pImageProc->Init()) return false; - //if (!_pEyeTrack->Init()) return false; - //if (!_pTobiiREST->Init()) return false; - //if (!_pBital->Init()) return false; - const int N_THREADS = 7; + // �X���b�h�J�n + const int N_THREADS = PROC::NUM; // GUI��������KeepAlive��������̂œ��� DWORD thIds[N_THREADS]; HANDLE thHandles[N_THREADS]; - //DWORD dwThreadIdSceneCam, dwThreadIdStimulus, dwThreadIdImageProc, dwThreadIdEyeTrack, dwThreadIdKeepAlive, dwThreadIdTobiiREST, dwThreadIdBital; thHandles[0] = CreateThread(NULL, 0, KeepAliveThreadEntry, this, 0, &thIds[0]); - for (int i = 1; i < NUM; i++) { + for (int i = 1; i < N_THREADS; i++) { thHandles[i] = CreateThread(NULL, 0, ThreadEntry, _pProcs[i], 0, &thIds[i]); } - //thHandles[0] = CreateThread(NULL, 0, ThreadEntry, _pSceneCam, 0, &thIds[0]); - //thHandles[1] = CreateThread(NULL, 0, ThreadEntry, _pStimulus, 0, &thIds[1]); - //thHandles[2] = CreateThread(NULL, 0, ThreadEntry, _pImageProc, 0, &thIds[2]); - //thHandles[3] = CreateThread(NULL, 0, ThreadEntry, _pEyeTrack, 0, &thIds[3]); - //thHandles[5] = CreateThread(NULL, 0, ThreadEntry, _pTobiiREST, 0, &thIds[5]); - //thHandles[6] = CreateThread(NULL, 0, ThreadEntry, _pBital, 0, &thIds[6]); - - //_pGui->MainLoop(); _pProcs[GUI]->MainLoop(); - //HANDLE handles[] = { hThreadSceneCam , hThreadStimulus, hThreadImageProc, hThreadEyeTrack, hThreadKeepAlive, hThreadTobiiREST, hThreadBital }; + // �X���b�h�I�� DWORD timeOut = 1000; // �^�C���A�E�g(ms) if (WaitForMultipleObjects(N_THREADS, thHandles, TRUE, timeOut) != WAIT_TIMEOUT) { OutputDebugString(_T("All threads stopped sccessfully.\n")); @@ -100,13 +63,6 @@ for (int i = 0; i < N_THREADS; i++) { if (thHandles[i]) CloseHandle(thHandles[i]); } - //if (hThreadSceneCam) CloseHandle(hThreadSceneCam); - //if (hThreadStimulus) CloseHandle(hThreadStimulus); - //if (hThreadImageProc) CloseHandle(hThreadImageProc); - //if (hThreadEyeTrack) CloseHandle(hThreadEyeTrack); - //if (hThreadKeepAlive) CloseHandle(hThreadKeepAlive); - //if (hThreadTobiiREST) CloseHandle(hThreadTobiiREST); - //if (hThreadBital) CloseHandle(hThreadBital); return true; } diff --git a/ECTrainer2/ECTrainer.h b/ECTrainer2/ECTrainer.h index c7efa56..94831c9 100644 --- a/ECTrainer2/ECTrainer.h +++ b/ECTrainer2/ECTrainer.h @@ -18,16 +18,9 @@ class ECTrainer { private: - enum BLOCK {GUI, IMGPROC, SCNCAM, STIM, EYETR, REST, BITAL, NUM }; + enum PROC {GUI, IMGPROC, SCNCAM, STIM, EYETR, REST, BITAL, NUM }; HINSTANCE _hInstance; - BaseProcess* _pProcs[NUM]; - //ECTrainerGUI* _pGui; - //SceneCamera* _pSceneCam; - //Stimulus* _pStimulus; - //ImageProc* _pImageProc; - //EyeTrack* _pEyeTrack; - //TobiiREST* _pTobiiREST; - //BitalMonitor* _pBital; + BaseProcess* _pProcs[PROC::NUM]; Marker* _pMarker; bool _Running; // ���s���t���O bool _HomographyOK; // �ϊ��s��̊l���L�� diff --git a/ECTrainer2/MyWinUtils.h b/ECTrainer2/MyWinUtils.h index f6c00a4..bd2cf79 100644 --- a/ECTrainer2/MyWinUtils.h +++ b/ECTrainer2/MyWinUtils.h @@ -6,17 +6,9 @@ #include #include -static std::wstring Multi2Wide(std::string const& src) +// �}���`�o�C�g����������C�h������iUNICODE�j�ɕϊ� +std::wstring Multi2Wide(std::string const& src) { - //std::size_t converted{}; - //std::vector dest(src.size(), L'\0'); - //if (::_mbstowcs_s_l(&converted, dest.data(), dest.size(), src.data(), _TRUNCATE, ::_create_locale(LC_ALL, "jpn")) != 0) { - // throw std::system_error{ errno, std::system_category() }; - //} - //dest.resize(std::char_traits::length(dest.data())); - //dest.shrink_to_fit(); - //return std::wstring(dest.begin(), dest.end()); - auto const dest_size = ::MultiByteToWideChar(CP_ACP, 0U, src.data(), -1, nullptr, 0U); std::vector dest(dest_size, L'\0'); if (::MultiByteToWideChar(CP_ACP, 0U, src.data(), -1, dest.data(), (int)dest.size()) == 0) { @@ -26,3 +18,19 @@ dest.shrink_to_fit(); return std::wstring(dest.begin(), dest.end()); } + +// �����t���f�o�b�O�o�� +int DebugPrintf(LPCTSTR format, ...) +{ + va_list args; + va_start(args, format); + + int len = _vsctprintf(format, args) + 1; + TCHAR* buf = (TCHAR*)malloc(len * sizeof(TCHAR)); + len = _vstprintf_s(buf, len - 1, format, args); + + OutputDebugString(buf); + free(buf); + + return len; +}