Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
perf(lanelet2_extension): more efficient getLinkedParkingLot
Browse files Browse the repository at this point in the history
Signed-off-by: Maxime CLEMENT <[email protected]>
  • Loading branch information
maxime-clem authored and xmfcx committed Jun 14, 2024
1 parent c3fa064 commit 56898c1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ bool getLinkedParkingLot(
lanelet::ConstPolygon3d * linked_parking_lot);
// get linked parking lot from current pose of ego car
bool getLinkedParkingLot(
const lanelet::BasicPoint2d & current_position, const lanelet::ConstPolygons3d & all_parking_lots,
const lanelet::BasicPoint2d & current_position, const lanelet::LaneletMapPtr & lanelet_map_ptr,
lanelet::ConstPolygon3d * linked_parking_lot);
// get linked parking lot from parking space
bool getLinkedParkingLot(
Expand Down
19 changes: 12 additions & 7 deletions tmp/lanelet2_extension/lib/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,15 +591,20 @@ bool query::getLinkedParkingLot(

// get overlapping parking lot
bool query::getLinkedParkingLot(
const lanelet::BasicPoint2d & current_position, const lanelet::ConstPolygons3d & all_parking_lots,
const lanelet::BasicPoint2d & current_position, const lanelet::LaneletMapPtr & lanelet_map_ptr,
lanelet::ConstPolygon3d * linked_parking_lot)
{
for (const auto & parking_lot : all_parking_lots) {
const double distance =
boost::geometry::distance(current_position, to2D(parking_lot).basicPolygon());
if (distance < std::numeric_limits<double>::epsilon()) {
*linked_parking_lot = parking_lot;
return true;
const auto candidates =
lanelet_map_ptr->polygonLayer.search(lanelet::geometry::boundingBox2d(current_position));

Check warning on line 598 in tmp/lanelet2_extension/lib/query.cpp

View check run for this annotation

Codecov / codecov/patch

tmp/lanelet2_extension/lib/query.cpp#L598

Added line #L598 was not covered by tests
for (const auto & candidate : candidates) {
const std::string type = candidate.attributeOr(lanelet::AttributeName::Type, "none");
if (type == "parking_lot") {
const double distance =
boost::geometry::distance(current_position, to2D(candidate).basicPolygon());
if (distance < std::numeric_limits<double>::epsilon()) {
*linked_parking_lot = candidate;
return true;
}
}
}
return false;
Expand Down
6 changes: 3 additions & 3 deletions tmp/lanelet2_extension_python/src/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,11 @@ lanelet::Optional<lanelet::ConstPolygon3d> getLinkedParkingLot(
}

lanelet::Optional<lanelet::ConstPolygon3d> getLinkedParkingLot(
const lanelet::BasicPoint2d & current_position, const lanelet::ConstPolygons3d & all_parking_lots)
const lanelet::BasicPoint2d & current_position, const lanelet::LaneletMapPtr lanelet_map_ptr)
{
lanelet::ConstPolygon3d linked_parking_lot;
if (lanelet::utils::query::getLinkedParkingLot(
current_position, all_parking_lots, &linked_parking_lot)) {
current_position, lanelet_map_ptr, &linked_parking_lot)) {
return linked_parking_lot;
} else {
return {};
Expand Down Expand Up @@ -506,7 +506,7 @@ BOOST_PYTHON_MODULE(_lanelet2_extension_python_boost_python_utility)
const lanelet::ConstLanelet &, const lanelet::ConstPolygons3d &)>(
"getLinkedParkingLot", ::getLinkedParkingLot);
bp::def<lanelet::Optional<lanelet::ConstPolygon3d>(
const lanelet::BasicPoint2d &, const lanelet::ConstPolygons3d &)>(
const lanelet::BasicPoint2d &, const lanelet::LaneletMapPtr)>(

Check warning on line 509 in tmp/lanelet2_extension_python/src/utility.cpp

View check run for this annotation

Codecov / codecov/patch

tmp/lanelet2_extension_python/src/utility.cpp#L509

Added line #L509 was not covered by tests
"getLinkedParkingLot", ::getLinkedParkingLot);
bp::def<lanelet::Optional<lanelet::ConstPolygon3d>(
const lanelet::ConstLineString3d &, const lanelet::ConstPolygons3d &)>(
Expand Down

0 comments on commit 56898c1

Please sign in to comment.