Apollo 11.0
自动驾驶开放平台
lidar_segmentation_component.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
18
19namespace apollo {
20namespace perception {
21namespace lidar {
22
24using onboard::LidarFrameMessage;
25
27 // hook: Apollo License Verification: v_apollo_park
29 if (!GetProtoConfig(&comp_config)) {
30 AERROR << "Get LidarSegmentationComponentConfig file failed";
31 return false;
32 }
33 AINFO << "LidarSegmentation Component Configs: " << comp_config.DebugString();
34
35 output_channel_name_ = comp_config.output_channel_name();
36 writer_ = node_->CreateWriter<onboard::LidarFrameMessage>(output_channel_name_);
37
38 // segmentor init
39 auto plugin_param = comp_config.plugin_param();
40 std::string segmentor_name = plugin_param.name();
41 BaseLidarDetector* segmentor = BaseLidarDetectorRegisterer::GetInstanceByName(segmentor_name);
42 CHECK_NOTNULL(segmentor);
43 segmentor_.reset(segmentor);
44
45 LidarDetectorInitOptions segmentr_init_options;
46 segmentr_init_options.config_path = plugin_param.config_path();
47 segmentr_init_options.config_file = plugin_param.config_file();
48 ACHECK(segmentor_->Init(segmentr_init_options)) << "lidar segmentor init error";
49
50 // semantic builder init
51 SemanticBuilderInitOptions semantic_init_options;
52 ACHECK(semantic_builder_.Init(semantic_init_options));
53
54 AINFO << "LidarSegmentationComponent init successful.";
55 return true;
56}
57
58bool LidarSegmentationComponent::Proc(const std::shared_ptr<LidarFrameMessage>& message) {
59 // internal proc
60 bool status = InternalProc(message);
61
62 if (status) {
63 writer_->Write(message);
64 AINFO << "Send lidar segmentation output message.";
65 }
66 return status;
67}
68
69bool LidarSegmentationComponent::InternalProc(const std::shared_ptr<LidarFrameMessage>& message) {
70 PERF_BLOCK("lidar_segmentation")
71 LidarDetectorOptions segmentor_options;
72 if (!segmentor_->Detect(segmentor_options, message->lidar_frame_.get())) {
73 AERROR << "lidar segmentation Detect error.";
74 return false;
75 }
77
78 // semantic builder, get semantic and motion type
79 PERF_BLOCK("semantic_builder")
80 SemanticBuilderOptions semantic_options;
81 if (!semantic_builder_.Build(semantic_options, message->lidar_frame_.get())) {
82 AERROR << "Lidar segmentation, semantic builder error.";
83 return false;
84 }
86
87 return true;
88}
89
90} // namespace lidar
91} // namespace perception
92} // namespace apollo
bool GetProtoConfig(T *config) const
std::shared_ptr< Node > node_
bool Proc(const std::shared_ptr< onboard::LidarFrameMessage > &message) override
Process of lidar segmentation
bool Init(const SemanticBuilderInitOptions &options=SemanticBuilderInitOptions())
Init the Semantic Builder with initialization options
#define ACHECK(cond)
Definition log.h:80
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
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
class register implement
Definition arena_queue.h:37
#define PERF_BLOCK_END
Definition profiler.h:53
#define PERF_BLOCK(...)
Definition profiler.h:52