forked from hku-mars/VoxelMap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreprocess.cpp
192 lines (166 loc) · 5.35 KB
/
preprocess.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
#include "preprocess.h"
#define RETURN0 0x00
#define RETURN0AND1 0x10
Preprocess::Preprocess()
: feature_enabled(0), lidar_type(AVIA), blind(0.01), point_filter_num(1) {
N_SCANS = 6;
given_offset_time = false;
}
Preprocess::~Preprocess() {}
void Preprocess::set(bool feat_en, int lid_type, double bld, int pfilt_num) {
feature_enabled = feat_en;
lidar_type = lid_type;
blind = bld;
point_filter_num = pfilt_num;
}
void Preprocess::process(const livox_ros_driver::CustomMsg::ConstPtr &msg,
PointCloudXYZI::Ptr &pcl_out) {
avia_handler(msg);
*pcl_out = pl_surf;
}
void Preprocess::process(const sensor_msgs::PointCloud2::ConstPtr &msg,
PointCloudXYZI::Ptr &pcl_out) {
switch (lidar_type) {
case L515:
l515_handler(msg);
break;
case VELO16:
velodyne_handler(msg);
break;
default:
printf("Error LiDAR Type");
break;
}
*pcl_out = pl_surf;
}
void Preprocess::avia_handler(
const livox_ros_driver::CustomMsg::ConstPtr &msg) {
pl_surf.clear();
pl_corn.clear();
pl_full.clear();
int plsize = msg->point_num;
std::vector<bool> is_valid_pt(plsize, false);
pl_corn.reserve(plsize);
pl_surf.reserve(plsize);
pl_full.resize(plsize);
for (int i = 0; i < N_SCANS; i++) {
pl_buff[i].clear();
pl_buff[i].reserve(plsize);
}
uint valid_num = 0;
for (uint i = 1; i < plsize; i++) {
if ((msg->points[i].line < N_SCANS) &&
((msg->points[i].tag & 0x30) == 0x10 ||
(msg->points[i].tag & 0x30) == 0x00)) {
valid_num++;
if (i % point_filter_num == 0) {
pl_full[i].x = msg->points[i].x;
pl_full[i].y = msg->points[i].y;
pl_full[i].z = msg->points[i].z;
pl_full[i].intensity = msg->points[i].reflectivity;
pl_full[i].curvature =
msg->points[i].offset_time /
float(1000000); // use curvature as time of each laser points
if ((abs(pl_full[i].x - pl_full[i - 1].x) > 1e-7) ||
(abs(pl_full[i].y - pl_full[i - 1].y) > 1e-7) ||
(abs(pl_full[i].z - pl_full[i - 1].z) > 1e-7) &&
(pl_full[i].x * pl_full[i].x + pl_full[i].y * pl_full[i].y +
pl_full[i].z + pl_full[i].z >
blind * blind)) {
is_valid_pt[i] = true;
}
}
}
}
for (uint i = 1; i < plsize; i++) {
if (is_valid_pt[i]) {
pl_surf.points.push_back(pl_full[i]);
}
}
}
void Preprocess::oust64_handler(const sensor_msgs::PointCloud2::ConstPtr &msg) {
pl_surf.clear();
pl_corn.clear();
pl_full.clear();
pcl::PointCloud<ouster_ros::Point> pl_orig;
pcl::fromROSMsg(*msg, pl_orig);
int plsize = pl_orig.size();
pl_corn.reserve(plsize);
pl_surf.reserve(plsize);
double time_stamp = msg->header.stamp.toSec();
// cout << "===================================" << endl;
// printf("Pt size = %d, N_SCANS = %d\r\n", plsize, N_SCANS);
for (int i = 0; i < pl_orig.points.size(); i++) {
if (i % point_filter_num != 0)
continue;
double range = pl_orig.points[i].x * pl_orig.points[i].x +
pl_orig.points[i].y * pl_orig.points[i].y +
pl_orig.points[i].z * pl_orig.points[i].z;
if (range < blind)
continue;
Eigen::Vector3d pt_vec;
PointType added_pt;
added_pt.x = pl_orig.points[i].x;
added_pt.y = pl_orig.points[i].y;
added_pt.z = pl_orig.points[i].z;
added_pt.intensity = pl_orig.points[i].intensity;
added_pt.normal_x = 0;
added_pt.normal_y = 0;
added_pt.normal_z = 0;
double yaw_angle = atan2(added_pt.y, added_pt.x) * 57.3;
if (yaw_angle >= 180.0)
yaw_angle -= 360.0;
if (yaw_angle <= -180.0)
yaw_angle += 360.0;
added_pt.curvature = pl_orig.points[i].t / 1e6;
pl_surf.points.push_back(added_pt);
}
}
void Preprocess::l515_handler(const sensor_msgs::PointCloud2::ConstPtr &msg) {
pl_surf.clear();
pcl::PointCloud<velodyne_ros::Point> pl_orig;
pcl::fromROSMsg(*msg, pl_orig);
int plsize = pl_orig.points.size();
// pl_surf.reserve(plsize);
for (int i = 0; i < pl_orig.size(); i++) {
PointType added_pt;
added_pt.x = pl_orig.points[i].x;
added_pt.y = pl_orig.points[i].y;
added_pt.z = pl_orig.points[i].z;
added_pt.intensity = pl_orig.points[i].intensity;
if (i % point_filter_num == 0) {
pl_surf.push_back(added_pt);
}
}
}
#define MAX_LINE_NUM 64
void Preprocess::velodyne_handler(
const sensor_msgs::PointCloud2::ConstPtr &msg) {
pl_surf.clear();
pl_corn.clear();
pl_full.clear();
pcl::PointCloud<velodyne_ros::Point> pl_orig;
pcl::fromROSMsg(*msg, pl_orig);
int plsize = pl_orig.points.size();
// pl_surf.reserve(plsize);
for (int i = 0; i < pl_orig.size(); i++) {
PointType added_pt;
added_pt.x = pl_orig.points[i].x;
added_pt.y = pl_orig.points[i].y;
added_pt.z = pl_orig.points[i].z;
added_pt.intensity = pl_orig.points[i].intensity;
float angle = atan(added_pt.z / sqrt(added_pt.x * added_pt.x +
added_pt.y * added_pt.y)) *
180 / M_PI;
int scanID = 0;
if (angle >= -8.83)
scanID = int((2 - angle) * 3.0 + 0.5);
else
scanID = N_SCANS / 2 + int((-8.83 - angle) * 2.0 + 0.5);
// use [0 50] > 50 remove outlies
if (angle > 2 || angle < -24.33 || scanID > 50 || scanID < 0) {
continue;
}
pl_surf.push_back(added_pt);
}
}