This repository has been archived by the owner on May 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
97 lines (86 loc) · 2.92 KB
/
main.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
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
// import libraries
#include <fstream>
#include <math.h>
#include <iostream>
#include <vector>
#include <sstream>
using namespace std;
// main code here
int main(){
// Configuraitons
string configCamera = "./Camera.config";
string configPositions = "./Positions.config";
// read the parameters of the camera
ifstream inConfigCamera(configCamera.c_str(), ifstream::in); // handle
string line; // temporary line
// focal length
double f;
// z
double z;
while(getline(inConfigCamera,line)){ // until the last line do your best :D
istringstream iss(line);
iss >> f;
iss >> z;
}
// read the list of motion actions
vector<double> motionActionsD;
vector<double> motionActionsTheta;
ifstream inConfigPositions(configPositions.c_str(), ifstream::in); // handle
while(getline(inConfigPositions,line)){ // until the last line do your best :D
istringstream iss(line);
// translation
double d;
// heading
double theta;
iss >> d;
iss >> theta;
motionActionsD.push_back(d);
motionActionsTheta.push_back(theta);
}
// initial pose by command line
double xInit;
double yInit;
double thetaInit;
double xFinal;
double yFinal;
double thetaFinal;
cout << "Please enter the initial position x: ";
cin >> xInit;
cout << "Please enter the initial position y: ";
cin >> yInit;
cout << "Please enter the initial rotation theta: ";
cin >> thetaInit;
// homogeneous transformation matrix
// T = (cosTheta, -sinTheta, xt)
// (sinTheta, cosTheta, yt)
// (0, 0, 1)
// p' = T*p roto-translation
// #TODO: vectorized form is easier, change it to matrix later
// #TODO: Check the perforrrrrrrrrrrrrrrrrrrrrrrmance later
int allMotions = motionActionsD.size();
double x = xInit;
double y = yInit;
for (int i = 0; i < allMotions ; ++i){
double d = motionActionsD[i];
double theta = motionActionsTheta[i];
double cosTheta = cos(theta);
double sinTheta = sin(theta);
xFinal = x*cosTheta - y*sinTheta + d;
yFinal = x*sinTheta + y*cosTheta + d;
x = xFinal;
y = yFinal;
}
// calculate the initial and final position projection
// (x,y,f) = f/z (x,y,z) image projection, the pinhole camera
double m = f/z; // camera parameter
double xProjectedI = m * xInit;
double xProjectedF = m * xFinal;
double yProjectedI = m * yInit;
double yProjectedF = m * yFinal;
double thetaProjectedI = m * thetaInit;
double thetaProjectedF = m * thetaFinal;
// print the results
cout << "Projected Initial Position: " << xProjectedI << ", "<< yProjectedI << ", " << thetaProjectedI << endl;
cout << "Projected Final Position: " << xProjectedF << ", "<< yProjectedF << ", " << thetaProjectedF << endl;
return 0;
}