-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdaraRed.cpp
More file actions
156 lines (146 loc) · 3.74 KB
/
daraRed.cpp
File metadata and controls
156 lines (146 loc) · 3.74 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
"""
Author: Lukasz Sliwinski luki3141@gmail.com
date: June 2019
project: ADD GDP
This code transforms the GPS data output from the rosbag files into data in ENU frame of reference using GeographicLib
"""
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <GeographicLib/Geocentric.hpp>
#include <GeographicLib/LocalCartesian.hpp>
using namespace std;
using namespace GeographicLib;
int main(int argc, char *argv[])
{
//Initializing GeographicLib
try
{
Geocentric earth(Constants::WGS84_a(), Constants::WGS84_f());
fstream infile;
fstream outfile;
cout << argv[1]<<endl;
//opening the input and output files
string inname="data/gpsData";
inname.append(argv[1]);
string outname="data/reduced";
outname.append(argv[1]);
string line;
infile.open(inname, fstream::in);
outfile.open(outname, fstream::out | fstream::trunc);
int i = 0;
int numData = 0;
size_t found,found2;
long double lati,longi,alti;
long int secs,nsecs;
// Looking through the input file for latitude, longitude, altitude and time data to put into output file
while (!(infile.eof()))
{
infile >> line;
found = line.find("latitude");
if (found!=string::npos)
{
infile >>lati;
i++;
}
found = line.find("longitude");
if (found!=string::npos)
{
infile>>longi;
i++;
}
found = line.find("altitude");
if (found!=string::npos)
{
infile>>alti;
i++;
}
found = line.find("secs:");
if (found!=string::npos)
{
found2 = line.find("nsecs:");
if (found2!=string::npos)
{
infile>>nsecs;
i++;
}
else
{
infile>>secs;
i++;
}
}
found = line.find("---");
//If managed to collect every part of given data point the numbers are put into output file
if (found!=string::npos)
{
if (i==5)
{
outfile<<setprecision(10)<<lati<<" "<<setprecision(10)<<longi<<" "<<setprecision(10)<<alti<<" "<<secs<<" "<<nsecs<<endl;
}
i=0;
numData++;
}
}
outfile.close();
infile.close();
//opening the file to write transformed data in
infile.open(outname, fstream::in);
outname = "data/localized";
outname.append(argv[1]);
outfile.open(outname, fstream::out | fstream::trunc);
double* longAr = new double[numData];
double* latiAr = new double[numData];
double* altiAr = new double[numData];
long int* secsAr = new long int[numData];
long int* nsecsAr = new long int[numData];
double latiMean, longMean;
latiMean = 0;
longMean = 0;
long int startT;
//reading the data
for (int j=0; j<(numData-1);j++)
{
infile>>latiAr[j];
infile>>longAr[j];
infile>>altiAr[j];
infile>>secsAr[j];
infile>>nsecsAr[j];
if (j==0)
startT=secsAr[0];
secsAr[j]=secsAr[j]-startT;
latiMean+=latiAr[j];
longMean+=longAr[j];
}
latiMean = latiMean/(numData-1);
longMean = longMean/(numData-1);
cout << numData << endl;
//Every data point is transformed to ENU and saved into localized<name.txt> file
const double lat0 = 51.48244505, lon0 = -0.2180541661; //some point in testing location
LocalCartesian proj(lat0, lon0, 0, earth);
double x, y, z;
double h=0;
double xMean,yMean;
xMean=0;
yMean=0;
for (int j=0; j<numData-1;j++)
{
proj.Forward(latiAr[j], longAr[j], h, x, y, z);
outfile<<setprecision(10)<<x<<" "<<setprecision(10)<<y<<" "<<setprecision(10)<<z<<" "<<secsAr[j]<<" "<<nsecsAr[j]<<endl;
xMean+=x;
yMean+=y;
cout<<secsAr[j]<<endl;
}
cout <<setprecision(10)<<latiMean<<" "<<setprecision(10)<<longMean<<endl;
cout <<setprecision(10)<<xMean<<" "<<setprecision(10)<<yMean<<endl;
infile.close();
outfile.close();
}
catch (const exception& e)
{
cerr << "Caught exception: " << e.what() << "\n";
return 1;
}
return 0;
}