-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathSystem.cpp
138 lines (102 loc) · 3.34 KB
/
System.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
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
//
// Created by buyi on 17-11-22.
//
#include "System.h"
namespace DSDTM
{
System::System(const std::string &Paramfile, const Camera_Model tSensor, const bool tbUseViewer):
mSensor(tSensor), mbUseViewer(tbUseViewer), mbReseted(false), mbPaused(false)
{
std::cout << "DSDTM" << std::endl;
if(mSensor==Mono_Pinhole)
cout << "Monocluar" <<std::endl;
else if(mSensor==RGB_PinHole)
std::cout << "RGBD" << std::endl;
Config::setParameterFile(Paramfile);
mCamera = CameraPtr(new Camera(mSensor));
mMap = new Map();
mLocalMapper = new LocalMapping(mMap);
mtLocalMapper = new std::thread(&LocalMapping::Run, mLocalMapper);
mTracker = new Tracking(mCamera, mMap, mLocalMapper);
mViewer = new Viewer(this, mTracker, mMap);
if(mbUseViewer)
mtViewer = new std::thread(&Viewer::Run, mViewer);
mTracker->SetViewer(mViewer);
}
Sophus::SE3 System::TrackRGBD(const cv::Mat &tColorImg, const cv::Mat &tDepthImg, const double ×tamp)
{
if(mSensor!=RGB_PinHole)
{
LOG(ERROR)<< "Called wrong Tracking API!" << std::endl;
std::cerr<< "Called wrong Tracking API!" << std::endl;
exit(-1);
}
while(mbPaused==true)
{
std::this_thread::sleep_for(std::chrono::milliseconds(3));
}
return mTracker->Track_RGBDCam(tColorImg, tDepthImg, timestamp);
}
void System::SaveKeyFrameTrajectoryTUM(const string &filename)
{
std::cout << "Saving KeyFrame trajectory!" <<std::endl;
std::vector<KeyFrame*> tvKeyframs = mMap->GetAllKeyFrames();
std::sort(tvKeyframs.begin(), tvKeyframs.end(), KeyFrame::CompareId);
ofstream f;
f.open(filename.c_str());
f << fixed;
for (size_t i = 0; i < tvKeyframs.size(); ++i)
{
KeyFrame *tkf = tvKeyframs[i];
Eigen::Quaterniond q = tkf->Get_Pose().inverse().unit_quaternion();
Eigen::Vector3f t = tkf->Get_CameraCnt().cast<float>();
f << setprecision(6) << tkf->mTimeStamp << setprecision(7) << " " << t(0) << " " << t(1) << " " << t(2)
<< " " << float(q.x()) << " " << float(q.y()) << " " << float(q.z()) << " " << float(q.w()) << endl;
}
}
void System::SaveCameraTrajectory(const string &filename)
{
std::cout << "Saving Camera trajectory!" <<std::endl;
std::vector<std::pair<double, Sophus::SE3>> tTrajectory = mTracker->mTrajectory;
ofstream f;
f.open(filename.c_str());
f << fixed;
for(const auto &it : tTrajectory)
{
Sophus::SE3 tPose = it.second.inverse();
Eigen::Quaterniond q = tPose.unit_quaternion();
Eigen::Vector3f t = tPose.translation().cast<float>();
f << setprecision(6) << it.first << setprecision(7) << " " << t(0) << " " << t(1) << " " << t(2)
<< " " << float(q.x()) << " " << float(q.y()) << " " << float(q.z()) << " " << float(q.w()) << endl;
}
}
void System::Shutdown()
{
mLocalMapper->RequestFinish();
mViewer->RequestFinish();
while(!mLocalMapper->IsFinished() || !mViewer->IsFinished())
{
std::this_thread::sleep_for(std::chrono::milliseconds(3));
}
}
void System::Reset()
{
mbReseted = true;
}
void System::RequestPause()
{
mbPaused = true;
}
void System::RequestStart()
{
mbPaused = false;
}
void System::OutputTimeCounter()
{
mTracker->CostTimeCount();
}
int System::GetSystemState()
{
return mTracker->GetState();
}
}