Skip to content

Commit

Permalink
fix: is_in_parking_lot check method (#992)
Browse files Browse the repository at this point in the history
Signed-off-by: NorahXiong <norah.xiong@autocore.ai>
  • Loading branch information
NorahXiong committed Jun 14, 2022
1 parent 73b76cf commit 8fbf378
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ lanelet::ConstLanelets getLinkedLanelets(
bool getLinkedParkingLot(
const lanelet::ConstLanelet & lanelet, const lanelet::ConstPolygons3d & all_parking_lots,
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,
lanelet::ConstPolygon3d * linked_parking_lot);
// get linked parking lot from parking space
bool getLinkedParkingLot(
const lanelet::ConstLineString3d & parking_space,
const lanelet::ConstPolygons3d & all_parking_lots, lanelet::ConstPolygon3d * linked_parking_lot);
Expand Down
16 changes: 16 additions & 0 deletions map/lanelet2_extension/lib/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,22 @@ bool query::getLinkedParkingLot(
return false;
}

// get overlapping parking lot
bool query::getLinkedParkingLot(
const lanelet::BasicPoint2d & current_position, const lanelet::ConstPolygons3d & all_parking_lots,
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;
}
}
return false;
}

// get overlapping parking lot
bool query::getLinkedParkingLot(
const lanelet::ConstLineString3d & parking_space,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,13 @@ geometry_msgs::msg::PoseStamped::ConstSharedPtr getCurrentPose(
// copied from scenario selector
std::shared_ptr<lanelet::ConstPolygon3d> findNearestParkinglot(
const std::shared_ptr<lanelet::LaneletMap> & lanelet_map_ptr,
const lanelet::BasicPoint2d & search_point)
const lanelet::BasicPoint2d & current_position)
{
std::vector<std::pair<double, lanelet::Lanelet>> nearest_lanelets =
lanelet::geometry::findNearest(lanelet_map_ptr->laneletLayer, search_point, 1);

if (nearest_lanelets.empty()) {
return {};
}

const auto nearest_lanelet = nearest_lanelets.front().second;
const auto all_parking_lots = lanelet::utils::query::getAllParkingLots(lanelet_map_ptr);

const auto linked_parking_lot = std::make_shared<lanelet::ConstPolygon3d>();
const auto result = lanelet::utils::query::getLinkedParkingLot(
nearest_lanelet, all_parking_lots, linked_parking_lot.get());
current_position, all_parking_lots, linked_parking_lot.get());

if (result) {
return linked_parking_lot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,13 @@ void onData(const T & data, T * buffer)

std::shared_ptr<lanelet::ConstPolygon3d> findNearestParkinglot(
const std::shared_ptr<lanelet::LaneletMap> & lanelet_map_ptr,
const lanelet::BasicPoint2d & search_point)
const lanelet::BasicPoint2d & current_position)
{
std::vector<std::pair<double, lanelet::Lanelet>> nearest_lanelets =
lanelet::geometry::findNearest(lanelet_map_ptr->laneletLayer, search_point, 1);

if (nearest_lanelets.empty()) {
return {};
}

const auto nearest_lanelet = nearest_lanelets.front().second;
const auto all_parking_lots = lanelet::utils::query::getAllParkingLots(lanelet_map_ptr);

const auto linked_parking_lot = std::make_shared<lanelet::ConstPolygon3d>();
const auto result = lanelet::utils::query::getLinkedParkingLot(
nearest_lanelet, all_parking_lots, linked_parking_lot.get());
current_position, all_parking_lots, linked_parking_lot.get());

if (result) {
return linked_parking_lot;
Expand Down

0 comments on commit 8fbf378

Please sign in to comment.