Apollo 11.0
自动驾驶开放平台
prediction_map.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 <limits>
21#include <unordered_set>
22#include <utility>
23
25
26namespace apollo {
27namespace prediction {
28
37
38bool PredictionMap::Ready() { return HDMapUtil::BaseMapPtr() != nullptr; }
39
41 const std::shared_ptr<const LaneInfo> lane_info, const double s) {
42 common::PointENU point = lane_info->GetSmoothPoint(s);
43 return {point.x(), point.y()};
44}
45
47 const std::shared_ptr<const LaneInfo> lane_info, const double s) {
48 return lane_info->Heading(s);
49}
50
51double PredictionMap::CurvatureOnLane(const std::string& lane_id,
52 const double s) {
53 std::shared_ptr<const hdmap::LaneInfo> lane_info = LaneById(lane_id);
54 if (lane_info == nullptr) {
55 AERROR << "Null lane_info ptr found";
56 return 0.0;
57 }
58 return lane_info->Curvature(s);
59}
60
62 const std::shared_ptr<const hdmap::LaneInfo> lane_info, const double s) {
63 double left = 0.0;
64 double right = 0.0;
65 lane_info->GetWidth(s, &left, &right);
66 return left + right;
67}
68
69std::shared_ptr<const LaneInfo> PredictionMap::LaneById(
70 const std::string& str_id) {
72}
73
74std::shared_ptr<const JunctionInfo> PredictionMap::JunctionById(
75 const std::string& str_id) {
77}
78
79std::shared_ptr<const OverlapInfo> PredictionMap::OverlapById(
80 const std::string& str_id) {
82}
83
85 const Eigen::Vector2d& pos, const std::shared_ptr<const LaneInfo> lane_info,
86 double* s, double* l) {
87 if (lane_info == nullptr) {
88 return false;
89 }
90 return lane_info->GetProjection({pos.x(), pos.y()}, s, l);
91}
92
93bool PredictionMap::HasNearbyLane(const double x, const double y,
94 const double radius) {
95 common::PointENU point_enu;
96 point_enu.set_x(x);
97 point_enu.set_y(y);
98 std::vector<std::shared_ptr<const LaneInfo>> lanes;
99 HDMapUtil::BaseMap().GetLanes(point_enu, radius, &lanes);
100 return (!lanes.empty());
101}
102
104 std::shared_ptr<const LaneInfo> lane_info, const double s,
105 MapPathPoint* path_point) {
106 if (lane_info == nullptr) {
107 return false;
108 }
109 const common::PointENU point = lane_info->GetSmoothPoint(s);
110 const double heading = HeadingOnLane(lane_info, s);
111 path_point->set_x(point.x());
112 path_point->set_y(point.y());
113 path_point->set_heading(heading);
114 return true;
115}
116
117bool PredictionMap::IsVirtualLane(const std::string& lane_id) {
118 std::shared_ptr<const LaneInfo> lane_info =
120 if (lane_info == nullptr) {
121 return false;
122 }
123 const hdmap::Lane& lane = lane_info->lane();
124 bool left_virtual = lane.has_left_boundary() &&
125 lane.left_boundary().has_virtual_() &&
126 lane.left_boundary().virtual_();
127 bool right_virtual = lane.has_right_boundary() &&
128 lane.right_boundary().has_virtual_() &&
129 lane.right_boundary().virtual_();
130 return left_virtual && right_virtual;
131}
132
133bool PredictionMap::OnVirtualLane(const Eigen::Vector2d& point,
134 const double radius) {
135 std::vector<std::shared_ptr<const LaneInfo>> lanes;
136 common::PointENU hdmap_point;
137 hdmap_point.set_x(point[0]);
138 hdmap_point.set_y(point[1]);
139 HDMapUtil::BaseMap().GetLanes(hdmap_point, radius, &lanes);
140 for (const auto& lane : lanes) {
141 if (IsVirtualLane(lane->id().id())) {
142 return true;
143 }
144 }
145 return false;
146}
147
149 const std::vector<std::shared_ptr<const LaneInfo>>& prev_lanes,
150 const Eigen::Vector2d& point, const double heading, const double radius,
151 const bool on_lane, const int max_num_lane,
152 const double max_lane_angle_diff,
153 std::vector<std::shared_ptr<const LaneInfo>>* lanes) {
154 std::vector<std::shared_ptr<const LaneInfo>> candidate_lanes;
155
156 common::PointENU hdmap_point;
157 hdmap_point.set_x(point.x());
158 hdmap_point.set_y(point.y());
159 if (HDMapUtil::BaseMap().GetLanesWithHeading(hdmap_point, radius, heading,
160 max_lane_angle_diff,
161 &candidate_lanes) != 0) {
162 return;
163 }
164
165 std::vector<std::pair<std::shared_ptr<const LaneInfo>, double>> lane_pairs;
166 for (const auto& candidate_lane : candidate_lanes) {
167 if (candidate_lane == nullptr) {
168 continue;
169 }
170 if (on_lane && !candidate_lane->IsOnLane({point.x(), point.y()})) {
171 continue;
172 }
173 if (!FLAGS_use_navigation_mode &&
174 !IsIdenticalLane(candidate_lane, prev_lanes) &&
175 !IsSuccessorLane(candidate_lane, prev_lanes) &&
176 !IsLeftNeighborLane(candidate_lane, prev_lanes) &&
177 !IsRightNeighborLane(candidate_lane, prev_lanes)) {
178 continue;
179 }
180 double distance = 0.0;
181 common::PointENU nearest_point =
182 candidate_lane->GetNearestPoint({point.x(), point.y()}, &distance);
183 double nearest_point_heading = PathHeading(candidate_lane, nearest_point);
184 double diff =
185 std::fabs(common::math::AngleDiff(heading, nearest_point_heading));
186 if (diff <= max_lane_angle_diff) {
187 lane_pairs.emplace_back(candidate_lane, diff);
188 }
189 }
190 if (lane_pairs.empty()) {
191 return;
192 }
193 std::sort(lane_pairs.begin(), lane_pairs.end(),
194 [](const std::pair<std::shared_ptr<const LaneInfo>, double>& p1,
195 const std::pair<std::shared_ptr<const LaneInfo>, double>& p2) {
196 return p1.second < p2.second;
197 });
198
199 int count = 0;
200 for (const auto& lane_pair : lane_pairs) {
201 lanes->push_back(lane_pair.first);
202 ++count;
203 if (count >= max_num_lane) {
204 break;
205 }
206 }
207}
208
209std::shared_ptr<const LaneInfo> PredictionMap::GetMostLikelyCurrentLane(
210 const common::PointENU& position, const double radius, const double heading,
211 const double angle_diff_threshold) {
212 std::vector<std::shared_ptr<const LaneInfo>> candidate_lanes;
213 if (HDMapUtil::BaseMap().GetLanesWithHeading(position, radius, heading,
214 angle_diff_threshold,
215 &candidate_lanes) != 0) {
216 return nullptr;
217 }
218 double min_angle_diff = 2.0 * M_PI;
219 std::shared_ptr<const LaneInfo> curr_lane_ptr = nullptr;
220 for (auto candidate_lane : candidate_lanes) {
221 if (!candidate_lane->IsOnLane({position.x(), position.y()})) {
222 continue;
223 }
224 double distance = 0.0;
225 common::PointENU nearest_point = candidate_lane->GetNearestPoint(
226 {position.x(), position.y()}, &distance);
227 double nearest_point_heading = PathHeading(candidate_lane, nearest_point);
228 double angle_diff =
229 std::fabs(common::math::AngleDiff(heading, nearest_point_heading));
230 if (angle_diff < min_angle_diff) {
231 min_angle_diff = angle_diff;
232 curr_lane_ptr = candidate_lane;
233 }
234 }
235 return curr_lane_ptr;
236}
237
239 const Eigen::Vector2d& ego_position, const std::string& lane_id) {
240 auto ptr_lane = LaneById(lane_id);
241 const auto& lane_points = ptr_lane->points();
242 if (lane_points.size() < 2) {
243 return false;
244 }
245
246 const auto& start_point = lane_points.front();
247 const auto& end_point = lane_points.back();
248
249 auto lane_vec = end_point - start_point;
250
251 auto approx_lane_length = lane_vec.Length();
252 if (approx_lane_length < 1.0e-3) {
253 return false;
254 }
255
256 auto dist_vec =
257 common::math::Vec2d(ego_position.x(), ego_position.y()) - start_point;
258
259 auto projection_length = dist_vec.InnerProd(lane_vec) / approx_lane_length;
260
261 if (projection_length < 0.0 || projection_length > approx_lane_length) {
262 return false;
263 }
264 return true;
265}
266
267bool PredictionMap::NearJunction(const Eigen::Vector2d& point,
268 const double radius) {
269 common::PointENU hdmap_point;
270 hdmap_point.set_x(point.x());
271 hdmap_point.set_y(point.y());
272 std::vector<std::shared_ptr<const JunctionInfo>> junctions;
273 HDMapUtil::BaseMap().GetJunctions(hdmap_point, radius, &junctions);
274 return junctions.size() > 0;
275}
276
278 const double x, const double y,
279 const std::shared_ptr<const JunctionInfo> junction_info_ptr) {
280 if (junction_info_ptr == nullptr) {
281 return false;
282 }
283 const Polygon2d& polygon = junction_info_ptr->polygon();
284 return polygon.IsPointIn({x, y});
285}
286
287std::vector<std::shared_ptr<const JunctionInfo>> PredictionMap::GetJunctions(
288 const Eigen::Vector2d& point, const double radius) {
289 common::PointENU hdmap_point;
290 hdmap_point.set_x(point.x());
291 hdmap_point.set_y(point.y());
292 std::vector<std::shared_ptr<const JunctionInfo>> junctions;
293 HDMapUtil::BaseMap().GetJunctions(hdmap_point, radius, &junctions);
294 return junctions;
295}
296
297std::vector<std::shared_ptr<const PNCJunctionInfo>>
298PredictionMap::GetPNCJunctions(const Eigen::Vector2d& point,
299 const double radius) {
300 common::PointENU hdmap_point;
301 hdmap_point.set_x(point.x());
302 hdmap_point.set_y(point.y());
303 std::vector<std::shared_ptr<const PNCJunctionInfo>> junctions;
304 HDMapUtil::BaseMap().GetPNCJunctions(hdmap_point, radius, &junctions);
305 return junctions;
306}
307
308bool PredictionMap::InJunction(const Eigen::Vector2d& point,
309 const double radius) {
310 auto junction_infos = GetJunctions(point, radius);
311 if (junction_infos.empty()) {
312 return false;
313 }
314 for (const auto junction_info : junction_infos) {
315 if (junction_info == nullptr || !junction_info->junction().has_polygon()) {
316 continue;
317 }
318 std::vector<Vec2d> vertices;
319 for (const auto& point : junction_info->junction().polygon().point()) {
320 vertices.emplace_back(point.x(), point.y());
321 }
322 if (vertices.size() < 3) {
323 continue;
324 }
325 Polygon2d junction_polygon{vertices};
326 if (junction_polygon.IsPointIn({point.x(), point.y()})) {
327 return true;
328 }
329 }
330 return false;
331}
332
334 const std::shared_ptr<const LaneInfo> lane_info,
335 const std::string& junction_id) {
336 if (lane_info == nullptr) {
337 return false;
338 }
339
340 // first, check whether the lane is virtual
341 if (!PredictionMap::IsVirtualLane(lane_info->lane().id().id())) {
342 return false;
343 }
344
345 // second, use junction from lane
346 if (lane_info->lane().has_junction_id() &&
347 lane_info->lane().junction_id().id() == junction_id) {
348 return true;
349 }
350
351 // third, use junction from road
352 auto ptr_road_info = HDMapUtil::BaseMap().GetRoadById(lane_info->road_id());
353 if (ptr_road_info->has_junction_id() &&
354 ptr_road_info->junction_id().id() == junction_id) {
355 return true;
356 }
357
358 return false;
359}
360
361double PredictionMap::PathHeading(std::shared_ptr<const LaneInfo> lane_info,
362 const common::PointENU& point) {
363 double s = 0.0;
364 double l = 0.0;
365 if (lane_info->GetProjection({point.x(), point.y()}, &s, &l)) {
366 return HeadingOnLane(lane_info, s);
367 } else {
368 return M_PI;
369 }
370}
371
372bool PredictionMap::SmoothPointFromLane(const std::string& id, const double s,
373 const double l, Eigen::Vector2d* point,
374 double* heading) {
375 if (point == nullptr || heading == nullptr) {
376 return false;
377 }
378 std::shared_ptr<const LaneInfo> lane = LaneById(id);
379 common::PointENU hdmap_point = lane->GetSmoothPoint(s);
380 *heading = PathHeading(lane, hdmap_point);
381 point->x() = hdmap_point.x() - std::sin(*heading) * l;
382 point->y() = hdmap_point.y() + std::cos(*heading) * l;
383 return true;
384}
385
387 const Eigen::Vector2d& point, const double heading, const double radius,
388 const std::vector<std::shared_ptr<const LaneInfo>>& lanes,
389 const int max_num_lane,
390 std::vector<std::shared_ptr<const LaneInfo>>* nearby_lanes) {
391 if (lanes.empty()) {
392 std::vector<std::shared_ptr<const LaneInfo>> prev_lanes;
393 OnLane(prev_lanes, point, heading, radius, false, max_num_lane,
394 FLAGS_max_lane_angle_diff, nearby_lanes);
395 } else {
396 std::unordered_set<std::string> lane_ids;
397 for (auto& lane_ptr : lanes) {
398 if (lane_ptr == nullptr) {
399 continue;
400 }
401 for (auto& lane_id : lane_ptr->lane().left_neighbor_forward_lane_id()) {
402 const std::string& id = lane_id.id();
403 if (lane_ids.find(id) != lane_ids.end()) {
404 continue;
405 }
406 std::shared_ptr<const LaneInfo> nearby_lane = LaneById(id);
407 double s = -1.0;
408 double l = 0.0;
409 GetProjection(point, nearby_lane, &s, &l);
410 if (s < 0.0 || s >= nearby_lane->total_length() ||
411 std::fabs(l) > radius) {
412 continue;
413 }
414 lane_ids.insert(id);
415 nearby_lanes->push_back(nearby_lane);
416 }
417 for (auto& lane_id : lane_ptr->lane().right_neighbor_forward_lane_id()) {
418 const std::string& id = lane_id.id();
419 if (lane_ids.find(id) != lane_ids.end()) {
420 continue;
421 }
422 std::shared_ptr<const LaneInfo> nearby_lane = LaneById(id);
423 double s = -1.0;
424 double l = 0.0;
425 GetProjection(point, nearby_lane, &s, &l);
426 if (s < 0.0 || s >= nearby_lane->total_length() ||
427 std::fabs(l) > radius) {
428 continue;
429 }
430 lane_ids.insert(id);
431 nearby_lanes->push_back(nearby_lane);
432 }
433 }
434 }
435}
436
437std::shared_ptr<const LaneInfo> PredictionMap::GetLeftNeighborLane(
438 const std::shared_ptr<const LaneInfo>& ptr_ego_lane,
439 const Eigen::Vector2d& ego_position, const double threshold) {
440 std::vector<std::string> neighbor_ids;
441 for (const auto& lane_id :
442 ptr_ego_lane->lane().left_neighbor_forward_lane_id()) {
443 neighbor_ids.push_back(lane_id.id());
444 }
445
446 return GetNeighborLane(ptr_ego_lane, ego_position, neighbor_ids, threshold);
447}
448
449std::shared_ptr<const LaneInfo> PredictionMap::GetRightNeighborLane(
450 const std::shared_ptr<const LaneInfo>& ptr_ego_lane,
451 const Eigen::Vector2d& ego_position, const double threshold) {
452 std::vector<std::string> neighbor_ids;
453 for (const auto& lane_id :
454 ptr_ego_lane->lane().right_neighbor_forward_lane_id()) {
455 neighbor_ids.push_back(lane_id.id());
456 }
457
458 return GetNeighborLane(ptr_ego_lane, ego_position, neighbor_ids, threshold);
459}
460
461std::shared_ptr<const LaneInfo> PredictionMap::GetNeighborLane(
462 const std::shared_ptr<const LaneInfo>& ptr_ego_lane,
463 const Eigen::Vector2d& ego_position,
464 const std::vector<std::string>& neighbor_lane_ids, const double threshold) {
465 double ego_s = 0.0;
466 double ego_l = 0.0;
467 GetProjection(ego_position, ptr_ego_lane, &ego_s, &ego_l);
468
469 double s_diff_min = std::numeric_limits<double>::max();
470 std::shared_ptr<const LaneInfo> ptr_lane_min = nullptr;
471
472 for (auto& lane_id : neighbor_lane_ids) {
473 std::shared_ptr<const LaneInfo> ptr_lane = LaneById(lane_id);
474 double s = -1.0;
475 double l = 0.0;
476 GetProjection(ego_position, ptr_lane, &s, &l);
477
478 double s_diff = std::fabs(s - ego_s);
479 if (s_diff < s_diff_min) {
480 s_diff_min = s_diff;
481 ptr_lane_min = ptr_lane;
482 }
483 }
484
485 if (s_diff_min > threshold) {
486 return nullptr;
487 }
488 return ptr_lane_min;
489}
490
491std::vector<std::string> PredictionMap::NearbyLaneIds(
492 const Eigen::Vector2d& point, const double radius) {
493 std::vector<std::string> lane_ids;
494 std::vector<std::shared_ptr<const LaneInfo>> lanes;
495 common::PointENU hdmap_point;
496 hdmap_point.set_x(point[0]);
497 hdmap_point.set_y(point[1]);
498 HDMapUtil::BaseMap().GetLanes(hdmap_point, radius, &lanes);
499 for (const auto& lane : lanes) {
500 lane_ids.push_back(lane->id().id());
501 }
502 return lane_ids;
503}
504
506 std::shared_ptr<const LaneInfo> target_lane,
507 std::shared_ptr<const LaneInfo> curr_lane) {
508 if (curr_lane == nullptr) {
509 return true;
510 }
511 if (target_lane == nullptr) {
512 return false;
513 }
514 for (const auto& left_lane_id :
515 curr_lane->lane().left_neighbor_forward_lane_id()) {
516 if (target_lane->id().id() == left_lane_id.id()) {
517 return true;
518 }
519 }
520 return false;
521}
522
524 std::shared_ptr<const LaneInfo> target_lane,
525 const std::vector<std::shared_ptr<const LaneInfo>>& lanes) {
526 if (lanes.empty()) {
527 return true;
528 }
529 for (auto& lane : lanes) {
530 if (IsLeftNeighborLane(target_lane, lane)) {
531 return true;
532 }
533 }
534 return false;
535}
536
538 std::shared_ptr<const LaneInfo> target_lane,
539 std::shared_ptr<const LaneInfo> curr_lane) {
540 if (curr_lane == nullptr) {
541 return true;
542 }
543 if (target_lane == nullptr) {
544 return false;
545 }
546 for (auto& right_lane_id :
547 curr_lane->lane().right_neighbor_forward_lane_id()) {
548 if (target_lane->id().id() == right_lane_id.id()) {
549 return true;
550 }
551 }
552 return false;
553}
554
556 std::shared_ptr<const LaneInfo> target_lane,
557 const std::vector<std::shared_ptr<const LaneInfo>>& lanes) {
558 if (lanes.empty()) {
559 return true;
560 }
561 for (const auto& lane : lanes) {
562 if (IsRightNeighborLane(target_lane, lane)) {
563 return true;
564 }
565 }
566 return false;
567}
568
569bool PredictionMap::IsSuccessorLane(std::shared_ptr<const LaneInfo> target_lane,
570 std::shared_ptr<const LaneInfo> curr_lane) {
571 if (curr_lane == nullptr) {
572 return true;
573 }
574 if (target_lane == nullptr) {
575 return false;
576 }
577 for (const auto& successor_lane_id : curr_lane->lane().successor_id()) {
578 if (target_lane->id().id() == successor_lane_id.id()) {
579 return true;
580 }
581 }
582 return false;
583}
584
586 std::shared_ptr<const LaneInfo> target_lane,
587 const std::vector<std::shared_ptr<const LaneInfo>>& lanes) {
588 if (lanes.empty()) {
589 return true;
590 }
591 for (auto& lane : lanes) {
592 if (IsSuccessorLane(target_lane, lane)) {
593 return true;
594 }
595 }
596 return false;
597}
598
600 std::shared_ptr<const LaneInfo> target_lane,
601 std::shared_ptr<const LaneInfo> curr_lane) {
602 if (curr_lane == nullptr) {
603 return true;
604 }
605 if (target_lane == nullptr) {
606 return false;
607 }
608 for (const auto& predecessor_lane_id : curr_lane->lane().predecessor_id()) {
609 if (target_lane->id().id() == predecessor_lane_id.id()) {
610 return true;
611 }
612 }
613 return false;
614}
615
617 std::shared_ptr<const LaneInfo> target_lane,
618 const std::vector<std::shared_ptr<const LaneInfo>>& lanes) {
619 if (lanes.empty()) {
620 return true;
621 }
622 for (auto& lane : lanes) {
623 if (IsPredecessorLane(target_lane, lane)) {
624 return true;
625 }
626 }
627 return false;
628}
629
630bool PredictionMap::IsIdenticalLane(std::shared_ptr<const LaneInfo> other_lane,
631 std::shared_ptr<const LaneInfo> curr_lane) {
632 if (curr_lane == nullptr || other_lane == nullptr) {
633 return true;
634 }
635 return other_lane->id().id() == curr_lane->id().id();
636}
637
639 std::shared_ptr<const LaneInfo> other_lane,
640 const std::vector<std::shared_ptr<const LaneInfo>>& lanes) {
641 if (lanes.empty()) {
642 return true;
643 }
644 for (auto& lane : lanes) {
645 if (IsIdenticalLane(other_lane, lane)) {
646 return true;
647 }
648 }
649 return false;
650}
651
652int PredictionMap::LaneTurnType(const std::string& lane_id) {
653 std::shared_ptr<const LaneInfo> lane = LaneById(lane_id);
654 if (lane != nullptr) {
655 return static_cast<int>(lane->lane().turn());
656 }
657 return 1;
658}
659
660std::vector<std::shared_ptr<const LaneInfo>> PredictionMap::GetNearbyLanes(
661 const common::PointENU& position, const double nearby_radius) {
662 ACHECK(position.has_x() && position.has_y() && position.has_z());
663 ACHECK(nearby_radius > 0.0);
664
665 std::vector<std::shared_ptr<const LaneInfo>> nearby_lanes;
666
667 HDMapUtil::BaseMap().GetLanes(position, nearby_radius, &nearby_lanes);
668 return nearby_lanes;
669}
670
672 const std::vector<std::shared_ptr<const LaneInfo>>& lane_infos) {
673 ACHECK(!lane_infos.empty());
674 size_t sample_size = FLAGS_sample_size_for_average_lane_curvature;
675 std::shared_ptr<const hdmap::LaneInfo> selected_lane_info = lane_infos[0];
676 if (selected_lane_info == nullptr) {
677 AERROR << "Lane Vector first element: selected_lane_info is nullptr.";
678 return nullptr;
679 }
680 double smallest_curvature =
681 AverageCurvature(selected_lane_info->id().id(), sample_size);
682 for (size_t i = 1; i < lane_infos.size(); ++i) {
683 std::shared_ptr<const hdmap::LaneInfo> lane_info = lane_infos[i];
684 if (lane_info == nullptr) {
685 AWARN << "Lane vector element: one lane_info is nullptr.";
686 continue;
687 }
688 double curvature = AverageCurvature(lane_info->id().id(), sample_size);
689 if (curvature < smallest_curvature) {
690 smallest_curvature = curvature;
691 selected_lane_info = lane_info;
692 }
693 }
694 return selected_lane_info;
695}
696
697double PredictionMap::AverageCurvature(const std::string& lane_id,
698 const size_t sample_size) {
699 CHECK_GT(sample_size, 0U);
700 std::shared_ptr<const hdmap::LaneInfo> lane_info_ptr =
702 if (lane_info_ptr == nullptr) {
703 return 0.0;
704 }
705 double lane_length = lane_info_ptr->total_length();
706 double s_gap = lane_length / static_cast<double>(sample_size);
707 double curvature_sum = 0.0;
708 for (size_t i = 0; i < sample_size; ++i) {
709 double s = s_gap * static_cast<double>(i);
710 curvature_sum += std::abs(PredictionMap::CurvatureOnLane(lane_id, s));
711 }
712 return curvature_sum / static_cast<double>(sample_size);
713}
714
715} // namespace prediction
716} // namespace apollo
The class of polygon in 2-D.
Definition polygon2d.h:42
bool IsPointIn(const Vec2d &point) const
Check if a point is within the polygon.
Definition polygon2d.cc:130
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
void set_x(const double x)
Setter for x component
Definition vec2d.h:60
double InnerProd(const Vec2d &other) const
Returns the inner product between these two Vec2d.
Definition vec2d.cc:61
void set_y(const double y)
Setter for y component
Definition vec2d.h:63
static const HDMap * BaseMapPtr()
static const HDMap & BaseMap()
int GetLanes(const apollo::common::PointENU &point, double distance, std::vector< LaneInfoConstPtr > *lanes) const
get all lanes in certain range
Definition hdmap.cc:90
LaneInfoConstPtr GetLaneById(const Id &id) const
Definition hdmap.cc:34
RoadInfoConstPtr GetRoadById(const Id &id) const
Definition hdmap.cc:78
JunctionInfoConstPtr GetJunctionById(const Id &id) const
Definition hdmap.cc:38
OverlapInfoConstPtr GetOverlapById(const Id &id) const
Definition hdmap.cc:74
int GetPNCJunctions(const apollo::common::PointENU &point, double distance, std::vector< PNCJunctionInfoConstPtr > *pnc_junctions) const
get all pnc junctions in certain range
Definition hdmap.cc:155
int GetJunctions(const apollo::common::PointENU &point, double distance, std::vector< JunctionInfoConstPtr > *junctions) const
get all junctions in certain range
Definition hdmap.cc:95
void set_heading(const double heading)
Definition path.h:119
static bool IsProjectionApproximateWithinLane(const Eigen::Vector2d &ego_position, const std::string &lane_id)
Check whether the projection of ego vehicle is on the target lane.
static bool IsSuccessorLane(std::shared_ptr< const hdmap::LaneInfo > target_lane, std::shared_ptr< const hdmap::LaneInfo > curr_lane)
Check if the target lane is a successor of another lane.
static bool InJunction(const Eigen::Vector2d &point, const double radius)
Check if the obstacle is in a junction.
static bool IsPointInJunction(const double x, const double y, const std::shared_ptr< const hdmap::JunctionInfo > junction_info_ptr)
Check if a point with coord x and y is in the junction.
static std::vector< std::shared_ptr< const hdmap::LaneInfo > > GetNearbyLanes(const common::PointENU &position, const double nearby_radius)
Get all nearby lanes within certain radius given a position
static void OnLane(const std::vector< std::shared_ptr< const hdmap::LaneInfo > > &prev_lanes, const Eigen::Vector2d &point, const double heading, const double radius, const bool on_lane, const int max_num_lane, const double max_lane_angle_diff, std::vector< std::shared_ptr< const hdmap::LaneInfo > > *lanes)
Get the connected lanes from some specified lanes.
static std::shared_ptr< const hdmap::JunctionInfo > JunctionById(const std::string &id)
Get a shared pointer to a junction by junction ID.
static bool IsIdenticalLane(std::shared_ptr< const hdmap::LaneInfo > other_lane, std::shared_ptr< const hdmap::LaneInfo > curr_lane)
Check if two lanes are identical.
static bool IsRightNeighborLane(std::shared_ptr< const hdmap::LaneInfo > target_lane, std::shared_ptr< const hdmap::LaneInfo > curr_lane)
Check if a lane is a right neighbor of another lane.
static std::vector< std::string > NearbyLaneIds(const Eigen::Vector2d &point, const double radius)
Get nearby lanes by a position.
static bool IsPredecessorLane(std::shared_ptr< const hdmap::LaneInfo > target_lane, std::shared_ptr< const hdmap::LaneInfo > curr_lane)
Check if the target lane is a predecessor of another lane.
static double LaneTotalWidth(const std::shared_ptr< const hdmap::LaneInfo > lane_info, const double s)
Get the width on a specified distance on a lane.
static double HeadingOnLane(const std::shared_ptr< const hdmap::LaneInfo > lane_info, const double s)
Get the heading of a point on a specific distance along a lane.
static bool ProjectionFromLane(std::shared_ptr< const hdmap::LaneInfo > lane_info, const double s, hdmap::MapPathPoint *path_point)
Get the nearest path point to a longitudinal coordinate on a lane.
static double AverageCurvature(const std::string &lane_id, const size_t sample_size)
Get the average curvature along a lane with the ID lane_id
static bool OnVirtualLane(const Eigen::Vector2d &position, const double radius)
Determine if a point is on a virtual lane.
static bool IsLeftNeighborLane(std::shared_ptr< const hdmap::LaneInfo > target_lane, std::shared_ptr< const hdmap::LaneInfo > curr_lane)
Check if a lane is a left neighbor of another lane.
static Eigen::Vector2d PositionOnLane(const std::shared_ptr< const hdmap::LaneInfo > lane_info, const double s)
Get the position of a point on a specific distance along a lane.
static std::shared_ptr< const hdmap::LaneInfo > GetRightNeighborLane(const std::shared_ptr< const hdmap::LaneInfo > &ptr_ego_lane, const Eigen::Vector2d &ego_position, const double threshold)
static bool HasNearbyLane(const double x, const double y, const double radius)
If there is a lane in the range with radius
static int LaneTurnType(const std::string &lane_id)
Get lane turn type.
static std::shared_ptr< const hdmap::LaneInfo > GetLeftNeighborLane(const std::shared_ptr< const hdmap::LaneInfo > &ptr_ego_lane, const Eigen::Vector2d &ego_position, const double threshold)
static bool NearJunction(const Eigen::Vector2d &point, const double radius)
Check if there are any junctions within the range centered at a certain point with a radius.
static void NearbyLanesByCurrentLanes(const Eigen::Vector2d &point, const double heading, const double radius, const std::vector< std::shared_ptr< const hdmap::LaneInfo > > &lanes, const int max_num_lane, std::vector< std::shared_ptr< const hdmap::LaneInfo > > *nearby_lanes)
Get nearby lanes by a position and current lanes.
static bool Ready()
Check if map is ready
static bool SmoothPointFromLane(const std::string &id, const double s, const double l, Eigen::Vector2d *point, double *heading)
Get the smooth point on a lane by a longitudinal coordinate.
static bool IsVirtualLane(const std::string &lane_id)
Determine if a lane is a virtual lane.
static std::shared_ptr< const hdmap::LaneInfo > LaneWithSmallestAverageCurvature(const std::vector< std::shared_ptr< const hdmap::LaneInfo > > &lane_infos)
Get the pointer to the lane with the smallest average curvature
static std::shared_ptr< const apollo::hdmap::LaneInfo > GetMostLikelyCurrentLane(const common::PointENU &position, const double radius, const double heading, const double angle_diff_threshold)
Get the lane that the position is on with minimal angle diff
static double CurvatureOnLane(const std::string &lane_id, const double s)
Get the curvature of a point on a specific distance along a lane.
static std::vector< std::shared_ptr< const apollo::hdmap::PNCJunctionInfo > > GetPNCJunctions(const Eigen::Vector2d &point, const double radius)
Get a list of junctions given a point and a search radius
static std::vector< std::shared_ptr< const apollo::hdmap::JunctionInfo > > GetJunctions(const Eigen::Vector2d &point, const double radius)
Get a list of junctions given a point and a search radius
static bool IsLaneInJunction(const std::shared_ptr< const hdmap::LaneInfo > lane_info, const std::string &junction_id)
Check if a lane is in a junction
static std::shared_ptr< const hdmap::LaneInfo > LaneById(const std::string &id)
Get a shared pointer to a lane by lane ID.
static double PathHeading(std::shared_ptr< const hdmap::LaneInfo > lane_info, const common::PointENU &point)
Get the lane heading on a point.
static bool GetProjection(const Eigen::Vector2d &position, const std::shared_ptr< const hdmap::LaneInfo > lane_info, double *s, double *l)
Get the frenet coordinates (s, l) on a lane by a position.
static std::shared_ptr< const hdmap::OverlapInfo > OverlapById(const std::string &id)
Get a shared pointer to an overlap by overlap ID.
#define ACHECK(cond)
Definition log.h:80
#define AERROR
Definition log.h:44
#define AWARN
Definition log.h:43
double AngleDiff(const double from, const double to)
Calculate the difference between angle from and to
Definition math_utils.cc:61
apollo::hdmap::Id MakeMapId(const std::string &id)
create a Map ID given a string.
Definition hdmap_util.h:85
class register implement
Definition arena_queue.h:37
optional LaneBoundary right_boundary
optional LaneBoundary left_boundary