-
Notifications
You must be signed in to change notification settings - Fork 10
/
stem_matching.h
117 lines (99 loc) · 3.92 KB
/
stem_matching.h
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
/*
* 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.
*
*/
#ifndef GLOBALMATCH_STEM_MATCHING_H
#define GLOBALMATCH_STEM_MATCHING_H
#include "common.h"
#include <pcl/kdtree/kdtree_flann.h>
#include <pcl/common/distances.h>
#include <pcl/PolygonMesh.h>
#include <pcl/registration/transformation_estimation_2D.h>
#include <algorithm>
#include <vector>
#include <set>
#include <fstream>
#include <numeric>
class Matching {
public:
Matching() : knn_(20),
max_stems_for_exhaustive_search_(50),
edge_diff_(0.05),
stem_positions_src_(new Cloud3D),
stem_positions_tgt_(new Cloud3D) {
}
inline void
setPairwiseStemPositions(const Cloud3D::ConstPtr& stem_positions_src,
const Cloud3D::ConstPtr& stem_positions_tgt) {
stem_positions_src_ = stem_positions_src;
stem_positions_tgt_ = stem_positions_tgt;
}
void
estimateTransformation(Eigen::Matrix4f& transform);
inline size_t
getNumberOfMatches() {
return stem_matches_.size();
};
// TODO: add setters and getters
private:
struct VertexSide {
int vertex;
float side;
};
typedef std::vector<VertexSide> Triangle;
void
constructTriangles(const Cloud3D::ConstPtr& stem_positions,
std::vector<Triangle>& triangles) const;
bool
satisfyLocalConsistency(const Point3D& feature_src,
const Point3D& feature_tgt) const;
bool
satisfyGlobalConsistency(const std::vector<int>& pair_initial,
const std::vector<int>& pair_candidate);
void
localMatching();
void
globalMatching();
/**
* @brief Accelerate global matching by growing only a limited number of (e.g., 10k)
* randomly sampled groups of triangle pairs. Use this function if your point cloud contains
* a large number of trees (e.g., more than 10k trees per point cloud).
*/
void
randomGlobalMatching();
Cloud3D::ConstPtr stem_positions_src_, stem_positions_tgt_;
std::vector<Triangle> triangles_src_, triangles_tgt_;
std::vector<std::pair<int, int>> locally_matched_pairs_;
std::vector<int> globally_matched_pairs_;
pcl::Correspondences stem_matches_;
int knn_;
int max_stems_for_exhaustive_search_;
float edge_diff_;
};
#endif //GLOBALMATCH_STEM_MATCHING_H