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

Last change on this file since 214 was 214, checked in by Sanahuja Guillaume, 5 years ago

matrix

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