-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathBioTrackerApp.cpp
More file actions
222 lines (173 loc) · 6.81 KB
/
Copy pathBioTrackerApp.cpp
File metadata and controls
222 lines (173 loc) · 6.81 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#include "BioTrackerApp.h"
#include <limits>
#include <thread>
#include <boost/algorithm/string.hpp>
#include "Exceptions.h"
namespace BioTracker {
namespace Core {
/**
* The consturctor instantiates m_settings.
* m_settings BioTrackerApp::m_settings is the BioTracker setting class BioTracker::Core::Settings.
* The default constructor of BioTracker::Core::Settings is used to instantiate m_settings.
*
* A registry Registry::getInstance() for loading and registering new tracker
* from a shared library is called by the constructor. In the whole BioTracker only one registry is
* allowed. Therefore the registry was designt as a singleton BioTracker::Util::Singleton.
*
* BioTrackerApp constructor also calles for a Registry. The Registry is a singleton and
* used for loading and registering new tracker from shared libraries.
* In the constructor
*/
BioTrackerApp::BioTrackerApp()
: m_settings()
, m_registry(Registry::getInstance())
, m_trackingThread(m_settings) {
initConnects();
loadModulesInPath(ConfigParam::MODULE_PATH);
m_trackingThread.start();
}
BioTrackerApp::~BioTrackerApp() {
m_trackingThread.terminate();
m_trackingThread.wait();
}
/**
* So far there are six connections between the BioTrackerApp and the TrackingThread and one connection to the
* Registry.
*
*
*/
void BioTrackerApp::initConnects() {
/** @code{.cpp} */
QObject::connect(&m_trackingThread, &Core::TrackingThread::frameCalculated,
this, &BioTrackerApp::frameCalculatedFromTrackingThread);
QObject::connect(&m_trackingThread, &Core::TrackingThread::notifyGUI,
this, &BioTrackerApp::notifyFromTrackingThread);
QObject::connect(&m_trackingThread, &Core::TrackingThread::fileOpened,
this, &BioTrackerApp::fileOpenedFromTrackingThread);
QObject::connect(&m_trackingThread, &Core::TrackingThread::trackerSelected,
this, &BioTrackerApp::trackerSelectedFromTrackingThread);
QObject::connect(&m_trackingThread, &Core::TrackingThread::registerViews,
this, &BioTrackerApp::registerViewsFromTrackingThread);
QObject::connect(&m_trackingThread, &Core::TrackingThread::requestPaint,
this, &BioTrackerApp::requestPaintFromTrackingThread);
QObject::connect(&m_registry, &Core::Registry::trackerIsAlreadyLoaded,
this, &BioTrackerApp::trackerIsAlreadyLoadedFromRegistry);
/** @endcode */
}
/**
* BioTrackerApp calls the loadVideo function of TrackingThread::loadVideo().
* TrackingThread will stored the file path as a parameter of Settings.
* Only video formats supported by OpenCV can be used with the BioTracker
*/
void BioTrackerApp::openVideo(const boost::filesystem::path &path) {
m_trackingThread.loadVideo(path);
}
void BioTrackerApp::openImages(std::vector<boost::filesystem::path> paths) {
m_trackingThread.loadPictures(std::move(paths));
}
void BioTrackerApp::openCamera(int device) {
m_trackingThread.loadCamera(device);
}
void BioTrackerApp::play() {
m_trackingThread.setPlay();
}
void BioTrackerApp::pause() {
m_trackingThread.setPause();
}
void BioTrackerApp::paint(const size_t w, const size_t h, QPainter &painter, PanZoomState zoom,
const TrackingAlgorithm::View &v) {
m_trackingThread.paint(w, h, painter, zoom, v);
}
bool BioTrackerApp::isRendering() {
return m_trackingThread.isRendering();
}
bool BioTrackerApp::isRunning() {
return !m_trackingThread.isPaused();
}
void BioTrackerApp::setFrame(const size_t frameNumber) {
m_trackingThread.setFrameNumber(frameNumber);
}
void BioTrackerApp::setTargetFps(const double fps) {
m_trackingThread.setFps(fps);
}
void BioTrackerApp::setMaxSpeed(bool enabled) {
m_trackingThread.setMaxSpeed(enabled);
}
double BioTrackerApp::getTargetFps() const {
return std::numeric_limits<double>::infinity();
}
size_t BioTrackerApp::getNumFrames() const {
return m_trackingThread.getVideoLength();
}
size_t BioTrackerApp::getCurrentFrameNumber() const {
return m_trackingThread.getFrameNumber();
}
void BioTrackerApp::setTrackingAlgorithm(std::shared_ptr<TrackingAlgorithm>
trackingAlgorithm) {
m_trackingThread.setTrackingAlgorithm(std::move(trackingAlgorithm));
}
void BioTrackerApp::setTrackingAlgorithm(const std::string &trackerName) {
const auto trackerType = m_registry.getTypeByString().at(trackerName);
if (trackerType != NoTracking) {
setTrackingAlgorithm(m_registry.makeNewTracker(trackerType, m_settings));
}
}
void BioTrackerApp::mouseEvent(QMouseEvent *event) {
m_trackingThread.mouseEvent(event);
}
void BioTracker::Core::BioTrackerApp::mouseWheelEvent(QWheelEvent *event) {
m_trackingThread.mouseWheelEvent(event);
}
void BioTrackerApp::keyboardEvent(QKeyEvent *event) {
m_trackingThread.keyboardEvent(event);
}
// all slots will only pass the signals through
void BioTrackerApp::notifyFromTrackingThread(const std::string &message,
const MessageType type) {
Q_EMIT notify(message, type);
}
void BioTrackerApp::frameCalculatedFromTrackingThread(const size_t frameNumber,
const std::string filename, const double currentFps) {
Q_EMIT frameCalculated(frameNumber, filename, currentFps);
}
void BioTrackerApp::loadModulesInPath(const boost::filesystem::path &path) {
if (!boost::filesystem::is_directory(path)) {
throw directory_not_found("Invalid path");
}
for (auto &p : boost::make_iterator_range(boost::filesystem::directory_iterator(path), {})) {
std::vector<std::string> parts;
boost::split(parts, p.path().string(), boost::is_any_of("."));
/** @note expect filename to be of form: name.tracker.ext */
if (parts.size() >= 3) {
getRegistry().loadTrackerLibrary(p);
}
}
}
void BioTrackerApp::fileOpenedFromTrackingThread(const std::string fileName,
const size_t numFrame, const double tfps) {
Q_EMIT fileOpened(fileName, numFrame, tfps);
}
void BioTracker::Core::BioTrackerApp::trackerSelectedFromTrackingThread(
std::shared_ptr<TrackingAlgorithm> a) {
Q_EMIT trackerSelected(a);
}
void BioTracker::Core::BioTrackerApp::registerViewsFromTrackingThread(const std::vector<TrackingAlgorithm::View>
views) {
Q_EMIT registerViews(views);
}
void BioTracker::Core::BioTrackerApp::requestPaintFromTrackingThread() {
Q_EMIT requestPaint();
}
void BioTracker::Core::BioTrackerApp::trackerIsAlreadyLoadedFromRegistry(const std::string name) {
std::stringstream ss;
ss << "Tracker " << name << " is already loaded!";
Q_EMIT notify(ss.str(), MessageType::FAIL);
}
void BioTracker::Core::BioTrackerApp::enableTracking() {
m_trackingThread.enableTracking();
}
void BioTracker::Core::BioTrackerApp::disableTracking() {
m_trackingThread.disableTracking();
}
} // Core
} // BioTracker