-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathTrackingThread.h
More file actions
239 lines (186 loc) · 5.13 KB
/
TrackingThread.h
File metadata and controls
239 lines (186 loc) · 5.13 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#pragma once
#include <atomic>
#include <memory>
#include <opencv2/opencv.hpp>
#include <boost/filesystem.hpp>
#include <QThread>
#include <condition_variable>
#include <QMouseEvent>
#include "util/MutexWrapper.h"
#include "TextureObject.h"
#include "TrackingAlgorithm.h"
#include "ImageStream.h"
#include "interpreter/Interpreter.h"
#include "TrackerStatus.h"
#include "PanZoomState.h"
class Settings;
namespace BioTracker {
namespace Core {
class TrackingThread : public QThread {
public:
Q_OBJECT
public:
TrackingThread(Settings &settings);
~TrackingThread(void);
TrackerStatus getStatus() const {
//TODO maybe lock this part?
return m_status;
}
/**
* Loads the last loaded file.
*/
void loadFromSettings();
/**
* Loads a video.
*/
void loadVideo(const boost::filesystem::path &filename);
/**
* Loads in pictures.
*/
void loadPictures(std::vector<boost::filesystem::path> &&filenames);
/**
* Opens a video device.
*/
void openCamera(int device);
/**
* Pause video plaing.
*/
void setPause();
/**
* Enables video playing.
*/
void setPlay();
/**
* @brief paint
* @param device
* @param painter
*/
void paint(const size_t, const size_t, QPainter &painter, BioTracker::Core::PanZoomState &z,
TrackingAlgorithm::View const &);
/**
* Checks if the thread is in the rendering stage right now
* @return
*/
bool isRendering() const;
/**
* Checks if thread is in pause state.
* @return true if paused, false otherwise.
*/
bool isPaused() const;
/**
* Toggles the playing state.
*/
void togglePlaying();
/**
* @return current fps setting
*/
double getFps() const;
size_t getVideoLength() const;
TextureObject const &getTexture() const {
return m_texture;
}
void mouseEvent(QMouseEvent *event);
void mouseWheelEvent(QWheelEvent *event);
void keyboardEvent(QKeyEvent *event);
private:
std::unique_ptr<ImageStream> m_imageStream;
Mutex m_trackerMutex;
std::mutex m_tickMutex;
std::mutex m_paintMutex;
std::mutex m_renderMutex;
std::condition_variable m_conditionVariable;
size_t m_lastFrameNumber;
bool m_playing;
bool m_playOnce;
bool m_isRendering;
bool m_somethingIsLoaded;
//defines whether to use pictures as source or a video
TrackerStatus m_status;
double m_fps;
bool m_maxSpeed;
GUIPARAM::MediaType m_mediaType;
Settings &m_settings;
TextureObject m_texture;
std::shared_ptr<TrackingAlgorithm> m_tracker GUARDED_BY(m_trackerMutex);
/**
* sends frame and everything else that is needed to selected
* tracking algorithm
*/
void doTracking();
/**
* Play and calculate the next frame only.
*/
void playOnce();
/**
* notifies the thread that it can do the next calculation
* Must be the last paint-call!!!!
* @brief paintDone
*/
void paintDone();
/**
* Does exactly one tick, eg. drawing one image and starting tracker once.
*/
void tick(const double fps);
/**
* Moves one frame forward
*/
void nextFrame();
/**
* thread running method.
*/
virtual void run() override;
public Q_SLOTS:
/**
* Sets the current frame number.
* @param frameNumber specifies the current frame number.
*/
void setFrameNumber(size_t frameNumber);
/**
* Gets current frame number.
* @return the current frame number.
*/
size_t getFrameNumber() const;
/**
* change framerate
*/
void setFps(double fps);
/**
* enable maximum playback speed
*/
void setMaxSpeed(bool enabled);
void setTrackingAlgorithm(std::shared_ptr<TrackingAlgorithm> TrackingAlgorithm);
void registerViewsFromTracker(const std::vector<TrackingAlgorithm::View> views);
void requestPaintFromTracker();
void requestTrackFromTracker();
void requestPauseFromTracker(bool pause);
void notifyGUIFromTracker(std::string m, MSGS::MTYPE type = MSGS::MTYPE::NOTIFICATION);
Q_SIGNALS:
/**
* emit current frame number.
* @param frameNumber the current frame number.
* @param filename the current file name
* @param currentFps the fps of the last frame: when the fps are -1, no fps should be shown
*/
void frameCalculated(const size_t frameNumber, const std::string filename,
const double currentFps);
/**
* emit new filename and entire frame quantity
*/
void fileOpened(const std::string fileName, const size_t numFrame,
const double targetFps);
/**
* send a message to the GUI.
*/
void notifyGUI(std::string message,
MSGS::MTYPE type = MSGS::MTYPE::NOTIFICATION);
/**
* @brief trackerSelected
* Notify the application that the tracker has changed
* @param tracker
*/
void trackerSelected(std::shared_ptr<TrackingAlgorithm> tracker);
void registerViews(const std::vector<TrackingAlgorithm::View> views);
void requestPaint();
};
}
}