Apollo  6.0
Open source self driving car software
map_service.h
Go to the documentation of this file.
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 
21 #pragma once
22 
23 #include <string>
24 #include <vector>
25 
26 #include <boost/thread/locks.hpp>
27 #include <boost/thread/shared_mutex.hpp>
28 
29 #include "modules/dreamview/proto/simulation_world.pb.h"
31 #include "nlohmann/json.hpp"
32 
37 namespace apollo {
38 namespace dreamview {
39 
40 class MapService {
41  public:
42  explicit MapService(bool use_sim_map = true);
43 
44  inline double GetXOffset() const { return x_offset_; }
45  inline double GetYOffset() const { return y_offset_; }
46 
47  void CollectMapElementIds(const apollo::common::PointENU &point,
48  double raidus, MapElementIds *ids) const;
49 
50  bool GetPathsFromRouting(const apollo::routing::RoutingResponse &routing,
51  std::vector<apollo::hdmap::Path> *paths) const;
52 
53  // The returned value is of a hdmap::Map proto. This
54  // makes it easy to convert to a JSON object and to send to the
55  // javascript clients.
56  hdmap::Map RetrieveMapElements(const MapElementIds &ids) const;
57 
58  bool GetPoseWithRegardToLane(const double x, const double y, double *theta,
59  double *s) const;
60 
61  // Get a point on the map to serve as dummy start point of SimControl
62  bool GetStartPoint(apollo::common::PointENU *start_point) const;
63 
72  bool ConstructLaneWayPoint(const double x, const double y,
73  routing::LaneWaypoint *laneWayPoint) const;
74 
76  const double x, const double y, const double heading,
77  routing::LaneWaypoint *laneWayPoint) const;
78 
79  bool CheckRoutingPoint(const double x, const double y) const;
80 
82 
83  // Reload map from current FLAGS_map_dir.
84  bool ReloadMap(bool force_reload);
85 
86  size_t CalculateMapHash(const MapElementIds &ids) const;
87 
88  private:
89  void UpdateOffsets();
90  bool GetNearestLane(const double x, const double y,
91  apollo::hdmap::LaneInfoConstPtr *nearest_lane,
92  double *nearest_s, double *nearest_l) const;
93 
94  bool GetNearestLaneWithHeading(const double x, const double y,
95  apollo::hdmap::LaneInfoConstPtr *nearest_lane,
96  double *nearest_s, double *nearest_l,
97  const double heading) const;
98 
99  bool CreatePathsFromRouting(const routing::RoutingResponse &routing,
100  std::vector<apollo::hdmap::Path> *paths) const;
101 
102  bool AddPathFromPassageRegion(const routing::Passage &passage_region,
103  std::vector<apollo::hdmap::Path> *paths) const;
104 
105  static const char kMetaFileName[];
106 
107  const bool use_sim_map_;
108  const hdmap::HDMap *HDMap() const;
109  // A downsampled map for dreamview frontend display.
110  const hdmap::HDMap *SimMap() const;
111  bool MapReady() const;
112 
113  double x_offset_ = 0.0;
114  double y_offset_ = 0.0;
115 
116  // RW lock to protect map data
117  mutable boost::shared_mutex mutex_;
118 };
119 
120 } // namespace dreamview
121 } // namespace apollo
bool CheckRoutingPointLaneType(apollo::hdmap::LaneInfoConstPtr lane) const
bool ReloadMap(bool force_reload)
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
void CollectMapElementIds(const apollo::common::PointENU &point, double raidus, MapElementIds *ids) const
double GetYOffset() const
Definition: map_service.h:45
bool ConstructLaneWayPointWithHeading(const double x, const double y, const double heading, routing::LaneWaypoint *laneWayPoint) const
Definition: map_service.h:40
hdmap::Map RetrieveMapElements(const MapElementIds &ids) const
bool ConstructLaneWayPoint(const double x, const double y, routing::LaneWaypoint *laneWayPoint) const
The function fills out proper routing lane waypoint from the given (x,y) position.
bool GetStartPoint(apollo::common::PointENU *start_point) const
bool GetPoseWithRegardToLane(const double x, const double y, double *theta, double *s) const
MapService(bool use_sim_map=true)
High-precision map loader interface.
Definition: hdmap.h:53
std::shared_ptr< const LaneInfo > LaneInfoConstPtr
Definition: hdmap_common.h:125
bool GetPathsFromRouting(const apollo::routing::RoutingResponse &routing, std::vector< apollo::hdmap::Path > *paths) const
double GetXOffset() const
Definition: map_service.h:44
size_t CalculateMapHash(const MapElementIds &ids) const
bool CheckRoutingPoint(const double x, const double y) const