-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSLTrackerWorker.cpp
More file actions
99 lines (78 loc) · 2.72 KB
/
SLTrackerWorker.cpp
File metadata and controls
99 lines (78 loc) · 2.72 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
#include "SLTrackerWorker.h"
#include "CalibrationData.h"
#include <QSettings>
#include <QEvent>
#include <QCoreApplication>
#include "TrackerICP.h"
#include "TrackerNDT.h"
#include "TrackerPCL.h"
#include <Eigen/Eigen>
void SLTrackerWorker::setup(){
// Initialize the tracker object
tracker = new TrackerICP();
CalibrationData calibration = CalibrationData();
calibration.load("calibration.xml");
Eigen::Matrix3f Kc;
Kc << calibration.Kc(0,0), calibration.Kc(0,1), calibration.Kc(0,2),
calibration.Kc(1,0), calibration.Kc(1,1), calibration.Kc(1,2),
calibration.Kc(2,0), calibration.Kc(2,1), calibration.Kc(2,2);
tracker->setCameraMatrix(Kc);
QSettings settings("SLStudio");
writeToDisk = settings.value("writeToDisk/tracking",false).toBool();
if(writeToDisk){
// Tracking file
QString fileName = QDateTime::currentDateTime().toString("yyyyMMdd_HHmmss");
fileName.append(".track");
ofStream = new std::ofstream;
ofStream->open(fileName.toLocal8Bit().data(), std::ofstream::out);
(*ofStream) << "#V1.1 SLStudio Tracking File" << std::endl << "t_ms,Tx,Ty,Tz,Q0,Qx,Qy,Qz,RMS" << std::endl;
trackingTime.start();
}
}
void SLTrackerWorker::setReference(PointCloudConstPtr referencePointCloud){
tracker->setReference(referencePointCloud);
referenceSet = true;
return;
}
void SLTrackerWorker::trackPointCloud(PointCloudConstPtr pointCloud){
// Recursively call self until latest event is hit
busy = true;
QCoreApplication::sendPostedEvents(this, QEvent::MetaCall);
bool result = busy;
busy = false;
if(!result){
std::cerr << "SLTrackerWorker: dropped point cloud!" << std::endl;
return;
}
if(!referenceSet){
tracker->setReference(pointCloud);
referenceSet = true;
return;
}
performanceTime.start();
Eigen::Affine3f T;
bool converged;
float RMS;
tracker->determineTransformation(pointCloud, T, converged, RMS);
// Emit result
if(converged)
emit newPoseEstimate(T);
// std::cout << "Pose: " << T.matrix() << std::endl;
std::cout << "Tracker: " << performanceTime.elapsed() << "ms" << std::endl;
if(writeToDisk){
Eigen::Vector3f t(T.translation());
Eigen::Quaternionf q(T.rotation());
(*ofStream) << trackingTime.elapsed() << ",";
(*ofStream) << t.x() << "," << t.y() << "," << t.z() << ",";
(*ofStream) << q.w() << "," << q.x() << "," << q.y() << "," << q.z() << "," << RMS;
(*ofStream) << std::endl;
}
}
SLTrackerWorker::~SLTrackerWorker(){
delete tracker;
if(writeToDisk){
ofStream->flush();
ofStream->close();
delete ofStream;
}
}