diff --git a/ECTrainer2/ECTrainerGUI.cpp b/ECTrainer2/ECTrainerGUI.cpp index b29e9a3..129bc8e 100644 --- a/ECTrainer2/ECTrainerGUI.cpp +++ b/ECTrainer2/ECTrainerGUI.cpp @@ -74,8 +74,9 @@ if (sceneBuf.empty()) sceneBuf = _blank; // �\���o�b�t�@���� - bool isNew = _pEct->PStimulus()->IsNewDisplay(); - cv::Mat dispBuf = _pEct->PStimulus()->GetDisplay().clone(); + bool fTarget = _pEct->PWorker()->GetAppStatus() == APP_STATUS::STIM; + bool isNew = fTarget ? _pEct->PWorker()->IsNewTargetImg() : _pEct->PStimulus()->IsNewDisplay(); + cv::Mat dispBuf = fTarget ? _pEct->PWorker()->GetTargetImg().clone() : _pEct->PStimulus()->GetDisplay().clone(); if (dispBuf.empty()) dispBuf = _blank; if (isNew && !_dsm->IsPlaying()) this->MakeFullDispBuffer(dispBuf); @@ -137,6 +138,7 @@ std::wstring movie = _pEct->PStimulus()->GetMovie(); if (movie.size() < 1 || movie == L"STOP") { _dsm->StopMovie(); + mwut::DebugPrintf(_T("ECTMSG::MOVIE_STOP [%s]\n"), movie.c_str()); ((BaseProcess*)_pEct->PWorker())->Tell(ECTMSG::MOVIE_STOP); } else { if (_dsm->PlayMovie(movie)) { diff --git a/ECTrainer2/MovieObject.cpp b/ECTrainer2/MovieObject.cpp index 180be12..b0f31c4 100644 --- a/ECTrainer2/MovieObject.cpp +++ b/ECTrainer2/MovieObject.cpp @@ -11,6 +11,7 @@ // �e�[�u������f�[�^���Z�b�g int MovieObject::SetData(mwut::STR_TABLE table) { + _frame.clear(); int addLines = 0; for (int r = 0; r < table.size(); r++) { // �s�`�F�b�N diff --git a/ECTrainer2/MovieObject.h b/ECTrainer2/MovieObject.h index 8b4148d..39cee57 100644 --- a/ECTrainer2/MovieObject.h +++ b/ECTrainer2/MovieObject.h @@ -41,4 +41,8 @@ std::vector GetElements(float sTime); // �t���[������Ԃ� int GetNumFrames() { return (int)_frame.size(); } + // �󂩂ǂ��� + bool IsEmpty() { return _frame.size() < 1; } + // ���� + void Clear() { _frame.clear(); } }; diff --git a/ECTrainer2/RingBuffer.h b/ECTrainer2/RingBuffer.h index fdc74b5..3b730f1 100644 --- a/ECTrainer2/RingBuffer.h +++ b/ECTrainer2/RingBuffer.h @@ -2,7 +2,6 @@ #include - template class RingBuffer { diff --git a/ECTrainer2/Stimulus.cpp b/ECTrainer2/Stimulus.cpp index 568a324..00b1621 100644 --- a/ECTrainer2/Stimulus.cpp +++ b/ECTrainer2/Stimulus.cpp @@ -1,13 +1,10 @@ #include "BaseProcess.h" #include "Stimulus.h" #include "ECTrainer.h" -#include "MovieObject.h" -#include "myWinUtils.h" // �R���X�g���N�^ Stimulus::Stimulus(ECTrainer* pEct) : BaseProcess(pEct) , _StimNo(-1) - , _StartTime(0) , _pMovieObject(NULL) , _Display(ECTrainer::RINGBUFSIZE) , _Movie(ECTrainer::RINGBUFSIZE) @@ -40,40 +37,36 @@ if (st.filename.size() > 0) _StimInfoSet.push_back(st); } - mwut::DebugPrintf(_T("Stimulus::Init\n")); return true; } // ��{���� bool Stimulus::Routine() { - mwut::DebugPrintf(_T("Stimulus::Routine\n")); - if (_StimNo >= 0) { - DWORD current = GetTickCount(); - if ((float)(current - _StartTime) / 1000.F > _StimInfoSet[_StimNo].dulation) { + if (_StimTimer.Elapse() / 1000. > (double)_StimInfoSet[_StimNo].dulation) { if (_StimInfoSet[_StimNo].type == 2) { _Movie.Put(L"STOP"); + mwut::DebugPrintf(L"movie put stop.\n"); } - if (++_StimNo < _StimInfoSet.size()) { - SetStimulus(); + if (_StimNo + 1 < (int)_StimInfoSet.size()) { + SetStimulus(_StimNo + 1); ((BaseProcess*)_pEct->PWorker())->Tell(ECTMSG::EXP_NEXT); } else { ((BaseProcess*)_pEct->PWorker())->Tell(ECTMSG::EXP_END); } } } - Sleep(30); + + Sleep(0); return true; } // �C�x���g���� bool Stimulus::EventProc(MSG& msg) { - mwut::DebugPrintf(_T("Stimulus::EventProc\n")); switch (msg.message) { case (int)ECTMSG::CALIB_START: // �L�����u���[�V�����J�n - mwut::DebugPrintf(_T("Stimulus::EventProc - ECTMSG::CALIB_START\n")); _Display.Put(cv::imread(CALIB_FILE)); break; @@ -87,8 +80,7 @@ break; case (int)ECTMSG::EXP_START: // �����J�n - _StimNo = 0; - SetStimulus(); + this->SetStimulus(0); break; case (int)ECTMSG::EXP_STOP: // ������~ @@ -100,30 +92,44 @@ } // �h���� -bool Stimulus::SetStimulus() { - if (_StimNo < 0 || _StimNo >= _StimInfoSet.size()) return false; +bool Stimulus::SetStimulus(int newStimNo) { + if (newStimNo < 0 || newStimNo >= _StimInfoSet.size()) return false; - _StartTime = GetTickCount(); - if (_StimInfoSet[_StimNo].type == 1) { - _Display.Put(cv::imread(_StimInfoSet[_StimNo].filename)); + _pMovieObject->Clear(); + if (_StimInfoSet[newStimNo].csvfile[0] != '_') { + this->LoadMovieObject(newStimNo); + } + + if (_StimInfoSet[newStimNo].type == 1) { + _Display.Put(cv::imread(_StimInfoSet[newStimNo].filename)); } else { - _Movie.Put(mwut::Multi2Wide(_StimInfoSet[_StimNo].filename)); + _Movie.Put(mwut::Multi2Wide(_StimInfoSet[newStimNo].filename)); } - if (_StimInfoSet[_StimNo].csvfile[0] != '_') { - this->LoadMovieObject(); - } + + _StimTimer.Reset(); + _StimNo = newStimNo; return true; } // CSV�ǂݍ��� -void Stimulus::LoadMovieObject() { - if (_pMovieObject->GetNumFrames() > 0) return; // �ǂݍ��ݍς� - int nFrames = _pMovieObject->SetData(_StimInfoSet[_StimNo].csvfile); +void Stimulus::LoadMovieObject(int stimNo) { + int nFrames = _pMovieObject->SetData(_StimInfoSet[stimNo].csvfile); mwut::DebugPrintf(_T("Movie object '%s' - %d frames read.\n"), - mwut::Multi2Wide(_StimInfoSet[_StimNo].csvfile).c_str(), nFrames); + mwut::Multi2Wide(_StimInfoSet[stimNo].csvfile).c_str(), nFrames); } +// �^�[�Q�b�g�����擾 +std::vector Stimulus::GetMovieObject(float eTime) { + if (!_pMovieObject || _pMovieObject->IsEmpty()) { + std::vector elems; + return elems; + } + if (eTime < 0) eTime = (float)_StimTimer.Elapse(); + return _pMovieObject->GetElements(eTime); +} + + // �摜�Ƀ}�[�J�[��`�� //void Stimulus::StimWithMarker() { // cv::Mat img = cv::imread(_StimImages[_StimNo].filename); diff --git a/ECTrainer2/Stimulus.h b/ECTrainer2/Stimulus.h index e2eb484..d129832 100644 --- a/ECTrainer2/Stimulus.h +++ b/ECTrainer2/Stimulus.h @@ -6,10 +6,11 @@ #include #include "myOpenCV.h" #include "RingBuffer.h" +#include "MovieObject.h" +#include "myWinUtils.h" class BaseProcess; class Marker; -class MovieObject; enum class STIM_PAGE; struct StimInfo { @@ -23,24 +24,24 @@ { public: private: + const std::string STIM_CONFIG_FILE = "StimConfig.txt"; const cv::String OPENING_FILE = "../images/ECT_toppage.png"; const cv::String CALIB_FILE = "../images/calib.png"; const cv::String CALIB_COMPLETE_FILE = "../images/CalibComplete.png"; const cv::String CALIB_FAILED_FILE = "../images/CalibFailed.png"; const cv::String WHITE_FILE = "../images/white.png"; - const std::string STIM_CONFIG_FILE = "StimConfig.txt"; std::vector _StimInfoSet; // �����ݒ� MovieObject* _pMovieObject; // �^�[�Q�b�g��� int _StimNo; // �h���f�[�^�ԍ��@-1:��~ - DWORD _StartTime; // �h���񎦊J�n���� + mwut::HPTimer _StimTimer; // �h���񎦃^�C�}�[ RingBuffer _Display; // �\���摜 RingBuffer _Movie; // ������ // �h����ݒ� - bool SetStimulus(); + bool SetStimulus(int newStimNo); // ����I�u�W�F�N�g�� - void LoadMovieObject(); + void LoadMovieObject(int stimNo); // ��{���� bool Routine(); // �C�x���g���� @@ -55,6 +56,14 @@ ~Stimulus(); // ������ bool Init(); + // �h���f�[�^�ԍ����擾 + int GetStimNo() { return _StimNo; } + // �h���t�@�C�������擾 + std::string GetStimFile() { return _StimInfoSet[_StimNo].filename; } + // �h���̎�ނ��擾 + bool IsStimMovie() { return (_StimInfoSet[_StimNo].type == 2); } + // �h���񎦂̌o�ߎ��Ԃ��擾 + double GetStimTime() { return _StimTimer.Elapse(); } // �������Ԃ� std::wstring GetMovie() { return _Movie.Get(); } // ������̍X�V��� @@ -63,4 +72,6 @@ cv::Mat GetDisplay() { return _Display.Get(); } // �\���摜�̍X�V��� bool IsNewDisplay() { return _Display.IsNew(); } + // �^�[�Q�b�g�����擾 + std::vector GetMovieObject(float eTime = -1.f); }; diff --git a/ECTrainer2/Worker.cpp b/ECTrainer2/Worker.cpp index 35125d3..a963650 100644 --- a/ECTrainer2/Worker.cpp +++ b/ECTrainer2/Worker.cpp @@ -5,6 +5,7 @@ #include "Stimulus.h" #include "BitalMonitor.h" #include "Marker.h" +#include "MovieObject.h" #include "myWinUtils.h" // �R���X�g���N�^ @@ -13,6 +14,7 @@ , _fpLogData(NULL) , _fpLogEvent(NULL) , _pTimer(NULL) + , _TargetImage(ECTrainer::RINGBUFSIZE) { } @@ -29,7 +31,7 @@ _pEct->MsgBox(_T("Can't open data log file."), MB_ICONERROR); return false; } - _ftprintf(_fpLogData, _T("time,gazeVx,gazeVy,H11,H12,H13,H21,H22,H23,H31,H32,H33,RR\n")); + _ftprintf(_fpLogData, _T("time,stimNo,stimTime,gazeVx,gazeVy,RR,H11,H12,H13,H21,H22,H23,H31,H32,H33\n")); if (_tfopen_s(&_fpLogEvent, EVENT_LOG_FILE, _T("w")) != 0) { _pEct->MsgBox(_T("Can't open event log file."), MB_ICONERROR); @@ -46,10 +48,38 @@ bool Worker::Routine() { // �������X�V��҂� - Sleep(0); + //Sleep(0); if (!_pEct->PEyeTrack()->IsNewGazeV()) return true; + cv::Point2f gazeV = (_pEct->PEyeTrack()->GetGazeV()); - this->DataLog(); + // �^�[�Q�b�g�摜���� + int stimNo = _pEct->PStimulus()->GetStimNo(); + std::vector elems = _pEct->PStimulus()->GetMovieObject(); + if (stimNo >= 0 && elems.size() > 0) { + cv::Mat stimImg = _pEct->PStimulus()->GetDisplay().clone(); + for (int e = 0; e < elems.size(); e++) { + cv::circle(stimImg, cv::Point2f(elems[e].x, elems[e].y), (int)elems[e].d, CV_RGB(255, 0, 0), 2); + } + _TargetImage.Put(stimImg); + } + + // ���O�o�� + if (_AppStatus == APP_STATUS::STIM) { + _ftprintf(_fpLogData, _T("%.1f"), _pTimer->Elapse()); // �o�ߎ��� + _ftprintf(_fpLogData, _T(",%d"), stimNo); // �h���f�[�^�ԍ� + _ftprintf(_fpLogData, _T(",%.1f"), _pEct->PStimulus()->GetStimTime()); // �h���񎦂̌o�ߎ��� + _ftprintf(_fpLogData, _T(",%.1f,%.1f"), gazeV.x, gazeV.y); // �����_�i����J�������W�j + _ftprintf(_fpLogData, _T(",%d"), _pEct->PBitalMonitor()->GetRR()); // �o�C�^���o��(RR�Ԋu�j + // �z���O���t�B�s��o�� + cv::Mat h = _pEct->PMarker()->GetHomography(); + if (!h.empty() && h.rows == 3 && h.cols == 3) { + double* ptr = h.ptr(0); + for (int i = 0; i < 9; i++) { + _ftprintf(_fpLogData, _T(",%lf"), *(ptr + i)); + } + } + _ftprintf(_fpLogData, _T("\n")); + } return true; } @@ -84,6 +114,7 @@ _AppStatus = APP_STATUS::STIM; ((BaseProcess*)_pEct->PStimulus())->Tell(ECTMSG::EXP_START); this->EventLog(_T("Experiment Start")); + _pTimer->Reset(); } break; @@ -126,24 +157,6 @@ return true; } -// �f�[�^���O�o�� -void Worker::DataLog() { - _ftprintf(_fpLogData, _T("%.1f"), _pTimer->Elapse()); - - cv::Point2f gazeV = (_pEct->PEyeTrack()->GetGazeV()); - _ftprintf(_fpLogData, _T(",%.1f,%.1f"), gazeV.x, gazeV.y); - cv::Mat h = _pEct->PMarker()->GetHomography(); - if (!h.empty() && h.rows == 3 && h.cols == 3) { - double* ptr = h.ptr(0); - for (int i = 0; i < 9; i++) { - _ftprintf(_fpLogData, _T(",%lf"), *(ptr + i)); - } - } - - _ftprintf(_fpLogData, _T(",%d"), _pEct->PBitalMonitor()->GetRR()); - _ftprintf(_fpLogData, _T("\n")); -} - // �C�x���g���O�o�� void Worker::EventLog(const TCHAR* msg) { _ftprintf(_fpLogEvent, _T("%.1f"), _pTimer->Elapse()); diff --git a/ECTrainer2/Worker.h b/ECTrainer2/Worker.h index dad1e55..26e6c13 100644 --- a/ECTrainer2/Worker.h +++ b/ECTrainer2/Worker.h @@ -3,6 +3,8 @@ #include #include #include +#include "myOpenCV.h" +#include "RingBuffer.h" namespace mwut { class HPTimer; @@ -24,9 +26,8 @@ FILE* _fpLogData; // �f�[�^���O�t�@�C���|�C���^ FILE* _fpLogEvent; // �C�x���g���O�t�@�C���|�C���^ mwut::HPTimer* _pTimer; // ���O�p�̃^�C�}�[ + RingBuffer _TargetImage; // �^�[�Q�b�g�摜 - // �f�[�^���O�o�� - void DataLog(); // �C�x���g���O�o�� void EventLog(const TCHAR* msg); // ��{���� @@ -43,4 +44,9 @@ bool Init(); // �A�v���P�[�V������Ԃ̎擾 APP_STATUS GetAppStatus() { return _AppStatus; } + // �^�[�Q�b�g�摜�̍X�V��� + bool IsNewTargetImg() { return _TargetImage.IsNew(); } + // �^�[�Q�b�g�摜�擾 + cv::Mat GetTargetImg() { return _TargetImage.Get(); } + };