source: flair-src/trunk/lib/FlairCore/src/Matrix.h@ 213

Last change on this file since 213 was 213, checked in by Sanahuja Guillaume, 4 years ago

thread stack size rework
add Matrix class

File size: 5.1 KB
Line 
1// %flair:license{
2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
4// %flair:license}
5/*!
6 * \file Matrix.h
7 * \brief Class defining a matrix
8 * \author Guillaume Sanahuja, Copyright Heudiasyc UMR UTC/CNRS 7253
9 * \date 2018/01/30
10 * \version 4.0
11 */
12
13#ifndef MATRIX_H
14#define MATRIX_H
15
16#include <io_data.h>
17#include <IODataElement.h>
18#include <cvmatrix_descriptor.h>
19
20class Matrix_impl;
21
22namespace flair {
23namespace core {
24
25/*! \class Matrix
26*
27* \brief Class defining a matrix
28*
29* Only supports float for the moment
30* TODO: write a template
31*
32*/
33class Matrix : public io_data {
34public:
35 class Type : public DataType {
36 public:
37 Type(size_t _nbRows, size_t _nbCols, ScalarType const &_elementDataType)
38 : nbRows(_nbRows), nbCols(_nbCols), elementDataType(_elementDataType) {}
39 size_t GetSize() const {
40 return nbRows * nbCols * elementDataType.GetSize();
41 }
42 std::string GetDescription() const { return "matrix"; }
43 size_t GetNbRows() const { return nbRows; }
44 size_t GetNbCols() const { return nbCols; }
45 ScalarType const &GetElementDataType() const { return elementDataType; }
46
47 private:
48 size_t nbRows, nbCols;
49 ScalarType const &elementDataType;
50 };
51
52 /*!
53 * \brief Constructor
54 *
55 * Construct an io_data representing a matrix. \n
56 * It uses a cvmatrix_descriptor to get size and elements' names. \n
57 * Names are used for graphs and logs. \n
58 * All values are initialized to 0.
59 *
60 * \param parent parent
61 * \param descriptor matrix description, it is safe to destroy it after calling this constructor
62 * \param type type of matrix elements
63 * \param name name
64 * \param n number of samples
65 */
66 Matrix(const Object *parent, const cvmatrix_descriptor *descriptor,
67 ScalarType const &elementDataType, std::string name = "",
68 uint32_t n = 1);
69
70 /*!
71 * \brief Constructor
72 *
73 * Construct an io_data representing a matrix. \n
74 * Elements are unamed. \n
75 * All values are initialized to 0.
76 *
77 * \param parent parent
78 * \param rows matrix rows
79 * \param cols matrix cols
80 * \param type type of matrix elements
81 * \param name name
82 * \param n number of samples
83 */
84 Matrix(const Object *parent, uint32_t rows, uint32_t cols,
85 ScalarType const &elementDataType, std::string name = "",
86 uint32_t n = 1);
87
88 /*!
89 * \brief Destructor
90 *
91 */
92 ~Matrix();
93
94 /*!
95 * \brief Element value
96 *
97 * Element is accessed by locking and unlocking the io_data Mutex.
98 *
99 * \param row element row
100 * \param col element col
101 *
102 * \return element value
103 */
104 float Value(uint32_t row, uint32_t col) const;
105
106 /*!
107 * \brief Element value
108 *
109 * Element is not accessed by locking and unlocking the io_data Mutex. \n
110 * Thus, this function should be called with Mutex locked. \n
111 * This function is usefull when multiple successive access are done to the
112 * elments of the matrix. It avoids unnecessary locking and unlocking.
113 *
114 * \param row element row
115 * \param col element col
116 *
117 * \return element value
118 */
119 float ValueNoMutex(uint32_t row, uint32_t col) const;
120
121 /*!
122 * \brief Set element value
123 *
124 * Element is accessed by locking and unlocking the io_data Mutex.
125 *
126 * \param row element row
127 * \param col element col
128 * \param value element value
129 */
130 void SetValue(uint32_t row, uint32_t col, float value);
131
132 /*!
133 * \brief Set element value
134 *
135 * Element is not accessed by locking and unlocking the io_data Mutex. \n
136 * Thus, this function should be called with Mutex locked. \n
137 * This function is usefull when multiple successive access are done to the
138 * elments of the matrix. It avoids unnecessary locking and unlocking.
139 *
140 * \param row element row
141 * \param col element col
142 * \param value element value
143 */
144 void SetValueNoMutex(uint32_t row, uint32_t col, float value);
145
146 /*!
147 * \brief Element name
148 *
149 * If Matrix was created without cvmatrix_descriptor, element name is empty.
150 *
151 * \param row element row
152 * \param col element col
153 *
154 * \return element name
155 */
156 std::string Name(uint32_t row, uint32_t col) const;
157
158 /*!
159 * \brief Element
160 *
161 * Get a pointer to a specific element. This pointer can be used for plotting.
162 *
163 * \param row element row
164 * \param col element col
165 *
166 * \return pointer to the element
167 */
168 IODataElement *Element(uint32_t row, uint32_t col) const;
169
170 /*!
171 * \brief Element
172 *
173 * Get a pointer to a specific element. This pointer can be used for plotting.
174 *\n
175 * This function can be used for a 1D matrix.
176 *
177 * \param index element index
178 *
179 * \return pointer to the element
180 */
181 IODataElement *Element(uint32_t index) const;
182
183 /*!
184 * \brief Number of rows
185 *
186 * \return rows
187 */
188 uint32_t Rows(void) const;
189
190 /*!
191 * \brief Number of colomns
192 *
193 * \return colomns
194 */
195 uint32_t Cols(void) const;
196
197 Type const &GetDataType() const { return dataType; };
198
199private:
200 /*!
201 * \brief Copy datas
202 *
203 * Reimplemented from io_data. \n
204 * See io_data::CopyDatas.
205 *
206 * \param dst destination buffer
207 */
208 void CopyDatas(char *dst) const;
209
210 class Matrix_impl *pimpl_;
211 Type dataType;
212};
213
214} // end namespace core
215} // end namespace flair
216
217#endif // MATRIX_H
Note: See TracBrowser for help on using the repository browser.