Apollo 10.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.h43 行定义.

构造及析构函数说明

◆ MapService()

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

在文件 map_service.cc88 行定义.

88 : use_sim_map_(use_sim_map) {
89 ReloadMap(false);
90}
bool ReloadMap(bool force_reload)

成员函数说明

◆ CalculateMapHash()

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

在文件 map_service.cc632 行定义.

632 {
633 static std::hash<std::string> hash_function;
634 return hash_function(ids.DebugString());
635}

◆ CheckRoutingPoint()

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

在文件 map_service.cc531 行定义.

531 {
532 double s, l;
533 LaneInfoConstPtr lane;
534 if (!GetNearestLaneWithDistance(x, y, &lane, &s, &l)) {
535 if (GetParkingSpaceId(x, y) != "-1") {
536 return true;
537 }
538 return false;
539 }
540 if (!CheckRoutingPointLaneType(lane)) {
541 return false;
542 }
543 return true;
544}
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.cc562 行定义.

562 {
563 if (lane->lane().type() != Lane::CITY_DRIVING) {
564 AERROR
565 << "Failed to construct LaneWayPoint for RoutingRequest: Expected lane "
566 << lane->id().id() << " to be CITY_DRIVING, but was "
567 << apollo::hdmap::Lane::LaneType_Name(lane->lane().type());
568 return false;
569 }
570 return true;
571}
#define AERROR
Definition log.h:44

◆ CheckRoutingPointWithHeading()

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

在文件 map_service.cc546 行定义.

547 {
548 double s, l;
549 LaneInfoConstPtr lane;
550 if (!GetNearestLaneWithHeading(x, y, &lane, &s, &l, heading)) {
551 if (GetParkingSpaceId(x, y) != "-1") {
552 return true;
553 }
554 return false;
555 }
556 if (!CheckRoutingPointLaneType(lane)) {
557 return false;
558 }
559 return true;
560}

◆ CollectMapElementIds()

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

在文件 map_service.cc169 行定义.

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

◆ 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.cc452 行定义.

453 {
454 double s, l;
455 LaneInfoConstPtr lane;
456 if (!GetNearestLane(x, y, &lane, &s, &l)) {
457 return false;
458 }
459
460 if (!CheckRoutingPointLaneType(lane)) {
461 return false;
462 }
463
464 laneWayPoint->set_id(lane->id().id());
465 laneWayPoint->set_s(s);
466 auto *pose = laneWayPoint->mutable_pose();
467 pose->set_x(x);
468 pose->set_y(y);
469
470 return true;
471}

◆ ConstructLaneWayPointWithHeading()

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

在文件 map_service.cc473 行定义.

475 {
476 double s, l;
477 LaneInfoConstPtr lane;
478 if (!GetNearestLaneWithHeading(x, y, &lane, &s, &l, heading)) {
479 return false;
480 }
481
482 if (!CheckRoutingPointLaneType(lane)) {
483 return false;
484 }
485
486 laneWayPoint->set_id(lane->id().id());
487 laneWayPoint->set_s(s);
488 auto *pose = laneWayPoint->mutable_pose();
489 pose->set_x(x);
490 pose->set_y(y);
491
492 return true;
493}

◆ ConstructLaneWayPointWithLaneId()

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

在文件 map_service.cc495 行定义.

497 {
498 LaneInfoConstPtr lane = HDMap()->GetLaneById(hdmap::MakeMapId(id));
499 if (!lane) {
500 return false;
501 }
502
503 if (!CheckRoutingPointLaneType(lane)) {
504 return false;
505 }
506
507 double s, l;
508 PointENU point;
509 point.set_x(x);
510 point.set_y(y);
511
512 if (!lane->GetProjection({point.x(), point.y()}, &s, &l)) {
513 return false;
514 }
515
516 // Limit s with max value of the length of the lane, or not the laneWayPoint
517 // may be invalid.
518 if (s > lane->lane().length()) {
519 s = lane->lane().length();
520 }
521
522 laneWayPoint->set_id(id);
523 laneWayPoint->set_s(s);
524 auto *pose = laneWayPoint->mutable_pose();
525 pose->set_x(x);
526 pose->set_y(y);
527
528 return true;
529}
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.cc637 行定义.

637 {
638 auto *hdmap = HDMap();
639 CHECK(hdmap) << "Failed to get hdmap";
640
641 Id id;
642 id.set_id(id_str);
643 LaneInfoConstPtr lane_ptr = hdmap->GetLaneById(id);
644 if (lane_ptr != nullptr) {
645 return lane_ptr->Heading(s);
646 }
647 return 0.0;
648}

◆ GetParkingSpaceId()

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

在文件 map_service.cc650 行定义.

651 {
652 PointENU point;
653 point.set_x(x);
654 point.set_y(y);
655 static constexpr double kSearchRadius = 3.0;
656 std::vector<ParkingSpaceInfoConstPtr> parking_spaces;
657
658 // Find parking spaces nearby
659 if (HDMap()->GetParkingSpaces(point, kSearchRadius, &parking_spaces) != 0) {
660 AERROR << "Fail to get parking space from sim_map.";
661 return "-1";
662 }
663
664 // Determine whether the point is in a neighboring parking space
665 for (const auto &parking_sapce : parking_spaces) {
666 if (!parking_sapce->polygon().is_convex()) {
667 AERROR << "The parking space information is incorrect and is not a "
668 "convex hull.";
669 return "-1";
670 }
671 apollo::common::math::Vec2d checked_point(x, y);
672 if (parking_sapce->polygon().IsPointIn(checked_point)) {
673 return parking_sapce->id().id();
674 }
675 }
676 return "-1";
677}
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.cc431 行定义.

432 {
433 if (!CreatePathsFromRouting(routing, paths)) {
434 AERROR << "Unable to get paths from routing!";
435 return false;
436 }
437 return true;
438}

◆ GetPoseWithRegardToLane()

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

在文件 map_service.cc440 行定义.

441 {
442 double l;
443 LaneInfoConstPtr nearest_lane;
444 if (!GetNearestLane(x, y, &nearest_lane, s, &l)) {
445 return false;
446 }
447
448 *theta = nearest_lane->Heading(*s);
449 return true;
450}

◆ GetStartPoint()

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

在文件 map_service.cc573 行定义.

573 {
574 // Start from origin to find a lane from the map.
575 double s, l;
576 LaneInfoConstPtr lane;
577 if (!GetNearestLane(0.0, 0.0, &lane, &s, &l)) {
578 return false;
579 }
580
581 *start_point = lane->GetSmoothPoint(0.0);
582 return true;
583}

◆ GetXOffset()

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

在文件 map_service.h47 行定义.

47{ return x_offset_; }

◆ GetYOffset()

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

在文件 map_service.h48 行定义.

48{ return y_offset_; }

◆ PointIsValid()

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

在文件 map_service.cc160 行定义.

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

◆ ReloadMap()

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

在文件 map_service.cc92 行定义.

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

◆ RetrieveMapElements()

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

在文件 map_service.cc250 行定义.

250 {
251 boost::shared_lock<boost::shared_mutex> reader_lock(mutex_);
252
253 Map result;
254 if (!MapReady()) {
255 return result;
256 }
257 Id map_id;
258
259 for (const auto &id : ids.lane()) {
260 map_id.set_id(id);
261 auto element = SimMap()->GetLaneById(map_id);
262 if (element) {
263 auto lane = element->lane();
264 lane.clear_left_sample();
265 lane.clear_right_sample();
266 lane.clear_left_road_sample();
267 lane.clear_right_road_sample();
268 *result.add_lane() = lane;
269 }
270 }
271
272 for (const auto &id : ids.clear_area()) {
273 map_id.set_id(id);
274 auto element = SimMap()->GetClearAreaById(map_id);
275 if (element) {
276 *result.add_clear_area() = element->clear_area();
277 }
278 }
279
280 for (const auto &id : ids.crosswalk()) {
281 map_id.set_id(id);
282 auto element = SimMap()->GetCrosswalkById(map_id);
283 if (element) {
284 *result.add_crosswalk() = element->crosswalk();
285 }
286 }
287
288 for (const auto &id : ids.junction()) {
289 map_id.set_id(id);
290 auto element = SimMap()->GetJunctionById(map_id);
291 if (element) {
292 *result.add_junction() = element->junction();
293 }
294 }
295
296 for (const auto &id : ids.signal()) {
297 map_id.set_id(id);
298 auto element = SimMap()->GetSignalById(map_id);
299 if (element) {
300 *result.add_signal() = element->signal();
301 }
302 }
303
304 for (const auto &id : ids.stop_sign()) {
305 map_id.set_id(id);
306 auto element = SimMap()->GetStopSignById(map_id);
307 if (element) {
308 *result.add_stop_sign() = element->stop_sign();
309 }
310 }
311
312 for (const auto &id : ids.yield()) {
313 map_id.set_id(id);
314 auto element = SimMap()->GetYieldSignById(map_id);
315 if (element) {
316 *result.add_yield() = element->yield_sign();
317 }
318 }
319
320 for (const auto &id : ids.road()) {
321 map_id.set_id(id);
322 auto element = SimMap()->GetRoadById(map_id);
323 if (element) {
324 *result.add_road() = element->road();
325 }
326 }
327
328 for (const auto &id : ids.parking_space()) {
329 map_id.set_id(id);
330 auto element = SimMap()->GetParkingSpaceById(map_id);
331 if (element) {
332 *result.add_parking_space() = element->parking_space();
333 }
334 }
335
336 for (const auto &id : ids.speed_bump()) {
337 map_id.set_id(id);
338 auto element = SimMap()->GetSpeedBumpById(map_id);
339 if (element) {
340 *result.add_speed_bump() = element->speed_bump();
341 }
342 }
343
344 for (const auto &id : ids.pnc_junction()) {
345 map_id.set_id(id);
346 auto element = SimMap()->GetPNCJunctionById(map_id);
347 if (element) {
348 *result.add_pnc_junction() = element->pnc_junction();
349 }
350 }
351
352 for (const auto &id : ids.ad_area()) {
353 map_id.set_id(id);
354 auto element = SimMap()->GetAreaById(map_id);
355 if (element) {
356 *result.add_ad_area() = element->area();
357 }
358 }
359
360 for (const auto &id : ids.barrier_gate()) {
361 map_id.set_id(id);
362 auto element = SimMap()->GetBarrierGateById(map_id);
363 if (element) {
364 *result.add_barrier_gate() = element->barrier_gate();
365 }
366 }
367
368 apollo::hdmap::Header map_header;
369 if (SimMap()->GetMapHeader(&map_header)) {
370 result.mutable_header()->CopyFrom(map_header);
371 }
372
373 return result;
374}
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
BarrierGateInfoConstPtr GetBarrierGateById(const Id &id) const
Definition hdmap.cc:50
ClearAreaInfoConstPtr GetClearAreaById(const Id &id) const
Definition hdmap.cc:66
AreaInfoConstPtr GetAreaById(const Id &id) const
Definition hdmap.cc:42
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

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