datatype_matrix.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 DATATYPE_MATRIX_H_
15 #define DATATYPE_MATRIX_H_
16 
17 #include "datatype.h"
18 
19 namespace ecvl {
20 // TODO internal doc
21 template<
22  template<DataType DT, typename ...> class _StructFun,
23  typename ...Args
24 >
25 struct Table1D {
26  using fun_type = decltype(&_StructFun<static_cast<DataType>(0), Args...>::_);
27 
28  template<int i>
29  struct integer {};
30 
31  template <int i>
32  constexpr void FillData(integer<i>) {
33  constexpr auto arr = DataTypeArray();
34  data[i] = _StructFun<arr[i], Args...>::_;
36  }
37 
38  constexpr void FillData(integer<DataTypeSize()>) {}
39 
40  constexpr Table1D() : data() {
41  FillData<0>(integer<0>());
42  }
43 
44  inline fun_type operator()(DataType dt) const {
45  return data[static_cast<int>(dt)];
46  }
47 
49 };
50 
51 // TODO internal doc
52 template<
53  template<DataType, typename ...>class _StructFun,
54  typename ...Args
55 >
56 struct SignedTable1D {
57  using fun_type = decltype(&_StructFun<static_cast<DataType>(0), Args...>::_);
58 
59  template<int i>
60  struct integer {};
61 
62  template <int i>
63  constexpr void FillData(integer<i>) {
64  constexpr auto arr = DataTypeSignedArray();
65  data[i] = _StructFun<arr[i], Args...>::_;
67  }
68 
69  constexpr void FillData(integer<DataTypeSignedSize()>) {}
70 
71  constexpr SignedTable1D() : data() {
72  FillData<0>(integer<0>());
73  }
74 
75  inline fun_type operator()(DataType dt) const {
76  return data[static_cast<int>(dt)];
77  }
78 
80 };
81 
82 // TODO internal doc
83 template<
84  template<DataType, DataType, typename ...>class _StructFun,
85  typename ...Args
86 >
87 struct Table2D {
88  using fun_type = decltype(&_StructFun<static_cast<DataType>(0), static_cast<DataType>(0), Args...>::_);
89 
90  template<int i>
91  struct integer {};
92 
93  template <int i>
94  constexpr void FillData(integer<i>) {
95  constexpr auto arr = DataTypeArray();
96  constexpr size_t src = i / DataTypeSize();
97  constexpr size_t dst = i % DataTypeSize();
98  data[i] = _StructFun<arr[src], arr[dst], Args...>::_;
100  }
101 
102  constexpr void FillData(integer< DataTypeSize()* DataTypeSize() >) {}
103 
104  constexpr Table2D() : data() {
105  FillData<0>(integer<0>());
106  }
107 
108  inline fun_type operator()(DataType src, DataType dst) const {
109  int row = static_cast<int>(src);
110  int col = static_cast<int>(dst);
111  return data[row * DataTypeSize() + col];
112  }
113 
115 };
116 
117 // TODO internal doc
118 template<
119  template<DataType, DataType, typename ...>class _StructFun,
120  typename ...Args
121 >
123  using fun_type = decltype(&_StructFun<static_cast<DataType>(0), static_cast<DataType>(0), Args...>::_);
124 
125  template<int i>
126  struct integer {};
127 
128  template <int i>
129  constexpr void FillData(integer<i>) {
130  constexpr auto arr = DataTypeSignedArray();
131  constexpr size_t src = i / DataTypeSignedSize();
132  constexpr size_t dst = i % DataTypeSignedSize();
133  data[i] = _StructFun<arr[src], arr[dst], Args...>::_;
135  }
136 
138 
139  constexpr SignedTable2D() : data() {
140  FillData<0>(integer<0>());
141  }
142 
143  inline fun_type operator()(DataType src, DataType dst) const {
144  int row = static_cast<int>(src);
145  int col = static_cast<int>(dst);
146  return data[row * DataTypeSignedSize() + col];
147  }
148 
150 };
151 } // namespace ecvl
152 
153 #endif // !DATATYPE_MATRIX_H_
decltype(&_StructFun< static_cast< DataType >(0), static_cast< DataType >(0), Args... >::_) fun_type
constexpr void FillData(integer< i >)
fun_type operator()(DataType src, DataType dst) const
constexpr void FillData(integer< i >)
constexpr void FillData(integer< DataTypeSignedSize() *DataTypeSignedSize() >)
fun_type operator()(DataType dt) const
constexpr void FillData(integer< DataTypeSize()>)
DataType
DataType is an enum class which defines data types allowed for images.
Definition: datatype.h:43
fun_type data[DataTypeSize() *DataTypeSize()]
constexpr Table1D()
constexpr SignedTable2D()
decltype(&_StructFun< static_cast< DataType >(0), static_cast< DataType >(0), Args... >::_) fun_type
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
constexpr void FillData(integer< DataTypeSize() *DataTypeSize() >)
constexpr Table2D()
constexpr void FillData(integer< DataTypeSignedSize()>)
constexpr std::array< DataType, DataTypeSize()> DataTypeArray()
Function to get a std::array with all the DataType values at compile time.
Definition: datatype.h:100
fun_type operator()(DataType src, DataType dst) const
constexpr SignedTable1D()
decltype(&_StructFun< static_cast< DataType >(0), Args... >::_) fun_type
fun_type operator()(DataType dt) const
decltype(&_StructFun< static_cast< DataType >(0), Args... >::_) fun_type
fun_type data[DataTypeSignedSize() *DataTypeSignedSize()]
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.
constexpr void FillData(integer< i >)
fun_type data[DataTypeSize()]
constexpr void FillData(integer< i >)
fun_type data[DataTypeSignedSize()]