-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSmartDownSample.h
162 lines (146 loc) · 4.91 KB
/
SmartDownSample.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
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
//
// Created by yyh on 22-7-12.
//
#ifndef CENTRAL_VOTING_SMARTDOWNSAMPLE_H
#define CENTRAL_VOTING_SMARTDOWNSAMPLE_H
#define PCL_NO_PRECOMPILE
#include <pcl/features/normal_3d.h>
#include <pcl/features/ppf.h>
#include <pcl/filters/extract_indices.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/io/pcd_io.h>
#include <pcl/io/ply_io.h>
#include <pcl/registration/ppf_registration.h>
#include <pcl/sample_consensus/method_types.h>
#include <pcl/sample_consensus/model_types.h>
#include <pcl/segmentation/sac_segmentation.h>
#include <pcl/visualization/pcl_visualizer.h>
#include "Eigen/Core"
#include "pcl/point_cloud.h"
#include "pcl/point_types.h"
#include <pcl/common/transforms.h>
#include <pcl/console/parse.h> //pcl控制台解析
#include <pcl/console/parse.h>
#include <pcl/features/fpfh_omp.h> //包含fpfh加速计算的omp(多核并行计算)
#include <pcl/features/integral_image_normal.h>
#include <pcl/filters/approximate_voxel_grid.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/registration/correspondence_estimation.h>
#include <pcl/registration/correspondence_rejection_features.h> //特征的错误对应关系去除
#include <pcl/registration/correspondence_rejection_sample_consensus.h> //随机采样一致性去除
#include <pcl/registration/icp.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <tbb/concurrent_vector.h>
#include <Eigen/Core>
#include <boost/thread/thread.hpp>
#include <iostream>
#include <thread>
#include "pcl/features/moment_of_inertia_estimation.h"
#include "pcl/features/normal_3d.h"
#include "pcl/features/normal_3d_omp.h"
#include "pcl/filters/filter.h"
#include "pcl/search/kdtree.h"
#include "pcl/impl/point_types.hpp"
#include <pcl/common/common.h>
#include "queue"
class SmartDownSample {
public:
SmartDownSample(const pcl::PointCloud<pcl::PointXYZ>::Ptr &input_cloud,
const std::pair<double, double> x_range,
const std::pair<double, double> y_range,
const std::pair<double, double> z_range, const float &step,
const float &angleThreshold, const float &distanceThreshold)
: input_cloud(input_cloud),
x_range(x_range),
y_range(y_range),
z_range(z_range),
step(step),
angleThreshold(angleThreshold),
distanceThreshold(distanceThreshold){};
/** \brief Smart down sample method, if the angle between two point normals
* bigger than angle threshold, this two point will also be sampled
* \param[out] the subsampled point cloud
*/
pcl::PointCloud<pcl::PointNormal>::Ptr compute();
/** \brief Set the radius of normal estimation
* \param[in] radius
*/
void setRadius(float data);
void setKSearch(const int data);
/** \brief Calculate the distance between two points
* \param[in] points
*/
template <class T>
float calculateDistance(T &pointA, T &pointB);
template <class T>
float calculateDistance(T &pointA, pcl::PointNormal &pointB);
void setIsdense(const bool &data);
void setViewPoint(const Eigen::Vector3f &view_point_){
this->view_point = view_point_;
isSetViewPoint = true;
}
void setViewPoint(const Eigen::Vector3f &&view_point_){
this->view_point = view_point_;
isSetViewPoint = true;
}
void setReverse(const bool &flag){
this->reverse = flag;
}
private:
decltype(auto) getMeanPointNormal(const std::vector<pcl::PointNormal> &cluster){
pcl::PointNormal Mean{};
for(auto &i:cluster){
Mean.x+=i.x;
Mean.y+=i.y;
Mean.z+=i.z;
Mean.normal_x+=i.normal_x;
Mean.normal_y+=i.normal_y;
Mean.normal_z+=i.normal_z;
Mean.curvature+=i.curvature;//对曲率做了平均处理
}
auto num = cluster.size();
Mean.x/=num;
Mean.y/=num;
Mean.z/=num;
Mean.curvature/=num;
Eigen::Vector3f normal_{Mean.normal_x,Mean.normal_y,Mean.normal_z};
normal_ = normal_.normalized();
Mean.normal_x = normal_[0];
Mean.normal_y = normal_[1];
Mean.normal_z = normal_[2];
return Mean;
}
struct data{
int i;
int j;
pcl::PointNormal Mean{};
data(const int &i_, const int &j_, const pcl::PointNormal &Mean_ ):i(i_), j(j_), Mean(Mean_){}
};
struct cmp {
bool operator()(data a, data b) {
if (a.i == b.i)
return a.j > b.j;
else
return a.i > b.i;
}
};
pcl::PointCloud<pcl::PointXYZ>::ConstPtr input_cloud;
std::pair<double, double> x_range;
std::pair<double, double> y_range;
std::pair<double, double> z_range;
std::priority_queue<data, std::vector<data>, cmp>q;
float step;
float angleThreshold, distanceThreshold;
float normal_estimation_search_radius;
Eigen::Vector3f view_point{};
int normal_estimation_search_k_points;
bool isSetRadius = false;
bool isSetPoints = false;
bool isdense = false;
bool reverse = false;
bool isSetViewPoint = false;
};
#endif // CENTRAL_VOTING_SMARTDOWNSAMPLE_H