-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.cpp
142 lines (130 loc) · 5.4 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
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
/*
* Software License Agreement (Apache License)
*
* Copyright (C) 2023, Xufei Wang ([email protected]),
* Zexin Yang ([email protected]),
* Liangliang Nan ([email protected]).
* All rights reserved.
*
* This file is part of GlobalMatch (https://github.com/zexinyang/GlobalMatch),
* which implements the point cloud registration method described in the following paper:
* -----------------------------------------------------------------------------------------------------------
* GlobalMatch: Registration of forest terrestrial point clouds by global matching of relative stem positions.
* Xufei Wang, Zexin Yang, Xiaojun Cheng, Jantien Stoter, Wenbing Xu, Zhenlun Wu, and Liangliang Nan.
* ISPRS Journal of Photogrammetry and Remote Sensing. Vol. 197, 71-86, 2023.
* -----------------------------------------------------------------------------------------------------------
* We kindly ask you to cite the above paper if you use (part of) the code or ideas in your academic work.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include <iomanip>
// PCL
#include <pcl/io/ply_io.h>
#include <pcl/console/parse.h>
// GlobalMatch
#include "stem_mapping.h"
#include "stem_matching.h"
using namespace pcl::console;
void
writeTransformationMatrix(const std::string& output_file,
const Eigen::Matrix4f& transformation_matrix) {
std::ofstream outFile(output_file);
if (outFile.is_open()) {
outFile << std::setprecision(8) << std::fixed << transformation_matrix; // write matrix to file
outFile.close();
} else {
// handle error or throw exception
std::cerr << "Unable to open file: " + output_file << std::endl;
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int
main(int argc, char** argv) {
#if defined(_OPENMP)
print_info("[PARALLEL PROCESSING USING ");
print_value("%d", omp_get_max_threads());
print_info(" THREADS] \n\n");
#else
print_info("[NON-PARALLEL PROCESSING] \n\n");
#endif
std::string filename_source = argv[1];
std::string filename_target = argv[2];
std::string filename_result = argv[3];
double tic, toc, time_val = 0.0;
//============================= Load Data =============================
std::cout << "1. LOADING RAW POINT CLOUDS:" << std::endl;
Cloud3D::Ptr cloud_src(new Cloud3D), cloud_tgt(new Cloud3D);
tic = omp_get_wtime();
pcl::io::loadPLYFile<Point3D>(filename_source, *cloud_src);
toc = omp_get_wtime();
print_info(" (1) ");
print_value("%d", cloud_src->size());
print_info(" source points in ");
print_value("%f", toc - tic);
print_info(" s.\n");
tic = omp_get_wtime();
pcl::io::loadPLYFile<Point3D>(filename_target, *cloud_tgt);
toc = omp_get_wtime();
print_info(" (2) ");
print_value("%d", cloud_tgt->size());
print_info(" target points in ");
print_value("%f", toc - tic);
print_info(" s.\n");
//======================= Pairwise Registration =======================
std::cout << "2. MAPPING STEMS:" << std::endl;
Cloud3D::Ptr cloud_pos_src(new Cloud3D), cloud_pos_tgt(new Cloud3D);
tic = omp_get_wtime();
Mapping mapping;
mapping.setInputCloud(cloud_src->makeShared());
mapping.extract(cloud_pos_src);
toc = omp_get_wtime();
time_val += (toc - tic);
print_info(" (1) ");
print_value("%d", cloud_pos_src->size());
print_info(" source stem positions in ");
print_value("%f", toc - tic);
print_info(" s.\n");
tic = omp_get_wtime();
mapping.setInputCloud(cloud_tgt->makeShared());
mapping.extract(cloud_pos_tgt);
toc = omp_get_wtime();
time_val += (toc - tic);
print_info(" (2) ");
print_value("%d", cloud_pos_tgt->size());
print_info(" target stem positions in ");
print_value("%f", toc - tic);
print_info(" s.\n");
std::cout << "3. MATCHING STEMS:" << std::endl;
tic = omp_get_wtime();
Eigen::Matrix4f mat_crs;
Matching matching;
matching.setPairwiseStemPositions(cloud_pos_src,
cloud_pos_tgt);
matching.estimateTransformation(mat_crs);
toc = omp_get_wtime();
time_val += (toc - tic);
print_info(" ");
print_value("%d", matching.getNumberOfMatches());
print_info(" pairs of correspondences in ");
print_value("%f", toc - tic);
print_info(" s.\n");
print_info("====> [Total running time] ");
print_value("%f", time_val);
print_info(" s.\n");
//============================ Output Matrix ==========================
writeTransformationMatrix(filename_result, mat_crs);
return 0;
}