SUMOReal MSEdge::getMeanSpeed() const { SUMOReal v = 0; SUMOReal no = 0; if (MSGlobals::gUseMesoSim) { for (MESegment* segment = MSGlobals::gMesoNet->getSegmentForEdge(*this); segment != 0; segment = segment->getNextSegment()) { const SUMOReal vehNo = (SUMOReal) segment->getCarNumber(); v += vehNo * segment->getMeanSpeed(); no += vehNo; } if (no == 0) { return getLength() / myEmptyTraveltime; // may include tls-penalty } } else { for (std::vector<MSLane*>::const_iterator i = myLanes->begin(); i != myLanes->end(); ++i) { const SUMOReal vehNo = (SUMOReal)(*i)->getVehicleNumber(); v += vehNo * (*i)->getMeanSpeed(); no += vehNo; } if (no == 0) { return getSpeedLimit(); } } return v / no; }
SUMOReal GUIEdge::getFlow() const { SUMOReal flow = 0; for (MESegment* segment = MSGlobals::gMesoNet->getSegmentForEdge(*this); segment != 0; segment = segment->getNextSegment()) { flow += (SUMOReal) segment->getCarNumber() * segment->getMeanSpeed(); } return 3600 * flow / (*myLanes)[0]->getLength(); }
unsigned int GUIEdge::getVehicleNo() const { size_t vehNo = 0; for (MESegment* segment = MSGlobals::gMesoNet->getSegmentForEdge(*this); segment != 0; segment = segment->getNextSegment()) { vehNo += segment->getCarNumber(); } return (unsigned int)vehNo; }
SUMOReal GUIEdge::getMeanSpeed() const { SUMOReal v = 0; SUMOReal no = 0; for (MESegment* segment = MSGlobals::gMesoNet->getSegmentForEdge(*this); segment != 0; segment = segment->getNextSegment()) { SUMOReal vehNo = (SUMOReal) segment->getCarNumber(); v += vehNo * segment->getMeanSpeed(); no += vehNo; } if (no == 0) { return getSpeedLimit(); } return v / no; }
bool GUIEdge::setMultiColor(const GUIColorer& c) const { const int activeScheme = c.getActive(); mySegmentColors.clear(); switch (activeScheme) { case 10: // alternating segments for (MESegment* segment = MSGlobals::gMesoNet->getSegmentForEdge(*this); segment != 0; segment = segment->getNextSegment()) { mySegmentColors.push_back(c.getScheme().getColor(segment->getIndex() % 2)); } //std::cout << getID() << " scheme=" << c.getScheme().getName() << " schemeCols=" << c.getScheme().getColors().size() << " thresh=" << toString(c.getScheme().getThresholds()) << " segmentColors=" << mySegmentColors.size() << " [0]=" << mySegmentColors[0] << " [1]=" << mySegmentColors[1] << "\n"; return true; case 11: // by segment jammed state for (MESegment* segment = MSGlobals::gMesoNet->getSegmentForEdge(*this); segment != 0; segment = segment->getNextSegment()) { mySegmentColors.push_back(c.getScheme().getColor(segment->free() ? 0 : 1)); } return true; case 12: // by segment occupancy for (MESegment* segment = MSGlobals::gMesoNet->getSegmentForEdge(*this); segment != 0; segment = segment->getNextSegment()) { mySegmentColors.push_back(c.getScheme().getColor(segment->getRelativeOccupancy())); } return true; case 13: // by segment speed for (MESegment* segment = MSGlobals::gMesoNet->getSegmentForEdge(*this); segment != 0; segment = segment->getNextSegment()) { mySegmentColors.push_back(c.getScheme().getColor(segment->getMeanSpeed())); } return true; case 14: // by segment flow for (MESegment* segment = MSGlobals::gMesoNet->getSegmentForEdge(*this); segment != 0; segment = segment->getNextSegment()) { mySegmentColors.push_back(c.getScheme().getColor(3600 * segment->getCarNumber() * segment->getMeanSpeed() / segment->getLength())); } return true; case 15: // by segment relative speed for (MESegment* segment = MSGlobals::gMesoNet->getSegmentForEdge(*this); segment != 0; segment = segment->getNextSegment()) { mySegmentColors.push_back(c.getScheme().getColor(segment->getMeanSpeed() / getAllowedSpeed())); } return true; default: return false; } }
void GUIEdge::drawMesoVehicles(const GUIVisualizationSettings& s) const { const GUIVisualizationTextSettings& nameSettings = s.vehicleName; const SUMOReal exaggeration = s.vehicleSize.getExaggeration(s); GUIMEVehicleControl* vehicleControl = GUINet::getGUIInstance()->getGUIMEVehicleControl(); if (vehicleControl != 0) { // draw the meso vehicles vehicleControl->secureVehicles(); size_t laneIndex = 0; MESegment::Queue queue; for (std::vector<MSLane*>::const_iterator msl = myLanes->begin(); msl != myLanes->end(); ++msl, ++laneIndex) { GUILane* l = static_cast<GUILane*>(*msl); // go through the vehicles SUMOReal segmentOffset = 0; // offset at start of current segment for (MESegment* segment = MSGlobals::gMesoNet->getSegmentForEdge(*this); segment != 0; segment = segment->getNextSegment()) { const SUMOReal length = segment->getLength() * segment->getLengthGeometryFactor(); if (laneIndex < segment->numQueues()) { // make a copy so we don't have to worry about synchronization queue = segment->getQueue(laneIndex); const SUMOReal avgCarSize = segment->getBruttoOccupancy() / segment->getCarNumber(); const SUMOReal avgCarHalfSize = 0.5 * avgCarSize; const size_t queueSize = queue.size(); SUMOReal vehiclePosition = segmentOffset + length; // draw vehicles beginning with the leader at the end of the segment SUMOReal xOff = 0; for (size_t i = 0; i < queueSize; ++i) { MSBaseVehicle* veh = queue[queueSize - i - 1]; const SUMOReal vehLength = veh->getVehicleType().getLengthWithGap(); setVehicleColor(s, veh); while (vehiclePosition < segmentOffset) { // if there is only a single queue for a // multi-lane edge shift vehicles and start // drawing again from the end of the segment vehiclePosition += length; xOff += 2; } const Position p = l->geometryPositionAtOffset(vehiclePosition); const SUMOReal angle = -l->getShape().rotationDegreeAtOffset(l->interpolateLanePosToGeometryPos(vehiclePosition)); glPushMatrix(); glTranslated(p.x(), p.y(), 0); glRotated(angle, 0, 0, 1); glTranslated(xOff, 0, GLO_VEHICLE); glScaled(exaggeration, vehLength * exaggeration, 1); glBegin(GL_TRIANGLES); glVertex2d(0, 0); glVertex2d(0 - 1.25, 1); glVertex2d(0 + 1.25, 1); glEnd(); glPopMatrix(); if (nameSettings.show) { glPushMatrix(); glRotated(angle, 0, 0, 1); glTranslated(xOff, 0, 0); glRotated(-angle, 0, 0, 1); GLHelper::drawText(veh->getID(), l->geometryPositionAtOffset(vehiclePosition - 0.5 * vehLength), GLO_MAX, nameSettings.size / s.scale, nameSettings.color); glPopMatrix(); } vehiclePosition -= vehLength; } } segmentOffset += length; } glPopMatrix(); } vehicleControl->releaseVehicles(); } }
void MSXMLRawOut::writeEdge(OutputDevice& of, const MSEdge& edge, SUMOTime timestep) { //en bool dump = !MSGlobals::gOmitEmptyEdgesOnDump; if (!dump) { #ifdef HAVE_INTERNAL if (MSGlobals::gUseMesoSim) { MESegment* seg = MSGlobals::gMesoNet->getSegmentForEdge(edge); while (seg != 0) { if (seg->getCarNumber() != 0) { dump = true; break; } seg = seg->getNextSegment(); } } else { #endif const std::vector<MSLane*>& lanes = edge.getLanes(); for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) { if (((**lane).getVehicleNumber() != 0)) { dump = true; break; } } #ifdef HAVE_INTERNAL } #endif } //en const std::vector<MSPerson*>& persons = edge.getSortedPersons(timestep); if (dump || persons.size() > 0) { of.openTag("edge") << " id=\"" << edge.getID() << "\""; if (dump) { #ifdef HAVE_INTERNAL if (MSGlobals::gUseMesoSim) { MESegment* seg = MSGlobals::gMesoNet->getSegmentForEdge(edge); while (seg != 0) { seg->writeVehicles(of); seg = seg->getNextSegment(); } } else { #endif const std::vector<MSLane*>& lanes = edge.getLanes(); for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) { writeLane(of, **lane); } #ifdef HAVE_INTERNAL } #endif } // write persons for (std::vector<MSPerson*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) { of.openTag(SUMO_TAG_PERSON); of.writeAttr(SUMO_ATTR_ID, (*it_p)->getID()); of.writeAttr(SUMO_ATTR_POSITION, (*it_p)->getEdgePos()); of.writeAttr(SUMO_ATTR_ANGLE, (*it_p)->getAngle()); of.writeAttr("stage", (*it_p)->getCurrentStageDescription()); of.closeTag(); } of.closeTag(); } }
void GUIEdge::drawGL(const GUIVisualizationSettings& s) const { if (s.hideConnectors && myFunction == MSEdge::EDGEFUNCTION_CONNECTOR) { return; } if (MSGlobals::gUseMesoSim) { glPushName(getGlID()); } // draw the lanes for (LaneWrapperVector::const_iterator i = myLaneGeoms.begin(); i != myLaneGeoms.end(); ++i) { #ifdef HAVE_INTERNAL if (MSGlobals::gUseMesoSim) { setColor(s); } #endif (*i)->drawGL(s); } #ifdef HAVE_INTERNAL if (MSGlobals::gUseMesoSim) { const GUIVisualizationTextSettings& nameSettings = s.vehicleName; GUIMEVehicleControl* vehicleControl = GUINet::getGUIInstance()->getGUIMEVehicleControl(); if (vehicleControl != 0) { // draw the meso vehicles vehicleControl->secureVehicles(); size_t laneIndex = 0; MESegment::Queue queue; for (LaneWrapperVector::const_iterator l = myLaneGeoms.begin(); l != myLaneGeoms.end(); ++l, ++laneIndex) { const PositionVector& shape = (*l)->getShape(); const std::vector<SUMOReal>& shapeRotations = (*l)->getShapeRotations(); const std::vector<SUMOReal>& shapeLengths = (*l)->getShapeLengths(); const Position& laneBeg = shape[0]; glPushMatrix(); glTranslated(laneBeg.x(), laneBeg.y(), 0); glRotated(shapeRotations[0], 0, 0, 1); // go through the vehicles int shapeIndex = 0; SUMOReal shapeOffset = 0; // ofset at start of current shape SUMOReal segmentOffset = 0; // offset at start of current segment for (MESegment* segment = MSGlobals::gMesoNet->getSegmentForEdge(*this); segment != 0; segment = segment->getNextSegment()) { const SUMOReal length = segment->getLength(); if (laneIndex < segment->numQueues()) { // make a copy so we don't have to worry about synchronization queue = segment->getQueue(laneIndex); const SUMOReal avgCarSize = segment->getOccupancy() / segment->getCarNumber(); const size_t queueSize = queue.size(); for (size_t i = 0; i < queueSize; i++) { MSBaseVehicle* veh = queue[queueSize - i - 1]; setVehicleColor(s, veh); SUMOReal vehiclePosition = segmentOffset + length - i * avgCarSize; SUMOReal xOff = 0.f; while (vehiclePosition < segmentOffset) { // if there is only a single queue for a // multi-lane edge shift vehicles and start // drawing again from the end of the segment vehiclePosition += length; xOff += 0.5f; } while (shapeIndex < (int)shapeRotations.size() - 1 && vehiclePosition > shapeOffset + shapeLengths[shapeIndex]) { glPopMatrix(); shapeOffset += shapeLengths[shapeIndex]; shapeIndex++; glPushMatrix(); glTranslated(shape[shapeIndex].x(), shape[shapeIndex].y(), 0); glRotated(shapeRotations[shapeIndex], 0, 0, 1); } glPushMatrix(); glTranslated(xOff, -(vehiclePosition - shapeOffset), GLO_VEHICLE); glPushMatrix(); glScaled(1, avgCarSize, 1); glBegin(GL_TRIANGLES); glVertex2d(0, 0); glVertex2d(0 - 1.25, 1); glVertex2d(0 + 1.25, 1); glEnd(); glPopMatrix(); glPopMatrix(); if (nameSettings.show) { GLHelper::drawText(veh->getID(), Position(xOff, -(vehiclePosition - shapeOffset)), GLO_MAX, nameSettings.size / s.scale, nameSettings.color, 0); } } } segmentOffset += length; } glPopMatrix(); } vehicleControl->releaseVehicles(); } glPopName(); } #endif // (optionally) draw the name and/or the street name const bool drawEdgeName = s.edgeName.show && myFunction == EDGEFUNCTION_NORMAL; const bool drawInternalEdgeName = s.internalEdgeName.show && myFunction != EDGEFUNCTION_NORMAL; const bool drawStreetName = s.streetName.show && myStreetName != ""; if (drawEdgeName || drawInternalEdgeName || drawStreetName) { GUILaneWrapper* lane1 = myLaneGeoms[0]; GUILaneWrapper* lane2 = myLaneGeoms[myLaneGeoms.size() - 1]; Position p = lane1->getShape().positionAtLengthPosition(lane1->getShape().length() / (SUMOReal) 2.); p.add(lane2->getShape().positionAtLengthPosition(lane2->getShape().length() / (SUMOReal) 2.)); p.mul(.5); SUMOReal angle = lane1->getShape().rotationDegreeAtLengthPosition(lane1->getShape().length() / (SUMOReal) 2.); angle += 90; if (angle > 90 && angle < 270) { angle -= 180; } if (drawEdgeName) { drawName(p, s.scale, s.edgeName, angle); } else if (drawInternalEdgeName) { drawName(p, s.scale, s.internalEdgeName, angle); } if (drawStreetName) { GLHelper::drawText(getStreetName(), p, GLO_MAX, s.streetName.size / s.scale, s.streetName.color, angle); } } myLock.lock(); for (std::set<MSPerson*>::const_iterator i = myPersons.begin(); i != myPersons.end(); ++i) { GUIPerson* person = dynamic_cast<GUIPerson*>(*i); assert(person != 0); person->drawGL(s); } myLock.unlock(); }