-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathicp_benchmark.cpp
264 lines (226 loc) · 9.06 KB
/
icp_benchmark.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/******************************************************************************
* BRICS_3D - 3D Perception and Modeling Library
* Copyright (c) 2011, GPS GmbH
*
* Author: Sebastian Blumenthal
*
*
* This software is published under a dual-license: GNU Lesser General Public
* License LGPL 2.1 and Modified BSD license. The dual-license implies that
* users of this code may choose which terms they prefer.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License LGPL and the BSD license for
* more details.
*
******************************************************************************/
#ifdef WIN32
#define _USE_MATH_DEFINES
#endif
#include <iostream>
#include <sstream>
#include "brics_3d/util/OSGPointCloudVisualizer.h"
#include "brics_3d/core/PointCloud3D.h"
#include "brics_3d/core/HomogeneousMatrix44.h"
#include "brics_3d/algorithm/nearestNeighbor/NearestNeighborANN.h"
#include "brics_3d/algorithm/nearestNeighbor/NearestNeighborFLANN.h"
#include "brics_3d/algorithm/nearestNeighbor/NearestNeighborSTANN.h"
#include "brics_3d/algorithm/registration/PointCorrespondenceKDTree.h"
#include "brics_3d/algorithm/registration/PointCorrespondenceGenericNN.h"
#include "brics_3d/algorithm/registration/RigidTransformationEstimationSVD.h"
#include "brics_3d/algorithm/registration/RigidTransformationEstimationHELIX.h"
#include "brics_3d/algorithm/registration/RigidTransformationEstimationAPX.h"
#include "brics_3d/algorithm/registration/RigidTransformationEstimationORTHO.h"
#include "brics_3d/algorithm/registration/RigidTransformationEstimationQUAT.h"
#include "brics_3d/algorithm/registration/IterativeClosestPoint.h"
#include "brics_3d/algorithm/registration/IIterativeClosestPointSetup.h"
#include "brics_3d/util/Timer.h"
#include "brics_3d/util/Benchmark.h"
#include <Eigen/Geometry>
using namespace std;
using namespace Eigen;
using namespace brics_3d;
//#include "Image/ImageProcessor.h"
//#include "Image/ByteImage.h"
//#include <stdio.h>
int main(int argc, char **argv) {
/*
* set up icp
*
* pointCorrespondence
* 0 k-d tree
* 1 ANN
* 2 FLANN
* 3 STANN
*
* rigidTransformationEstimation
* 0 SVD
* 1 QUAT
* 2 HELIX
* 3 APX
* (ORTHO does not work)
*
*/
int pointCorrespondence = 0;
int rigidTransformationEstimation = 0;
/* check arguments */
string filename1;
string filename2;
if (argc == 1) {
cout << "Usage: " << argv[0] << " <filename>" << " <filename>" << "[p2p-algo transEst-algo]" << endl;
char defaultFilename1[255] = { BRICS_MODELS_DIR };
strcat(defaultFilename1, "/scan1.txt\0");
filename1 = defaultFilename1;
char defaultFilename2[255] = { BRICS_MODELS_DIR };
strcat(defaultFilename2, "/scan2.txt\0");
filename2 = defaultFilename2;
cout << "Trying to get default files: " << filename1 << ", " << filename2 << endl;
} else if (argc == 3) {
filename1 = argv[1];
filename2 = argv[2];
cout << filename1 << ", " << filename2 << endl;
// } else if (argc == 5) {
// filename1 = argv[1];
// filename2 = argv[2];
// pointCorrespondence = atoi[3];
// rigidTransformationEstimation = atoi[4];
// cout << filename1 << ", " << filename2 << endl;
} else {
cout << "Usage: " << argv[0] << " <filename>" << " <filename>" << endl;
return -1;
}
Timer timer0;
long double tmpTimeStamp = 0.0;
Benchmark icpBenchmark("icp_blackbox");
icpBenchmark.output << "#Algorithm index combination, time for matching [ms], number iterations, resulting error" << endl;
PointCloud3D* pointCloud1 = new PointCloud3D();
PointCloud3D* pointCloud2 = new PointCloud3D();
pointCloud1->readFromTxtFile(filename1);
cout << "Size of first point cloud: " << pointCloud1->getSize() << endl;
pointCloud2->readFromTxtFile(filename2);
cout << "Size of second point cloud: " << pointCloud2->getSize() << endl;
// PointCloud3D* pointCloud3 = new PointCloud3D();
// stringstream tmpSteam;
// tmpSteam << *pointCloud1;
// tmpSteam << *pointCloud2;
// tmpSteam >> *pointCloud3;
// cout << "Size of third point cloud: " << pointCloud3->getSize() << endl;
/* manipulate second point cloud */
// AngleAxis<double> rotation(M_PI_2l/4.0, Vector3d(1,0,0));
AngleAxis<double> rotation(M_PI_2/4.0, Vector3d(1,0,0));
Transform3d transformation;
transformation = rotation;
// OSGPointCloudVisualizer* viewer = new OSGPointCloudVisualizer();
//viewer->addPointCloud(pointCloud3, 1.0f, 0.0f, 0.0f, 1.0f); //combined version
//viewer->addPointCloud(pointCloud2, 1.0f, 0.0f, 0.0f, 1.0f);
// viewer->addPointCloud(pointCloud1, 0.0f, 1.0f, 0.0f, 1.0f); //initial
IIterativeClosestPoint* icp = 0; //abstract interface to ICP
IIterativeClosestPointSetup* icpConfigurator = 0; //abstract interface to ICP
IPointCorrespondence* assigner = 0; //only needed for generic icp
INearestPoint3DNeighbor* nearestNeigbourFinder = 0;
IRigidTransformationEstimation* estimator = 0;
IterativeClosestPoint* concreteIcp = 0;
// IterativeClosestPoint6DSLAM* concreteIcp6DSLAM;
// /* set up assigner */
// INearestNeighbor* nearestNeigbourFinder = new NearestNeighborFLANN();
//// nearestNeigbourFinder->setMaxDistance(1);
// NearestNeighborFLANN* nearestNeigbourFinderFLANN = dynamic_cast<NearestNeighborFLANN*>(nearestNeigbourFinder); //polymorph down cast
// FLANNParameters parameters;
// parameters = nearestNeigbourFinderFLANN->getParameters();
//// parameters.algorithm = KMEANS;
// parameters.target_precision = -1;
// parameters.trees = 16;
// nearestNeigbourFinderFLANN->setParameters(parameters);
for (int i = 0; i <= 3; ++i) { // loop over all combinations
for (int j = 0; j <= 3; ++j) {
pointCorrespondence = i;
rigidTransformationEstimation = j;
/* alwas read _fresh_ data */
pointCloud1->getPointCloud()->clear();
pointCloud1->readFromTxtFile(filename1);
cout << "Size of first point cloud: " << pointCloud1->getSize() << endl;
pointCloud2->getPointCloud()->clear();
pointCloud2->readFromTxtFile(filename2);
cout << "Size of second point cloud: " << pointCloud2->getSize() << endl;
/* set up point-to-point correspondence */
switch (pointCorrespondence) {
case 0:
assigner = new PointCorrespondenceKDTree();
cout << "INFO: Using PointCorrespondenceKDTree." << endl;
break;
case 1:
nearestNeigbourFinder = new NearestNeighborANN();
assigner = new PointCorrespondenceGenericNN(nearestNeigbourFinder);
cout << "INFO: Using PointCorrespondenceGenericNN with NearestNeighborANN." << endl;
break;
case 2:
nearestNeigbourFinder = new NearestNeighborFLANN();
assigner = new PointCorrespondenceGenericNN(nearestNeigbourFinder);
cout << "INFO: Using PointCorrespondenceGenericNN with NearestNeighborFLANN." << endl;
break;
case 3:
nearestNeigbourFinder = new NearestNeighborSTANN();
assigner = new PointCorrespondenceGenericNN(nearestNeigbourFinder);
cout << "INFO: Using PointCorrespondenceGenericNN with NearestNeighborSTANN." << endl;
break;
default:
cout << "ERROR: No pointCorrespondence algorithm given." << endl;
return -1;
break;
}
/* setup estimator */
switch (rigidTransformationEstimation) {
case 0:
estimator = new RigidTransformationEstimationSVD();
cout << "INFO: Using RigidTransformationEstimationSVD." << endl;
break;
case 1:
estimator = new RigidTransformationEstimationQUAT();
cout << "INFO: Using RigidTransformationEstimationQUAT." << endl;
break;
case 2:
estimator = new RigidTransformationEstimationHELIX();
cout << "INFO: Using RigidTransformationEstimationHELIX." << endl;
break;
case 3:
estimator = new RigidTransformationEstimationAPX();
cout << "INFO: Using RigidTransformationEstimationAPX." << endl;
break;
default:
cout << "ERROR: No rigidTransformationEstimation algorithm given." << endl;
return -1;
break;
}
icpBenchmark.output << i << j << " ";
// icp = new IterativeClosestPoint(assigner, estimator);
concreteIcp = new IterativeClosestPoint(assigner, estimator);
icp = dynamic_cast<IIterativeClosestPoint*>(concreteIcp);
icpConfigurator = dynamic_cast<IIterativeClosestPointSetup*>(concreteIcp);
/* invoke ICP */
IHomogeneousMatrix44* resultTransformation = new HomogeneousMatrix44();
icpConfigurator->setMaxIterations(100);
timer0.reset();
icp->match(pointCloud1, pointCloud2, resultTransformation);
tmpTimeStamp = timer0.getElapsedTime();
icpBenchmark.output << tmpTimeStamp << " ";
icpBenchmark.output << concreteIcp->icpresultIterations << " ";
icpBenchmark.output << concreteIcp->icpResultError << " ";
icpBenchmark.output << endl;
cout << concreteIcp->icpresultIterations << "ITS, " << concreteIcp->icpResultError << "RMS" << endl;
cout << "Time for matching [ms]: " << tmpTimeStamp << endl;
}
}
// viewer->visualizePointCloud(pointCloud2, 1.0f, 1.0f, 1.0f, 1.0f);
//viewer->visualizePointCloud(pointCloud3, 1.0f,0.0f,1.0f,1.0f);
/* clean up */
delete icp;
//delete estimator; //TODO: crashes (+following lines)
//delete assigner;
// delete viewer;
delete pointCloud2;
delete pointCloud1;
return 0;
}
/* EOF */