Precalculed lane offset from the center of the road

This commit is contained in:
Marc 2018-11-05 18:35:24 +01:00
parent a82b80eb30
commit 5015ab782b
4 changed files with 51 additions and 25 deletions

View File

@ -5,6 +5,7 @@
// For a copy, see <https://opensource.org/licenses/MIT>.
#include "carla/road/MapBuilder.h"
#include "carla/road/element/RoadInfoVisitor.h"
using namespace carla::road::element;
@ -41,6 +42,46 @@ namespace road {
}
}
// Set the _lane_center_offset of all the lanes
for (auto &&element : _map_data._elements) {
RoadSegment *road_seg = element.second.get();
auto up_bound_g = decltype(road_seg->_info)::reverse_iterator(road_seg->_info.upper_bound(0.0));
auto general_info = MakeRoadInfoIterator<RoadGeneralInfo>(up_bound_g, road_seg->_info.rend());
auto up_bound_l = decltype(road_seg->_info)::reverse_iterator(road_seg->_info.upper_bound(0.0));
auto lane_info = MakeRoadInfoIterator<RoadInfoLane>(up_bound_l, road_seg->_info.rend());
// check that have a RoadGeneralInfo
if (!lane_info.IsAtEnd()) {
double lane_offset = 0.0;
if (!general_info.IsAtEnd()) {
lane_offset = (*general_info)->GetLanesOffset().at(0).second;
}
double current_width = lane_offset;
for (auto &&current_lane_id : (*lane_info)->getLanesIDs(carla::road::element::RoadInfoLane::which_lane_e::Left)) {
const double half_width = (*lane_info)->getLane(current_lane_id)->_width * 0.5;
current_width += half_width;
(*lane_info)->_lanes[current_lane_id]._lane_center_offset = current_width;
current_width += half_width;
}
current_width = lane_offset;
for (auto &&current_lane_id : (*lane_info)->getLanesIDs(carla::road::element::RoadInfoLane::which_lane_e::Right)) {
const double half_width = (*lane_info)->getLane(current_lane_id)->_width * 0.5;
current_width -= half_width;
(*lane_info)->_lanes[current_lane_id]._lane_center_offset = current_width;
current_width -= half_width;
}
}
}
// _map_data is a memeber of MapBuilder so you must especify if
// you want to keep it (will return copy -> Map(const Map &))
// or move it (will return move -> Map(Map &&))

View File

@ -13,6 +13,7 @@
namespace carla {
namespace road {
class MapBuilder;
namespace element {
class RoadInfo {
@ -84,6 +85,7 @@ namespace element {
int _id;
double _width;
double _lane_center_offset;
std::string _type;
std::vector<int> _successor;
@ -91,17 +93,21 @@ namespace element {
LaneInfo()
: _id(0),
_width(0.0) {}
_width(0.0),
_lane_center_offset(0.0) {}
LaneInfo(int id, double width, const std::string &type)
: _id(id),
_width(width),
_lane_center_offset(0.0),
_type(type) {}
};
class RoadInfoLane : public RoadInfo {
private:
friend MapBuilder;
using lane_t = std::map<int, LaneInfo>;
lane_t _lanes;

View File

@ -283,6 +283,8 @@ namespace element {
private:
friend class MapBuilder;
id_type _id;
std::vector<RoadSegment *> _predecessors;
std::vector<RoadSegment *> _successors;

View File

@ -77,34 +77,11 @@ namespace element {
if (_lane_id > 0) {
rot.yaw += 180.0;
}
double current_width = 0.0;
auto *info = GetRoad(*_map, _road_id).GetInfo<RoadInfoLane>(0.0);
DEBUG_ASSERT(info != nullptr);
if (_lane_id > 0) {
// Left lanes
for (auto &&current_lane_id : info->getLanesIDs(carla::road::element::RoadInfoLane::which_lane_e::Left)) {
const double half_width = info->getLane(current_lane_id)->_width * 0.5;
current_width -= half_width;
if (current_lane_id == _lane_id) {
break;
}
current_width -= half_width;
}
} else {
// Right lanes
for (auto &&current_lane_id : info->getLanesIDs(carla::road::element::RoadInfoLane::which_lane_e::Right)) {
const double half_width = info->getLane(current_lane_id)->_width * 0.5;
current_width += half_width;
if (current_lane_id == _lane_id) {
break;
}
current_width += half_width;
}
}
dp.ApplyLateralOffset(-current_width);
dp.ApplyLateralOffset(info->getLane(_lane_id)->_lane_center_offset);
return geom::Transform(dp.location, rot);
}