mars_lib 0.1.0.2abe2576fe7f
Modular and Robust Sensor-Fusion
Loading...
Searching...
No Matches
write_csv.h
Go to the documentation of this file.
1// Copyright (C) 2021 Christian Brommer, Control of Networked Systems, University of Klagenfurt, Austria.
2//
3// All rights reserved.
4//
5// This software is licensed under the terms of the BSD-2-Clause-License with
6// no commercial use allowed, the full terms of which are made available
7// in the LICENSE file. No license in patents is granted.
8//
9// You can contact the author at <christian.brommer@ieee.org>
10
11#ifndef WRITE_CSV_H
12#define WRITE_CSV_H
13
14#include <Eigen/Dense>
15#include <iostream>
16#include <sstream>
17
18namespace mars
19{
21{
22public:
23 inline static std::string vec_to_csv(const Eigen::VectorXd& a)
24 {
25 std::stringstream os;
26 for (int k = 0; k < a.size(); k++)
27 {
28 os << ", " << a(k);
29 }
30 return os.str();
31 }
32
37 inline static std::string cov_mat_to_csv(const Eigen::MatrixXd& cov)
38 {
39 if (cov.rows() != cov.cols())
40 {
41 std::cout << "Cov Mat to CSV: Cov matrix non-squared. No line written." << std::endl;
42 return std::string("");
43 }
44
45 std::stringstream os;
46 const int num_cov_state = static_cast<int>(cov.rows());
47
48 for (int k = 0; k < num_cov_state; k++)
49 {
50 int row_count = k * num_cov_state + k;
51 int col_count = num_cov_state - k; // Size relative to row_count
52 os << vec_to_csv(Eigen::Map<const Eigen::VectorXd>(cov.data() + row_count, col_count));
53 }
54
55 return os.str();
56 }
57
58 static std::string get_cov_header_string(const int& num_states)
59 {
60 std::stringstream os;
61
62 const std::string var("p_");
63 for (int row = 1; row <= num_states; row++)
64 {
65 for (int col = row; col <= num_states; col++)
66 {
67 os << ", " << var << row << "_" << col;
68 }
69 }
70
71 return os.str();
72 }
73};
74} // namespace mars
75
76#endif // WRITE_CSV_H
Definition write_csv.h:21
static std::string vec_to_csv(const Eigen::VectorXd &a)
Definition write_csv.h:23
static std::string cov_mat_to_csv(const Eigen::MatrixXd &cov)
get_csv_state_with_cov_header_string generate string with state and upper triangular covariance
Definition write_csv.h:37
static std::string get_cov_header_string(const int &num_states)
Definition write_csv.h:58
Definition buffer.h:27