Add basic lane information

This commit is contained in:
iFuSiiOnzZ 2018-10-17 12:18:40 +02:00
parent db47f8a000
commit 9718238df6
3 changed files with 97 additions and 2 deletions

View File

@ -69,6 +69,19 @@ namespace opendrive {
// Transforma data for the MapBuilder
for (road_data_t::iterator it = roadData.begin(); it != roadData.end(); ++it) {
carla::road::RoadSegmentDefinition roadSegment(it->first);
carla::road::element::RoadInfoLane *roadInfoLanes = roadSegment.MakeInfo<carla::road::element::RoadInfoLane>();
std::vector<carla::opendrive::types::Lane> &lanesLeft = it->second->lane_sections.left;
for(size_t i = 0; i < lanesLeft.size(); ++i)
{
roadInfoLanes->addLaneInfo(lanesLeft[i].attributes.id, lanesLeft[i].lane_width[0].width, lanesLeft[i].attributes.type);
}
std::vector<carla::opendrive::types::Lane> &lanesRight = it->second->lane_sections.right;
for(size_t i = 0; i < lanesRight.size(); ++i)
{
roadInfoLanes->addLaneInfo(lanesRight[i].attributes.id, lanesRight[i].lane_width[0].width, lanesRight[i].attributes.type);
}
if (it->second->road_link.successor != nullptr) {
if (it->second->road_link.successor->element_type == "junction") {

View File

@ -6,7 +6,10 @@
#pragma once
#include "carla/road/element/RoadSegment.h"
#include "RoadSegment.h"
#include <string>
#include <vector>
#include <map>
namespace carla {
namespace road {
@ -22,6 +25,73 @@ namespace element {
double d = 0; // [meters]
};
class LaneInfo
{
public:
int _id;
double _width;
std::string _type;
std::vector<int> _successor;
std::vector<int> _predecessor;
LaneInfo() :
_id(0), _width(0.0) {}
LaneInfo(int id, double width, const std::string &type) :
_id(id), _width(width), _type(type) {}
};
class RoadInfoLane : public RoadInfo {
private:
using lane_t = std::map<int, LaneInfo>;
lane_t _lanes;
public:
enum class which_lane_e : int {
Left,
Right,
Both
};
inline void addLaneInfo(int id, double width, const std::string &type) {
_lanes[id] = LaneInfo(id, width, type);
}
inline int size() {
return (int) _lanes.size();
}
std::vector<int> getLanesIDs(which_lane_e whichLanes = which_lane_e::Both) {
std::vector<int> lanesId;
for(lane_t::iterator it = _lanes.begin(); it != _lanes.end(); ++it) {
switch(whichLanes) {
case which_lane_e::Both: {
lanesId.push_back(it->first);
} break;
case which_lane_e::Left: {
if(it->first > 0) {
lanesId.push_back(it->first);
}
} break;
case which_lane_e::Right: {
if(it->first < 0) {
lanesId.push_back(it->first);
}
} break;
}
}
}
const LaneInfo *getLane(int id) {
lane_t::iterator it = _lanes.find(id);
return it == _lanes.end() ? nullptr : &it->second;
}
};
} // namespace element
} // namespace road
} // namespace carla

View File

@ -57,7 +57,7 @@ void AOpenDriveActor::BeginPlay()
processed.Add(id);
}
std::vector<carla::road::id_type> successorIds = map.GetRoad(id)->GetSuccessorsIds();
/*std::vector<carla::road::id_type> successorIds = map.GetRoad(id)->GetSuccessorsIds();
if (successorIds.size())
{
ARoutePlanner *routePlaner = GetWorld()->SpawnActor<ARoutePlanner>();
@ -68,6 +68,18 @@ void AOpenDriveActor::BeginPlay()
processed.Add(successorID);
}
}
std::vector<carla::road::id_type> predecessorIds = map.GetRoad(id)->GetPredecessorsIds();
if (predecessorIds.size())
{
ARoutePlanner *routePlaner = GetWorld()->SpawnActor<ARoutePlanner>();
for (auto &&predeccesorID : predecessorIds)
{
fnc_generate_points(map.GetRoad(predeccesorID), routePlaner);
processed.Add(predeccesorID);
}
}*/
}
}