6#ifndef OPENEV_REPRESENTATIONS_ABSTRACT_REPRESENTATION_HPP
7#define OPENEV_REPRESENTATIONS_ABSTRACT_REPRESENTATION_HPP
9#include "openev/containers/array.hpp"
10#include "openev/containers/queue.hpp"
11#include "openev/containers/vector.hpp"
17#include <opencv2/core/mat.hpp>
18#include <opencv2/core/matx.hpp>
19#include <opencv2/core/traits.hpp>
24#include <opencv2/viz/types.hpp>
29enum RepresentationOptions : uint8_t {
31 IGNORE_POLARITY = 0b00000001,
32 ONLY_IF_POSITIVE = 0b00000010,
33 ONLY_IF_NEGATIVE = 0b00000100
35constexpr bool REPRESENTATION_OPTION_CHECK(
const uint8_t a,
const RepresentationOptions b) {
36 return static_cast<bool>(a &
static_cast<uint8_t
>(b));
40template <
typename T,
typename =
void>
46struct DataTypeTrait<T, std::void_t<typename T::value_type>> {
47 using type =
typename T::value_type;
54 using TypeArray = std::array<T, 3>;
55 using PrimitiveDataType =
typename DataTypeTrait<T>::type;
56 using FloatingPointType =
typename std::conditional<std::is_same<T, double>::value, double,
float>::type;
57 using ChannelType =
typename cv::Mat_<PrimitiveDataType>;
58 static constexpr int NumChannels = cv::DataType<T>::channels;
60 static constexpr TypeArray initialize() {
61 if constexpr(std::is_floating_point_v<PrimitiveDataType>) {
62 return TypeArray{repeat(1.0), repeat(-1.0), repeat(0.0)};
64 if constexpr(NumChannels == 1) {
65 constexpr Type white = 255;
66 constexpr Type black = 0;
67 constexpr Type gray = 128;
68 return TypeArray{white, black, gray};
70 return TypeArray{Type(255, 0, 0), Type(0, 0, 255), Type(0, 0, 0)};
75 static constexpr Type repeat(
const double &value) {
76 if constexpr(NumChannels == 1) {
77 return static_cast<Type
>(value);
80 for(
int i = 0; i < NumChannels; i++) {
88 static constexpr Type convert(
const cv::viz::Color &color) {
89 if constexpr(NumChannels == 1) {
93 for(
int i = 0; i < NumChannels; i++) {
100 static cv::viz::Color convert(
const Type &noncolor) {
101 if constexpr(NumChannels == 1) {
102 return cv::viz::Color(noncolor);
105 for(
int i = 0; i < NumChannels; i++) {
106 ret[i] = noncolor[i];
118template <
typename T, const RepresentationOptions Options = RepresentationOptions::NONE>
121 using Type =
typename TypeHelper<T>::Type;
127 [[nodiscard]]
inline std::size_t
count()
const {
return count_; }
134 if(tLimits_[MIN] == DBL_MAX || tLimits_[MAX] == DBL_MIN) {
137 return tLimits_[MAX] - tLimits_[MIN];
145 if(tLimits_[MIN] == DBL_MAX || tLimits_[MAX] == DBL_MIN) {
148 return 0.5 * (tLimits_[MAX] + tLimits_[MIN]);
161 void clear(
const cv::Mat &background);
176 template <std::
size_t N>
192 bool insert(
Queue &queue,
const bool keep_events_in_queue =
false);
243 inline void setColor(
const bool polarity,
const cv::viz::Color &color) {
244 setValue(polarity, TypeHelper<T>::convert(color));
252 inline void setColor(
const cv::viz::Color &color) {
253 setValue(TypeHelper<T>::convert(color));
263 inline void setColors(
const cv::viz::Color &positive,
const cv::viz::Color &negative,
const cv::viz::Color &reset) {
264 setValues(TypeHelper<T>::convert(positive), TypeHelper<T>::convert(negative), TypeHelper<T>::convert(reset));
274 return polarity ? ON : OFF;
287 enum : uint8_t { MIN,
290 Type ON = TypeHelper<T>::initialize()[0];
291 Type OFF = TypeHelper<T>::initialize()[1];
292 Type RESET = TypeHelper<T>::initialize()[2];
294 double timeOffset_{0};
295 std::array<double, 2> tLimits_{DBL_MAX, DBL_MIN};
296 std::size_t count_{0};
298 virtual void clear_() = 0;
299 virtual void clear_(
const cv::Mat &background) = 0;
300 virtual bool insert_(
const Event &e) = 0;
307#include "openev/representations/abstract-representation.tpp"
This is an auxiliary class. This class cannot be instanced.
Definition abstract-representation.hpp:119
Type getValue(const bool polarity) const
Get current values for ON and OFF pixels.
Definition abstract-representation.hpp:273
void clear()
Remove all events from the representation.
void setValue(const bool polarity, const Type &value)
Set values for ON and OFF pixels.
Definition abstract-representation.hpp:208
void setTimeOffset(const Event &e)
Set time offset.
Definition abstract-representation.hpp:199
bool insert(const Array< N > &array)
Insert an array of events in the representation.
typename TypeHelper< T >::Type Type
Definition abstract-representation.hpp:121
void setValue(const Type &value)
Set value for non-activated pixels (background).
Definition abstract-representation.hpp:220
void clear(const cv::Mat &background)
Remove all events from the representation and add a background image.
bool insert(Queue &queue, const bool keep_events_in_queue=false)
Insert a queue of events in the representation.
void setValues(const Type &positive, const Type &negative, const Type &reset)
Set values for ON, OFF, and non-activated pixels.
Definition abstract-representation.hpp:230
bool insert(const Event &e)
Insert one event in the representation.
Type getValue() const
Get current values for non-activated pixels (background).
Definition abstract-representation.hpp:281
double midTime() const
Calculate the midpoint time between the oldest and the newest event.
Definition abstract-representation.hpp:144
bool insert(const Vector &vector)
Insert a vector of events in the representation.
std::size_t count() const
Number of events integrated in the representation.
Definition abstract-representation.hpp:127
double duration() const
Time difference between the oldest and the newest event integrated in the representation.
Definition abstract-representation.hpp:133
This class extends std::array to implement event arrays. For more information, please refer here.
Definition array.hpp:21
This class extends cv::Point_<T> for event data. For more information, please refer here.
Definition types.hpp:60
double t
Definition types.hpp:62
This class extends std::queue to implement event queues. For more information, please refer here.
Definition queue.hpp:35
This class extends std::vector to implement event vectors. For more information, please refer here.
Definition vector.hpp:36
OpenEV compilation options.
Basic event-based vision structures based on OpenCV components.