Apollo 10.0
自动驾驶开放平台
hdmap_impl.h
浏览该文件的文档.
1/* Copyright 2017 The Apollo Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14=========================================================================*/
15
16#pragma once
17
18#include <memory>
19#include <string>
20#include <unordered_map>
21#include <utility>
22#include <vector>
23
24#include "modules/common_msgs/map_msgs/map.pb.h"
25#include "modules/common_msgs/map_msgs/map_area.pb.h"
26#include "modules/common_msgs/map_msgs/map_barrier_gate.pb.h"
27#include "modules/common_msgs/map_msgs/map_clear_area.pb.h"
28#include "modules/common_msgs/map_msgs/map_crosswalk.pb.h"
29#include "modules/common_msgs/map_msgs/map_geometry.pb.h"
30#include "modules/common_msgs/map_msgs/map_junction.pb.h"
31#include "modules/common_msgs/map_msgs/map_lane.pb.h"
32#include "modules/common_msgs/map_msgs/map_overlap.pb.h"
33#include "modules/common_msgs/map_msgs/map_parking_space.pb.h"
34#include "modules/common_msgs/map_msgs/map_pnc_junction.pb.h"
35#include "modules/common_msgs/map_msgs/map_signal.pb.h"
36#include "modules/common_msgs/map_msgs/map_speed_bump.pb.h"
37#include "modules/common_msgs/map_msgs/map_stop_sign.pb.h"
38#include "modules/common_msgs/map_msgs/map_yield_sign.pb.h"
39
46
51namespace apollo {
52namespace hdmap {
53
59class HDMapImpl {
60 public:
61 using LaneTable = std::unordered_map<std::string, std::shared_ptr<LaneInfo>>;
63 std::unordered_map<std::string, std::shared_ptr<JunctionInfo>>;
64 using AreaTable = std::unordered_map<std::string, std::shared_ptr<AreaInfo>>;
66 std::unordered_map<std::string, std::shared_ptr<SignalInfo>>;
68 std::unordered_map<std::string, std::shared_ptr<BarrierGateInfo>>;
70 std::unordered_map<std::string, std::shared_ptr<CrosswalkInfo>>;
72 std::unordered_map<std::string, std::shared_ptr<StopSignInfo>>;
74 std::unordered_map<std::string, std::shared_ptr<YieldSignInfo>>;
76 std::unordered_map<std::string, std::shared_ptr<ClearAreaInfo>>;
78 std::unordered_map<std::string, std::shared_ptr<SpeedBumpInfo>>;
80 std::unordered_map<std::string, std::shared_ptr<OverlapInfo>>;
81 using RoadTable = std::unordered_map<std::string, std::shared_ptr<RoadInfo>>;
83 std::unordered_map<std::string, std::shared_ptr<ParkingSpaceInfo>>;
85 std::unordered_map<std::string, std::shared_ptr<PNCJunctionInfo>>;
86 using RSUTable = std::unordered_map<std::string, std::shared_ptr<RSUInfo>>;
87
88 public:
94 int LoadMapFromFile(const std::string& map_filename);
95
101 int LoadMapFromProto(const Map& map_proto);
102
103 LaneInfoConstPtr GetLaneById(const Id& id) const;
104 JunctionInfoConstPtr GetJunctionById(const Id& id) const;
105 SignalInfoConstPtr GetSignalById(const Id& id) const;
107 StopSignInfoConstPtr GetStopSignById(const Id& id) const;
111 OverlapInfoConstPtr GetOverlapById(const Id& id) const;
112 RoadInfoConstPtr GetRoadById(const Id& id) const;
115 RSUInfoConstPtr GetRSUById(const Id& id) const;
116 AreaInfoConstPtr GetAreaById(const Id& id) const;
118
124 Id CreateHDMapId(const std::string& string_id) const;
132 int GetAreas(const apollo::common::PointENU& point, double distance,
133 std::vector<AreaInfoConstPtr>* areas) const;
141 int GetLanes(const apollo::common::PointENU& point, double distance,
142 std::vector<LaneInfoConstPtr>* lanes) const;
150 int GetJunctions(const apollo::common::PointENU& point, double distance,
151 std::vector<JunctionInfoConstPtr>* junctions) const;
159 int GetCrosswalks(const apollo::common::PointENU& point, double distance,
160 std::vector<CrosswalkInfoConstPtr>* crosswalks) const;
168 int GetSignals(const apollo::common::PointENU& point, double distance,
169 std::vector<SignalInfoConstPtr>* signals) const;
177 int GetBarrierGates(const apollo::common::PointENU& point, double distance,
178 std::vector<BarrierGateInfoConstPtr>* barrier_gates) const;
186 int GetStopSigns(const apollo::common::PointENU& point, double distance,
187 std::vector<StopSignInfoConstPtr>* stop_signs) const;
195 int GetYieldSigns(const apollo::common::PointENU& point, double distance,
196 std::vector<YieldSignInfoConstPtr>* yield_signs) const;
204 int GetClearAreas(const apollo::common::PointENU& point, double distance,
205 std::vector<ClearAreaInfoConstPtr>* clear_areas) const;
213 int GetSpeedBumps(const apollo::common::PointENU& point, double distance,
214 std::vector<SpeedBumpInfoConstPtr>* speed_bumps) const;
222 int GetRoads(const apollo::common::PointENU& point, double distance,
223 std::vector<RoadInfoConstPtr>* roads) const;
224
233 const apollo::common::PointENU& point, double distance,
234 std::vector<ParkingSpaceInfoConstPtr>* parking_spaces) const;
235
243 int GetPNCJunctions(
244 const apollo::common::PointENU& point, double distance,
245 std::vector<PNCJunctionInfoConstPtr>* pnc_junctions) const;
246
257 const double distance,
258 LaneInfoConstPtr* nearest_lane,
259 double* nearest_s, double* nearest_l) const;
260
270 LaneInfoConstPtr* nearest_lane, double* nearest_s,
271 double* nearest_l) const;
284 const double distance,
285 const double central_heading,
286 const double max_heading_difference,
287 LaneInfoConstPtr* nearest_lane,
288 double* nearest_s, double* nearest_l) const;
299 const double distance, const double central_heading,
300 const double max_heading_difference,
301 std::vector<LaneInfoConstPtr>* lanes) const;
310 int GetRoadBoundaries(const apollo::common::PointENU& point, double radius,
311 std::vector<RoadROIBoundaryPtr>* road_boundaries,
312 std::vector<JunctionBoundaryPtr>* junctions) const;
321 int GetRoadBoundaries(const apollo::common::PointENU& point, double radius,
322 std::vector<RoadRoiPtr>* road_boundaries,
323 std::vector<JunctionInfoConstPtr>* junctions) const;
332 int GetRoi(const apollo::common::PointENU& point, double radius,
333 std::vector<RoadRoiPtr>* roads_roi,
334 std::vector<PolygonRoiPtr>* polygons_roi);
345 const apollo::common::PointENU& point, const double distance,
346 std::vector<SignalInfoConstPtr>* signals) const;
347
356 const apollo::common::PointENU& point, const double distance,
357 std::vector<BarrierGateInfoConstPtr>* barrier_gates) const;
358
367 const Id& id, std::vector<StopSignInfoConstPtr>* stop_signs) const;
368
375 int GetStopSignAssociatedLanes(const Id& id,
376 std::vector<LaneInfoConstPtr>* lanes) const;
377
386 int GetLocalMap(const apollo::common::PointENU& point,
387 const std::pair<double, double>& range, Map* local_map) const;
388
399 double distance, double central_heading,
400 double max_heading_difference,
401 std::vector<RSUInfoConstPtr>* rsus) const;
402
403 bool GetMapHeader(Header* map_header) const;
404
405 private:
406 int GetLanes(const apollo::common::math::Vec2d& point, double distance,
407 std::vector<LaneInfoConstPtr>* lanes) const;
408 int GetJunctions(const apollo::common::math::Vec2d& point, double distance,
409 std::vector<JunctionInfoConstPtr>* junctions) const;
410 int GetAreas(const apollo::common::math::Vec2d&, double distance,
411 std::vector<AreaInfoConstPtr>* areas) const;
412 int GetCrosswalks(const apollo::common::math::Vec2d& point, double distance,
413 std::vector<CrosswalkInfoConstPtr>* crosswalks) const;
414 int GetSignals(const apollo::common::math::Vec2d& point, double distance,
415 std::vector<SignalInfoConstPtr>* signals) const;
416 int GetBarrierGates(const apollo::common::math::Vec2d& point, double distance,
417 std::vector<BarrierGateInfoConstPtr>* barrier_gates) const;
418 int GetStopSigns(const apollo::common::math::Vec2d& point, double distance,
419 std::vector<StopSignInfoConstPtr>* stop_signs) const;
420 int GetYieldSigns(const apollo::common::math::Vec2d& point, double distance,
421 std::vector<YieldSignInfoConstPtr>* yield_signs) const;
422 int GetClearAreas(const apollo::common::math::Vec2d& point, double distance,
423 std::vector<ClearAreaInfoConstPtr>* clear_areas) const;
424 int GetSpeedBumps(const apollo::common::math::Vec2d& point, double distance,
425 std::vector<SpeedBumpInfoConstPtr>* speed_bumps) const;
427 const apollo::common::math::Vec2d& point, double distance,
428 std::vector<ParkingSpaceInfoConstPtr>* parking_spaces) const;
429 int GetPNCJunctions(
430 const apollo::common::math::Vec2d& point, double distance,
431 std::vector<PNCJunctionInfoConstPtr>* pnc_junctions) const;
433 LaneInfoConstPtr* nearest_lane, double* nearest_s,
434 double* nearest_l) const;
436 const double distance,
437 const double central_heading,
438 const double max_heading_difference,
439 LaneInfoConstPtr* nearest_lane,
440 double* nearest_s, double* nearest_l) const;
442 const double distance, const double central_heading,
443 const double max_heading_difference,
444 std::vector<LaneInfoConstPtr>* lanes) const;
445 int GetRoads(const apollo::common::math::Vec2d& point, double distance,
446 std::vector<RoadInfoConstPtr>* roads) const;
448 const double distance,
449 LaneInfoConstPtr* nearest_lane,
450 double* nearest_s, double* nearest_l) const;
451
452 template <class Table, class BoxTable, class KDTree>
453 static void BuildSegmentKDTree(
454 const Table& table, const apollo::common::math::AABoxKDTreeParams& params,
455 BoxTable* const box_table, std::unique_ptr<KDTree>* const kdtree);
456
457 template <class Table, class BoxTable, class KDTree>
458 static void BuildPolygonKDTree(
459 const Table& table, const apollo::common::math::AABoxKDTreeParams& params,
460 BoxTable* const box_table, std::unique_ptr<KDTree>* const kdtree);
461
462 void BuildLaneSegmentKDTree();
463 void BuildJunctionPolygonKDTree();
464 void BuildCrosswalkPolygonKDTree();
465 void BuildSignalSegmentKDTree();
466 void BuildStopSignSegmentKDTree();
467 void BuildYieldSignSegmentKDTree();
468 void BuildClearAreaPolygonKDTree();
469 void BuildSpeedBumpSegmentKDTree();
470 void BuildParkingSpacePolygonKDTree();
471 void BuildPNCJunctionPolygonKDTree();
472 void BuildAreaPolygonKDTree();
473 void BuildBarrierGateSegmentKDTree();
474
475 template <class KDTree>
476 static int SearchObjects(const apollo::common::math::Vec2d& center,
477 const double radius, const KDTree& kdtree,
478 std::vector<std::string>* const results);
479
480 void Clear();
481
482 private:
483 Map map_;
484 LaneTable lane_table_;
485 JunctionTable junction_table_;
486 AreaTable area_table_;
487 CrosswalkTable crosswalk_table_;
488 SignalTable signal_table_;
489 BarrierGateTable barrier_gate_table_;
490 StopSignTable stop_sign_table_;
491 YieldSignTable yield_sign_table_;
492 ClearAreaTable clear_area_table_;
493 SpeedBumpTable speed_bump_table_;
494 OverlapTable overlap_table_;
495 RoadTable road_table_;
496 ParkingSpaceTable parking_space_table_;
497 PNCJunctionTable pnc_junction_table_;
498 RSUTable rsu_table_;
499
500 std::vector<LaneSegmentBox> lane_segment_boxes_;
501 std::unique_ptr<LaneSegmentKDTree> lane_segment_kdtree_;
502
503 std::vector<JunctionPolygonBox> junction_polygon_boxes_;
504 std::unique_ptr<JunctionPolygonKDTree> junction_polygon_kdtree_;
505
506 std::vector<AreaPolygonBox> area_polygon_boxes_;
507 std::unique_ptr<AreaPolygonKDTree> area_polygon_kdtree_;
508
509 std::vector<CrosswalkPolygonBox> crosswalk_polygon_boxes_;
510 std::unique_ptr<CrosswalkPolygonKDTree> crosswalk_polygon_kdtree_;
511
512 std::vector<SignalSegmentBox> signal_segment_boxes_;
513 std::unique_ptr<SignalSegmentKDTree> signal_segment_kdtree_;
514
515 std::vector<BarrierGateSegmentBox> barrier_gate_segment_boxes_;
516 std::unique_ptr<BarrierGateSegmentKDTree> barrier_gate_segment_kdtree_;
517
518 std::vector<StopSignSegmentBox> stop_sign_segment_boxes_;
519 std::unique_ptr<StopSignSegmentKDTree> stop_sign_segment_kdtree_;
520
521 std::vector<YieldSignSegmentBox> yield_sign_segment_boxes_;
522 std::unique_ptr<YieldSignSegmentKDTree> yield_sign_segment_kdtree_;
523
524 std::vector<ClearAreaPolygonBox> clear_area_polygon_boxes_;
525 std::unique_ptr<ClearAreaPolygonKDTree> clear_area_polygon_kdtree_;
526
527 std::vector<SpeedBumpSegmentBox> speed_bump_segment_boxes_;
528 std::unique_ptr<SpeedBumpSegmentKDTree> speed_bump_segment_kdtree_;
529
530 std::vector<ParkingSpacePolygonBox> parking_space_polygon_boxes_;
531 std::unique_ptr<ParkingSpacePolygonKDTree> parking_space_polygon_kdtree_;
532
533 std::vector<PNCJunctionPolygonBox> pnc_junction_polygon_boxes_;
534 std::unique_ptr<PNCJunctionPolygonKDTree> pnc_junction_polygon_kdtree_;
535};
536
537} // namespace hdmap
538} // namespace apollo
Defines the AABox2d class.
Defines the templated AABoxKDTree2dNode class.
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
High-precision map loader implement.
Definition hdmap_impl.h:59
std::unordered_map< std::string, std::shared_ptr< YieldSignInfo > > YieldSignTable
Definition hdmap_impl.h:74
std::unordered_map< std::string, std::shared_ptr< SignalInfo > > SignalTable
Definition hdmap_impl.h:66
std::unordered_map< std::string, std::shared_ptr< SpeedBumpInfo > > SpeedBumpTable
Definition hdmap_impl.h:78
int GetNearestLaneWithHeading(const apollo::common::PointENU &point, const double distance, const double central_heading, const double max_heading_difference, LaneInfoConstPtr *nearest_lane, double *nearest_s, double *nearest_l) const
get the nearest lane within a certain range by pose
int GetAreas(const apollo::common::PointENU &point, double distance, std::vector< AreaInfoConstPtr > *areas) const
get all areas in certain range
std::unordered_map< std::string, std::shared_ptr< BarrierGateInfo > > BarrierGateTable
Definition hdmap_impl.h:68
std::unordered_map< std::string, std::shared_ptr< StopSignInfo > > StopSignTable
Definition hdmap_impl.h:72
Id CreateHDMapId(const std::string &string_id) const
convert id data type
Definition hdmap_impl.cc:45
int GetRoadBoundaries(const apollo::common::PointENU &point, double radius, std::vector< RoadROIBoundaryPtr > *road_boundaries, std::vector< JunctionBoundaryPtr > *junctions) const
get all road and junctions boundaries within certain range
int GetStopSignAssociatedStopSigns(const Id &id, std::vector< StopSignInfoConstPtr > *stop_signs) const
get all other stop signs associated with a stop sign in the same junction
int GetJunctions(const apollo::common::PointENU &point, double distance, std::vector< JunctionInfoConstPtr > *junctions) const
get all junctions in certain range
int GetBarrierGates(const apollo::common::PointENU &point, double distance, std::vector< BarrierGateInfoConstPtr > *barrier_gates) const
get all barrier_gates in certain range
int GetNearestLane(const apollo::common::PointENU &point, LaneInfoConstPtr *nearest_lane, double *nearest_s, double *nearest_l) const
get nearest lane from target point,
std::unordered_map< std::string, std::shared_ptr< JunctionInfo > > JunctionTable
Definition hdmap_impl.h:63
OverlapInfoConstPtr GetOverlapById(const Id &id) const
std::unordered_map< std::string, std::shared_ptr< LaneInfo > > LaneTable
Definition hdmap_impl.h:61
std::unordered_map< std::string, std::shared_ptr< OverlapInfo > > OverlapTable
Definition hdmap_impl.h:80
int GetStopSigns(const apollo::common::PointENU &point, double distance, std::vector< StopSignInfoConstPtr > *stop_signs) const
get all stop signs in certain range
StopSignInfoConstPtr GetStopSignById(const Id &id) const
AreaInfoConstPtr GetAreaById(const Id &id) const
int GetLanesWithHeading(const apollo::common::PointENU &point, const double distance, const double central_heading, const double max_heading_difference, std::vector< LaneInfoConstPtr > *lanes) const
get all lanes within a certain range by pose
int GetRoadBoundaries(const apollo::common::PointENU &point, double radius, std::vector< RoadRoiPtr > *road_boundaries, std::vector< JunctionInfoConstPtr > *junctions) const
get all road boundaries and junctions within certain range
int LoadMapFromProto(const Map &map_proto)
load map from a protobuf message
Definition hdmap_impl.cc:74
JunctionInfoConstPtr GetJunctionById(const Id &id) const
ParkingSpaceInfoConstPtr GetParkingSpaceById(const Id &id) const
int GetNearestLaneWithDistance(const apollo::common::PointENU &point, const double distance, LaneInfoConstPtr *nearest_lane, double *nearest_s, double *nearest_l) const
get nearest lane from target point with search radius,
std::unordered_map< std::string, std::shared_ptr< AreaInfo > > AreaTable
Definition hdmap_impl.h:64
CrosswalkInfoConstPtr GetCrosswalkById(const Id &id) const
ClearAreaInfoConstPtr GetClearAreaById(const Id &id) const
int GetRoads(const apollo::common::PointENU &point, double distance, std::vector< RoadInfoConstPtr > *roads) const
get all roads in certain range
SignalInfoConstPtr GetSignalById(const Id &id) const
int GetPNCJunctions(const apollo::common::PointENU &point, double distance, std::vector< PNCJunctionInfoConstPtr > *pnc_junctions) const
get all pnc junctions in certain range
int GetForwardNearestRSUs(const apollo::common::PointENU &point, double distance, double central_heading, double max_heading_difference, std::vector< RSUInfoConstPtr > *rsus) const
get forward nearest rsus within certain range
int GetSignals(const apollo::common::PointENU &point, double distance, std::vector< SignalInfoConstPtr > *signals) const
get all signals in certain range
YieldSignInfoConstPtr GetYieldSignById(const Id &id) const
std::unordered_map< std::string, std::shared_ptr< CrosswalkInfo > > CrosswalkTable
Definition hdmap_impl.h:70
std::unordered_map< std::string, std::shared_ptr< RSUInfo > > RSUTable
Definition hdmap_impl.h:86
int GetCrosswalks(const apollo::common::PointENU &point, double distance, std::vector< CrosswalkInfoConstPtr > *crosswalks) const
get all crosswalks in certain range
int GetLocalMap(const apollo::common::PointENU &point, const std::pair< double, double > &range, Map *local_map) const
get a local map which is identical to the origin map except that all map elements without overlap wit...
int GetClearAreas(const apollo::common::PointENU &point, double distance, std::vector< ClearAreaInfoConstPtr > *clear_areas) const
get all clear areas in certain range
int GetRoi(const apollo::common::PointENU &point, double radius, std::vector< RoadRoiPtr > *roads_roi, std::vector< PolygonRoiPtr > *polygons_roi)
get ROI within certain range
PNCJunctionInfoConstPtr GetPNCJunctionById(const Id &id) const
std::unordered_map< std::string, std::shared_ptr< ParkingSpaceInfo > > ParkingSpaceTable
Definition hdmap_impl.h:83
int GetForwardNearestBarriersOnLane(const apollo::common::PointENU &point, const double distance, std::vector< BarrierGateInfoConstPtr > *barrier_gates) const
get forward nearest barrier_gates within certain range on the lane
RoadInfoConstPtr GetRoadById(const Id &id) const
int GetYieldSigns(const apollo::common::PointENU &point, double distance, std::vector< YieldSignInfoConstPtr > *yield_signs) const
get all yield signs in certain range
std::unordered_map< std::string, std::shared_ptr< ClearAreaInfo > > ClearAreaTable
Definition hdmap_impl.h:76
LaneInfoConstPtr GetLaneById(const Id &id) const
std::unordered_map< std::string, std::shared_ptr< PNCJunctionInfo > > PNCJunctionTable
Definition hdmap_impl.h:85
BarrierGateInfoConstPtr GetBarrierGateById(const Id &id) const
bool GetMapHeader(Header *map_header) const
Definition hdmap_impl.cc:66
RSUInfoConstPtr GetRSUById(const Id &id) const
int GetParkingSpaces(const apollo::common::PointENU &point, double distance, std::vector< ParkingSpaceInfoConstPtr > *parking_spaces) const
get all parking space in certain range
std::unordered_map< std::string, std::shared_ptr< RoadInfo > > RoadTable
Definition hdmap_impl.h:81
int GetSpeedBumps(const apollo::common::PointENU &point, double distance, std::vector< SpeedBumpInfoConstPtr > *speed_bumps) const
get all speed bumps in certain range
int LoadMapFromFile(const std::string &map_filename)
load map from local file
Definition hdmap_impl.cc:51
int GetForwardNearestSignalsOnLane(const apollo::common::PointENU &point, const double distance, std::vector< SignalInfoConstPtr > *signals) const
get forward nearest signals within certain range on the lane if there are two signals related to one ...
SpeedBumpInfoConstPtr GetSpeedBumpById(const Id &id) const
int GetStopSignAssociatedLanes(const Id &id, std::vector< LaneInfoConstPtr > *lanes) const
get all lanes associated with a stop sign in the same junction
int GetLanes(const apollo::common::PointENU &point, double distance, std::vector< LaneInfoConstPtr > *lanes) const
get all lanes in certain range
Define the LineSegment2d class.
std::shared_ptr< const PNCJunctionInfo > PNCJunctionInfoConstPtr
std::shared_ptr< const JunctionInfo > JunctionInfoConstPtr
std::shared_ptr< const StopSignInfo > StopSignInfoConstPtr
std::shared_ptr< const AreaInfo > AreaInfoConstPtr
std::shared_ptr< const LaneInfo > LaneInfoConstPtr
std::shared_ptr< const ClearAreaInfo > ClearAreaInfoConstPtr
std::shared_ptr< const BarrierGateInfo > BarrierGateInfoConstPtr
std::shared_ptr< const SignalInfo > SignalInfoConstPtr
std::shared_ptr< const SpeedBumpInfo > SpeedBumpInfoConstPtr
std::shared_ptr< const RoadInfo > RoadInfoConstPtr
std::shared_ptr< const CrosswalkInfo > CrosswalkInfoConstPtr
std::shared_ptr< const RSUInfo > RSUInfoConstPtr
std::shared_ptr< const YieldSignInfo > YieldSignInfoConstPtr
std::shared_ptr< const ParkingSpaceInfo > ParkingSpaceInfoConstPtr
std::shared_ptr< const OverlapInfo > OverlapInfoConstPtr
class register implement
Definition arena_queue.h:37
Define the Polygon2d class.
Contains parameters of axis-aligned bounding box.
Defines the Vec2d class.