Apollo 11.0
自动驾驶开放平台
roi_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 "cyber/common/file.h"
19#include "modules/perception/common/lidar/scene_manager/roi_service/proto/roi_service.pb.h"
20
21namespace apollo {
22namespace perception {
23namespace lidar {
24
26
28 ROIServiceContent* roi_content = dynamic_cast<ROIServiceContent*>(content);
29 if (roi_content == nullptr) {
30 return;
31 }
32 roi_content->bitmap_ = bitmap_;
33 roi_content->map_size_ = map_size_;
34 roi_content->cell_size_ = cell_size_;
35 roi_content->range_ = range_;
36 roi_content->major_dir_ = major_dir_;
37 roi_content->transform_ = transform_;
38 roi_content->service_ready_ = service_ready_;
39}
40
42 const ROIServiceContent* roi_content =
43 dynamic_cast<const ROIServiceContent*>(&content);
44 if (roi_content == nullptr) {
45 return;
46 }
47 // copy content
48 bitmap_ = roi_content->bitmap_;
49 map_size_ = roi_content->map_size_;
50 cell_size_ = roi_content->cell_size_;
51 range_ = roi_content->range_;
52 major_dir_ = roi_content->major_dir_;
53 transform_ = roi_content->transform_;
54 // set ready to true
55 service_ready_ = true;
56}
57
58inline bool ROIServiceContent::CheckBit(const size_t loc,
59 const uint64_t block) const {
60 return block & (static_cast<uint64_t>(1) << loc);
61}
62
63bool ROIServiceContent::Check(const Eigen::Vector3d& world_point) const {
64 if (!service_ready_) {
65 return false;
66 }
67 Eigen::Vector2d pt;
68 pt(0) = world_point(0) - transform_(0) + range_;
69 pt(1) = world_point(1) - transform_(1) + range_;
70 if (pt(0) >= 0 && pt(0) < 2 * range_ && pt(1) >= 0 && pt(1) < 2 * range_) {
71 const size_t ix =
72 static_cast<size_t>(pt(static_cast<size_t>(major_dir_)) / cell_size_);
73 const size_t iy = static_cast<size_t>(
74 pt(static_cast<size_t>(major_dir_) ^ 1) / cell_size_);
75 const size_t idx_y = iy >> 6;
76 const size_t idx_z = iy & 63;
77 const size_t idx = ix * map_size_[1] + idx_y;
78 return CheckBit(idx_z, bitmap_[idx]);
79 }
80 return false;
81}
82
85 roi_content_ref_ = dynamic_cast<ROIServiceContent*>(self_content_.get());
86
87 std::string config_file = FLAGS_roi_service_file;
88 if (!options.config_file.empty()) {
89 config_file = options.config_file;
90 }
91
92 config_file = GetCommonConfigFile(config_file);
93 ROIServiceConfig config;
94 ACHECK(cyber::common::GetProtoFromFile(config_file, &config));
96 roi_content_ref_->range_ = config.range();
97 return true;
98}
99
100bool ROIService::QueryIsPointInROI(const Eigen::Vector3d& world_point) {
101 std::lock_guard<std::mutex> lock(mutex_);
102 bool status = QueryIsPointInROI(world_point, *roi_content_ref_);
103 return status;
104}
105
106bool ROIService::QueryIsPointInROI(const Eigen::Vector3d& world_point,
107 const ROIServiceContent& content) {
108 return content.Check(world_point);
109}
110
113
114} // namespace lidar
115} // namespace perception
116} // namespace apollo
bool Check(const Eigen::Vector3d &world_point) const
bool CheckBit(const size_t loc, const uint64_t block) const
void GetCopy(SceneServiceContent *content) const override
void SetContent(const SceneServiceContent &content) override
bool QueryIsPointInROI(const Eigen::Vector3d &world_point)
bool Init(const SceneServiceInitOptions &options=SceneServiceInitOptions()) override
#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
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)