Apollo 11.0
自动驾驶开放平台
ground_service_detector.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 *****************************************************************************/
16
18
19#include "cyber/common/file.h"
20
23#include "modules/perception/pointcloud_ground_detection/ground_detector/proto/ground_service_detector_config.pb.h"
24
25namespace apollo {
26namespace perception {
27namespace lidar {
28
30 std::string config_file =
31 GetConfigFile(options.config_path, options.config_file);
33 ACHECK(cyber::common::GetProtoFromFile(config_file, &config));
34 ground_threshold_ = config.ground_threshold();
35
36 ground_service_ = std::dynamic_pointer_cast<GroundService>(
37 SceneManager::Instance().Service("GroundService"));
38 if (ground_service_ == nullptr) {
39 AERROR << "Ground service is nullptr, Init scene manager first !";
40 return false;
41 }
42 return true;
43}
44
46 LidarFrame* frame) {
47 if (frame == nullptr || frame->world_cloud == nullptr) {
48 AERROR << "Frame is nullptr.";
49 return false;
50 }
51 ground_service_->GetServiceContentCopy(&ground_service_content_);
52 if (!ground_service_content_.IsServiceReady()) {
53 AERROR << "service is not ready.";
54 return false;
55 }
56 auto& cloud = frame->world_cloud;
57 auto& non_ground_indices = frame->non_ground_indices;
58 non_ground_indices.indices.clear();
59 non_ground_indices.indices.reserve(cloud->size());
60 for (size_t i = 0; i < cloud->size(); ++i) {
61 auto& pt = cloud->at(i);
62 Eigen::Vector3d world_point(pt.x, pt.y, pt.z);
63 float dist = ground_service_->QueryPointToGroundDistance(
64 world_point, ground_service_content_);
65 frame->cloud->mutable_points_height()->at(i) = dist;
66 frame->world_cloud->mutable_points_height()->at(i) = dist;
67 if (dist > ground_threshold_) {
68 non_ground_indices.indices.push_back(static_cast<int>(i));
69 } else {
70 frame->cloud->mutable_points_label()->at(i) =
71 static_cast<uint8_t>(LidarPointLabel::GROUND);
72 }
73 }
74 return true;
75}
76
78
79} // namespace lidar
80} // namespace perception
81} // namespace apollo
#define PERCEPTION_REGISTER_GROUNDDETECTOR(name)
bool Init(const GroundDetectorInitOptions &options=GroundDetectorInitOptions()) override
Init ground service detector
bool Detect(const GroundDetectorOptions &options, LidarFrame *frame) override
Ground service detect
#define ACHECK(cond)
Definition log.h:80
#define AERROR
Definition log.h:44
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 GetConfigFile(const std::string &config_path, const std::string &config_file)
Definition util.cc:80
class register implement
Definition arena_queue.h:37
std::shared_ptr< base::AttributePointCloud< base::PointD > > world_cloud
Definition lidar_frame.h:37
std::shared_ptr< base::AttributePointCloud< base::PointF > > cloud
Definition lidar_frame.h:35