Apollo 11.0
自动驾驶开放平台
preprocess_points.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2020 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
17/*
18 * Copyright 2018-2019 Autoware Foundation. All rights reserved.
19 *
20 * Licensed under the Apache License, Version 2.0 (the "License");
21 * you may not use this file except in compliance with the License.
22 * You may obtain a copy of the License at
23 *
24 * http://www.apache.org/licenses/LICENSE-2.0
25 *
26 * Unless required by applicable law or agreed to in writing, software
27 * distributed under the License is distributed on an "AS IS" BASIS,
28 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 * See the License for the specific language governing permissions and
30 * limitations under the License.
31 */
32
33// headers in STL
34#include <cmath>
35#include <iostream>
36
37// headers in local files
39
40namespace apollo {
41namespace perception {
42namespace lidar {
43
45 const int max_num_pillars, const int max_points_per_pillar,
46 const int num_point_feature, const int grid_x_size, const int grid_y_size,
47 const int grid_z_size, const float pillar_x_size, const float pillar_y_size,
48 const float pillar_z_size, const float min_x_range, const float min_y_range,
49 const float min_z_range, const int num_inds_for_scan)
50 : max_num_pillars_(max_num_pillars),
51 max_num_points_per_pillar_(max_points_per_pillar),
52 num_point_feature_(num_point_feature),
53 grid_x_size_(grid_x_size),
54 grid_y_size_(grid_y_size),
55 grid_z_size_(grid_z_size),
56 pillar_x_size_(pillar_x_size),
57 pillar_y_size_(pillar_y_size),
58 pillar_z_size_(pillar_z_size),
59 min_x_range_(min_x_range),
60 min_y_range_(min_y_range),
61 min_z_range_(min_z_range),
62 num_inds_for_scan_(num_inds_for_scan) {}
63
64void PreprocessPoints::InitializeVariables(int* coor_to_pillaridx,
65 float* sparse_pillar_map,
66 float* pillar_point_feature,
67 float* pillar_coors) {
68 for (int i = 0; i < grid_y_size_; ++i) {
69 for (int j = 0; j < grid_x_size_; ++j) {
70 coor_to_pillaridx[i * grid_x_size_ + j] = -1;
71 }
72 }
73
74 for (int i = 0; i < num_inds_for_scan_; ++i) {
75 for (int j = 0; j < num_inds_for_scan_; ++j) {
76 sparse_pillar_map[i * num_inds_for_scan_ + j] = 0;
77 }
78 }
79
80 for (int i = 0;
81 i < max_num_pillars_ * max_num_points_per_pillar_ * num_point_feature_;
82 ++i) {
83 pillar_point_feature[i] = 0;
84 }
85
86 for (int i = 0; i < max_num_pillars_ * 4; ++i) {
87 pillar_coors[i] = 0;
88 }
89}
90
91void PreprocessPoints::Preprocess(const float* in_points_array,
92 int in_num_points, int* x_coors, int* y_coors,
93 float* num_points_per_pillar,
94 float* pillar_point_feature,
95 float* pillar_coors, float* sparse_pillar_map,
96 int* host_pillar_count) {
97 int pillar_count = 0;
98 // init variables
99 int* coor_to_pillaridx = new int[grid_y_size_ * grid_x_size_];
100 InitializeVariables(coor_to_pillaridx, sparse_pillar_map,
101 pillar_point_feature, pillar_coors);
102 for (int i = 0; i < in_num_points; ++i) {
103 int x_coor = std::floor(
104 (in_points_array[i * num_point_feature_ + 0] - min_x_range_) /
105 pillar_x_size_);
106 int y_coor = std::floor(
107 (in_points_array[i * num_point_feature_ + 1] - min_y_range_) /
108 pillar_y_size_);
109 int z_coor = std::floor(
110 (in_points_array[i * num_point_feature_ + 2] - min_z_range_) /
111 pillar_z_size_);
112 if (x_coor < 0 || x_coor >= grid_x_size_ || y_coor < 0 ||
113 y_coor >= grid_y_size_ || z_coor < 0 || z_coor >= grid_z_size_) {
114 continue;
115 }
116 // reverse index
117 int pillar_index = coor_to_pillaridx[y_coor * grid_x_size_ + x_coor];
118 if (pillar_index == -1) {
119 pillar_index = pillar_count;
120 if (pillar_count >= max_num_pillars_) {
121 break;
122 }
123 pillar_count += 1;
124 coor_to_pillaridx[y_coor * grid_x_size_ + x_coor] = pillar_index;
125
126 y_coors[pillar_index] = std::floor(y_coor);
127 x_coors[pillar_index] = std::floor(x_coor);
128
129 sparse_pillar_map[y_coor * num_inds_for_scan_ + x_coor] = 1;
130 }
131 int num = num_points_per_pillar[pillar_index];
132 if (num < max_num_points_per_pillar_) {
133 for (int j = 0; j < num_point_feature_; ++j) {
134 pillar_point_feature[pillar_index * max_num_points_per_pillar_ *
135 num_point_feature_ +
136 num * num_point_feature_ + j] =
137 in_points_array[i * num_point_feature_ + j];
138 }
139 num_points_per_pillar[pillar_index] += 1;
140 }
141 }
142
143 for (int i = 0; i < max_num_pillars_; ++i) {
144 float x = 0;
145 float y = 0;
146 if (i < pillar_count) {
147 x = static_cast<float>(x_coors[i]);
148 y = static_cast<float>(y_coors[i]);
149 }
150 pillar_coors[i * 4 + 0] = 0; // batch idx, but currently it is useless
151 pillar_coors[i * 4 + 1] = 0; // z
152 pillar_coors[i * 4 + 2] = y;
153 pillar_coors[i * 4 + 3] = x;
154 }
155 host_pillar_count[0] = pillar_count;
156
157 delete[] coor_to_pillaridx;
158}
159
160} // namespace lidar
161} // namespace perception
162} // namespace apollo
PreprocessPoints(const int max_num_pillars, const int max_points_per_pillar, const int num_point_feature, const int grid_x_size, const int grid_y_size, const int grid_z_size, const float pillar_x_size, const float pillar_y_size, const float pillar_z_size, const float min_x_range, const float min_y_range, const float min_z_range, const int num_inds_for_scan)
Constructor
void InitializeVariables(int *coor_to_pillaridx, float *sparse_pillar_map, float *pillar_point_feature, float *pillar_coors)
Initializing variables for preprocessing
void Preprocess(const float *in_points_array, int in_num_points, int *x_coors, int *y_coors, float *num_points_per_pillar, float *pillar_point_feature, float *pillar_coors, float *sparse_pillar_map, int *host_pillar_count)
CPU preprocessing for input pointcloud
CPU version of preprocess points
class register implement
Definition arena_queue.h:37