-
Notifications
You must be signed in to change notification settings - Fork 2
/
file_parser.cpp
66 lines (62 loc) · 1.67 KB
/
file_parser.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <Eigen/Geometry>
using namespace std;
using namespace Eigen;
vector<int> find_spaces(string line){
char space = ' ';
vector<int> index;
for(int i=0; i<line.length(); ++i){
if(line[i]==space){
index.push_back(i);
}
}
return index;
}
vector<double> extract_substring(string line, vector<int> spaces){
vector<double> substrings;
for(int i=0; i<9; ++i){
string word{};
for(int j=spaces[i]+1; j<spaces[i+1]; ++j){
word += line[j];
}
substrings.push_back(stod(word));
}
return substrings;
}
int main(int argc, char const *argv[]){
if(argc!=3){
cerr << "Usage: ./file_parser input.g2o output_isam.txt\n";
return 1;
}
ifstream file_read(argv[1]);
ofstream file_write(argv[2]);
string line;
string keyword = "EDGE_SE3:QUAT";
string covariance2 = " 50 0 0 50 0 100";
string covariance3 = " 10 0 0 0 0 0 10 0 0 0 0 10 0 0 0 100 0 0 100 0 25";
vector<double> sub;
if(file_read.is_open()){
while(getline(file_read, line)){
size_t found = line.find(keyword);
if(found!=std::string::npos){
sub = extract_substring(line, find_spaces(line));
Quaternionf q(sub[8],sub[5],sub[6],sub[7]);
for(int i=0; i<sub.size(); ++i){
cout << sub[i] << " ";
}
auto euler = q.toRotationMatrix().eulerAngles(0, 1, 2);
cout << endl << euler << endl;
fprintf(stdout, "Final pose_i pose_j x y yaw:%g %g %g %g %g\n",sub[0], sub[1], sub[2], sub[3], euler[2] );
file_write << "EDGE2 "<<sub[0]<<" "<<sub[1]<<" "<<sub[2]<<" "<<sub[3]<<" "<< euler[2]<<covariance2<< endl ;
}
}
file_read.close();
file_write.close();
}
else
cout << "Unable to read file!!\n";
return 0;
}