Newer
Older
PrismSoftware / ECTrainer2 / ECTrainer.cpp
@Toshiya Nakaguchi Toshiya Nakaguchi on 16 Feb 2020 1 KB Stimulusクラス実装開始


#include "ECTrainer.h"
#include "ECTrainerGUI.h"
#include "SceneCamera.h"
#include "Stimulus.h"

// コンストラクタ
ECTrainer::ECTrainer()
	: _pGui(NULL)
	, _pSceneCam(NULL)
	, _pStimulus(NULL)
	, _Running(true)
{
	_pGui = new ECTrainerGUI(this);
	_pSceneCam = new SceneCamera(this);
	_pStimulus = new Stimulus(this);
}

// デストラクタ
ECTrainer::~ECTrainer() {
	if (_pGui) delete _pGui;
	if (_pSceneCam) delete _pSceneCam;
	if (_pStimulus) delete _pStimulus;
}

// 初期化
bool ECTrainer::Process() {
	if (!_pGui->Init()) return false;
	if (!_pSceneCam->Init()) return false;

	DWORD dwThreadId;
	HANDLE hThSceneCam = CreateThread(NULL, 0, SceneCamThreadEntry, this, 0, &dwThreadId);

	_pGui->MainLoop();

	if (WaitForSingleObject(hThSceneCam, 1000) == WAIT_OBJECT_0) {
#ifdef _DEBUG
		std::cout << "Scene Cam thread end." << std::endl;
#endif
	}
	CloseHandle(hThSceneCam);

	return true;
}

// キャリブレーション
void ECTrainer::Calib() {
	_pStimulus->StartCalib();
}

// 開始
void ECTrainer::Start() {
	_pStimulus->StartImage();
}

// 視野画像バッファに画像を設定
void ECTrainer::SetSceneBuffer(cv::Mat& img) {
	_pGui->SetSceneBuffer(img);
}

// 刺激画像バッファに画像を設定
void ECTrainer::SetDispBuffer(cv::Mat& img) {
	_pGui->SetDispBuffer(img);
}

// 視野カメラスレッド開始点
DWORD WINAPI ECTrainer::SceneCamThreadEntry(LPVOID lpParameter) {
	((ECTrainer*)lpParameter)->_pSceneCam->MainLoop();
	return 0;
}