Apollo 9.0
自动驾驶开放平台
apollo::dreamview::MapService类 参考

#include <map_service.h>

apollo::dreamview::MapService 的协作图:

Public 成员函数

 MapService (bool use_sim_map=true)
 
double GetXOffset () const
 
double GetYOffset () const
 
bool PointIsValid (const double x, const double y) const
 
void CollectMapElementIds (const apollo::common::PointENU &point, double raidus, MapElementIds *ids) const
 
bool GetPathsFromRouting (const apollo::routing::RoutingResponse &routing, std::vector< apollo::hdmap::Path > *paths) const
 
hdmap::Map RetrieveMapElements (const MapElementIds &ids) const
 
bool GetPoseWithRegardToLane (const double x, const double y, double *theta, double *s) const
 
bool GetStartPoint (apollo::common::PointENU *start_point) 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 ConstructLaneWayPointWithHeading (const double x, const double y, const double heading, routing::LaneWaypoint *laneWayPoint) const
 
bool ConstructLaneWayPointWithLaneId (const double x, const double y, const std::string id, routing::LaneWaypoint *laneWayPoint) const
 
bool CheckRoutingPoint (const double x, const double y) const
 
bool CheckRoutingPointWithHeading (const double x, const double y, const double heading) const
 
bool CheckRoutingPointLaneType (apollo::hdmap::LaneInfoConstPtr lane) const
 
bool ReloadMap (bool force_reload)
 
size_t CalculateMapHash (const MapElementIds &ids) const
 
double GetLaneHeading (const std::string &id_str, double s)
 
std::string GetParkingSpaceId (const double x, const double y) const
 

详细描述

在文件 map_service.h 第 43 行定义.

构造及析构函数说明

◆ MapService()

apollo::dreamview::MapService::MapService ( bool  use_sim_map = true)
explicit

在文件 map_service.cc 第 86 行定义.

86 : use_sim_map_(use_sim_map) {
87 ReloadMap(false);
88}
bool ReloadMap(bool force_reload)

成员函数说明

◆ CalculateMapHash()

size_t apollo::dreamview::MapService::CalculateMapHash ( const MapElementIds &  ids) const

在文件 map_service.cc 第 601 行定义.

601 {
602 static std::hash<std::string> hash_function;
603 return hash_function(ids.DebugString());
604}

◆ CheckRoutingPoint()

bool apollo::dreamview::MapService::CheckRoutingPoint ( const double  x,
const double  y 
) const

在文件 map_service.cc 第 500 行定义.

500 {
501 double s, l;
502 LaneInfoConstPtr lane;
503 if (!GetNearestLaneWithDistance(x, y, &lane, &s, &l)) {
504 if (GetParkingSpaceId(x, y) != "-1") {
505 return true;
506 }
507 return false;
508 }
509 if (!CheckRoutingPointLaneType(lane)) {
510 return false;
511 }
512 return true;
513}
bool CheckRoutingPointLaneType(apollo::hdmap::LaneInfoConstPtr lane) const
std::string GetParkingSpaceId(const double x, const double y) const
std::shared_ptr< const LaneInfo > LaneInfoConstPtr

◆ CheckRoutingPointLaneType()

bool apollo::dreamview::MapService::CheckRoutingPointLaneType ( apollo::hdmap::LaneInfoConstPtr  lane) const

在文件 map_service.cc 第 531 行定义.

531 {
532 if (lane->lane().type() != Lane::CITY_DRIVING) {
533 AERROR
534 << "Failed to construct LaneWayPoint for RoutingRequest: Expected lane "
535 << lane->id().id() << " to be CITY_DRIVING, but was "
536 << apollo::hdmap::Lane::LaneType_Name(lane->lane().type());
537 return false;
538 }
539 return true;
540}
#define AERROR
Definition log.h:44

◆ CheckRoutingPointWithHeading()

bool apollo::dreamview::MapService::CheckRoutingPointWithHeading ( const double  x,
const double  y,
const double  heading 
) const

在文件 map_service.cc 第 515 行定义.

516 {
517 double s, l;
518 LaneInfoConstPtr lane;
519 if (!GetNearestLaneWithHeading(x, y, &lane, &s, &l, heading)) {
520 if (GetParkingSpaceId(x, y) != "-1") {
521 return true;
522 }
523 return false;
524 }
525 if (!CheckRoutingPointLaneType(lane)) {
526 return false;
527 }
528 return true;
529}

◆ CollectMapElementIds()

void apollo::dreamview::MapService::CollectMapElementIds ( const apollo::common::PointENU &  point,
double  raidus,
MapElementIds *  ids 
) const

在文件 map_service.cc 第 167 行定义.

168 {
169 if (!MapReady()) {
170 return;
171 }
172 boost::shared_lock<boost::shared_mutex> reader_lock(mutex_);
173
174 std::vector<LaneInfoConstPtr> lanes;
175 if (SimMap()->GetLanes(point, radius, &lanes) != 0) {
176 AERROR << "Fail to get lanes from sim_map.";
177 }
178 ExtractRoadAndLaneIds(lanes, ids->mutable_lane(), ids->mutable_road());
179
180 std::vector<ClearAreaInfoConstPtr> clear_areas;
181 if (SimMap()->GetClearAreas(point, radius, &clear_areas) != 0) {
182 AERROR << "Fail to get clear areas from sim_map.";
183 }
184 ExtractIds(clear_areas, ids->mutable_clear_area());
185
186 std::vector<CrosswalkInfoConstPtr> crosswalks;
187 if (SimMap()->GetCrosswalks(point, radius, &crosswalks) != 0) {
188 AERROR << "Fail to get crosswalks from sim_map.";
189 }
190 ExtractIds(crosswalks, ids->mutable_crosswalk());
191
192 std::vector<JunctionInfoConstPtr> junctions;
193 if (SimMap()->GetJunctions(point, radius, &junctions) != 0) {
194 AERROR << "Fail to get junctions from sim_map.";
195 }
196 ExtractIds(junctions, ids->mutable_junction());
197
198 std::vector<PNCJunctionInfoConstPtr> pnc_junctions;
199 if (SimMap()->GetPNCJunctions(point, radius, &pnc_junctions) != 0) {
200 AERROR << "Fail to get pnc junctions from sim_map.";
201 }
202 ExtractIds(pnc_junctions, ids->mutable_pnc_junction());
203
204 std::vector<ParkingSpaceInfoConstPtr> parking_spaces;
205 if (SimMap()->GetParkingSpaces(point, radius, &parking_spaces) != 0) {
206 AERROR << "Fail to get parking space from sim_map.";
207 }
208 ExtractIds(parking_spaces, ids->mutable_parking_space());
209
210 std::vector<SpeedBumpInfoConstPtr> speed_bumps;
211 if (SimMap()->GetSpeedBumps(point, radius, &speed_bumps) != 0) {
212 AERROR << "Fail to get speed bump from sim_map.";
213 }
214 ExtractIds(speed_bumps, ids->mutable_speed_bump());
215
216 std::vector<SignalInfoConstPtr> signals;
217 if (SimMap()->GetSignals(point, radius, &signals) != 0) {
218 AERROR << "Failed to get signals from sim_map.";
219 }
220
221 ExtractIds(signals, ids->mutable_signal());
222
223 std::vector<StopSignInfoConstPtr> stop_signs;
224 if (SimMap()->GetStopSigns(point, radius, &stop_signs) != 0) {
225 AERROR << "Failed to get stop signs from sim_map.";
226 }
227 ExtractIds(stop_signs, ids->mutable_stop_sign());
228
229 std::vector<YieldSignInfoConstPtr> yield_signs;
230 if (SimMap()->GetYieldSigns(point, radius, &yield_signs) != 0) {
231 AERROR << "Failed to get yield signs from sim_map.";
232 }
233 ExtractIds(yield_signs, ids->mutable_yield());
234}

◆ ConstructLaneWayPoint()

bool apollo::dreamview::MapService::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.

参数
xposition
yposition
laneWayPointRoutingRequest's lane waypoint
返回
True if the lane waypoint is filled successfully.

在文件 map_service.cc 第 421 行定义.

422 {
423 double s, l;
424 LaneInfoConstPtr lane;
425 if (!GetNearestLane(x, y, &lane, &s, &l)) {
426 return false;
427 }
428
429 if (!CheckRoutingPointLaneType(lane)) {
430 return false;
431 }
432
433 laneWayPoint->set_id(lane->id().id());
434 laneWayPoint->set_s(s);
435 auto *pose = laneWayPoint->mutable_pose();
436 pose->set_x(x);
437 pose->set_y(y);
438
439 return true;
440}

◆ ConstructLaneWayPointWithHeading()

bool apollo::dreamview::MapService::ConstructLaneWayPointWithHeading ( const double  x,
const double  y,
const double  heading,
routing::LaneWaypoint *  laneWayPoint 
) const

在文件 map_service.cc 第 442 行定义.

444 {
445 double s, l;
446 LaneInfoConstPtr lane;
447 if (!GetNearestLaneWithHeading(x, y, &lane, &s, &l, heading)) {
448 return false;
449 }
450
451 if (!CheckRoutingPointLaneType(lane)) {
452 return false;
453 }
454
455 laneWayPoint->set_id(lane->id().id());
456 laneWayPoint->set_s(s);
457 auto *pose = laneWayPoint->mutable_pose();
458 pose->set_x(x);
459 pose->set_y(y);
460
461 return true;
462}

◆ ConstructLaneWayPointWithLaneId()

bool apollo::dreamview::MapService::ConstructLaneWayPointWithLaneId ( const double  x,
const double  y,
const std::string  id,
routing::LaneWaypoint *  laneWayPoint 
) const

在文件 map_service.cc 第 464 行定义.

466 {
467 LaneInfoConstPtr lane = HDMap()->GetLaneById(hdmap::MakeMapId(id));
468 if (!lane) {
469 return false;
470 }
471
472 if (!CheckRoutingPointLaneType(lane)) {
473 return false;
474 }
475
476 double s, l;
477 PointENU point;
478 point.set_x(x);
479 point.set_y(y);
480
481 if (!lane->GetProjection({point.x(), point.y()}, &s, &l)) {
482 return false;
483 }
484
485 // Limit s with max value of the length of the lane, or not the laneWayPoint
486 // may be invalid.
487 if (s > lane->lane().length()) {
488 s = lane->lane().length();
489 }
490
491 laneWayPoint->set_id(id);
492 laneWayPoint->set_s(s);
493 auto *pose = laneWayPoint->mutable_pose();
494 pose->set_x(x);
495 pose->set_y(y);
496
497 return true;
498}
LaneInfoConstPtr GetLaneById(const Id &id) const
Definition hdmap.cc:34
apollo::hdmap::Id MakeMapId(const std::string &id)
create a Map ID given a string.
Definition hdmap_util.h:85

◆ GetLaneHeading()

double apollo::dreamview::MapService::GetLaneHeading ( const std::string &  id_str,
double  s 
)

在文件 map_service.cc 第 606 行定义.

606 {
607 auto *hdmap = HDMap();
608 CHECK(hdmap) << "Failed to get hdmap";
609
610 Id id;
611 id.set_id(id_str);
612 LaneInfoConstPtr lane_ptr = hdmap->GetLaneById(id);
613 if (lane_ptr != nullptr) {
614 return lane_ptr->Heading(s);
615 }
616 return 0.0;
617}

◆ GetParkingSpaceId()

std::string apollo::dreamview::MapService::GetParkingSpaceId ( const double  x,
const double  y 
) const

在文件 map_service.cc 第 619 行定义.

620 {
621 PointENU point;
622 point.set_x(x);
623 point.set_y(y);
624 static constexpr double kSearchRadius = 3.0;
625 std::vector<ParkingSpaceInfoConstPtr> parking_spaces;
626
627 // Find parking spaces nearby
628 if (HDMap()->GetParkingSpaces(point, kSearchRadius, &parking_spaces) != 0) {
629 AERROR << "Fail to get parking space from sim_map.";
630 return "-1";
631 }
632
633 // Determine whether the point is in a neighboring parking space
634 for (const auto &parking_sapce : parking_spaces) {
635 if (!parking_sapce->polygon().is_convex()) {
636 AERROR << "The parking space information is incorrect and is not a "
637 "convex hull.";
638 return "-1";
639 }
640 apollo::common::math::Vec2d checked_point(x, y);
641 if (parking_sapce->polygon().IsPointIn(checked_point)) {
642 return parking_sapce->id().id();
643 }
644 }
645 return "-1";
646}
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42

◆ GetPathsFromRouting()

bool apollo::dreamview::MapService::GetPathsFromRouting ( const apollo::routing::RoutingResponse &  routing,
std::vector< apollo::hdmap::Path > *  paths 
) const

在文件 map_service.cc 第 400 行定义.

401 {
402 if (!CreatePathsFromRouting(routing, paths)) {
403 AERROR << "Unable to get paths from routing!";
404 return false;
405 }
406 return true;
407}

◆ GetPoseWithRegardToLane()

bool apollo::dreamview::MapService::GetPoseWithRegardToLane ( const double  x,
const double  y,
double *  theta,
double *  s 
) const

在文件 map_service.cc 第 409 行定义.

410 {
411 double l;
412 LaneInfoConstPtr nearest_lane;
413 if (!GetNearestLane(x, y, &nearest_lane, s, &l)) {
414 return false;
415 }
416
417 *theta = nearest_lane->Heading(*s);
418 return true;
419}

◆ GetStartPoint()

bool apollo::dreamview::MapService::GetStartPoint ( apollo::common::PointENU *  start_point) const

在文件 map_service.cc 第 542 行定义.

542 {
543 // Start from origin to find a lane from the map.
544 double s, l;
545 LaneInfoConstPtr lane;
546 if (!GetNearestLane(0.0, 0.0, &lane, &s, &l)) {
547 return false;
548 }
549
550 *start_point = lane->GetSmoothPoint(0.0);
551 return true;
552}

◆ GetXOffset()

double apollo::dreamview::MapService::GetXOffset ( ) const
inline

在文件 map_service.h 第 47 行定义.

47{ return x_offset_; }

◆ GetYOffset()

double apollo::dreamview::MapService::GetYOffset ( ) const
inline

在文件 map_service.h 第 48 行定义.

48{ return y_offset_; }

◆ PointIsValid()

bool apollo::dreamview::MapService::PointIsValid ( const double  x,
const double  y 
) const

在文件 map_service.cc 第 158 行定义.

158 {
159 MapElementIds ids;
160 PointENU point;
161 point.set_x(x);
162 point.set_y(y);
163 CollectMapElementIds(point, 20, &ids);
164 return (ids.ByteSizeLong() != 0);
165}
void CollectMapElementIds(const apollo::common::PointENU &point, double raidus, MapElementIds *ids) const

◆ ReloadMap()

bool apollo::dreamview::MapService::ReloadMap ( bool  force_reload)

在文件 map_service.cc 第 90 行定义.

90 {
91 boost::unique_lock<boost::shared_mutex> writer_lock(mutex_);
92 bool ret = true;
93 if (force_reload) {
95 }
96
97 // Update the x,y-offsets if present.
98 // UpdateOffsets();
99 return ret;
100}

◆ RetrieveMapElements()

Map apollo::dreamview::MapService::RetrieveMapElements ( const MapElementIds &  ids) const

在文件 map_service.cc 第 236 行定义.

236 {
237 boost::shared_lock<boost::shared_mutex> reader_lock(mutex_);
238
239 Map result;
240 if (!MapReady()) {
241 return result;
242 }
243 Id map_id;
244
245 for (const auto &id : ids.lane()) {
246 map_id.set_id(id);
247 auto element = SimMap()->GetLaneById(map_id);
248 if (element) {
249 auto lane = element->lane();
250 lane.clear_left_sample();
251 lane.clear_right_sample();
252 lane.clear_left_road_sample();
253 lane.clear_right_road_sample();
254 *result.add_lane() = lane;
255 }
256 }
257
258 for (const auto &id : ids.clear_area()) {
259 map_id.set_id(id);
260 auto element = SimMap()->GetClearAreaById(map_id);
261 if (element) {
262 *result.add_clear_area() = element->clear_area();
263 }
264 }
265
266 for (const auto &id : ids.crosswalk()) {
267 map_id.set_id(id);
268 auto element = SimMap()->GetCrosswalkById(map_id);
269 if (element) {
270 *result.add_crosswalk() = element->crosswalk();
271 }
272 }
273
274 for (const auto &id : ids.junction()) {
275 map_id.set_id(id);
276 auto element = SimMap()->GetJunctionById(map_id);
277 if (element) {
278 *result.add_junction() = element->junction();
279 }
280 }
281
282 for (const auto &id : ids.signal()) {
283 map_id.set_id(id);
284 auto element = SimMap()->GetSignalById(map_id);
285 if (element) {
286 *result.add_signal() = element->signal();
287 }
288 }
289
290 for (const auto &id : ids.stop_sign()) {
291 map_id.set_id(id);
292 auto element = SimMap()->GetStopSignById(map_id);
293 if (element) {
294 *result.add_stop_sign() = element->stop_sign();
295 }
296 }
297
298 for (const auto &id : ids.yield()) {
299 map_id.set_id(id);
300 auto element = SimMap()->GetYieldSignById(map_id);
301 if (element) {
302 *result.add_yield() = element->yield_sign();
303 }
304 }
305
306 for (const auto &id : ids.road()) {
307 map_id.set_id(id);
308 auto element = SimMap()->GetRoadById(map_id);
309 if (element) {
310 *result.add_road() = element->road();
311 }
312 }
313
314 for (const auto &id : ids.parking_space()) {
315 map_id.set_id(id);
316 auto element = SimMap()->GetParkingSpaceById(map_id);
317 if (element) {
318 *result.add_parking_space() = element->parking_space();
319 }
320 }
321
322 for (const auto &id : ids.speed_bump()) {
323 map_id.set_id(id);
324 auto element = SimMap()->GetSpeedBumpById(map_id);
325 if (element) {
326 *result.add_speed_bump() = element->speed_bump();
327 }
328 }
329
330 for (const auto &id : ids.pnc_junction()) {
331 map_id.set_id(id);
332 auto element = SimMap()->GetPNCJunctionById(map_id);
333 if (element) {
334 *result.add_pnc_junction() = element->pnc_junction();
335 }
336 }
337 apollo::hdmap::Header map_header;
338 if (SimMap()->GetMapHeader(&map_header)) {
339 result.mutable_header()->CopyFrom(map_header);
340 }
341
342 return result;
343}
StopSignInfoConstPtr GetStopSignById(const Id &id) const
Definition hdmap.cc:58
PNCJunctionInfoConstPtr GetPNCJunctionById(const Id &id) const
Definition hdmap.cc:86
YieldSignInfoConstPtr GetYieldSignById(const Id &id) const
Definition hdmap.cc:62
ClearAreaInfoConstPtr GetClearAreaById(const Id &id) const
Definition hdmap.cc:66
RoadInfoConstPtr GetRoadById(const Id &id) const
Definition hdmap.cc:78
JunctionInfoConstPtr GetJunctionById(const Id &id) const
Definition hdmap.cc:38
ParkingSpaceInfoConstPtr GetParkingSpaceById(const Id &id) const
Definition hdmap.cc:82
CrosswalkInfoConstPtr GetCrosswalkById(const Id &id) const
Definition hdmap.cc:54
SignalInfoConstPtr GetSignalById(const Id &id) const
Definition hdmap.cc:46
SpeedBumpInfoConstPtr GetSpeedBumpById(const Id &id) const
Definition hdmap.cc:70

该类的文档由以下文件生成: