6#ifndef OPENEV_CORE_TYPES_HPP
7#define OPENEV_CORE_TYPES_HPP
13#include <opencv2/core/base.hpp>
14#include <opencv2/core/matx.hpp>
15#include <opencv2/core/types.hpp>
16#include <opencv2/core/utils/logger.hpp>
22constexpr bool USING_TYPES_HPP =
true;
24using TimeType = double;
25using PolarityType = bool;
26using WeightType = float;
27using DepthType = float;
28using CounterType = int16_t;
30constexpr PolarityType
POSITIVE =
static_cast<PolarityType
>(
true);
31constexpr PolarityType
NEGATIVE =
static_cast<PolarityType
>(
false);
52 DISTANCE_NORM_INF =
static_cast<uint8_t
>(cv::NORM_INF),
53 DISTANCE_NORM_L1 =
static_cast<uint8_t
>(cv::NORM_L1),
54 DISTANCE_NORM_L2 =
static_cast<uint8_t
>(cv::NORM_L2),
55 DISTANCE_NORM_L2SQR =
static_cast<uint8_t
>(cv::NORM_L2SQR),
56 DISTANCE_NORM_MANHATTAN = DISTANCE_NORM_L1,
57 DISTANCE_NORM_EUCLIDEAN = DISTANCE_NORM_L2,
79 static_assert(std::is_arithmetic_v<T>,
"ev::Event_: the coordinate type must be arithmetic.");
124 Event_(
const T x,
const T y,
const TimeType
t,
const PolarityType
p) : cv::Point_<T>(x, y),
t{
t},
p{
p} {};
132 Event_(
const cv::Point_<T> &pt,
const TimeType
t,
const PolarityType
p) : cv::Point_<T>(pt),
t{
t},
p{
p} {};
142 template <
typename U>
178 [[nodiscard]] inline
bool operator==(const
Event_<T> &e)
const {
185 [[nodiscard]]
inline bool operator==(
const cv::Point_<T> &pt)
const {
192 [[nodiscard]]
inline bool operator==(
const cv::Point3_<T> &pt)
const {
206 template <
typename U>
207 [[nodiscard]]
inline explicit operator cv::Point_<U>()
const {
214 template <
typename U>
215 [[nodiscard]]
inline explicit operator cv::Point3_<U>()
const {
236 CV_Error(cv::Error::StsBadArg,
"ev::Event_::distance: Bad distance option.");
246 os << std::string(
"(" + std::to_string(e.x) +
"," + std::to_string(e.y) +
") " + std::to_string(e.
t) + (e.
p ?
" [+]" :
" [-]"));
284 os << std::string(
"(" + std::to_string(e.x) +
"," + std::to_string(e.y) +
") " + std::to_string(e.
t) + (e.
p ?
" [+]" :
" [-]"));
285 os <<
" w=" + std::to_string(e.
weight);
286 os <<
" d=" + std::to_string(e.
depth);
287 os <<
" s=" + (e.
stereo ==
Stereo::LEFT ? std::string(
"LEFT") : std::string(
"RIGHT"));
353 [[nodiscard]]
inline bool empty()
const {
354 return cv::Size_<T>::width <= 0 || cv::Size_<T>::height <= 0 ||
length <= 0;
363 return cv::Size_<T>::width * cv::Size_<T>::height *
length;
426 Rect3_(
const T x,
const T y,
const T
t,
const T w,
const T h,
const T l) : cv::Rect_<T>(x, y, w, h),
t{
t},
length{l} {};
441 Rect3_(
const cv::Point3_<T> &pt,
const Size3_<T> sz) : cv::Rect_<T>(cv::Point_<T>(pt.x, pt.y), cv::Size_<T>(sz.width, sz.height)),
t{pt.z},
length{sz.
length} {};
448 Rect3_(
const cv::Point3_<T> &pt1,
const cv::Point3_<T> &pt2) : cv::Rect_<T>(cv::Point_<T>(pt1.x, pt1.y), cv::Size_<T>(pt2.x - pt1.x, pt2.y - pt1.y)),
t{pt1.z},
length{pt2.z - pt1.z} {};
454 [[nodiscard]]
inline bool empty()
const {
464 template <
typename Te>
466 return cv::Rect_<T>::contains(e) && e.
t >=
t && e.
t <
t +
length;
506 cv::Point_<T> center;
512 Circ_() : center{0, 0}, radius{0} {};
519 Circ_(
const cv::Point_<T> center,
const T radius) : center{center}, radius{std::max(radius, static_cast<T>(0))} {}
525 [[nodiscard]]
inline bool empty()
const {
535 template <
typename Te>
537 return !
empty() && pow(center.x - e.x, 2) + pow(center.y - e.y, 2) <= radius * radius;
544 [[nodiscard]]
inline cv::Size
size()
const {
545 return {radius, radius};
553 [[nodiscard]]
inline double area()
const {
554 return M_PI * radius * radius;
This class extends Event to include: weigth, depth, and stereo.
Definition types.hpp:269
DepthType depth
Definition types.hpp:274
WeightType weight
Definition types.hpp:273
Stereo stereo
Definition types.hpp:275
friend std::ostream & operator<<(std::ostream &os, const AugmentedEvent_< T > &e)
Overload of << operator.
Definition types.hpp:283
This class extends cv::Point_<T> for event data. For more information, please refer here.
Definition types.hpp:78
PolarityType p
Definition types.hpp:83
bool operator<(const Event_< T > &e) const
Definition types.hpp:199
Event_< T > & operator=(const cv::Point_< T > &p)
Definition types.hpp:164
Event_(const T x, const T y, const TimeType t, const PolarityType p)
Definition types.hpp:124
bool operator==(const cv::Point3_< T > &pt) const
Definition types.hpp:192
Event_(const cv::Point_< T > &pt, const TimeType t, const PolarityType p)
Definition types.hpp:132
Event_< T > & operator=(Event_< T > &&) noexcept=default
Event_< T > & operator=(const Event_< U > &e)
Definition types.hpp:143
bool operator==(const cv::Point_< T > &pt) const
Definition types.hpp:185
TimeType t
Definition types.hpp:82
Event_()
Definition types.hpp:88
Event_< T > & operator=(const cv::Point3_< T > &p)
Definition types.hpp:154
Event_< T > & operator=(const Event_< T > &)=default
Event_(Event_< T > &&) noexcept=default
double distance(const Event_< T > &e, const uint8_t type=DISTANCE_NORM_L2|DISTANCE_FLAG_SPATIAL) const
Definition types.hpp:226
Event_(const Event_< T > &)=default
Event_(const cv::Point_< T > &pt)
Definition types.hpp:115
friend std::ostream & operator<<(std::ostream &os, const Event_< T > &e)
Overload of << operator.
Definition types.hpp:245
This class extends cv::Rect_<T> for event data. For more information, please refer here.
Definition types.hpp:407
Rect3_(const T x, const T y, const T t, const T w, const T h, const T l)
Definition types.hpp:426
Rect3_(const Rect2_< T > &rect, const T t, const T l)
Definition types.hpp:434
Size3_< T > size() const
Size of the rectangular cuboid.
Definition types.hpp:473
T volume() const
Compute the volume.
Definition types.hpp:482
bool empty() const
Check if empty.
Definition types.hpp:454
Rect3_(const cv::Point3_< T > &pt1, const cv::Point3_< T > &pt2)
Definition types.hpp:448
Rect3_(const cv::Point3_< T > &pt, const Size3_< T > sz)
Definition types.hpp:441
int t
Definition types.hpp:409
bool contains(const Event_< Te > &e) const
Check if the rectangular cuboid contains an event.
Definition types.hpp:465
Rect3_()
Definition types.hpp:415
int length
Definition types.hpp:410
This class extends cv::Size_<T> for event data. For more information, please refer here.
Definition types.hpp:332
bool empty() const
Check if empty.
Definition types.hpp:353
T volume() const
Compute the volume.
Definition types.hpp:362
Size3_(T w, T h, T l)
Definition types.hpp:347
int length
Definition types.hpp:334
Size3_()
Definition types.hpp:339
This class defines a circle given its center and radius.
Definition types.hpp:505
Circ_()
Definition types.hpp:512
double area() const
Compute the area of the circle.
Definition types.hpp:553
Circ_(const cv::Point_< T > center, const T radius)
Definition types.hpp:519
cv::Size size() const
Bounding square of the circle as a cv::Size (radius x radius).
Definition types.hpp:544
bool contains(const Event_< Te > &e) const
Check if the circle contains an event.
Definition types.hpp:536
bool empty() const
Check if empty.
Definition types.hpp:525
Event_< long > Eventl
Definition types.hpp:251
Rect2_< double > Rect2d
Definition types.hpp:390
constexpr PolarityType POSITIVE
Definition types.hpp:30
Event_< int > Eventi
Definition types.hpp:250
Size2_< double > Size2d
Definition types.hpp:315
Size2i Size2
Definition types.hpp:316
Rect2i Rect2
Definition types.hpp:391
Rect2 Rect
Definition types.hpp:392
Event_< double > Eventd
Definition types.hpp:253
Size2_< int > Size2i
Definition types.hpp:312
Circ_< long > Circl
Definition types.hpp:558
Rect3_< int > Rect3i
Definition types.hpp:486
Size3i Size3
Definition types.hpp:370
Circ_< double > Circd
Definition types.hpp:560
Rect3i Rect3
Definition types.hpp:490
Circ_< int > Circi
Definition types.hpp:557
cv::Size_< T > Size2_
Type alias for cv::Size_<T> providing a named 2D size for event data. For more information,...
Definition types.hpp:311
Rect3_< double > Rect3d
Definition types.hpp:489
Size2 Size
Definition types.hpp:317
DistanceTypes
Norm types and dimensional flags for Event_::distance().
Definition types.hpp:51
@ DISTANCE_FLAG_SPATIOTEMPORAL
Definition types.hpp:60
@ DISTANCE_FLAG_TEMPORAL
Definition types.hpp:59
@ DISTANCE_FLAG_2D
Definition types.hpp:62
@ DISTANCE_FLAG_SPATIAL
Definition types.hpp:58
@ DISTANCE_FLAG_3D
Definition types.hpp:61
cv::Rect_< T > Rect2_
Type alias for cv::Rect_<T> providing a named 2D rectangle for event data. For more information,...
Definition types.hpp:386
Circ_< float > Circf
Definition types.hpp:559
AugmentedEvent_< float > AugmentedEventf
Definition types.hpp:293
AugmentedEventi AugmentedEvent
Definition types.hpp:295
Rect2_< long > Rect2l
Definition types.hpp:388
Rect3_< float > Rect3f
Definition types.hpp:488
AugmentedEvent_< long > AugmentedEventl
Definition types.hpp:292
Size3_< float > Size3f
Definition types.hpp:368
Rect2_< int > Rect2i
Definition types.hpp:387
Stereo
Stereo camera side identifier.
Definition types.hpp:36
@ RIGHT
Definition types.hpp:38
@ LEFT
Definition types.hpp:37
AugmentedEvent_< int > AugmentedEventi
Definition types.hpp:291
Size3_< double > Size3d
Definition types.hpp:369
Event_< float > Eventf
Definition types.hpp:252
Size3_< long > Size3l
Definition types.hpp:367
Circi Circ
Definition types.hpp:561
AugmentedEvent_< double > AugmentedEventd
Definition types.hpp:294
Rect2_< float > Rect2f
Definition types.hpp:389
Size2_< long > Size2l
Definition types.hpp:313
Size2_< float > Size2f
Definition types.hpp:314
Eventi Event
Definition types.hpp:254
Size3_< int > Size3i
Definition types.hpp:366
Rect3_< long > Rect3l
Definition types.hpp:487
constexpr PolarityType NEGATIVE
Definition types.hpp:31