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 | // created: 2014/02/05
|
---|
6 | // filename: cvmatrix_descriptor.cpp
|
---|
7 | //
|
---|
8 | // author: Guillaume Sanahuja
|
---|
9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
10 | //
|
---|
11 | // version: $Id: $
|
---|
12 | //
|
---|
13 | // purpose: Class describing cvmatrix elements, for log and graphs purpose
|
---|
14 | //
|
---|
15 | /*********************************************************************/
|
---|
16 |
|
---|
17 | #include "cvmatrix_descriptor.h"
|
---|
18 | #include "FrameworkManager.h"
|
---|
19 |
|
---|
20 | using std::string;
|
---|
21 |
|
---|
22 | namespace flair {
|
---|
23 | namespace core {
|
---|
24 |
|
---|
25 | cvmatrix_descriptor::cvmatrix_descriptor(uint32_t rows, uint32_t cols) {
|
---|
26 | this->rows = rows;
|
---|
27 | this->cols = cols;
|
---|
28 |
|
---|
29 | if (rows == 0 || cols == 0)
|
---|
30 | getFrameworkManager()->Err("rows and cols must be >0\n");
|
---|
31 |
|
---|
32 | element_names = (string **)malloc(rows * cols * sizeof(string *));
|
---|
33 | for (uint32_t i = 0; i < rows * cols; i++) {
|
---|
34 | element_names[i] = new string();
|
---|
35 | }
|
---|
36 | }
|
---|
37 |
|
---|
38 | cvmatrix_descriptor::~cvmatrix_descriptor() {
|
---|
39 | for (uint32_t i = 0; i < rows * cols; i++) {
|
---|
40 | delete element_names[i];
|
---|
41 | }
|
---|
42 | free(element_names);
|
---|
43 | }
|
---|
44 |
|
---|
45 | void cvmatrix_descriptor::SetElementName(uint32_t row, uint32_t col,
|
---|
46 | string name) {
|
---|
47 | if (row >= rows || col >= cols) {
|
---|
48 | getFrameworkManager()->Err("index out of bound %s (%i,%i), range (%i,%i)\n",
|
---|
49 | name.c_str(), row, col, rows - 1, cols - 1);
|
---|
50 | return;
|
---|
51 | }
|
---|
52 | *element_names[row * cols + col] = name;
|
---|
53 | }
|
---|
54 |
|
---|
55 | string cvmatrix_descriptor::ElementName(uint32_t row, uint32_t col) const {
|
---|
56 | if (row >= rows || col >= cols) {
|
---|
57 | getFrameworkManager()->Err("index out of bound (%i,%i), range (%i,%i)\n",
|
---|
58 | row, col, rows - 1, cols - 1);
|
---|
59 | return *element_names[0]; // safe value...
|
---|
60 | }
|
---|
61 | return *element_names[row * cols + col];
|
---|
62 | }
|
---|
63 |
|
---|
64 | uint32_t cvmatrix_descriptor::Rows() const { return rows; }
|
---|
65 |
|
---|
66 | uint32_t cvmatrix_descriptor::Cols() const { return cols; }
|
---|
67 |
|
---|
68 | } // end namespace core
|
---|
69 | } // end namespace flair
|
---|