datatype.h
Go to the documentation of this file.
1 /*
2 * ECVL - European Computer Vision Library
3 * Version: 0.3.4
4 * copyright (c) 2021, Università degli Studi di Modena e Reggio Emilia (UNIMORE), AImageLab
5 * Authors:
6 * Costantino Grana (costantino.grana@unimore.it)
7 * Federico Bolelli (federico.bolelli@unimore.it)
8 * Michele Cancilla (michele.cancilla@unimore.it)
9 * Laura Canalini (laura.canalini@unimore.it)
10 * Stefano Allegretti (stefano.allegretti@unimore.it)
11 * All rights reserved.
12 */
13 
14 #ifndef ECVL_DATATYPE_H_
15 #define ECVL_DATATYPE_H_
16 
17 #include <cstdint>
18 #include <cstddef>
19 #include <limits>
20 #include <array>
21 #include <vector>
22 
23 namespace ecvl {
24 
25 typedef std::array<int, 2> Point2i;
26 typedef std::array<double, 2> Point2d;
27 typedef std::array<int, 2> Size2i;
28 typedef std::array<double, 2> Size2d;
29 typedef std::vector<double> Scalar;
30 
36 double SqDist(const Point2i& a, const Point2i& b);
37 
43 enum class DataType {
44 #define ECVL_TUPLE(name, ...) name,
45 #include "datatype_tuples.inc.h"
46 #undef ECVL_TUPLE
47 };
48 
57 uint8_t DataTypeSize(DataType dt);
58 
61 template<ecvl::DataType> struct TypeInfo { using basetype = void; };
62 #define ECVL_TUPLE(name, size, type, ...) template<> struct TypeInfo<ecvl::DataType::name> { using basetype = type; };
63 #include "datatype_tuples.inc.h"
64 #undef ECVL_TUPLE
65 
66 template<ecvl::DataType DT>
68 
73 constexpr size_t DataTypeSize() {
74  constexpr size_t size = 0
75 #define ECVL_TUPLE(name, ...) + 1
77 #undef ECVL_TUPLE
78  ;
79  return size;
80 }
81 
86 constexpr size_t DataTypeSignedSize() {
87  constexpr size_t size = 0
88 #define ECVL_TUPLE(name, ...) + 1
90 #undef ECVL_TUPLE
91  ;
92  return size;
93 }
94 
100 constexpr std::array<DataType, DataTypeSize()> DataTypeArray() {
101  //@cond
102  constexpr std::array<DataType, DataTypeSize()> arr = {
103 #define ECVL_TUPLE(name, ...) DataType::name,
105 #undef ECVL_TUPLE
106  };
107  return arr;
108  //@endcond
109 }
110 
115 constexpr std::array<DataType, DataTypeSignedSize()> DataTypeSignedArray() {
116  //@cond
117  constexpr std::array<DataType, DataTypeSignedSize()> arr = {
118 #define ECVL_TUPLE(name, ...) DataType::name,
120 #undef ECVL_TUPLE
121  };
122  return arr;
123  //@endcond
124 }
125 } // namespace ecvl
126 
127 #endif // ECVL_DATATYPE_H_
std::array< double, 2 > Point2d
Definition: datatype.h:26
DataType
DataType is an enum class which defines data types allowed for images.
Definition: datatype.h:43
constexpr std::array< DataType, DataTypeSignedSize()> DataTypeSignedArray()
Function to get a std::array with all the signed DataType values at compile time.
Definition: datatype.h:115
typename TypeInfo< DT >::basetype TypeInfo_t
Definition: datatype.h:67
void basetype
Definition: datatype.h:61
constexpr std::array< DataType, DataTypeSize()> DataTypeArray()
Function to get a std::array with all the DataType values at compile time.
Definition: datatype.h:100
std::array< int, 2 > Point2i
Definition: datatype.h:25
std::vector< double > Scalar
Definition: datatype.h:29
std::array< double, 2 > Size2d
Definition: datatype.h:28
constexpr size_t DataTypeSignedSize()
Function to get the number of existing signed DataType at compile time.
Definition: datatype.h:86
uint8_t DataTypeSize(DataType dt)
Provides the size in bytes of a given DataType.
double SqDist(const Point2i &a, const Point2i &b)
Calculate the distance squared between two ecvl::Point2i.
std::array< int, 2 > Size2i
Definition: datatype.h:27