Bench-MR
A Motion Planning Benchmark for Wheeled Mobile Robots
Table.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <QtCharts/QVXYModelMapper>
4#include <QtCore/QAbstractTableModel>
5#include <QtCore/QRect>
6#include <QtWidgets/QHeaderView>
7#include <QtWidgets/QTableView>
8
9#include <iomanip>
10#include <sstream>
11
13
14class Table : public QAbstractTableModel {
15 public:
16 explicit Table(QObject *parent = nullptr) : QAbstractTableModel(parent) {}
17
18 std::vector<std::string> header;
19 std::vector<std::pair<std::string, std::vector<double> > > rows;
20
21 QWidget *createWidget() {
22 auto *tableView = new QTableView;
23 tableView->setModel(this);
24 tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
25 tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
26 tableView->show();
27 return tableView;
28 }
29
30 std::string str() const {
31 std::vector<int> columnSizes(header.size() + 1, 0);
32 for (auto &row : rows)
33 columnSizes[0] = std::max((int)row.first.length(), columnSizes[0]);
34 for (int i = 0; i < header.size(); ++i)
35 columnSizes[i + 1] = std::max((int)header[i].length(), 15);
36 std::stringstream ss;
37 ss << std::setw(columnSizes[0]) << " ";
38 int c = 1;
39 for (auto &h : header) ss << std::setw(columnSizes[c++]) << h;
40 ss << std::endl;
41 for (auto &row : rows) {
42 ss << std::setw(columnSizes[0]) << row.first;
43 c = 1;
44 for (auto d : row.second)
45 ss << std::setw(columnSizes[c++]) << std::setprecision(10) << std::right
46 << d;
47 ss << std::endl;
48 }
49 return ss.str();
50 }
51
52 std::string latex() const {
53 std::vector<int> columnSizes(header.size() + 1, 0);
54 for (auto &row : rows)
55 columnSizes[0] = std::max((int)row.first.length(), columnSizes[0]);
56 for (int i = 0; i < header.size(); ++i)
57 columnSizes[i + 1] = std::max((int)header[i].length(), 20);
58 std::stringstream ss;
59 ss << std::setw(columnSizes[0]);
60 int c = 1;
61 for (auto &h : header) ss << " & " << std::setw(columnSizes[c++]) << h;
62 ss << " \\\\\\hline" << std::endl;
63 for (auto &row : rows) {
64 ss << std::setw(columnSizes[0]) << row.first;
65 c = 1;
66 double m = stat::min(row.second);
67 for (auto d : row.second) {
68 ss << " & " << std::setw(columnSizes[c++]);
69 if (d == m) ss << "\\bfseries ";
70 ss << std::setprecision(4) << std::right << d;
71 }
72 ss << " \\\\" << std::endl;
73 }
74 return ss.str();
75 }
76
77 int rowCount(const QModelIndex &parent = QModelIndex()) const override {
78 return static_cast<int>(rows.size() + 1);
79 }
80
81 int columnCount(const QModelIndex &parent = QModelIndex()) const override {
82 return static_cast<int>(header.size());
83 }
84
85 QVariant headerData(int section, Qt::Orientation orientation,
86 int role = Qt::DisplayRole) const override {
87 if (orientation == Qt::Horizontal)
88 return QString::fromStdString(header[section % header.size()]);
89 return QString::fromStdString(rows[section % rows.size()].first);
90 }
91
92 QVariant data(const QModelIndex &index,
93 int role = Qt::DisplayRole) const override {
94 if (index.row() <= rowCount() - 1 && index.column() <= columnCount() - 1)
95 return rows[index.row()].second[index.column()];
96 return QVariant();
97 }
98
99 Qt::ItemFlags flags(const QModelIndex &index) const override {
100 return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
101 }
102
103 void addStatsRows(std::string columnName, const std::vector<double> &values1,
104 const std::vector<double> &values2,
105 const std::vector<double> &values3,
106 const std::vector<double> &values4,
107 const std::vector<double> &values5) {
108 rows.push_back(std::make_pair<std::string, std::vector<double> >(
109 "Mdn " + columnName,
110 std::vector<double>{
111 values1.empty() ? std::nan("N/A") : stat::median(values1),
112 values2.empty() ? std::nan("N/A") : stat::median(values2),
113 values3.empty() ? std::nan("N/A") : stat::median(values3),
114 values4.empty() ? std::nan("N/A") : stat::median(values4),
115 values5.empty() ? std::nan("N/A") : stat::median(values5)}));
116 rows.push_back(std::make_pair<std::string, std::vector<double> >(
117 "Avg " + columnName,
118 std::vector<double>{
119 values1.empty() ? std::nan("N/A") : stat::mean(values1),
120 values2.empty() ? std::nan("N/A") : stat::mean(values2),
121 values3.empty() ? std::nan("N/A") : stat::mean(values3),
122 values4.empty() ? std::nan("N/A") : stat::mean(values4),
123 values5.empty() ? std::nan("N/A") : stat::mean(values5)}));
124 rows.push_back(std::make_pair<std::string, std::vector<double> >(
125 "Min " + columnName,
126 std::vector<double>{
127 values1.empty() ? std::nan("N/A") : stat::min(values1),
128 values2.empty() ? std::nan("N/A") : stat::min(values2),
129 values3.empty() ? std::nan("N/A") : stat::min(values3),
130 values4.empty() ? std::nan("N/A") : stat::min(values4),
131 values5.empty() ? std::nan("N/A") : stat::min(values5)}));
132 rows.push_back(std::make_pair<std::string, std::vector<double> >(
133 "Max " + columnName,
134 std::vector<double>{
135 values1.empty() ? std::nan("N/A") : stat::max(values1),
136 values2.empty() ? std::nan("N/A") : stat::max(values2),
137 values3.empty() ? std::nan("N/A") : stat::max(values3),
138 values4.empty() ? std::nan("N/A") : stat::max(values4),
139 values5.empty() ? std::nan("N/A") : stat::max(values5)}));
140 rows.push_back(std::make_pair<std::string, std::vector<double> >(
141 "Std " + columnName,
142 std::vector<double>{
143 values1.empty() ? std::nan("N/A") : stat::std(values1),
144 values2.empty() ? std::nan("N/A") : stat::std(values2),
145 values3.empty() ? std::nan("N/A") : stat::std(values3),
146 values4.empty() ? std::nan("N/A") : stat::std(values4),
147 values5.empty() ? std::nan("N/A") : stat::std(values5)}));
148 }
149};
int orientation(const Point &p, const Point &q, const Point &r)
Definition: Primitives.cpp:100
Definition: Table.hpp:14
QWidget * createWidget()
Definition: Table.hpp:21
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: Table.hpp:99
std::string str() const
Definition: Table.hpp:30
std::vector< std::pair< std::string, std::vector< double > > > rows
Definition: Table.hpp:19
void addStatsRows(std::string columnName, const std::vector< double > &values1, const std::vector< double > &values2, const std::vector< double > &values3, const std::vector< double > &values4, const std::vector< double > &values5)
Definition: Table.hpp:103
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: Table.hpp:92
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: Table.hpp:81
std::string latex() const
Definition: Table.hpp:52
Table(QObject *parent=nullptr)
Definition: Table.hpp:16
std::vector< std::string > header
Definition: Table.hpp:18
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Definition: Table.hpp:85
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: Table.hpp:77
double max(const std::vector< double > &values)
Definition: PathStatistics.hpp:79
double std(const std::vector< double > &values)
Definition: PathStatistics.hpp:85
double min(const std::vector< double > &values)
Definition: PathStatistics.hpp:73
double median(std::vector< double > values)
Definition: PathStatistics.hpp:57
double mean(const std::vector< double > &values)
Definition: PathStatistics.hpp:67