-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathTrackingThread.h
More file actions
234 lines (184 loc) · 5.1 KB
/
Copy pathTrackingThread.h
File metadata and controls
234 lines (184 loc) · 5.1 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
#pragma once
#include <atomic>
#include <memory>
#include <opencv2/opencv.hpp>
#include <boost/filesystem.hpp>
#include <QThread>
#include <condition_variable>
#include <QMouseEvent>
#include "biotracker/util/MutexWrapper.h"
#include "biotracker/core/TextureObject.h"
#include "biotracker/core/TrackingAlgorithm.h"
#include "biotracker/core/ImageStream.h"
#include "biotracker/core/interpreter/interpreter.h"
class Settings;
namespace BioTracker {
namespace Core {
class TrackingThread : public QThread {
public:
/**
* @brief The TrackerStatus enum
* describes the current status of the tracking algorithm
*/
enum class TrackerStatus {
NothingLoaded, ///< No media selected
Running, ///< The tracker is running
Paused, ///< The tracker is paused. The calculation of the current frame might still be running
Invalid ///< The replayed file is invalid
};
Q_OBJECT
public:
TrackingThread(Settings &settings);
~TrackingThread(void);
void initializeOpenGL(QOpenGLContext *context,
TextureObject &texture);
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();
/**
* allows to paint an overlay when rendered AFTER paintRaw.
* @brief paint
*/
void paintOverlay(QPainter &painter);
/**
* Paints the raw texture of the data of the current frame
* @brief paintRaw
*/
void paintRaw();
/**
* notifies the thread that it can do the next calculation
* Must be the last paint-call!!!!
* @brief paintDone
*/
void paintDone();
/**
* Checks if the thread is in the rendering stage right now
* @return
*/
bool isRendering() const;
/**
* Toggles the playing state.
*/
void togglePlaying();
/**
* @return current fps setting
*/
double getFps() const;
size_t getVideoLength() const;
void mouseEvent(QMouseEvent *event);
void keyboardEvent(QKeyEvent *event);
private:
std::unique_ptr<ImageStream> m_imageStream;
Mutex m_trackerMutex;
std::mutex m_tickMutex;
std::mutex m_renderMutex;
std::condition_variable m_conditionVariable;
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;
double m_runningFps;
bool m_maxSpeed;
GUIPARAM::MediaType m_mediaType;
Settings &m_settings;
TextureObject *m_texture;
std::shared_ptr<TrackingAlgorithm> m_tracker GUARDED_BY(m_trackerMutex);
QOpenGLDebugLogger m_openGLLogger;
/**
* Checks if thread is in pause state.
* @return true if paused, false otherwise.
*/
bool isPaused() const;
/**
* sends frame and everything else that is needed to selected
* tracking algorithm
*/
void doTracking();
/**
* Play and calculate the next frame only.
*/
void playOnce();
/**
* 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);
private Q_SLOTS:
void handleLoggedMessage(const QOpenGLDebugMessage &debugMessage);
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 newFrameNumber(int frameNumber);
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);
/**
* send a message to the GUI.
*/
void notifyGUI(std::string message,
MSGS::MTYPE type = MSGS::MTYPE::NOTIFICATION);
};
}
}