50 std::string
id = ptStop->getID();
63std::shared_ptr<NBPTStop>
74 std::vector<std::shared_ptr<NBPTStop> > reverseStops;
77 std::shared_ptr<NBPTStop>
const stop = ptStopIt.second;
78 bool multipleStopPositions = stop->getIsMultipleStopPositions();
79 bool platformsDefined = !stop->getPlatformCands().empty();
80 if (!platformsDefined) {
82 std::shared_ptr<NBPTStop> reverseStop =
getReverseStop(stop, cont);
83 if (reverseStop !=
nullptr) {
84 reverseStops.push_back(reverseStop);
86 }
else if (multipleStopPositions) {
92 if (additionalStop !=
nullptr) {
93 reverseStops.push_back(additionalStop);
98 for (std::shared_ptr<NBPTStop>& reverseStop : reverseStops) {
108 std::shared_ptr<NBPTStop> stop = i->second;
109 if (!stop->findLaneAndComputeBusStopExtent(cont)) {
110 WRITE_WARNINGF(
TL(
"Could not find corresponding edge or compatible lane for pt stop '%' (%). Thus, it will be removed!"),
111 i->first, i->second->getName());
124 int existingBidiStops = 0;
125 std::vector<std::shared_ptr<NBPTStop> > toAdd;
127 std::shared_ptr<NBPTStop> stop = i->second;
131 assert(bidiEdge != 0);
135 WRITE_WARNINGF(
TL(
"Could not create reverse-direction stop for superposed edge '%' (origStop '%'). Stop id '%' already in use by stop on edge '%'."),
142 std::shared_ptr<NBPTStop> bidiStop = std::make_shared<NBPTStop>(stop->getElement(),
id,
145 stop->getOrigEdgeId(),
148 stop->getPermissions());
149 if (bidiStop->findLaneAndComputeBusStopExtent(ec)) {
150 toAdd.push_back(bidiStop);
151 stop->setBidiStop(bidiStop);
152 bidiStop->setBidiStop(stop);
157 }
else if (edge !=
nullptr) {
159 if (bidiEdge !=
nullptr) {
167 for (std::shared_ptr<NBPTStop> newStop : toAdd) {
170 if (toAdd.size() > 0) {
173 return (
int)toAdd.size() + existingBidiStops;
179 int existingBidiStops = 0;
181 auto stop = item.second;
185 assert(bidiEdge != 0);
189 if (it !=
myPTStops.end() && it->second->getEdgeId() == bidiEdge->
getID()) {
194 return existingBidiStops;
198std::shared_ptr<NBPTStop>
200 std::string edgeId = pStop->getEdgeId();
203 if (reverse !=
nullptr) {
204 const std::string reverseID =
getReverseID(pStop->getID());
206 return std::make_shared<NBPTStop>(pStop->getElement(), reverseID, pStop->getPosition(), reverse->
getID(), reverse->
getID(),
207 pStop->getLength(), pStop->getName(), pStop->getPermissions());
216std::shared_ptr<NBPTStop>
218 std::string edgeId = pStop->getEdgeId();
220 if (edge ==
nullptr) {
223 bool rightOfEdge =
false;
224 bool leftOfEdge =
false;
226 for (
const NBPTPlatform& platform : pStop->getPlatformCands()) {
234 pStop->setPTStopLength(platform.getLength());
238 if (leftOfEdge && rightOfEdge) {
241 leftStop->setPTStopLength(left->
getLength());
244 }
else if (leftOfEdge) {
246 if (reverse !=
nullptr) {
247 pStop->setEdgeId(reverse->
getID(), cont);
248 pStop->setPTStopLength(left->
getLength());
258 std::string edgeId = pStop->getEdgeId();
262 pStop->setPTStopLength(closestPlatform->
getLength());
263 if (reverse !=
nullptr) {
273 pStop->setEdgeId(reverse->
getID(), cont);
286 if (offset2 < offset) {
293 if (idx1 < 0 || idx1 >= (
int) geom.size() || idx2 < 0 || idx2 >= (
int) geom.size()) {
304 double x2 = closestPlatform.
x();
305 double y2 = closestPlatform.
y();
306 double crossProd = (x1 - x0) * (y2 - y0) - (y1 - y0) * (x2 - x0);
313 Position stopPosition = pStop->getPosition();
315 double minSqrDist = std::numeric_limits<double>::max();
316 for (
const NBPTPlatform& platform : pStop->getPlatformCands()) {
318 if (sqrDist < minSqrDist) {
319 minSqrDist = sqrDist;
330 if (edge !=
nullptr) {
335 if ((*it)->getToNode() == edge->
getFromNode() && (*it)->getGeometry() == rGeom) {
348 if (cont.
getByID(i->second->getEdgeId()) ==
nullptr) {
349 WRITE_WARNINGF(
TL(
"Removing pt stop '%' on non existing edge '%'."), i->first, i->second->getEdgeId());
363 into.insert(stop.second->getEdgeId());
377 const std::vector<std::shared_ptr<NBPTStop> > stops =
myPTStopLookup[edgeID];
378 for (std::shared_ptr<NBPTStop> stop : stops) {
379 if (!stop->replaceEdge(edgeID, replacement)) {
380 WRITE_WARNINGF(
TL(
"Could not re-assign pt stop '%' after replacing edge '%'."), stop->getID(), edgeID);
392 if (usedStops.find(i->second->getID()) == usedStops.end()) {
402 return id.size() > 0 &&
id[0] ==
'-' ?
id.substr(1) :
"-" + id;
408 for (
auto& i : stops) {
409 std::shared_ptr<NBPTStop> s = i.second;
410 const std::string& stopId = s->getID();
411 if (s->getEdgeId() ==
"" || s->wasLoaded()) {
414 const char edgeSign = s->getEdgeId().at(0);
415 const char stopSign = stopId.at(0);
416 if (edgeSign != stopSign && (edgeSign ==
'-' || stopSign ==
'-')) {
418 std::shared_ptr<NBPTStop> rs =
get(reverseID);
419 if (rs !=
nullptr && rs->wasLoaded()) {
422 s->setPTStopId(reverseID);
426 rs->setPTStopId(stopId);
437 for (
const auto& item : cont) {
438 NBEdge* edge = item.second;
443 float min[2] = {
static_cast<float>(bound.
xmin()),
static_cast<float>(bound.
ymin()) };
444 float max[2] = {
static_cast<float>(bound.
xmax()),
static_cast<float>(bound.
ymax()) };
448 std::set<const Named*> edges;
450 const Position& pos = ptStop->getPosition();
451 float min[2] = {
static_cast<float>(pos.
x() - maxRadius),
static_cast<float>(pos.
y() - maxRadius)};
452 float max[2] = {
static_cast<float>(pos.
x() + maxRadius),
static_cast<float>(pos.
y() + maxRadius)};
453 r.
Search(min, max, visitor);
454 std::vector<NBEdge*> nearby;
455 for (
const Named* namedEdge : edges) {
461 std::sort(nearby.begin(), nearby.end(), [pos](
NBEdge * a,
NBEdge * b) {
462 return a->getLaneShape(0).distance2D(pos, false) < b->getLaneShape(0).distance2D(pos, false);
465 for (
NBEdge* e : nearby) {
466 ptStop->setEdgeId(e->getID(), cont);
467 if (ptStop->getLaneId() !=
"") {
471 if (ptStop->getLaneId() ==
"") {
472 WRITE_WARNINGF(
TL(
"Could not find corresponding edge or compatible lane for free-floating pt stop '%' (%). Thus, it will be removed!"),
473 ptStop->getID(), ptStop->getName());
482 for (
auto edge : cont) {
483 const Boundary& bound = edge.second->getGeometry().getBoxBoundary();
484 float min[2] = {
static_cast<float>(bound.
xmin()),
static_cast<float>(bound.
ymin()) };
485 float max[2] = {
static_cast<float>(bound.
xmax()),
static_cast<float>(bound.
ymax()) };
486 r.
Insert(min, max, edge.second);
489 const std::string& stopEdgeID = ptStop.second->getEdgeId();
494 std::set<const Named*> edges;
496 const Position& pos = ptStop.second->getPosition();
497 float min[2] = {
static_cast<float>(pos.
x() - maxRadius),
static_cast<float>(pos.
y() - maxRadius)};
498 float max[2] = {
static_cast<float>(pos.
x() + maxRadius),
static_cast<float>(pos.
y() + maxRadius)};
499 r.
Search(min, max, visitor);
500 std::vector<NBEdge*> edgCants;
501 for (
const Named* namedEdge : edges) {
503 edgCants.push_back(e);
505 std::sort(edgCants.begin(), edgCants.end(), [pos](
NBEdge * a,
NBEdge * b) {
506 return a->getLaneShape(0).distance2D(pos, false) < b->getLaneShape(0).distance2D(pos, false);
509 for (
auto edge : edgCants) {
511 for (
auto lane : edge->getLanes()) {
513 double offset = lane.shape.nearest_offset_to_point2D(pos,
false);
514 double finalLength = edge->getFinalLength();
515 double laneLength = lane.shape.length();
516 double accessLength = pos.
distanceTo2D(lane.shape.positionAtOffset2D(offset)) * accessFactor;
517 ptStop.second->addAccess(edge->getLaneID(laneIdx), offset * finalLength / laneLength, accessLength);
523 if (cnt == maxCount) {
532std::shared_ptr<NBPTStop>
535 if (item.second->getOrigEdgeId() == origEdgeID &&
536 item.second->getPosition().distanceTo2D(pos) < threshold) {
#define WRITE_WARNINGF(...)
#define WRITE_MESSAGEF(...)
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
long long int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
@ SVC_RAIL
vehicle is a not electrified rail
@ SVC_RAIL_URBAN
vehicle is a city rail
@ SVC_TRAM
vehicle is a light rail
@ SVC_TAXI
vehicle is a taxi
@ SVC_BUS
vehicle is a bus
@ SVC_PEDESTRIAN
pedestrian
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
A class that stores a 2D geometrical boundary.
double ymin() const
Returns minimum y-coordinate.
double xmin() const
Returns minimum x-coordinate.
double ymax() const
Returns maximum y-coordinate.
double xmax() const
Returns maximum x-coordinate.
Storage for edges, including some functionality operating on multiple edges.
NBEdge * getByID(const std::string &edgeID) const
Returns the edge with id if it exists.
The representation of a single edge during network building.
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
NBNode * getToNode() const
Returns the destination node of the edge.
const PositionVector & getGeometry() const
Returns the geometry of the edge.
bool isBidiRail(bool ignoreSpread=false) const
whether this edge is part of a bidirectional railway
const std::string & getID() const
NBNode * getFromNode() const
Returns the origin node of the edge.
NBEdge * getTurnDestination(bool possibleDestination=false) const
const EdgeVector & getOutgoingEdges() const
Returns this node's outgoing edges (The edges which start at this node)
static std::string getReverseID(const std::string &id)
void replaceEdge(const std::string &edgeID, const std::vector< NBEdge * > &replacement)
replace the edge with the closes edge on the given edge list in all stops
int cleanupDeleted(NBEdgeCont &cont)
remove stops on non existing (removed) edges
void assignPTStopToEdgeOfClosestPlatform(std::shared_ptr< NBPTStop > pStop, NBEdgeCont &cont)
static std::set< std::string > myIgnoredStops
static NBEdge * getReverseEdge(NBEdge *edge)
double computeCrossProductEdgePosition(const NBEdge *edge, const Position &closestPlatform) const
void postprocess(std::set< std::string > &usedStops)
std::map< std::string, std::vector< std::shared_ptr< NBPTStop > > > myPTStopLookup
The map of edge ids to stops.
std::shared_ptr< NBPTStop > get(std::string id) const
Retrieve a previously inserted pt stop.
void addEdges2Keep(const OptionsCont &oc, std::set< std::string > &into)
add edges that must be kept
PTStopsCont myPTStops
The map of names to pt stops.
std::vector< std::shared_ptr< NBPTStop > > myFloatingStops
void localizePTStops(NBEdgeCont &cont)
std::shared_ptr< NBPTStop > getReverseStop(std::shared_ptr< NBPTStop > pStop, const NBEdgeCont &ec)
std::map< std::string, std::shared_ptr< NBPTStop > > PTStopsCont
Definition of the map of names to pt stops.
void assignEdgeForFloatingStops(NBEdgeCont &cont, double maxRadius)
void findAccessEdgesForRailStops(NBEdgeCont &cont, double maxRadius, int maxCount, double accessFactor)
const NBPTPlatform * getClosestPlatformToPTStopPosition(std::shared_ptr< NBPTStop > pStop)
int generateBidiStops(NBEdgeCont &cont)
duplicate stops for superposed rail edges and return the number of generated stops
std::shared_ptr< NBPTStop > findStop(const std::string &origEdgeID, Position pos, double threshold=1) const
void assignLanes(NBEdgeCont &cont)
std::shared_ptr< NBPTStop > assignAndCreatNewPTStopAsNeeded(std::shared_ptr< NBPTStop > pStop, NBEdgeCont &cont)
int countBidiStops(NBEdgeCont &cont) const
count number of stop-pairs for superposed rail-edges
bool insert(std::shared_ptr< NBPTStop > ptStop, bool floating=false)
Inserts a node into the map.
Allows to store the object; used as context while traveling the rtree in TraCI.
Base class for objects which have an id.
A RT-tree for efficient storing of SUMO's Named objects.
void Insert(const float a_min[2], const float a_max[2], Named *const &a_data)
Insert entry.
int Search(const float a_min[2], const float a_max[2], const Named::StoringVisitor &c) const
Find all within search rectangle.
A storage for options typed value containers)
A point in 2D or 3D with translation and scaling methods.
double distanceSquaredTo2D(const Position &p2) const
returns the square of the distance to another position (Only using x and y positions)
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
double x() const
Returns the x-position.
double y() const
Returns the y-position.
double nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
int indexOfClosest(const Position &p, bool twoD=false) const
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
double offsetAtIndex2D(int index) const
return the offset at the given index
PositionVector reverse() const
reverse position vector