-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patheventbuffer.cpp
More file actions
89 lines (70 loc) · 2.08 KB
/
eventbuffer.cpp
File metadata and controls
89 lines (70 loc) · 2.08 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
#include "eventbuffer.h"
#include <QMutexLocker>
#include "settings.h"
EventBuffer::EventBuffer():m_timeWindow(0),m_sx(0),m_sy(0)
{
}
void EventBuffer::clear()
{
QMutexLocker locker(&m_lock);
m_buffer.clear();
}
void EventBuffer::setup(const uint32_t timewindow, const uint16_t sx, const uint16_t sy)
{
QMutexLocker locker(&m_lock);
m_timeWindow = timewindow;
m_sx = sx;
m_sy = sy;
m_buffer.clear();
}
void EventBuffer::addEvent(const sDVSEventDepacked &event)
{
QMutexLocker locker(&m_lock);
// Remove all old events
while (m_buffer.size() > 0 &&
event.ts - m_buffer.back().ts > m_timeWindow) {
m_buffer.pop_back();
}
// Add new event
m_buffer.push_front(event);
}
void EventBuffer::addEvents(std::queue<sDVSEventDepacked> & events)
{
if(events.size() == 0)
return;
uint32_t newTsStart = events.back().ts;
QMutexLocker locker(&m_lock);
// Remove all old events
// Here, we have to lock for the whole period
while (m_buffer.size() > 0 &&
newTsStart - m_buffer.back().ts > m_timeWindow) {
m_buffer.pop_back();
}
// Add events
while(!events.empty()) {
const sDVSEventDepacked &ev = events.front();
// Don't block for the whole function or other threads are slowed down
if(m_buffer.size() > 0 && m_buffer.front().ts > events.front().ts)
printf("Time jump: %d to %d\n", m_buffer.front().ts,events.front().ts);
{
m_buffer.push_front(ev);
}
events.pop();
}
//printf("Buff: %zu\n",m_buffer.size());
}
QImage EventBuffer::toImage()
{
QImage img(m_sx,m_sy,QImage::Format_RGB888);
img.fill(Qt::white);
QMutexLocker locker(&m_lock);
// Get current time and color according to temporal distance
uint32_t currTime = m_buffer.front().ts;
for(sDVSEventDepacked e:m_buffer) {
uchar c = 255*(currTime-e.ts)/m_timeWindow;
*(img.scanLine(e.y) + 3*e.x) = c;
*(img.scanLine(e.y) + 3*e.x + 1) = c;
*(img.scanLine(e.y) + 3*e.x + 2) = c;
}
return img;
}