22static auto MakeMap(
const std::string &opendrive_contents) {
24 auto stream = std::istringstream(opendrive_contents);
28 if (!map.has_value()) {
32 return std::move(*map);
35 Map::Map(
rpc::MapInfo description, std::string xodr_content)
36 : _description(
std::move(description)),
39 open_drive_file = xodr_content;
42 Map::Map(std::string name, std::string xodr_content)
45 std::vector<geom::Transform>{}}, xodr_content) {
46 open_drive_file = xodr_content;
49 Map::~Map() =
default;
51 SharedPtr<Waypoint> Map::GetWaypoint(
52 const geom::Location &location,
54 int32_t lane_type)
const {
56 boost::optional<road::element::Waypoint> waypoint;
58 if (project_to_road) {
59 waypoint = _map.GetClosestWaypointOnRoad(location, lane_type);
61 waypoint = _map.GetWaypoint(location, lane_type);
64 return waypoint.has_value() ?
65 SharedPtr<Waypoint>(
new Waypoint{shared_from_this(), *waypoint}) :
69 SharedPtr<Waypoint> Map::GetWaypointXODR(
74 boost::optional<road::element::Waypoint> waypoint;
76 waypoint = _map.GetWaypoint(road_id, lane_id, s);
78 return waypoint.has_value() ?
79 SharedPtr<Waypoint>(
new Waypoint{shared_from_this(), *waypoint}) :
83 Map::TopologyList Map::GetTopology()
const {
87 std::unordered_map<re::Waypoint, SharedPtr<Waypoint>> waypoints;
89 auto get_or_make_waypoint = [&](
const auto &waypoint) {
90 auto it = waypoints.find(waypoint);
91 if (it == waypoints.end()) {
92 it = waypoints.emplace(
94 SharedPtr<Waypoint>(
new Waypoint{shared_from_this(), waypoint})).first;
101 auto topology = _map.GenerateTopology();
103 result.reserve(topology.size());
105 for (
const auto &pair : topology) {
107 get_or_make_waypoint(pair.first),
108 get_or_make_waypoint(pair.second));
113 std::vector<SharedPtr<Waypoint>> Map::GenerateWaypoints(
double distance)
const {
115 std::vector<SharedPtr<Waypoint>> result;
117 const auto waypoints = _map.GenerateWaypoints(distance);
119 result.reserve(waypoints.size());
121 for (
const auto &waypoint : waypoints) {
127 std::vector<road::element::LaneMarking> Map::CalculateCrossedLanes(
131 return _map.CalculateCrossedLanes(origin, destination);
136 return _map.GetGeoReference();
139 std::vector<geom::Location> Map::GetAllCrosswalkZones()
const {
141 return _map.GetAllCrosswalkZones();
146 const road::Junction *juncptr = GetMap().GetJunction(waypoint.GetJunctionId());
158 auto junction_waypoints = GetMap().GetJunctionWaypoints(
id, lane_type);
160 for (
auto &waypoint_pair : junction_waypoints) {
168 std::vector<SharedPtr<Landmark>> Map::GetAllLandmarks()
const {
170 std::vector<SharedPtr<Landmark>> result;
172 auto signal_references = _map.GetAllSignalReferences();
174 for(
auto* signal_reference : signal_references) {
176 new Landmark(
nullptr, shared_from_this(), signal_reference, 0));
181 std::vector<SharedPtr<Landmark>> Map::GetLandmarksFromId(std::string
id)
const {
183 std::vector<SharedPtr<Landmark>> result;
185 auto signal_references = _map.GetAllSignalReferences();
187 for(
auto* signal_reference : signal_references) {
188 if(signal_reference->GetSignalId() ==
id) {
190 new Landmark(
nullptr, shared_from_this(), signal_reference, 0));
196 std::vector<SharedPtr<Landmark>> Map::GetAllLandmarksOfType(std::string type)
const {
198 std::vector<SharedPtr<Landmark>> result;
200 auto signal_references = _map.GetAllSignalReferences();
202 for(
auto* signal_reference : signal_references) {
203 if(signal_reference->GetSignal()->GetType() == type) {
205 new Landmark(
nullptr, shared_from_this(), signal_reference, 0));
211 std::vector<SharedPtr<Landmark>>
212 Map::GetLandmarkGroup(
const Landmark &landmark)
const {
214 std::vector<SharedPtr<Landmark>> result;
216 auto &controllers = landmark._signal->GetSignal()->GetControllers();
218 for (
auto& controller_id : controllers) {
219 const auto &controller = _map.GetControllers().at(controller_id);
220 for(
auto& signal_id : controller->GetSignals()) {
221 auto& signal = _map.GetSignals().at(signal_id);
222 auto new_landmarks = GetLandmarksFromId(signal->GetSignalId());
223 result.insert(result.end(), new_landmarks.begin(), new_landmarks.end());
229 void Map::CookInMemoryMap(
const std::string& path)
const {
231 traffic_manager::InMemoryMap::Cook(shared_from_this(), path);
地图类的前向声明,用于在LaneInvasionSensor类中可能的引用。
static boost::optional< road::Map > Load(const std::string &opendrive)
static auto MakeMap(const std::string &opendrive_contents)
std::vector< std::pair< WaypointPtr, WaypointPtr > > TopologyList
void throw_exception(const std::exception &e)
boost::shared_ptr< T > SharedPtr
使用这个SharedPtr(boost::shared_ptr)以保持与boost::python的兼容性, 但未来如果可能的话,我们希望能为std::shared_ptr制作一个Python适配器。