OpenEV
Extending OpenCV to event-based vision
 
Loading...
Searching...
No Matches
abstract-reader.hpp
1
6#ifndef OPENEV_READERS_ABSTRACT_READER_HPP
7#define OPENEV_READERS_ABSTRACT_READER_HPP
8
10#include "openev/containers/vector.hpp"
11#include "openev/core/types.hpp"
12#include <atomic>
13#include <cstddef>
14#include <limits>
15#include <mutex>
16#include <thread>
17
18namespace ev {
19
24public:
25 static constexpr std::size_t NO_BUFFER = 0;
26 static constexpr std::size_t INF_BUFFER = std::numeric_limits<std::size_t>::max();
27
29 virtual ~AbstractReader_();
30 AbstractReader_(const AbstractReader_ &) = delete;
31 AbstractReader_(AbstractReader_ &&) noexcept = delete;
32 AbstractReader_ &operator=(const AbstractReader_ &) = delete;
33 AbstractReader_ &operator=(AbstractReader_ &&) noexcept = delete;
35
40 AbstractReader_(const std::size_t buffer_size, const bool use_threading);
41
47 bool read(Event &e);
48
55 bool read(Vector &vector, const int n);
56
64 bool read(Queue &queue, const int n, const bool keep_size = false);
65
72 bool read_t(Vector &vector, const double t);
73
81 bool read_t(Queue &queue, const double t, const bool keep_size = false);
82
88 bool skip(int n);
89
95 bool skip_t(const double t);
96
101 void reset();
102
107 [[nodiscard]] virtual std::size_t count() = 0;
108
109protected:
110 const std::size_t bufferSize_;
111 std::thread thread_;
112 Queue buffer_;
113 std::mutex bufferMutex_;
114 std::atomic<bool> threadRunning_{};
115
116 virtual bool read_(Event &e) = 0;
117 virtual void reset_() = 0;
118
119private:
120 void threadFunction();
121 bool loadBuffer();
122};
123
124} // namespace ev
125
126#endif // OPENEV_READERS_ABSTRACT_READER_HPP
bool skip_t(const double t)
Skip events for the specified duration.
Definition abstract-reader.cpp:115
void reset()
Start reading from the first event.
Definition abstract-reader.cpp:129
AbstractReader_(const std::size_t buffer_size, const bool use_threading)
Constructor for AbstractReader_.
Definition abstract-reader.cpp:9
bool read(Event &e)
Read the next event.
Definition abstract-reader.cpp:23
virtual std::size_t count()=0
Count the total number of events available.
bool read_t(Vector &vector, const double t)
Read the next events until the specified duration is reached.
Definition abstract-reader.cpp:64
bool skip(int n)
Skip the next n events.
Definition abstract-reader.cpp:107
Queue container for basic event structures.
Queuei Queue
Definition queue.hpp:64
Basic event-based vision structures based on OpenCV components.
Eventi Event
Definition types.hpp:209