Skip to content

Commit

Permalink
using explicit rerouter position in visualization #15426
Browse files Browse the repository at this point in the history
  • Loading branch information
behrisch committed Jan 14, 2025
1 parent 1621789 commit 1e6ba8b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 23 deletions.
34 changes: 22 additions & 12 deletions src/guisim/GUITriggeredRerouter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,12 @@ GUITriggeredRerouter::GUITriggeredRerouter(const std::string& id, const MSEdgeVe
myShiftProbDistIndex(0) {
// add visualisation objects for edges which trigger the rerouter
for (MSEdgeVector::const_iterator it = edges.begin(); it != edges.end(); ++it) {
myEdgeVisualizations.push_back(new GUITriggeredRerouterEdge(dynamic_cast<GUIEdge*>(*it), this, REROUTER_TRIGGER_EDGE));
myEdgeVisualizations.push_back(new GUITriggeredRerouterEdge(dynamic_cast<GUIEdge*>(*it), this, REROUTER_TRIGGER_EDGE, -1, pos, radius));
rtree.addAdditionalGLObject(myEdgeVisualizations.back());
myBoundary.add(myEdgeVisualizations.back()->getCenteringBoundary());
if (pos != Position::INVALID) {
break;
}
}
}

Expand Down Expand Up @@ -382,25 +385,32 @@ GUITriggeredRerouter::shiftProbs() {
/* -------------------------------------------------------------------------
* GUITriggeredRerouterEdge - methods
* ----------------------------------------------------------------------- */
GUITriggeredRerouter::GUITriggeredRerouterEdge::GUITriggeredRerouterEdge(GUIEdge* edge, GUITriggeredRerouter* parent, RerouterEdgeType edgeType, int distIndex) :
GUITriggeredRerouter::GUITriggeredRerouterEdge::GUITriggeredRerouterEdge(GUIEdge* edge, GUITriggeredRerouter* parent, RerouterEdgeType edgeType, int distIndex,
const Position& pos, const double radius) :
GUIGlObject(GLO_REROUTER_EDGE, parent->getID() + ":" + edge->getID(), GUIIconSubSys::getIcon(GUIIcon::REROUTER)),
myParent(parent),
myEdge(edge),
myEdgeType(edgeType),
myDistIndex(distIndex) {
UNUSED_PARAMETER(radius); // it would be nice to have this in the visualization too
const std::vector<MSLane*>& lanes = edge->getLanes();
myFGPositions.reserve(lanes.size());
myFGRotations.reserve(lanes.size());
for (const MSLane* lane : lanes) {
if ((lane->getPermissions() & ~SVC_PEDESTRIAN) == 0) {
continue;
if (pos == Position::INVALID) {
for (const MSLane* lane : lanes) {
if ((lane->getPermissions() & ~SVC_PEDESTRIAN) == 0) {
continue;
}
const PositionVector& v = lane->getShape();
const double lanePos = edgeType == REROUTER_TRIGGER_EDGE ? MAX2(0.0, v.length() - 6) : MIN2(v.length(), 3.0);
myFGPositions.push_back(v.positionAtOffset(lanePos));
myFGRotations.push_back(-v.rotationDegreeAtOffset(lanePos));
myBoundary.add(myFGPositions.back());
myHalfWidths.push_back(lane->getWidth() * 0.5 * 0.875);
}
const PositionVector& v = lane->getShape();
const double pos = edgeType == REROUTER_TRIGGER_EDGE ? MAX2(0.0, v.length() - 6) : MIN2(v.length(), 3.0);
myFGPositions.push_back(v.positionAtOffset(pos));
myFGRotations.push_back(-v.rotationDegreeAtOffset(pos));
} else {
myFGPositions.push_back(pos);
myFGRotations.push_back(0);
myBoundary.add(myFGPositions.back());
myHalfWidths.push_back(lane->getWidth() * 0.5 * 0.875);
myHalfWidths.push_back(SUMO_const_halfLaneWidth * 0.875);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/guisim/GUITriggeredRerouter.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ class GUITriggeredRerouter
class GUITriggeredRerouterEdge : public GUIGlObject {

public:
GUITriggeredRerouterEdge(GUIEdge* edge, GUITriggeredRerouter* parent, RerouterEdgeType edgeType, int distIndex = -1);
GUITriggeredRerouterEdge(GUIEdge* edge, GUITriggeredRerouter* parent, RerouterEdgeType edgeType, int distIndex = -1,
const Position& pos = Position::INVALID, const double radius = std::numeric_limits<double>::max());

virtual ~GUITriggeredRerouterEdge();

Expand Down
3 changes: 3 additions & 0 deletions src/microsim/trigger/MSTriggeredRerouter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ MSTriggeredRerouter::MSTriggeredRerouter(const std::string& id,
}
const std::vector<std::string> vt = StringTokenizer(vTypes).getVector();
myVehicleTypes.insert(vt.begin(), vt.end());
if (myPosition == Position::INVALID) {
myPosition = edges.front()->getLanes()[0]->getShape()[0];
}
}


Expand Down
25 changes: 15 additions & 10 deletions src/netload/NLTriggerBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,18 +723,23 @@ NLTriggerBuilder::parseAndBuildRerouter(MSNet& net, const SUMOSAXAttributes& att
const bool optional = attrs.getOpt<bool>(SUMO_ATTR_OPTIONAL, id.c_str(), ok, false);
const SUMOTime timeThreshold = TIME2STEPS(attrs.getOpt<double>(SUMO_ATTR_HALTING_TIME_THRESHOLD, id.c_str(), ok, 0));
const std::string vTypes = attrs.getOpt<std::string>(SUMO_ATTR_VTYPES, id.c_str(), ok, "");
const std::string pos = attrs.getOpt<std::string>(SUMO_ATTR_POSITION, id.c_str(), ok, "0");
const std::string pos = attrs.getOpt<std::string>(SUMO_ATTR_POSITION, id.c_str(), ok, "");
const double radius = attrs.getOpt<double>(SUMO_ATTR_RADIUS, id.c_str(), ok, std::numeric_limits<double>::max());
if (attrs.hasAttribute(SUMO_ATTR_RADIUS) && !attrs.hasAttribute(SUMO_ATTR_POSITION)) {
WRITE_WARNINGF(TL("It is strongly advisable to give an explicit position when using radius in the definition of rerouter '%'."), id)
}
Position p = Position::INVALID;
const std::vector<std::string> posSplit = StringTokenizer(pos, ",").getVector();
if (posSplit.size() == 1) {
p = edges.front()->getLanes()[0]->geometryPositionAtOffset(StringUtils::toDouble(posSplit[0]));
} else if (posSplit.size() == 2) {
p = Position(StringUtils::toDouble(posSplit[0]), StringUtils::toDouble(posSplit[1]));
} else if (posSplit.size() == 3) {
p = Position(StringUtils::toDouble(posSplit[0]), StringUtils::toDouble(posSplit[1]), StringUtils::toDouble(posSplit[2]));
} else {
throw InvalidArgument("Invalid position for rerouter '" + id + "'.");
if (pos != "") {
const std::vector<std::string> posSplit = StringTokenizer(pos, ",").getVector();
if (posSplit.size() == 1) {
p = edges.front()->getLanes()[0]->geometryPositionAtOffset(StringUtils::toDouble(pos));
} else if (posSplit.size() == 2) {
p = Position(StringUtils::toDouble(posSplit[0]), StringUtils::toDouble(posSplit[1]));
} else if (posSplit.size() == 3) {
p = Position(StringUtils::toDouble(posSplit[0]), StringUtils::toDouble(posSplit[1]), StringUtils::toDouble(posSplit[2]));
} else {
throw InvalidArgument("Invalid position for rerouter '" + id + "'.");
}
}
if (!ok) {
throw InvalidArgument("Could not parse rerouter '" + id + "'.");
Expand Down

0 comments on commit 1e6ba8b

Please sign in to comment.