This repository was archived by the owner on Feb 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathController.cpp
More file actions
83 lines (71 loc) · 3.09 KB
/
Controller.cpp
File metadata and controls
83 lines (71 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "Controller.h"
//单例模式的静态指针的定义+初始化
Controller* Controller::ptr2Controller = nullptr;
Controller::Controller():currentAnalyseIndex(-1)
{
this->opticalFlowCalculater = OpticalFlowCalculater::getInstance();
this->opticalFlowCalculaterThread = new QThread();
this->opticalFlowCalculater->moveToThread(this->opticalFlowCalculaterThread);
this->opticalFlowCalculaterThread->start();
this->faceAligner = FaceAligner::getInstance(); //提前加载faceAligner
faceAlignerThread = new QThread();
faceAligner->moveToThread(faceAlignerThread);
faceAlignerThread->start();
analyserFactory = new AnalyserFactory();
QThread::connect(this,SIGNAL(startNextAnalyserSignal()),this,SLOT(startNextAnalyserSlot())); //由Controller自行调用自身的slot
webcamCapture = WebcamCapture::getInstance();
webcamThread = new QThread();
webcamCapture->moveToThread(webcamThread);
webcamThread->start();
QObject::connect(this,SIGNAL(webcamStart()),webcamCapture,SLOT(start()));
}
//单例模式创建函数
Controller* Controller::getInstance(){
if(Controller::ptr2Controller == nullptr){
Controller::ptr2Controller = new Controller();
}
return Controller::ptr2Controller;
}
void Controller::start(){
std::cout << "Controller at " << QThread::currentThreadId()<< std::endl;
this->currentAnalyseIndex = -1;
analyserOrder.clear();
for(std::string elemStr : analyserFactory->analyserType){
this->analyserOrder.push_back(elemStr);
}
Utils::randomizeVector(this->analyserOrder);
std::cout << "------------------------" << std::endl;
for(std::string elemStr : this->analyserOrder){
std::cout << elemStr << std::endl;
}
std::cout << "------------------------" << std::endl;
emit this->webcamStart(); //开启摄像头
emit this->startNextAnalyserSignal();
}
void Controller::startNextAnalyserSlot(){
this->currentAnalyseIndex++;
if(this->currentAnalyseIndex < this->analyserOrder.size()){
Analyser* analyser = AnalyserFactory::createAnalyser(this->analyserOrder.at(this->currentAnalyseIndex));
QObject::connect(this,SIGNAL(analyserStartSignal()),analyser,SLOT(start()));
analyserVector.push_back(analyser);
analyserThread = new QThread();
analyser->moveToThread(analyserThread);
QObject::connect(analyser,SIGNAL(done(bool)),this,SLOT(receiveAnalyserResultSlot(bool)));
QObject::connect(analyser,SIGNAL(updateSlider(int)),this,SLOT(receiveSliderPercentage(int)));
analyserThread->start();
emit this->analyserStartSignal();
QObject::disconnect(this,SIGNAL(analyserStartSignal()),analyser,SLOT(start())); //解除与当前线程的控制联系
}else{
std::cout << "All over" << std::endl;
}
}
void Controller::receiveAnalyserResultSlot(bool result){
if(result == true){
emit this->startNextAnalyserSignal();
}else{
std::cout << "Controller deny" <<std::endl;
}
}
void Controller::receiveSliderPercentage(int percentage){
emit this->updateSlider(percentage);
}