73 auto info = GetInfo<element::RoadInfoElevation>(s);
74 if (info ==
nullptr) {
77 return info->GetPolynomial();
82 auto *lane = section.GetLane(lane_id);
83 if (lane !=
nullptr) {
95 std::vector<Lane*> result;
97 for (
auto &lane_section : lane_sections) {
98 for (
auto & lane_pair : lane_section.GetLanes()) {
99 result.emplace_back(&lane_pair.second);
106 std::vector<const Lane*> result;
108 for (
const auto &lane_section : lane_sections) {
109 for (
const auto & lane_pair : lane_section.GetLanes()) {
110 result.emplace_back(&lane_pair.second);
131 Lane *ptr = upper->second.GetLane(lane_id);
132 if (ptr !=
nullptr) {
145 auto rlower = std::make_reverse_iterator(lower);
149 Lane *ptr = rlower->second.GetLane(lane_id);
150 if (ptr !=
nullptr) {
164 Lane *ptr = it->second.GetLane(
id);
165 if (ptr !=
nullptr) {
166 return &(it->second);
177 Lane *ptr = it->second.GetLane(
id);
178 if (ptr !=
nullptr) {
179 return &(it->second);
189 if (shapes.empty()) {
196 auto EvalStation = [t](
const std::vector<const element::RoadInfoLateralShape *> &station) {
198 for (
const auto *record : station) {
199 if (record->GetT() <= t) {
210 std::vector<const element::RoadInfoLateralShape *> before, after;
211 double s_before = -1.0, s_after = -1.0;
212 std::vector<const element::RoadInfoLateralShape *> current;
213 double s_current = -1.0;
214 auto CloseStation = [&]() {
215 if (current.empty()) {
218 std::sort(current.begin(), current.end(),
219 [](
const auto *a,
const auto *b) { return a->GetT() < b->GetT(); });
220 if (s_current <= clamped_s) {
221 before = current; s_before = s_current;
222 }
else if (after.empty()) {
223 after = current; s_after = s_current;
227 for (
const auto *record : shapes) {
228 if (record->GetDistance() != s_current) {
230 s_current = record->GetDistance();
232 current.push_back(record);
236 if (before.empty()) {
237 return after.empty() ? 0.0 : EvalStation(after);
239 if (after.empty() || s_after <= s_before) {
240 return EvalStation(before);
242 const double u = (clamped_s - s_before) / (s_after - s_before);
243 return (1.0 - u) * EvalStation(before) + u * EvalStation(after);
253 offset =
static_cast<float>(lane_offset->GetPolynomial().Evaluate(clamped_s));
262 p.
location.
z =
static_cast<float>(elevation_info.Evaluate(s));
263 p.
pitch = elevation_info.Tangent(s);
276 p.location.z =
static_cast<float>(elevation_info.Evaluate(s));
277 p.pitch = elevation_info.Tangent(s);
283 std::pair<double, double>
last = { 0.0, std::numeric_limits<double>::max() };
286 decltype(geom_info_list)::iterator nearest_geom = geom_info_list.end();
288 for (
auto g = geom_info_list.begin(); g != geom_info_list.end(); ++g) {
290 auto dist = (*g)->GetGeometry().DistanceTo(loc);
291 if (dist.second <
last.second) {
297 for (
auto g = geom_info_list.begin();
298 g != geom_info_list.end() && g != nearest_geom;
301 last.first += (*g)->GetGeometry().GetLength();
310 uint32_t lane_type)
const {
312 std::map<LaneId, const Lane *> lanes(
GetLanesAt(s));
314 auto right_lanes = MakeListView(
315 std::make_reverse_iterator(lanes.lower_bound(0)), lanes.rend());
317 auto left_lanes = MakeListView(
318 lanes.lower_bound(1), lanes.end());
321 std::pair<const Lane *, double> result =
322 std::make_pair(
nullptr, std::numeric_limits<double>::max());
325 for (
const auto &lane : right_lanes) {
327 const auto half_width =
static_cast<float>(lane_width_info->GetPolynomial().Evaluate(s)) * 0.5f;
333 if (current_dist <= result.second) {
336 if ((
static_cast<uint32_t
>(lane.second->GetType()) & lane_type) > 0) {
337 result.first = &(*lane.second);
338 result.second = current_dist;
347 current_dp = dp_lane_zero;
348 for (
const auto &lane : left_lanes) {
350 const auto half_width = -
static_cast<float>(lane_width_info->GetPolynomial().Evaluate(s)) * 0.5f;
356 if (current_dist <= result.second) {
359 if ((
static_cast<uint32_t
>(lane.second->GetType()) & lane_type) > 0) {
360 result.first = &(*lane.second);
361 result.second = current_dist;
374 std::map<LaneId, const Lane *> map;
376 for (
auto &&lane : lane_section.GetLanes()) {
377 map[lane.first] = &(lane.second);
#define DEBUG_ASSERT(predicate)
std::map< std::string, unsigned int > road
Describes a Cubic Polynomial so: f(x) = a + bx + cx^2 + dx^3.
static auto Distance(const Vector3D &a, const Vector3D &b)
static constexpr T Clamp(T a, T min=T(0), T max=T(1))
std::map< LaneId, Lane > & GetLanes()
RoadId GetPredecessor() const
const std::pair< double, double > GetNearestPoint(const geom::Location &loc) const
Returns a pair containing:
std::vector< Road * > GetPrevs() const
Lane * GetPrevLane(const double s, const LaneId lane_id)
std::vector< Road * > _nexts
Lane & GetLaneById(SectionId section_id, LaneId lane_id)
LaneSectionMap _lane_sections
RoadId GetSuccessor() const
double GetLateralShapeZ(const double s, const double t) const
Surface height offset from the <lateralProfile><shape> records at (s, t).
std::map< LaneId, const Lane * > GetLanesAt(const double s) const
Get all lanes at a given s.
std::vector< Road * > GetNexts() const
LaneSection * GetStartSection(LaneId id)
Get the start section (from road coordinates s) given a lane id.
Lane * GetNextLane(const double s, const LaneId lane_id)
const geom::CubicPolynomial & GetElevationOn(const double s) const
Lane & GetLaneByDistance(double s, LaneId lane_id)
std::vector< Road * > _prevs
auto GetLaneSectionsAt(const double s)
const std::pair< const Lane *, double > GetNearestLane(const double s, const geom::Location &loc, uint32_t type=static_cast< uint32_t >(Lane::LaneType::Any)) const
Returns a pointer to the nearest lane, given s relative to Road and a location.
element::DirectedPoint GetDirectedPointIn(const double s) const
Returns a directed point on the center of the road (lane 0), with the corresponding laneOffset and el...
std::vector< Lane * > GetLanesByDistance(double s)
Get all lanes from all lane sections in a specific s.
element::DirectedPoint GetDirectedPointInNoLaneOffset(const double s) const
Returns a directed point on the center of the road (lane 0), with the corresponding laneOffset and el...
JuncId GetJunctionId() const
LaneSection * GetEndSection(LaneId id)
Get the end section (from road coordinates s) given a lane id.
std::string GetName() const
const MapData * GetMap() const
LaneSection & GetLaneSectionById(SectionId id)
The lane offset record defines a lateral shift of the lane reference line(which is usually identical ...
Lane Width RecordEach lane within a road’scross section can be provided with severalwidth entries.
One <lateralProfile><shape> record: at station s, the road surface height relative to the elevation p...
double Evaluate(const double t) const
Evaluate the surface height offset at lateral position t (the polynomial is defined over t - t_record...
This file contains definitions of common data structures used in traffic manager.
void throw_exception(const ExceptionT &e)
Templated on the static type so the thrown object keeps its dynamic type: taking a const std::excepti...
void ApplyLateralOffset(float lateral_offset)