Skip to content

Commit 865668e

Browse files
tobifalkcassava
authored andcommitted
osi: Fix lane boundary point order
1 parent 26dde03 commit 865668e

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

optional/osi/include/osi/utility/osi_message_handler.hpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ void from_osi_mov_obj_type_classification(
8585
void from_osi_detected_moving_object_alt(const osi3::DetectedMovingObject& osi_mo,
8686
const OsiGroundTruth& ground_truth, cloe::Object& obj);
8787

88-
void from_osi_boundary_points(const osi3::LaneBoundary& osi_lb, cloe::LaneBoundary& lb);
89-
9088
void transform_ego_coord_from_osi_data(const Eigen::Vector3d& dimensions_gt, cloe::Object& obj);
9189

9290
/**
@@ -270,7 +268,8 @@ class OsiMsgHandler {
270268

271269
void detected_lane_boundaries_from_ground_truth();
272270

273-
void from_osi_boundary_points(const osi3::LaneBoundary& osi_lb, cloe::LaneBoundary& lb);
271+
void from_osi_boundary_points(const osi3::LaneBoundary& osi_lb, cloe::LaneBoundary& lb,
272+
bool reverse_pt_order);
274273

275274
/**
276275
* Store the ego object that should be passed to Cloe.

optional/osi/src/osi/utility/osi_message_handler.cpp

+38-3
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,8 @@ void OsiMsgHandler::detected_static_objects_from_ground_truth() {
896896
}
897897

898898
void OsiMsgHandler::from_osi_boundary_points(const osi3::LaneBoundary& osi_lb,
899-
cloe::LaneBoundary& lb) {
899+
cloe::LaneBoundary& lb,
900+
bool reverse_pt_order = false) {
900901
assert(osi_lb.boundary_line_size() > 0);
901902
for (int i = 0; i < osi_lb.boundary_line_size(); ++i) {
902903
const auto& osi_pt = osi_lb.boundary_line(i);
@@ -906,6 +907,10 @@ void OsiMsgHandler::from_osi_boundary_points(const osi3::LaneBoundary& osi_lb,
906907
cloe::utility::transform_point_to_child_frame(osi_sensor_pose_, &position);
907908
lb.points.push_back(position);
908909
}
910+
// Provide points in ascending order.
911+
if (reverse_pt_order) {
912+
std::reverse(lb.points.begin(), lb.points.end());
913+
}
909914
// Compute clothoid segment. TODO(tobias): implement curved segments.
910915
lb.dx_start = lb.points.front()(0);
911916
lb.dy_start = lb.points.front()(1);
@@ -918,8 +923,33 @@ void OsiMsgHandler::from_osi_boundary_points(const osi3::LaneBoundary& osi_lb,
918923

919924
void OsiMsgHandler::detected_lane_boundaries_from_ground_truth() {
920925
const auto& osi_gt = ground_truth_->get_gt();
921-
int lb_id = 0;
926+
// Flip lane boundary point order if centerline is not in ascending order.
927+
std::map<int, int> lbs_flip_pt_order;
928+
for (const auto& osi_lane : osi_gt.lane()) {
929+
if (!osi_lane.has_classification()) {
930+
continue;
931+
}
932+
if (osi_lane.classification().centerline_is_driving_direction()) {
933+
continue;
934+
}
935+
int lane_id;
936+
osi_identifier_to_int(osi_lane.id(), lane_id);
937+
int lb_id;
938+
for (const auto& osi_lb_id : osi_lane.classification().right_lane_boundary_id()) {
939+
osi_identifier_to_int(osi_lb_id, lb_id);
940+
lbs_flip_pt_order[lb_id] = lane_id;
941+
}
942+
for (const auto& osi_lb_id : osi_lane.classification().left_lane_boundary_id()) {
943+
osi_identifier_to_int(osi_lb_id, lb_id);
944+
lbs_flip_pt_order[lb_id] = lane_id;
945+
}
946+
for (const auto& osi_lb_id : osi_lane.classification().free_lane_boundary_id()) {
947+
osi_identifier_to_int(osi_lb_id, lb_id);
948+
lbs_flip_pt_order[lb_id] = lane_id;
949+
}
950+
}
922951
// If some of the OSI data does not have an id, avoid id clashes.
952+
int lb_id = 0;
923953
for (const auto& osi_lb : osi_gt.lane_boundary()) {
924954
if (osi_lb.has_classification() && osi_lb.has_id()) {
925955
int id;
@@ -940,7 +970,12 @@ void OsiMsgHandler::detected_lane_boundaries_from_ground_truth() {
940970
lb.prev_id = -1; // no concatenated line segments for now
941971
lb.next_id = -1;
942972
++lb_id;
943-
from_osi_boundary_points(osi_lb, lb);
973+
if (lbs_flip_pt_order.find(lb.id) == lbs_flip_pt_order.end()) {
974+
from_osi_boundary_points(osi_lb, lb, false);
975+
976+
} else {
977+
from_osi_boundary_points(osi_lb, lb, true);
978+
}
944979
lb.type = osi_lane_bdry_type_map.at(osi_lb.classification().type());
945980
lb.color = osi_lane_bdry_color_map.at(osi_lb.classification().color());
946981
store_lane_boundary(lb);

0 commit comments

Comments
 (0)