Refactor MapData
This commit is contained in:
parent
f9293c80ed
commit
a4fda4213b
|
@ -1,38 +0,0 @@
|
|||
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
|
||||
// de Barcelona (UAB).
|
||||
//
|
||||
// This work is licensed under the terms of the MIT license.
|
||||
// For a copy, see <https://opensource.org/licenses/MIT>.
|
||||
|
||||
#include "carla/road/MapData.h"
|
||||
|
||||
using namespace carla::road::element;
|
||||
|
||||
namespace carla {
|
||||
namespace road {
|
||||
|
||||
bool MapData::ExistId(id_type id) const {
|
||||
return _elements.count(id);
|
||||
}
|
||||
|
||||
const RoadSegment *MapData::GetRoad(id_type id) const {
|
||||
if (ExistId(id)) {
|
||||
return _elements.find(id)->second.get();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<id_type> MapData::GetAllIds() const {
|
||||
std::vector<id_type> result;
|
||||
for (auto &&e : _elements) {
|
||||
result.emplace_back(e.first);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t MapData::GetRoadCount() const {
|
||||
return _elements.size();
|
||||
}
|
||||
|
||||
} // namespace road
|
||||
} // namespace carla
|
|
@ -6,16 +6,17 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "carla/Iterator.h"
|
||||
#include "carla/ListView.h"
|
||||
#include "carla/NonCopyable.h"
|
||||
#include "carla/road/element/RoadSegment.h"
|
||||
|
||||
#include <map>
|
||||
#include <boost/iterator/transform_iterator.hpp>
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
namespace carla {
|
||||
namespace road {
|
||||
namespace element {
|
||||
class Waypoint;
|
||||
}
|
||||
|
||||
struct lane_junction_t {
|
||||
std::string contact_point = "start";
|
||||
|
@ -32,35 +33,48 @@ namespace element {
|
|||
: private MovableNonCopyable {
|
||||
public:
|
||||
|
||||
bool ExistId(element::id_type id) const;
|
||||
|
||||
const element::RoadSegment *GetRoad(element::id_type id) const;
|
||||
|
||||
std::vector<element::id_type> GetAllIds() const;
|
||||
|
||||
uint32_t GetRoadCount() const;
|
||||
|
||||
const element::RoadSegment &NearestRoad(const geom::Location &loc);
|
||||
|
||||
void SetJunctionInformation(const std::vector<lane_junction_t> &junctionInfo) {
|
||||
_junction_information = junctionInfo;
|
||||
const element::RoadSegment *GetRoad(element::id_type id) const {
|
||||
auto it = _elements.find(id);
|
||||
return it != _elements.end() ? it->second.get() : nullptr;
|
||||
}
|
||||
|
||||
std::vector<lane_junction_t> GetJunctionInformation() const {
|
||||
auto GetAllIds() const {
|
||||
return MakeListView(
|
||||
iterator::make_map_keys_iterator(_elements.begin()),
|
||||
iterator::make_map_keys_iterator(_elements.end()));
|
||||
}
|
||||
|
||||
size_t GetRoadCount() const {
|
||||
return _elements.size();
|
||||
}
|
||||
|
||||
const std::vector<lane_junction_t> &GetJunctionInformation() const {
|
||||
return _junction_information;
|
||||
}
|
||||
|
||||
auto GetRoadSegments() const {
|
||||
using const_ref = const element::RoadSegment &;
|
||||
auto get = [](auto &pair) -> const_ref { return *pair.second; };
|
||||
return MakeListView(
|
||||
boost::make_transform_iterator(_elements.begin(), get),
|
||||
boost::make_transform_iterator(_elements.end(), get));
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
friend class MapBuilder;
|
||||
friend class Map;
|
||||
friend element::Waypoint;
|
||||
|
||||
MapData() = default;
|
||||
|
||||
void SetJunctionInformation(const std::vector<lane_junction_t> &junctionInfo) {
|
||||
_junction_information = junctionInfo;
|
||||
}
|
||||
|
||||
std::vector<lane_junction_t> _junction_information;
|
||||
|
||||
std::map<element::id_type, std::unique_ptr<element::RoadSegment>> _elements;
|
||||
std::unordered_map<
|
||||
element::id_type,
|
||||
std::unique_ptr<element::RoadSegment>> _elements;
|
||||
};
|
||||
|
||||
} // namespace road
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "carla/NonCopyable.h"
|
||||
#include "carla/geom/Location.h"
|
||||
#include "carla/road/element/RoadInfo.h"
|
||||
#include "carla/road/element/Types.h"
|
||||
|
@ -22,7 +23,7 @@ namespace road {
|
|||
|
||||
namespace element {
|
||||
|
||||
class RoadSegment {
|
||||
class RoadSegment : private NonCopyable {
|
||||
public:
|
||||
|
||||
RoadSegment(id_type id) : _id(id) {}
|
||||
|
|
|
@ -43,14 +43,13 @@ namespace element {
|
|||
Waypoint::Waypoint(SharedPtr<const Map> m, const geom::Location &loc)
|
||||
: _map(m) {
|
||||
DEBUG_ASSERT(_map != nullptr);
|
||||
|
||||
// max_nearests represents the max nearests roads
|
||||
// where we will search for nearests lanes
|
||||
constexpr int max_nearests = 10;
|
||||
// in case that map has less than max_nearests lanes,
|
||||
// we will use the maximum lanes
|
||||
const int max_nearest_allowed = _map->GetData()._elements.size() <
|
||||
max_nearests ? _map->GetData()._elements.size() : max_nearests;
|
||||
const int max_nearest_allowed = _map->GetData().GetRoadCount() <
|
||||
max_nearests ? _map->GetData().GetRoadCount() : max_nearests;
|
||||
|
||||
double nearest_dist[max_nearests];
|
||||
std::fill(nearest_dist, nearest_dist + max_nearest_allowed,
|
||||
|
@ -63,8 +62,8 @@ namespace element {
|
|||
std::fill(dists, dists + max_nearest_allowed, 0.0);
|
||||
|
||||
|
||||
for (auto &&r : _map->GetData()._elements) {
|
||||
auto current_dist = r.second->GetNearestPoint(loc);
|
||||
for (auto &&r : _map->GetData().GetRoadSegments()) {
|
||||
auto current_dist = r.GetNearestPoint(loc);
|
||||
|
||||
// search for nearests points
|
||||
for (int i = 0; i < max_nearest_allowed; ++i) {
|
||||
|
@ -76,7 +75,7 @@ namespace element {
|
|||
dists[j] = dists[j - 1];
|
||||
}
|
||||
nearest_dist[i] = current_dist.second;
|
||||
ids[i] = r.first;
|
||||
ids[i] = r.GetId();
|
||||
dists[i] = current_dist.first;
|
||||
|
||||
break;
|
||||
|
|
|
@ -62,7 +62,8 @@ void AOpenDriveActor::BuildRoutes()
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
// NOTE(Andrei): Build the roads that are not junctions
|
||||
|
||||
std::vector<carla::road::element::id_type> roadIDs = map.GetAllIds();
|
||||
auto RoadIDsView = map.GetAllIds();
|
||||
std::vector<carla::road::element::id_type> roadIDs(RoadIDsView.begin(), RoadIDsView.end());
|
||||
std::sort(roadIDs.begin(), roadIDs.end());
|
||||
|
||||
for (auto &&id : roadIDs)
|
||||
|
|
Loading…
Reference in New Issue