-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patheventbuffer.h
More file actions
94 lines (82 loc) · 2.07 KB
/
eventbuffer.h
File metadata and controls
94 lines (82 loc) · 2.07 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
#ifndef EVENTFIFO_H
#define EVENTFIFO_H
#include <QMutex>
#include <QImage>
#include <deque>
#include <libcaer/events/polarity.h>
#include "datatypes.h"
#include <queue>
class EventBuffer
{
public:
EventBuffer();
/**
* @brief setup Creates an empty event buffer that
* holds all events in the specified timewindow.
* @param timewindow
*/
void setup(const uint32_t timewindow, const uint16_t sx, const uint16_t sy);
/**
* @brief addEvent Adds a new event to the
* buffer and removes all old events
* @param event
*/
void addEvent(const sDVSEventDepacked & event);
void addEvents(std::queue<sDVSEventDepacked> &events);
/**
* @brief clear removes all events from its memory.
*/
void clear();
/**
* @brief getSize Returns the number of events in the buffer
* @return
*/
int getSize()
{
QMutexLocker locker(&m_lock);
return m_buffer.size();
}
/**
* @brief getCurrTime Returns the time of the newest event in the buffer
* @return
*/
uint32_t getCurrTime()
{
QMutexLocker locker(&m_lock);
if(m_buffer.size() > 0)
return m_buffer.front().ts;
else
return 0;
}
/**
* @brief getLockedBuffer Locks and returns the internal deque.
* Make sure to release the buffer after acessing the deque!
* @return
*/
std::deque<sDVSEventDepacked> &getLockedBuffer()
{
// Lock the buffer
m_lock.lock();
return m_buffer;
}
/**
* @brief releaseLockedBuffer Releases the previously locked buffer.
*/
void releaseLockedBuffer()
{
m_lock.unlock();
}
/**
* @brief toImage Converts the current buffer state into a grayscale image.
* @return
*/
QImage toImage();
protected:
// Queue used as event buffer
// deque provides fast insert and delete operataions.
std::deque<sDVSEventDepacked> m_buffer;
uint32_t m_timeWindow;
uint16_t m_sx,m_sy;
QMutex m_lock;
};
#endif // EVENTFIFO_H