Apollo  6.0
Open source self driving car software
hdmap_impl.h
Go to the documentation of this file.
1 /* Copyright 2017 The Apollo Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7  http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations 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 
30 #include "modules/map/proto/map.pb.h"
31 #include "modules/map/proto/map_clear_area.pb.h"
32 #include "modules/map/proto/map_crosswalk.pb.h"
33 #include "modules/map/proto/map_geometry.pb.h"
34 #include "modules/map/proto/map_junction.pb.h"
35 #include "modules/map/proto/map_lane.pb.h"
36 #include "modules/map/proto/map_overlap.pb.h"
37 #include "modules/map/proto/map_parking_space.pb.h"
38 #include "modules/map/proto/map_pnc_junction.pb.h"
39 #include "modules/map/proto/map_signal.pb.h"
40 #include "modules/map/proto/map_speed_bump.pb.h"
41 #include "modules/map/proto/map_stop_sign.pb.h"
42 #include "modules/map/proto/map_yield_sign.pb.h"
43 
48 namespace apollo {
49 namespace hdmap {
50 
56 class HDMapImpl {
57  public:
58  using LaneTable = std::unordered_map<std::string, std::shared_ptr<LaneInfo>>;
59  using JunctionTable =
60  std::unordered_map<std::string, std::shared_ptr<JunctionInfo>>;
61  using SignalTable =
62  std::unordered_map<std::string, std::shared_ptr<SignalInfo>>;
63  using CrosswalkTable =
64  std::unordered_map<std::string, std::shared_ptr<CrosswalkInfo>>;
65  using StopSignTable =
66  std::unordered_map<std::string, std::shared_ptr<StopSignInfo>>;
67  using YieldSignTable =
68  std::unordered_map<std::string, std::shared_ptr<YieldSignInfo>>;
69  using ClearAreaTable =
70  std::unordered_map<std::string, std::shared_ptr<ClearAreaInfo>>;
71  using SpeedBumpTable =
72  std::unordered_map<std::string, std::shared_ptr<SpeedBumpInfo>>;
73  using OverlapTable =
74  std::unordered_map<std::string, std::shared_ptr<OverlapInfo>>;
75  using RoadTable = std::unordered_map<std::string, std::shared_ptr<RoadInfo>>;
76  using ParkingSpaceTable =
77  std::unordered_map<std::string, std::shared_ptr<ParkingSpaceInfo>>;
78  using PNCJunctionTable =
79  std::unordered_map<std::string, std::shared_ptr<PNCJunctionInfo>>;
80  using RSUTable =
81  std::unordered_map<std::string, std::shared_ptr<RSUInfo>>;
82 
83  public:
89  int LoadMapFromFile(const std::string& map_filename);
90 
96  int LoadMapFromProto(const Map& map_proto);
97 
98  LaneInfoConstPtr GetLaneById(const Id& id) const;
99  JunctionInfoConstPtr GetJunctionById(const Id& id) const;
100  SignalInfoConstPtr GetSignalById(const Id& id) const;
101  CrosswalkInfoConstPtr GetCrosswalkById(const Id& id) const;
102  StopSignInfoConstPtr GetStopSignById(const Id& id) const;
103  YieldSignInfoConstPtr GetYieldSignById(const Id& id) const;
104  ClearAreaInfoConstPtr GetClearAreaById(const Id& id) const;
105  SpeedBumpInfoConstPtr GetSpeedBumpById(const Id& id) const;
106  OverlapInfoConstPtr GetOverlapById(const Id& id) const;
107  RoadInfoConstPtr GetRoadById(const Id& id) const;
108  ParkingSpaceInfoConstPtr GetParkingSpaceById(const Id& id) const;
109  PNCJunctionInfoConstPtr GetPNCJunctionById(const Id& id) const;
110  RSUInfoConstPtr GetRSUById(const Id& id) const;
111 
119  int GetLanes(const apollo::common::PointENU& point, double distance,
120  std::vector<LaneInfoConstPtr>* lanes) const;
128  int GetJunctions(const apollo::common::PointENU& point, double distance,
129  std::vector<JunctionInfoConstPtr>* junctions) const;
137  int GetCrosswalks(const apollo::common::PointENU& point, double distance,
138  std::vector<CrosswalkInfoConstPtr>* crosswalks) const;
146  int GetSignals(const apollo::common::PointENU& point, double distance,
147  std::vector<SignalInfoConstPtr>* signals) const;
155  int GetStopSigns(const apollo::common::PointENU& point, double distance,
156  std::vector<StopSignInfoConstPtr>* stop_signs) const;
164  int GetYieldSigns(const apollo::common::PointENU& point, double distance,
165  std::vector<YieldSignInfoConstPtr>* yield_signs) const;
173  int GetClearAreas(const apollo::common::PointENU& point, double distance,
174  std::vector<ClearAreaInfoConstPtr>* clear_areas) const;
182  int GetSpeedBumps(const apollo::common::PointENU& point, double distance,
183  std::vector<SpeedBumpInfoConstPtr>* speed_bumps) const;
191  int GetRoads(const apollo::common::PointENU& point, double distance,
192  std::vector<RoadInfoConstPtr>* roads) const;
193 
201  int GetParkingSpaces(
202  const apollo::common::PointENU& point, double distance,
203  std::vector<ParkingSpaceInfoConstPtr>* parking_spaces) const;
204 
212  int GetPNCJunctions(
213  const apollo::common::PointENU& point, double distance,
214  std::vector<PNCJunctionInfoConstPtr>* pnc_junctions) const;
215 
224  int GetNearestLane(const apollo::common::PointENU& point,
225  LaneInfoConstPtr* nearest_lane, double* nearest_s,
226  double* nearest_l) const;
238  int GetNearestLaneWithHeading(const apollo::common::PointENU& point,
239  const double distance,
240  const double central_heading,
241  const double max_heading_difference,
242  LaneInfoConstPtr* nearest_lane,
243  double* nearest_s, double* nearest_l) const;
253  int GetLanesWithHeading(const apollo::common::PointENU& point,
254  const double distance, const double central_heading,
255  const double max_heading_difference,
256  std::vector<LaneInfoConstPtr>* lanes) const;
265  int GetRoadBoundaries(const apollo::common::PointENU& point, double radius,
266  std::vector<RoadROIBoundaryPtr>* road_boundaries,
267  std::vector<JunctionBoundaryPtr>* junctions) const;
276  int GetRoadBoundaries(const apollo::common::PointENU& point, double radius,
277  std::vector<RoadRoiPtr>* road_boundaries,
278  std::vector<JunctionInfoConstPtr>* junctions) const;
287  int GetRoi(const apollo::common::PointENU& point, double radius,
288  std::vector<RoadRoiPtr>* roads_roi,
289  std::vector<PolygonRoiPtr>* polygons_roi);
300  const apollo::common::PointENU& point, const double distance,
301  std::vector<SignalInfoConstPtr>* signals) const;
302 
311  const Id& id, std::vector<StopSignInfoConstPtr>* stop_signs) const;
312 
319  int GetStopSignAssociatedLanes(const Id& id,
320  std::vector<LaneInfoConstPtr>* lanes) const;
321 
330  int GetLocalMap(const apollo::common::PointENU& point,
331  const std::pair<double, double>& range, Map* local_map) const;
332 
342  int GetForwardNearestRSUs(const apollo::common::PointENU& point,
343  double distance, double central_heading,
344  double max_heading_difference,
345  std::vector<RSUInfoConstPtr>* rsus) const;
346 
347  private:
348  int GetLanes(const apollo::common::math::Vec2d& point, double distance,
349  std::vector<LaneInfoConstPtr>* lanes) const;
350  int GetJunctions(const apollo::common::math::Vec2d& point, double distance,
351  std::vector<JunctionInfoConstPtr>* junctions) const;
352  int GetCrosswalks(const apollo::common::math::Vec2d& point, double distance,
353  std::vector<CrosswalkInfoConstPtr>* crosswalks) const;
354  int GetSignals(const apollo::common::math::Vec2d& point, double distance,
355  std::vector<SignalInfoConstPtr>* signals) const;
356  int GetStopSigns(const apollo::common::math::Vec2d& point, double distance,
357  std::vector<StopSignInfoConstPtr>* stop_signs) const;
358  int GetYieldSigns(const apollo::common::math::Vec2d& point, double distance,
359  std::vector<YieldSignInfoConstPtr>* yield_signs) const;
360  int GetClearAreas(const apollo::common::math::Vec2d& point, double distance,
361  std::vector<ClearAreaInfoConstPtr>* clear_areas) const;
362  int GetSpeedBumps(const apollo::common::math::Vec2d& point, double distance,
363  std::vector<SpeedBumpInfoConstPtr>* speed_bumps) const;
364  int GetParkingSpaces(
365  const apollo::common::math::Vec2d& point, double distance,
366  std::vector<ParkingSpaceInfoConstPtr>* parking_spaces) const;
367  int GetPNCJunctions(
368  const apollo::common::math::Vec2d& point, double distance,
369  std::vector<PNCJunctionInfoConstPtr>* pnc_junctions) const;
371  LaneInfoConstPtr* nearest_lane, double* nearest_s,
372  double* nearest_l) const;
374  const double distance,
375  const double central_heading,
376  const double max_heading_difference,
377  LaneInfoConstPtr* nearest_lane,
378  double* nearest_s, double* nearest_l) const;
380  const double distance, const double central_heading,
381  const double max_heading_difference,
382  std::vector<LaneInfoConstPtr>* lanes) const;
383  int GetRoads(const apollo::common::math::Vec2d& point, double distance,
384  std::vector<RoadInfoConstPtr>* roads) const;
385 
386  template <class Table, class BoxTable, class KDTree>
387  static void BuildSegmentKDTree(
388  const Table& table, const apollo::common::math::AABoxKDTreeParams& params,
389  BoxTable* const box_table, std::unique_ptr<KDTree>* const kdtree);
390 
391  template <class Table, class BoxTable, class KDTree>
392  static void BuildPolygonKDTree(
393  const Table& table, const apollo::common::math::AABoxKDTreeParams& params,
394  BoxTable* const box_table, std::unique_ptr<KDTree>* const kdtree);
395 
396  void BuildLaneSegmentKDTree();
397  void BuildJunctionPolygonKDTree();
398  void BuildCrosswalkPolygonKDTree();
399  void BuildSignalSegmentKDTree();
400  void BuildStopSignSegmentKDTree();
401  void BuildYieldSignSegmentKDTree();
402  void BuildClearAreaPolygonKDTree();
403  void BuildSpeedBumpSegmentKDTree();
404  void BuildParkingSpacePolygonKDTree();
405  void BuildPNCJunctionPolygonKDTree();
406 
407  template <class KDTree>
408  static int SearchObjects(const apollo::common::math::Vec2d& center,
409  const double radius, const KDTree& kdtree,
410  std::vector<std::string>* const results);
411 
412  void Clear();
413 
414  private:
415  Map map_;
416  LaneTable lane_table_;
417  JunctionTable junction_table_;
418  CrosswalkTable crosswalk_table_;
419  SignalTable signal_table_;
420  StopSignTable stop_sign_table_;
421  YieldSignTable yield_sign_table_;
422  ClearAreaTable clear_area_table_;
423  SpeedBumpTable speed_bump_table_;
424  OverlapTable overlap_table_;
425  RoadTable road_table_;
426  ParkingSpaceTable parking_space_table_;
427  PNCJunctionTable pnc_junction_table_;
428  RSUTable rsu_table_;
429 
430  std::vector<LaneSegmentBox> lane_segment_boxes_;
431  std::unique_ptr<LaneSegmentKDTree> lane_segment_kdtree_;
432 
433  std::vector<JunctionPolygonBox> junction_polygon_boxes_;
434  std::unique_ptr<JunctionPolygonKDTree> junction_polygon_kdtree_;
435 
436  std::vector<CrosswalkPolygonBox> crosswalk_polygon_boxes_;
437  std::unique_ptr<CrosswalkPolygonKDTree> crosswalk_polygon_kdtree_;
438 
439  std::vector<SignalSegmentBox> signal_segment_boxes_;
440  std::unique_ptr<SignalSegmentKDTree> signal_segment_kdtree_;
441 
442  std::vector<StopSignSegmentBox> stop_sign_segment_boxes_;
443  std::unique_ptr<StopSignSegmentKDTree> stop_sign_segment_kdtree_;
444 
445  std::vector<YieldSignSegmentBox> yield_sign_segment_boxes_;
446  std::unique_ptr<YieldSignSegmentKDTree> yield_sign_segment_kdtree_;
447 
448  std::vector<ClearAreaPolygonBox> clear_area_polygon_boxes_;
449  std::unique_ptr<ClearAreaPolygonKDTree> clear_area_polygon_kdtree_;
450 
451  std::vector<SpeedBumpSegmentBox> speed_bump_segment_boxes_;
452  std::unique_ptr<SpeedBumpSegmentKDTree> speed_bump_segment_kdtree_;
453 
454  std::vector<ParkingSpacePolygonBox> parking_space_polygon_boxes_;
455  std::unique_ptr<ParkingSpacePolygonKDTree> parking_space_polygon_kdtree_;
456 
457  std::vector<PNCJunctionPolygonBox> pnc_junction_polygon_boxes_;
458  std::unique_ptr<PNCJunctionPolygonKDTree> pnc_junction_polygon_kdtree_;
459 };
460 
461 } // namespace hdmap
462 } // namespace apollo
std::unordered_map< std::string, std::shared_ptr< SpeedBumpInfo > > SpeedBumpTable
Definition: hdmap_impl.h:72
std::unordered_map< std::string, std::shared_ptr< RoadInfo > > RoadTable
Definition: hdmap_impl.h:75
std::shared_ptr< const PNCJunctionInfo > PNCJunctionInfoConstPtr
Definition: hdmap_common.h:138
SpeedBumpInfoConstPtr GetSpeedBumpById(const Id &id) const
std::shared_ptr< const RoadInfo > RoadInfoConstPtr
Definition: hdmap_common.h:133
std::unordered_map< std::string, std::shared_ptr< LaneInfo > > LaneTable
Definition: hdmap_impl.h:58
int GetJunctions(const apollo::common::PointENU &point, double distance, std::vector< JunctionInfoConstPtr > *junctions) const
get all junctions in certain range
Define the LineSegment2d class.
std::shared_ptr< const ParkingSpaceInfo > ParkingSpaceInfoConstPtr
Definition: hdmap_common.h:134
CrosswalkInfoConstPtr GetCrosswalkById(const Id &id) const
Defines the Vec2d class.
int LoadMapFromFile(const std::string &map_filename)
load map from local file
int GetSpeedBumps(const apollo::common::PointENU &point, double distance, std::vector< SpeedBumpInfoConstPtr > *speed_bumps) const
get all speed bumps in certain range
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 ...
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
int GetSignals(const apollo::common::PointENU &point, double distance, std::vector< SignalInfoConstPtr > *signals) const
get all signals in certain range
RoadInfoConstPtr GetRoadById(const Id &id) const
int GetRoads(const apollo::common::PointENU &point, double distance, std::vector< RoadInfoConstPtr > *roads) const
get all roads in certain range
int GetPNCJunctions(const apollo::common::PointENU &point, double distance, std::vector< PNCJunctionInfoConstPtr > *pnc_junctions) const
get all pnc junctions in certain range
std::unordered_map< std::string, std::shared_ptr< ClearAreaInfo > > ClearAreaTable
Definition: hdmap_impl.h:70
int GetStopSigns(const apollo::common::PointENU &point, double distance, std::vector< StopSignInfoConstPtr > *stop_signs) const
get all stop signs in certain range
int GetCrosswalks(const apollo::common::PointENU &point, double distance, std::vector< CrosswalkInfoConstPtr > *crosswalks) const
get all crosswalks in certain range
OverlapInfoConstPtr GetOverlapById(const Id &id) const
RSUInfoConstPtr GetRSUById(const Id &id) const
LaneInfoConstPtr GetLaneById(const Id &id) const
StopSignInfoConstPtr GetStopSignById(const Id &id) const
std::unordered_map< std::string, std::shared_ptr< SignalInfo > > SignalTable
Definition: hdmap_impl.h:62
PNCJunctionInfoConstPtr GetPNCJunctionById(const Id &id) const
int GetRoi(const apollo::common::PointENU &point, double radius, std::vector< RoadRoiPtr > *roads_roi, std::vector< PolygonRoiPtr > *polygons_roi)
get ROI within 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...
Defines the templated AABoxKDTree2dNode class.
std::unordered_map< std::string, std::shared_ptr< RSUInfo > > RSUTable
Definition: hdmap_impl.h:81
std::unordered_map< std::string, std::shared_ptr< OverlapInfo > > OverlapTable
Definition: hdmap_impl.h:74
Defines the AABox2d class.
std::shared_ptr< const CrosswalkInfo > CrosswalkInfoConstPtr
Definition: hdmap_common.h:128
int GetNearestLane(const apollo::common::PointENU &point, LaneInfoConstPtr *nearest_lane, double *nearest_s, double *nearest_l) const
get nearest lane from target point,
Implements a class of 2-dimensional vectors.
Definition: vec2d.h:42
std::shared_ptr< const YieldSignInfo > YieldSignInfoConstPtr
Definition: hdmap_common.h:130
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< PNCJunctionInfo > > PNCJunctionTable
Definition: hdmap_impl.h:79
ClearAreaInfoConstPtr GetClearAreaById(const Id &id) const
YieldSignInfoConstPtr GetYieldSignById(const Id &id) const
std::shared_ptr< const SpeedBumpInfo > SpeedBumpInfoConstPtr
Definition: hdmap_common.h:132
std::unordered_map< std::string, std::shared_ptr< StopSignInfo > > StopSignTable
Definition: hdmap_impl.h:66
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
std::shared_ptr< const LaneInfo > LaneInfoConstPtr
Definition: hdmap_common.h:125
std::shared_ptr< const SignalInfo > SignalInfoConstPtr
Definition: hdmap_common.h:127
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
JunctionInfoConstPtr GetJunctionById(const Id &id) const
std::unordered_map< std::string, std::shared_ptr< ParkingSpaceInfo > > ParkingSpaceTable
Definition: hdmap_impl.h:77
High-precision map loader implement.
Definition: hdmap_impl.h:56
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 GetParkingSpaces(const apollo::common::PointENU &point, double distance, std::vector< ParkingSpaceInfoConstPtr > *parking_spaces) const
get all parking space in certain range
SignalInfoConstPtr GetSignalById(const Id &id) const
std::shared_ptr< const RSUInfo > RSUInfoConstPtr
Definition: hdmap_common.h:139
int GetClearAreas(const apollo::common::PointENU &point, double distance, std::vector< ClearAreaInfoConstPtr > *clear_areas) const
get all clear areas in certain range
int GetLanes(const apollo::common::PointENU &point, double distance, std::vector< LaneInfoConstPtr > *lanes) const
get all lanes in certain range
int GetStopSignAssociatedLanes(const Id &id, std::vector< LaneInfoConstPtr > *lanes) const
get all lanes associated with a stop sign in the same junction
std::shared_ptr< const ClearAreaInfo > ClearAreaInfoConstPtr
Definition: hdmap_common.h:131
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
std::shared_ptr< const StopSignInfo > StopSignInfoConstPtr
Definition: hdmap_common.h:129
ParkingSpaceInfoConstPtr GetParkingSpaceById(const Id &id) const
std::unordered_map< std::string, std::shared_ptr< CrosswalkInfo > > CrosswalkTable
Definition: hdmap_impl.h:64
std::shared_ptr< const OverlapInfo > OverlapInfoConstPtr
Definition: hdmap_common.h:124
Define the Polygon2d class.
std::shared_ptr< const JunctionInfo > JunctionInfoConstPtr
Definition: hdmap_common.h:126
std::unordered_map< std::string, std::shared_ptr< YieldSignInfo > > YieldSignTable
Definition: hdmap_impl.h:68
int LoadMapFromProto(const Map &map_proto)
load map from a protobuf message
Contains parameters of axis-aligned bounding box.
Definition: aaboxkdtree2d.h:46
std::unordered_map< std::string, std::shared_ptr< JunctionInfo > > JunctionTable
Definition: hdmap_impl.h:60
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