Apollo 11.0
自动驾驶开放平台
ground_service.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 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 *****************************************************************************/
17
18#include <limits>
19
20#include "cyber/common/file.h"
22#include "modules/perception/common/lidar/scene_manager/ground_service/proto/ground_service_config.pb.h"
23
24namespace apollo {
25namespace perception {
26namespace lidar {
27
29
31 GroundServiceContent* ground_content =
32 dynamic_cast<GroundServiceContent*>(content);
33 if (ground_content == nullptr) {
34 return;
35 }
36 ground_content->grid_ = grid_;
37 ground_content->grid_center_ = grid_center_;
38 ground_content->resolution_x_ = resolution_x_;
39 ground_content->resolution_y_ = resolution_y_;
40 ground_content->bound_x_min_ = bound_x_min_;
41 ground_content->bound_y_min_ = bound_y_min_;
42 ground_content->bound_x_max_ = bound_x_max_;
43 ground_content->bound_y_max_ = bound_y_max_;
44 ground_content->rows_ = rows_;
45 ground_content->cols_ = cols_;
46 ground_content->service_ready_ = service_ready_;
47}
48
50 const GroundServiceContent* ground_content =
51 dynamic_cast<const GroundServiceContent*>(&content);
52 if (ground_content == nullptr) {
53 return;
54 }
55 grid_ = ground_content->grid_;
56 grid_center_ = ground_content->grid_center_;
57 resolution_x_ = ground_content->resolution_x_;
58 resolution_y_ = ground_content->resolution_y_;
59 bound_x_min_ = ground_content->bound_x_min_;
60 bound_y_min_ = ground_content->bound_y_min_;
61 bound_x_max_ = ground_content->bound_x_max_;
62 bound_y_max_ = ground_content->bound_y_max_;
63 rows_ = ground_content->rows_;
64 cols_ = ground_content->cols_;
65
66 service_ready_ = true;
67}
68
69uint32_t inline GetIndex(uint32_t r, uint32_t c, uint32_t cols) {
70 return (r * cols + c);
71}
72
73bool GroundServiceContent::PointToGrid(const Eigen::Vector3d& world_point,
74 uint32_t* grid_index) const {
75 double x = world_point(0) - grid_center_(0);
76 double y = world_point(1) - grid_center_(1);
77 if (x < bound_x_min_ || x > bound_x_max_ || y < bound_y_min_ ||
78 y > bound_y_max_) {
79 (*grid_index) = 0;
80 return false;
81 }
82 uint32_t c = std::min(
83 cols_ - 1, static_cast<uint32_t>((x - bound_x_min_) / resolution_x_));
84 uint32_t r = std::min(
85 rows_ - 1, static_cast<uint32_t>((y - bound_y_min_) / resolution_y_));
86 (*grid_index) = GetIndex(r, c, cols_);
87 return true;
88}
89
91 const Eigen::Vector3d& world_point) const {
92 uint32_t grid_index = 0;
93 if (!PointToGrid(world_point, &grid_index)) {
94 return std::numeric_limits<float>::max();
95 }
96
97 float offset_pt[3];
98 float params[4];
99 float out = std::numeric_limits<float>::max();
100
101 offset_pt[0] = static_cast<float>(world_point(0) - grid_center_(0));
102 offset_pt[1] = static_cast<float>(world_point(1) - grid_center_(1));
103 offset_pt[2] = static_cast<float>(world_point(2) - grid_center_(2));
104
105 const GroundNode* node = grid_.DataPtr() + grid_index;
106 if (node->confidence > 0.f) {
107 params[0] = node->params(0);
108 params[1] = node->params(1);
109 params[2] = node->params(2);
110 params[3] = node->params(3);
112 }
113 return out;
114}
115
116bool GroundServiceContent::Init(double roi_x, double roi_y, uint32_t rows,
117 uint32_t cols) {
118 bound_x_min_ = -roi_x;
119 bound_y_min_ = -roi_y;
120 bound_x_max_ = roi_x;
121 bound_y_max_ = roi_y;
122
123 rows_ = rows;
124 cols_ = cols;
125
128
130 return true;
131}
132
136 dynamic_cast<GroundServiceContent*>(self_content_.get());
137 // initialize ground service content from config manager and proto
138 // including resolution, grid size, ...
139 std::string config_file = FLAGS_ground_service_file;
140 if (!options.config_file.empty()) {
141 config_file = options.config_file;
142 }
143
144 config_file = GetCommonConfigFile(config_file);
145
146 GroundServiceConfig config_params;
147 ACHECK(cyber::common::GetProtoFromFile(config_file, &config_params))
148 << "Failed to parse GroundServiceConfig config file.";
149
150 double roi_region_rad_x = config_params.roi_rad_x();
151 double roi_region_rad_y = config_params.roi_rad_y();
152 uint32_t rows = config_params.grid_size();
153 uint32_t cols = config_params.grid_size();
154
155 ground_content_ref_->Init(roi_region_rad_x, roi_region_rad_y, rows, cols);
156
157 return true;
158}
159
161 const Eigen::Vector3d& world_point) {
162 std::lock_guard<std::mutex> lock(mutex_);
163 float distance =
165 return distance;
166}
167
169 const Eigen::Vector3d& world_point, const GroundServiceContent& content) {
170 return content.PointToPlaneDistance(world_point);
171}
172
175
176} // namespace lidar
177} // namespace perception
178} // namespace apollo
void Init(int32_t rows, int32_t cols)
bool PointToGrid(const Eigen::Vector3d &world_point, uint32_t *grid_index) const
bool Init(double roi_x, double roi_y, uint32_t rows, uint32_t cols)
void SetContent(const SceneServiceContent &content) override
void GetCopy(SceneServiceContent *content) const override
float PointToPlaneDistance(const Eigen::Vector3d &world_point) const
bool Init(const SceneServiceInitOptions &options=SceneServiceInitOptions()) override
float QueryPointToGroundDistance(const Eigen::Vector3d &world_point)
#define ACHECK(cond)
Definition log.h:80
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
Definition file.cc:132
std::string GetAbsolutePath(const std::string &prefix, const std::string &relative_path)
Get absolute path by concatenating prefix and relative_path.
Definition file.cc:179
T IPlaneToPointSignedDistanceWUnitNorm(const T *pi, const T *p)
Definition i_plane.h:102
uint32_t GetIndex(uint32_t r, uint32_t c, uint32_t cols)
std::string GetCommonConfigFile(const std::string &config_file)
Get the perception common config path
Definition util.cc:28
class register implement
Definition arena_queue.h:37
#define PERCEPTION_REGISTER_SCENESERVICE(name)
#define PERCEPTION_REGISTER_SCENESERVICECONTENT(name)