source: flair-src/trunk/lib/FlairCore/src/cvmatrix.h@ 251

Last change on this file since 251 was 148, checked in by Sanahuja Guillaume, 8 years ago

m

File size: 5.3 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 cvmatrix.h
7 * \brief Class defining a matrix of kind CvMat
8 * \author Guillaume Sanahuja, Copyright Heudiasyc UMR UTC/CNRS 7253
9 * \date 2012/03/21
10 * \version 4.0
11 */
12
13#ifndef CVMATRIX_H
14#define CVMATRIX_H
15
16#include <io_data.h>
17#include <IODataElement.h>
18#include <cvmatrix_descriptor.h>
19
20class cvmatrix_impl;
21struct CvMat;
22
23namespace flair {
24namespace core {
25
26/*! \class cvmatrix
27*
28* \brief Class defining a matrix of kind CvMat
29*
30* CvMat is a matrix struct defined in OpenCV.
31*
32*/
33class cvmatrix : 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 CvMat. \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 cvmatrix(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 CvMat. \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 cvmatrix(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 ~cvmatrix();
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 get CvMat
148 *
149 * The io_data Mutex must be used by the user.
150 */
151 CvMat *getCvMat(void) const;
152
153 /*!
154 * \brief Element name
155 *
156 * If cvmatrix was created without cvmatrix_descriptor, element name is empty.
157 *
158 * \param row element row
159 * \param col element col
160 *
161 * \return element name
162 */
163 std::string Name(uint32_t row, uint32_t col) const;
164
165 /*!
166 * \brief Element
167 *
168 * Get a pointer to a specific element. This pointer can be used for plotting.
169 *
170 * \param row element row
171 * \param col element col
172 *
173 * \return pointer to the element
174 */
175 IODataElement *Element(uint32_t row, uint32_t col) const;
176
177 /*!
178 * \brief Element
179 *
180 * Get a pointer to a specific element. This pointer can be used for plotting.
181 *\n
182 * This function can be used for a 1D matrix.
183 *
184 * \param index element index
185 *
186 * \return pointer to the element
187 */
188 IODataElement *Element(uint32_t index) const;
189
190 /*!
191 * \brief Number of rows
192 *
193 * \return rows
194 */
195 uint32_t Rows(void) const;
196
197 /*!
198 * \brief Number of colomns
199 *
200 * \return colomns
201 */
202 uint32_t Cols(void) const;
203
204 Type const &GetDataType() const { return dataType; };
205
206private:
207 /*!
208 * \brief Copy datas
209 *
210 * Reimplemented from io_data. \n
211 * See io_data::CopyDatas.
212 *
213 * \param dst destination buffer
214 */
215 void CopyDatas(char *dst) const;
216
217 class cvmatrix_impl *pimpl_;
218 Type dataType;
219};
220
221} // end namespace core
222} // end namespace flair
223
224#endif // CVMATRIX_H
Note: See TracBrowser for help on using the repository browser.