Apollo 10.0
自动驾驶开放平台
topo_range_manager.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 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 <algorithm>
20#include <utility>
21
22#include "cyber/common/log.h"
23
24namespace apollo {
25namespace routing {
26namespace {
27
28void merge_block_range(const TopoNode* topo_node,
29 const std::vector<NodeSRange>& origin_range,
30 std::vector<NodeSRange>* block_range) {
31 std::vector<NodeSRange> sorted_origin_range(origin_range);
32 std::sort(sorted_origin_range.begin(), sorted_origin_range.end());
33 size_t cur_index = 0;
34 auto total_size = sorted_origin_range.size();
35 while (cur_index < total_size) {
36 NodeSRange range(sorted_origin_range[cur_index]);
37 ++cur_index;
38 while (cur_index < total_size &&
39 range.MergeRangeOverlap(sorted_origin_range[cur_index])) {
40 ++cur_index;
41 }
42 if (range.EndS() < topo_node->StartS() ||
43 range.StartS() > topo_node->EndS()) {
44 continue;
45 }
46 range.SetStartS(std::max(topo_node->StartS(), range.StartS()));
47 range.SetEndS(std::min(topo_node->EndS(), range.EndS()));
48 block_range->push_back(std::move(range));
49 }
50}
51
52} // namespace
53
54const std::unordered_map<const TopoNode*, std::vector<NodeSRange>>&
56 return range_map_;
57}
58const std::vector<NodeSRange>* TopoRangeManager::Find(
59 const TopoNode* node) const {
60 auto iter = range_map_.find(node);
61 if (iter == range_map_.end()) {
62 return nullptr;
63 } else {
64 return &(iter->second);
65 }
66}
67
69 for (const auto& map : range_map_) {
70 for (const auto& range : map.second) {
71 AINFO << "black lane id: " << map.first->LaneId()
72 << ", start s: " << range.StartS() << ", end s: " << range.EndS();
73 }
74 }
75}
76
77void TopoRangeManager::Clear() { range_map_.clear(); }
78
79void TopoRangeManager::Add(const TopoNode* node, double start_s, double end_s) {
80 NodeSRange range(start_s, end_s);
81 range_map_[node].push_back(range);
82}
83
85 for (auto& iter : range_map_) {
86 std::vector<NodeSRange> merged_range_vec;
87 merge_block_range(iter.first, iter.second, &merged_range_vec);
88 iter.second.assign(merged_range_vec.begin(), merged_range_vec.end());
89 }
90}
91
92} // namespace routing
93} // namespace apollo
const TopoNode * topo_node
const std::unordered_map< const TopoNode *, std::vector< NodeSRange > > & RangeMap() const
const std::vector< NodeSRange > * Find(const TopoNode *node) const
void Add(const TopoNode *node, double start_s, double end_s)
#define AINFO
Definition log.h:42
class register implement
Definition arena_queue.h:37