-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscanhandler.cpp
More file actions
110 lines (78 loc) · 2.59 KB
/
scanhandler.cpp
File metadata and controls
110 lines (78 loc) · 2.59 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "scanhandler.h"
#include <QThread>
std::map<int, std::pair<MyStandardItemModel *, std::function<ImgMatchFinderBase *()> >> ScanHandler::_algoData;
ScanHandler::ScanHandler()
{
}
void ScanHandler::registerAlgo(int type, QAbstractItemModel * mod,
std::function<ImgMatchFinderBase *()> func)
{
auto model = static_cast<MyStandardItemModel *>(mod);
if(!mod){
std::cerr << "WRONG MODEL TYPE!" <<std::endl;
return;
}
_algoData.emplace(type, std::make_pair(model, func));
}
void ScanHandler::setBar(QProgressBar *bar)
{
connect(this , &ScanHandler::setRange, bar, &QProgressBar::setRange);
connect(this , &ScanHandler::setValue, bar, &QProgressBar::setValue);
connect(this , &ScanHandler::setFormat, bar, &QProgressBar::setFormat);
}
ScanHandler::~ScanHandler()
{
// m_stop_scan = true;
// numfu.get();
// scanfu.get();
// updatefu.get();
}
void ScanHandler::stop()
{
emit setFormat("Aborting scan.. this may take a while..");
m_stop_scan = true;
}
void ScanHandler::run()
{
std::clock_t start =std::clock();
emit setFormat("Loading...");
auto root_copy = m_root;
scanfu = std::future(std::async([&](){ ImgFileScanner::scan(m_root, std::ref(m_stop_scan)); }));
numfu = std::future<int>(std::async( &ImgFileScanner::getNumberOfImages , root_copy, std::ref(m_stop_scan)));
int num_of_images = numfu.get();
emit setRange(0, num_of_images);
emit setFormat("Reading images: %v/%m ");
for(int val=0 ; !m_stop_scan && val < num_of_images; QThread::msleep(100)){
val = ImgFileScanner::size();
emit setValue(val);
}
scanfu.get();
emit setFormat("Calculating Matches.. "); //TODO add more info.
emit setRange(0,0);
static std::mutex mu;
std::lock_guard<std::mutex> lk(mu);
ImgMatchFinderBase * algo = _algoData[m_algoType].second();
algo->makeMatchGroups();
emit setRange(0, algo->numberOfGroupsFound());
emit setFormat("Adding match groups: %v/%m ");
int found = 0;
AddingImgThread addImgThread(_algoData[m_algoType].first);
for(const auto & x: algo->getMatchGroups()){
if(m_stop_scan) break;
QThread::msleep(300);
addImgThread.addStringList(x);
emit setValue(++found);
}
delete algo;
m_stop_scan = false;
std::clock_t time = std::clock() - start;
emit setFormat(QString("Done scan ") + QString::fromStdString(std::to_string(time)));
}
void ScanHandler::setRoot(QString s)
{
m_root = s.toStdWString();
}
void ScanHandler::setAlgo(int i)
{
m_algoType = i;
}