26 void Loader::load_data(std::string path_traj, std::vector<double> ×, std::vector<Eigen::Matrix<double, 7, 1>> &poses,
27 std::vector<Eigen::Matrix3d> &cov_ori, std::vector<Eigen::Matrix3d> &cov_pos) {
30 std::ifstream file(path_traj);
31 if (!file.is_open()) {
34 std::exit(EXIT_FAILURE);
38 std::string current_line;
39 while (std::getline(file, current_line)) {
42 if (!current_line.find(
"#"))
47 std::istringstream
s(current_line);
49 Eigen::Matrix<double, 20, 1> data;
52 while (std::getline(s, field,
' ')) {
54 if (field.empty() || i >= data.rows())
57 data(i) = std::atof(field.c_str());
64 times.push_back(data(0));
65 poses.push_back(data.block(1, 0, 7, 1));
67 Eigen::Matrix3d c_ori, c_pos;
68 c_ori << data(8), data(9), data(10), data(9), data(11), data(12), data(10), data(12), data(13);
69 c_pos << data(14), data(15), data(16), data(15), data(17), data(18), data(16), data(18), data(19);
70 c_ori = 0.5 * (c_ori + c_ori.transpose());
71 c_pos = 0.5 * (c_pos + c_pos.transpose());
72 cov_ori.push_back(c_ori);
73 cov_pos.push_back(c_pos);
75 times.push_back(data(0));
76 poses.push_back(data.block(1, 0, 7, 1));
87 std::exit(EXIT_FAILURE);
91 if (times.size() != poses.size()) {
94 std::exit(EXIT_FAILURE);
98 if (!cov_ori.empty() && (times.size() != cov_ori.size() || times.size() != cov_pos.size())) {
99 PRINT_ERROR(
RED "[LOAD]: Parsing error, timestamps covariance size do not match!!\n" RESET);
101 std::exit(EXIT_FAILURE);
109 void Loader::load_data_csv(std::string path_traj, std::vector<double> ×, std::vector<Eigen::Matrix<double, 7, 1>> &poses,
110 std::vector<Eigen::Matrix3d> &cov_ori, std::vector<Eigen::Matrix3d> &cov_pos) {
113 std::ifstream file(path_traj);
114 if (!file.is_open()) {
117 std::exit(EXIT_FAILURE);
121 std::string current_line;
122 while (std::getline(file, current_line)) {
125 if (!current_line.find(
"#"))
130 std::istringstream
s(current_line);
132 Eigen::Matrix<double, 20, 1> data;
135 while (std::getline(s, field,
',')) {
137 if (field.empty() || i >= data.rows())
140 data(i) = std::atof(field.c_str());
148 times.push_back(1e-9 * data(0));
149 Eigen::Matrix<double, 7, 1> imustate;
150 imustate(0, 0) = data(1, 0);
151 imustate(1, 0) = data(2, 0);
152 imustate(2, 0) = data(3, 0);
153 imustate(3, 0) = data(5, 0);
154 imustate(4, 0) = data(6, 0);
155 imustate(5, 0) = data(7, 0);
156 imustate(6, 0) = data(4, 0);
157 poses.push_back(imustate);
168 std::exit(EXIT_FAILURE);
172 if (times.size() != poses.size()) {
175 std::exit(EXIT_FAILURE);
182 std::ifstream file(path);
183 if (!file.is_open()) {
186 std::exit(EXIT_FAILURE);
190 std::string current_line;
191 while (std::getline(file, current_line)) {
194 if (!current_line.find(
"#"))
198 std::istringstream
s(current_line);
200 std::vector<double> vec;
203 while (std::getline(s, field,
' ')) {
208 vec.push_back(std::atof(field.c_str()));
212 Eigen::VectorXd temp(vec.size());
213 for (
size_t i = 0; i < vec.size(); i++) {
216 values.push_back(temp);
223 if (values.empty()) {
226 std::exit(EXIT_FAILURE);
230 int rowsize = values.at(0).rows();
231 for (
size_t i = 0; i < values.size(); i++) {
232 if (values.at(i).rows() != rowsize) {
233 PRINT_ERROR(
RED "[LOAD]: Invalid row size on line %d (of size %d instead of %d)\n" RESET, (
int)i, (
int)values.at(i).rows(), rowsize);
235 std::exit(EXIT_FAILURE);
241 std::vector<Eigen::VectorXd> &timing_values) {
244 std::ifstream file(path);
245 if (!file.is_open()) {
248 std::exit(EXIT_FAILURE);
252 std::string current_line;
253 while (std::getline(file, current_line)) {
257 if (!current_line.find(
"#")) {
259 std::istringstream
s(current_line);
263 bool skipped_first =
false;
264 while (std::getline(s, field,
',')) {
270 names.push_back(field);
271 skipped_first =
true;
277 std::istringstream
s(current_line);
279 std::vector<double> vec;
282 while (std::getline(s, field,
',')) {
287 vec.push_back(std::atof(field.c_str()));
291 Eigen::VectorXd temp(vec.size() - 1);
292 for (
size_t i = 1; i < vec.size(); i++) {
293 temp(i - 1) = vec.at(i);
295 times.push_back(vec.at(0));
296 timing_values.push_back(temp);
303 if (timing_values.empty()) {
306 std::exit(EXIT_FAILURE);
310 int rowsize = names.size();
311 for (
size_t i = 0; i < timing_values.size(); i++) {
312 if (timing_values.at(i).rows() != rowsize) {
313 PRINT_ERROR(
RED "[LOAD]: Invalid row size on line %d (of size %d instead of %d)\n" RESET, (
int)i, (
int)timing_values.at(i).rows(),
316 std::exit(EXIT_FAILURE);
322 std::vector<Eigen::VectorXd> &node_values) {
325 std::ifstream file(path);
326 if (!file.is_open()) {
329 std::exit(EXIT_FAILURE);
333 std::string current_line;
334 while (std::getline(file, current_line)) {
337 if (!current_line.find(
"#"))
341 std::istringstream
s(current_line);
343 std::vector<double> vec;
346 while (std::getline(s, field,
' ')) {
351 vec.push_back(std::atof(field.c_str()));
355 Eigen::VectorXd temp(vec.size());
356 for (
size_t i = 0; i < vec.size(); i++) {
365 times.push_back(temp(0));
366 summed_values.push_back(temp.block(1, 0, 3, 1));
367 node_values.push_back(temp.block(4, 0, temp.rows() - 4, 1));
377 std::exit(EXIT_FAILURE);
381 if (times.size() != summed_values.size() || times.size() != node_values.size()) {
384 std::exit(EXIT_FAILURE);
391 double distance = 0.0;
392 for (
size_t i = 1; i < poses.size(); i++) {
393 distance += (poses[i].block(0, 0, 3, 1) - poses[i - 1].block(0, 0, 3, 1)).norm();
static void load_data(std::string path_traj, std::vector< double > ×, std::vector< Eigen::Matrix< double, 7, 1 >> &poses, std::vector< Eigen::Matrix3d > &cov_ori, std::vector< Eigen::Matrix3d > &cov_pos)
This will load space separated trajectory into memory.
static double get_total_length(const std::vector< Eigen::Matrix< double, 7, 1 >> &poses)
Will calculate the total trajectory distance.
Evaluation and recording utilities.
static void load_data_csv(std::string path_traj, std::vector< double > ×, std::vector< Eigen::Matrix< double, 7, 1 >> &poses, std::vector< Eigen::Matrix3d > &cov_ori, std::vector< Eigen::Matrix3d > &cov_pos)
This will load comma separated trajectory into memory (ASL/ETH format)
static void load_timing_percent(std::string path, std::vector< double > ×, std::vector< Eigen::Vector3d > &summed_values, std::vector< Eigen::VectorXd > &node_values)
Load space separated timing file from pid_ros.py file.
#define PRINT_ERROR(x...)
static void load_simulation(std::string path, std::vector< Eigen::VectorXd > &values)
Load an arbitrary sized row of space separated values, used for our simulation.
static void load_timing_flamegraph(std::string path, std::vector< std::string > &names, std::vector< double > ×, std::vector< Eigen::VectorXd > &timing_values)
Load comma separated timing file from pid_ros.py file.