-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathssa_to_pcd.cpp
116 lines (101 loc) · 3.06 KB
/
ssa_to_pcd.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
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <istream>
#include <fstream>
#include <sstream>
#include <list>
#include <cstring>
#include <limits>
#include <cmath>
#include "Eigen/Core"
#include "pcl/io/pcd_io.h"
#include "pcl/point_types.h"
#include "pcl/point_cloud.h"
#include "pcl/common/transforms.h"
#include "pcl/common/eigen.h"
#include "pcl_ssa_hierarchical.h"
using namespace std;
using namespace ssa;
const char *message[]={
"ssa_to_pcd: converts a ssa3d graph into one pcd point cloud file",
"usage ssa_convert_to_pcd: [options] <ssa3d_file> <pcd_file>",
"options:",
"-p [string] set prefix and enable dumping of single view point clouds to disk.",
0
};
int main(int argc, char **argv)
{
if (argc<3){
const char**v=message;
while (*v){
cout << *v << endl;
v++;
}
return 0;
}
const char* ssaFile=0;
const char* outputFile=0;
string pcPrefix = "ssa_model";
bool saveViews = false;
bool reproject = false;
int c=1;
while (c<argc){
if (!strcmp(argv[c],"-p")){
c++;
pcPrefix=argv[c];
c++;
saveViews = true;
}
if (!strcmp(argv[c],"-r")){
reproject=true;
c++;
}
if (! ssaFile){
ssaFile=argv[c];
c++;
}
if (! outputFile){
outputFile=argv[c];
c++;
break;
}
}
cerr << ssaFile << " -> " << outputFile << endl;
//Create ssa 3d graph
SparseSurfaceAdjustmentGraph3D ssaGraph;
//Load SSA3D graph
ssaGraph.load(ssaFile);
pcl::PointCloud<pcl::PointXYZRGBA> cloud;
if(reproject){
cloud = PCLSSAHierarchicalT<pcl::PointCloud<pcl::PointXYZRGBA> >::landmarksToPointCloud(ssaGraph._edges_observations);
} else {
int i = 0;
std::map<int, int> keys = ssaGraph.getScanIds();
for(std::map<int, int>::iterator it = keys.begin(); it != keys.end(); ++it){
int scanId = it->first;
pcl::PointCloud<pcl::PointXYZRGBA> tmp = PCLSSAHierarchicalT<pcl::PointCloud<pcl::PointXYZRGBA> >::landmarksToPointCloud(ssaGraph._verticies_observations[scanId]);
//copy points to global point cloud
std::copy(tmp.points.begin(), tmp.points.end(), back_inserter(cloud.points));
if(saveViews){
//transform points in local coordinate frame (scan)
g2o::VertexSE3* v = dynamic_cast<g2o::VertexSE3*>(ssaGraph._optimizer.vertex(scanId));
Eigen::Affine3f transformation = v->estimate().cast<float>();
pcl::transformPointCloud(tmp, tmp, transformation.inverse());
float x, y, z, roll, pitch, yaw;
pcl::getTranslationAndEulerAngles(transformation, x, y, z, roll, pitch, yaw);
tmp.sensor_origin_(0) = x;
tmp.sensor_origin_(1) = y;
tmp.sensor_origin_(2) = z;
tmp.sensor_origin_(3) = 1;
tmp.sensor_orientation_ = transformation.rotation();
char filename[128];
sprintf(filename, "%s%05d.pcd", pcPrefix.c_str(), i);
cerr << "saving file:" << filename << endl;
pcl::io::savePCDFileBinary(filename, tmp);
i++;
}
}
}
pcl::io::savePCDFileBinary(outputFile , cloud);
}