Apollo 11.0
自动驾驶开放平台
background_map.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2023 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
19
20namespace apollo {
21namespace perception {
22namespace lidar {
23
24bool BackgroundMap::Init(int width, int height, float resolution, float height_threshold) {
25 width_ = width;
26 height_ = height;
27 resolution_ = resolution;
28 height_threshold_ = height_threshold;
29 return true;
30}
31
32bool BackgroundMap::Init(float xmin, float xmax, float ymin, float ymax, float resolution, float height_threshold) {
33 resolution_ = resolution;
34 xmin_ = xmin;
35 xmax_ = xmax;
36 ymin_ = ymin;
37 ymax_ = ymax;
38 height_threshold_ = height_threshold;
39
40 // in pointcloud-cooridinate system
41 width_ = static_cast<int>((ymax - ymin) * 1.0f / resolution);
42 height_ = static_cast<int>((xmax - xmin) * 1.0f / resolution);
43 return true;
44}
45
46bool BackgroundMap::Reset(size_t point_number) {
47 // clear all data
48 bg_nodes_.clear();
49 point_idx_.clear();
50 point_importance_.clear();
51 point_mask_.clear();
52 point_number_ = point_number;
53 valid_node_number_ = 0;
54
55 // reset data
56 bg_nodes_.resize(width_ * height_);
57 point_idx_.resize(point_number_, 0);
58 point_mask_.resize(point_number_, false);
59 point_importance_.resize(point_number_, false);
60 return true;
61}
62
64 // update idx and mask
65 ACHECK(UpdateMask(frame));
66 // update node
67 ACHECK(UpdateNodes(frame));
68 return true;
69}
70
72 if (frame->secondary_indices.indices.size() == 0) {
73 AINFO << "UpdateMask, secondary_indices size is 0.";
74 }
75 // secondary_indices
76 for (auto index : frame->secondary_indices.indices) {
77 if (index < 0 || static_cast<size_t>(index) >= point_number_) {
78 continue;
79 }
80 auto pt = frame->cloud->at(index);
81 // filter point beyond height_threshold_
82 Eigen::Vector4d trans_point(pt.x, pt.y, pt.z, 1);
83 trans_point = frame->lidar2novatel_extrinsics * trans_point;
84 if (trans_point(2) >= height_threshold_) {
85 continue;
86 }
87 // filter point use semantic_label
88 if (static_cast<PointSemanticLabel>(frame->cloud->points_semantic_label(index) & 15)
90 continue;
91 }
92 // filter point outside grid
93 int grid_x = -1;
94 int grid_y = -1;
95 GetNodeCoord(pt.x, pt.y, &grid_x, &grid_y);
96 if (grid_y < 0 || grid_y >= width_ || grid_x < 0 || grid_x >= height_) {
97 continue;
98 }
99 // valid point
100 size_t grid_idx = grid_x * width_ + grid_y;
101 point_mask_.at(index) = true;
102 point_idx_.at(index) = grid_idx;
103
104 // in novatel-cooridinate system
105 if (trans_point(1) > FLAGS_y_back && trans_point(1) < FLAGS_y_front && trans_point(0) > FLAGS_x_back
106 && trans_point(0) < FLAGS_x_front) {
107 point_importance_.at(index) = true;
108 }
109 }
110
111 return true;
112}
113
115 auto original_cloud = frame->cloud;
116 for (size_t i = 0; i < point_mask_.size(); ++i) {
117 if (!point_mask_.at(i)) {
118 continue;
119 }
120 auto pt = original_cloud->at(i);
121 // update node state
122 size_t grid_idx = point_idx_.at(i);
123 bg_nodes_.at(grid_idx).is_valid = true;
124 bg_nodes_.at(grid_idx).is_important = bg_nodes_.at(grid_idx).is_important || point_importance_.at(i);
125
126 if (bg_nodes_.at(grid_idx).point_number == 0) {
127 bg_nodes_.at(grid_idx).id = valid_node_number_;
128 valid_node_number_ += 1;
129 }
130 bg_nodes_.at(grid_idx).point_number += 1;
131 // update node feature
132 int pt_number = bg_nodes_.at(grid_idx).point_number;
133 // mean height, mean intensity
134 if (pt_number == 1) {
135 bg_nodes_.at(grid_idx).mean_height = pt.z;
136 bg_nodes_.at(grid_idx).mean_intensity = pt.intensity;
137 } else {
138 bg_nodes_.at(grid_idx).mean_height = bg_nodes_.at(grid_idx).mean_height
139 + (pt.z - bg_nodes_.at(grid_idx).mean_height) / static_cast<float>(pt_number);
140 bg_nodes_.at(grid_idx).mean_intensity = bg_nodes_.at(grid_idx).mean_intensity
141 + (pt.intensity - bg_nodes_.at(grid_idx).mean_intensity) / static_cast<float>(pt_number);
142 }
143 // max height
144 bg_nodes_.at(grid_idx).max_height = std::max(bg_nodes_.at(grid_idx).max_height, pt.z);
145
146 // get semantic label
147 PointSemanticLabel label = GetSemanticLabel(original_cloud->points_semantic_label(i));
148 int index = static_cast<int>(label);
149 if (index >= 0 && index < static_cast<int>(PointSemanticLabel::MAX_LABEL)) {
150 bg_nodes_.at(grid_idx).pc_semantic_types[index]++;
151 }
152 // get motion label
153 PointMotionLabel motion_label = GetMotionLabel(original_cloud->points_semantic_label(i));
154 int motion_index = static_cast<int>(motion_label);
155 if (motion_index >= 0 && motion_index < static_cast<int>(PointMotionLabel::MAX_LABEL)) {
156 bg_nodes_.at(grid_idx).pc_motion_types[motion_index]++;
157 }
158 }
159 return true;
160}
161
162void BackgroundMap::GetNodeCoord(float x, float y, int* grid_x, int* grid_y) {
163 *grid_x = static_cast<int>((x - xmin_) / resolution_);
164 *grid_y = static_cast<int>((y - ymin_) / resolution_);
165}
166
167} // namespace lidar
168} // namespace perception
169} // namespace apollo
bool UpdateMask(LidarFrame *frame)
Update point mask and point index
bool UpdateMap(LidarFrame *frame)
Update map, update mask and node
bool UpdateNodes(LidarFrame *frame)
Update node feature based on points
bool Init(int width, int height, float resolution, float height_threshold)
Init background map
bool Reset(size_t point_number)
Reset all data
void GetNodeCoord(float x, float y, int *grid_x, int *grid_y)
Get Node Coordinate based on point
#define ACHECK(cond)
Definition log.h:80
#define AINFO
Definition log.h:42
PointSemanticLabel GetSemanticLabel(uint8_t value)
PointMotionLabel GetMotionLabel(uint8_t value)
class register implement
Definition arena_queue.h:37
std::shared_ptr< base::AttributePointCloud< base::PointF > > cloud
Definition lidar_frame.h:35