SUMO - Simulation of Urban MObility
GUIVehicle.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // A MSVehicle extended by some values for usage within the gui
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <cmath>
34 #include <vector>
35 #include <string>
40 #include <utils/geom/GeomHelper.h>
47 #include <utils/gui/div/GLHelper.h>
50 #include <microsim/MSGlobals.h>
51 #include <microsim/MSVehicle.h>
52 #include <microsim/MSJunction.h>
53 #include <microsim/MSLane.h>
61 #include <gui/GUIGlobals.h>
62 #include "GUIVehicle.h"
63 #include "GUIPerson.h"
64 #include "GUIContainer.h"
65 #include "GUINet.h"
66 #include "GUIEdge.h"
67 #include "GUILane.h"
68 
69 //#define DRAW_BOUNDING_BOX
70 //#define DEBUG_FOES
71 
72 // ===========================================================================
73 // FOX callback mapping
74 // ===========================================================================
75 
76 // Object implementation
77 
78 
79 /* -------------------------------------------------------------------------
80  * GUIVehicle - methods
81  * ----------------------------------------------------------------------- */
82 #ifdef _MSC_VER
83 #pragma warning(push)
84 #pragma warning(disable: 4355)
85 #endif
87  MSVehicleType* type, const double speedFactor) :
88  MSVehicle(pars, route, type, speedFactor),
89  GUIBaseVehicle((MSBaseVehicle&) * this) {
90 }
91 #ifdef _MSC_VER
92 #pragma warning(pop)
93 #endif
94 
95 
97 }
98 
99 
103  const int sublaneParams = MSGlobals::gLateralResolution > 0 ? 4 : 0;
105  new GUIParameterTableWindow(app, *this, 37 + sublaneParams + (int)getParameter().getMap().size());
106  // add items
107  ret->mkItem("lane [id]", false, Named::getIDSecure(myLane, "n/a"));
109  const MSLane* shadowLane = getLaneChangeModel().getShadowLane();
110  ret->mkItem("shadow lane [id]", false, shadowLane == 0 ? "" : shadowLane->getID());
111  }
112  ret->mkItem("position [m]", true,
114  ret->mkItem("lateral offset [m]", true,
116  ret->mkItem("speed [m/s]", true,
118  ret->mkItem("lateral speed [m/s]", true,
120  ret->mkItem("acceleration [m/s^2]", true,
122  ret->mkItem("angle [degree]", true,
124  ret->mkItem("slope [degree]", true,
126  ret->mkItem("speed factor", false, getChosenSpeedFactor());
127  ret->mkItem("time gap on lane [s]", true,
129  ret->mkItem("waiting time [s]", true,
131  ret->mkItem(("waiting time (accumulated, " + time2string(MSGlobals::gWaitingTimeMemory) + "s) [s]").c_str(), true,
133  ret->mkItem("time loss [s]", true,
135  ret->mkItem("impatience", true,
137  ret->mkItem("last lane change [s]", true,
139  ret->mkItem("desired depart [s]", false, time2string(getParameter().depart));
140  ret->mkItem("depart delay [s]", false, time2string(getDepartDelay()));
141  if (getParameter().repetitionNumber < std::numeric_limits<int>::max()) {
142  ret->mkItem("remaining [#]", false, (int) getParameter().repetitionNumber - getParameter().repetitionsDone);
143  }
144  if (getParameter().repetitionOffset > 0) {
145  ret->mkItem("insertion period [s]", false, time2string(getParameter().repetitionOffset));
146  }
147  if (getParameter().repetitionProbability > 0) {
148  ret->mkItem("insertion probability", false, getParameter().repetitionProbability);
149  }
150  ret->mkItem("stop info", false, getStopInfo());
151  ret->mkItem("line", false, myParameter->line);
152  ret->mkItem("CO2 [mg/s]", true,
154  ret->mkItem("CO [mg/s]", true,
156  ret->mkItem("HC [mg/s]", true,
158  ret->mkItem("NOx [mg/s]", true,
160  ret->mkItem("PMx [mg/s]", true,
162  ret->mkItem("fuel [ml/s]", true,
164  ret->mkItem("electricity [Wh/s]", true,
166  ret->mkItem("noise (Harmonoise) [dB]", true,
168  std::ostringstream str;
169  for (std::vector<MSDevice*>::const_iterator i = myDevices.begin(); i != myDevices.end(); ++i) {
170  if (i != myDevices.begin()) {
171  str << ' ';
172  }
173  str << (*i)->getID().substr(0, (*i)->getID().find(getID()));
174  }
175  ret->mkItem("devices", false, str.str());
176  ret->mkItem("persons", true,
178  ret->mkItem("containers", true,
180  // close building
182  ret->mkItem("right side on edge [m]", true, new FunctionBinding<GUIVehicle, double>(this, &GUIVehicle::getRightSideOnEdge2));
183  ret->mkItem("left side on edge [m]", true, new FunctionBinding<GUIVehicle, double>(this, &GUIVehicle::getLeftSideOnEdge));
184  ret->mkItem("rightmost edge sublane [#]", true, new FunctionBinding<GUIVehicle, int>(this, &GUIVehicle::getRightSublaneOnEdge));
185  ret->mkItem("leftmost edge sublane [#]", true, new FunctionBinding<GUIVehicle, int>(this, &GUIVehicle::getLeftSublaneOnEdge));
186  }
187  ret->closeBuilding(&getParameter());
188  return ret;
189 }
190 
191 
196  new GUIParameterTableWindow(app, *this, 24 + (int)myType->getParameter().getMap().size());
197  // add items
198  ret->mkItem("Type Information:", false, "");
199  ret->mkItem("type [id]", false, myType->getID());
200  ret->mkItem("length", false, myType->getLength());
201  ret->mkItem("width", false, myType->getWidth());
202  ret->mkItem("height", false, myType->getHeight());
203  ret->mkItem("minGap", false, myType->getMinGap());
204  ret->mkItem("vehicle class", false, SumoVehicleClassStrings.getString(myType->getVehicleClass()));
205  ret->mkItem("emission class", false, PollutantsInterface::getName(myType->getEmissionClass()));
206  ret->mkItem("car follow model", false, SUMOXMLDefinitions::CarFollowModels.getString((SumoXMLTag)getCarFollowModel().getModelID()));
207  ret->mkItem("maximum speed [m/s]", false, getMaxSpeed());
208  ret->mkItem("maximum acceleration [m/s^2]", false, getCarFollowModel().getMaxAccel());
209  ret->mkItem("maximum deceleration [m/s^2]", false, getCarFollowModel().getMaxDecel());
210  ret->mkItem("emergency deceleration [m/s^2]", false, getCarFollowModel().getEmergencyDecel());
211  ret->mkItem("apparent deceleration [m/s^2]", false, getCarFollowModel().getApparentDecel());
212  ret->mkItem("imperfection (sigma)", false, getCarFollowModel().getImperfection());
213  ret->mkItem("desired headway (tau)", false, getCarFollowModel().getHeadwayTime());
214  ret->mkItem("person capacity", false, myType->getPersonCapacity());
215  ret->mkItem("boarding time", false, STEPS2TIME(myType->getBoardingDuration()));
216  ret->mkItem("container capacity", false, myType->getContainerCapacity());
217  ret->mkItem("loading time", false, STEPS2TIME(myType->getLoadingDuration()));
219  ret->mkItem("minGapLat", false, myType->getMinGapLat());
220  ret->mkItem("maxSpeedLat", false, myType->getMaxSpeedLat());
221  ret->mkItem("latAlignment", false, toString(myType->getPreferredLateralAlignment()));
222  }
223 
224  // close building
225  ret->closeBuilding(&(myType->getParameter()));
226  return ret;
227 }
228 
229 
230 
231 
232 void
234  if (myPersonDevice != 0) {
235  const std::vector<MSTransportable*>& ps = myPersonDevice->getTransportables();
236  int personIndex = 0;
237  for (std::vector<MSTransportable*>::const_iterator i = ps.begin(); i != ps.end(); ++i) {
238  GUIPerson* person = dynamic_cast<GUIPerson*>(*i);
239  assert(person != 0);
240  person->setPositionInVehicle(getSeatPosition(personIndex++));
241  person->drawGL(s);
242  }
243  }
244  if (myContainerDevice != 0) {
245  const std::vector<MSTransportable*>& cs = myContainerDevice->getTransportables();
246  int containerIndex = 0;
247  for (std::vector<MSTransportable*>::const_iterator i = cs.begin(); i != cs.end(); ++i) {
248  GUIContainer* container = dynamic_cast<GUIContainer*>(*i);
249  assert(container != 0);
250  container->setPositionInVehicle(getSeatPosition(containerIndex++));
251  container->drawGL(s);
252  }
253  }
254 #ifdef DRAW_BOUNDING_BOX
255  glPushName(getGlID());
256  glPushMatrix();
257  glTranslated(0, 0, getType());
258  PositionVector boundingBox = getBoundingBox();
259  boundingBox.push_back(boundingBox.front());
260  PositionVector smallBB = getBoundingPoly();
261  glColor3d(0, .8, 0);
262  GLHelper::drawLine(boundingBox);
263  glColor3d(0.5, .8, 0);
264  GLHelper::drawLine(smallBB);
265  //GLHelper::drawBoxLines(getBoundingBox(), 0.5);
266  glPopMatrix();
267  glPopName();
268 #endif
269 }
270 
271 
272 void
274  for (DriveItemVector::const_iterator i = myLFLinkLanes.begin(); i != myLFLinkLanes.end(); ++i) {
275  if ((*i).myLink == 0) {
276  continue;
277  }
278  MSLink* link = (*i).myLink;
279  MSLane* via = link->getViaLaneOrLane();
280  if (via != 0) {
281  Position p = via->getShape()[0];
282  if ((*i).mySetRequest) {
283  glColor3d(0, .8, 0);
284  } else {
285  glColor3d(.8, 0, 0);
286  }
287  const SUMOTime leaveTime = (*i).myLink->getLeaveTime(
288  (*i).myArrivalTime, (*i).myArrivalSpeed, (*i).getLeaveSpeed(), getVehicleType().getLength());
289  drawLinkItem(p, (*i).myArrivalTime, leaveTime, s.vehicleName.size / s.scale);
290  // the time slot that ego vehicle uses when checking opened may
291  // differ from the one it requests in setApproaching
292  MSLink::ApproachingVehicleInformation avi = (*i).myLink->getApproaching(this);
293  assert(avi.arrivalTime == (*i).myArrivalTime && avi.leavingTime == leaveTime);
294  UNUSED_PARAMETER(avi); // only used for assertion
295  }
296  }
297 }
298 
299 
300 bool
302  switch (guiShape) {
303  case SVS_BUS_FLEXIBLE:
304  drawAction_drawRailCarriages(s, 8.25, 0, 0, asImage); // 16.5 overall, 2 modules http://de.wikipedia.org/wiki/Ikarus_180
305  break;
306  case SVS_RAIL:
307  drawAction_drawRailCarriages(s, 24.5, 1, 1, asImage); // http://de.wikipedia.org/wiki/UIC-Y-Wagen_%28DR%29
308  break;
309  case SVS_RAIL_CAR:
310  drawAction_drawRailCarriages(s, 16.85, 1, 0, asImage); // 67.4m overall, 4 carriages http://de.wikipedia.org/wiki/DB-Baureihe_423
311 // drawAction_drawRailCarriages(s, 5.71, 0, 0, asImage); // 40.0m overall, 7 modules http://de.wikipedia.org/wiki/Bombardier_Flexity_Berlin
312 // drawAction_drawRailCarriages(s, 9.44, 1, 1, asImage); // actually length of the locomotive http://de.wikipedia.org/wiki/KJI_Nr._20_und_21
313 // drawAction_drawRailCarriages(s, 24.775, 0, 0, asImage); // http://de.wikipedia.org/wiki/ICE_3
314  break;
315  case SVS_RAIL_CARGO:
316  drawAction_drawRailCarriages(s, 13.86, 1, 0, asImage); // UIC 571-1 http://de.wikipedia.org/wiki/Flachwagen
317  break;
318  default:
319  return false;
320  }
321  return true;
322 }
323 
324 #define BLINKER_POS_FRONT .5
325 #define BLINKER_POS_BACK .5
326 
327 inline void
328 drawAction_drawBlinker(double dir, double length) {
329  glColor3d(1.f, .8f, 0);
330  glPushMatrix();
331  glTranslated(dir, BLINKER_POS_FRONT, -0.1);
333  glPopMatrix();
334  glPushMatrix();
335  glTranslated(dir, length - BLINKER_POS_BACK, -0.1);
337  glPopMatrix();
338 }
339 
340 
341 void
344  return;
345  }
346  const double offset = MAX2(.5 * getVehicleType().getWidth(), .4);
348  drawAction_drawBlinker(-offset, length);
349  }
351  drawAction_drawBlinker(offset, length);;
352  }
354  drawAction_drawBlinker(-offset, length);
355  drawAction_drawBlinker(offset, length);
356  }
357 }
358 
359 
360 inline void
361 GUIVehicle::drawAction_drawVehicleBrakeLight(double length, bool onlyOne) const {
363  return;
364  }
365  glColor3f(1.f, .2f, 0);
366  glPushMatrix();
367  if (onlyOne) {
368  glTranslated(0, length, -0.1);
370  } else {
371  glTranslated(-getVehicleType().getWidth() * 0.5, length, -0.1);
373  glPopMatrix();
374  glPushMatrix();
375  glTranslated(getVehicleType().getWidth() * 0.5, length, -0.1);
377  }
378  glPopMatrix();
379 }
380 
381 inline void
384  glPushMatrix();
385  glTranslated(0, 2.5, .5);
386  glColor3f(0, 0, 1);
388  glPopMatrix();
389  }
390 }
391 
392 
393 double
394 GUIVehicle::getColorValue(int activeScheme) const {
395  switch (activeScheme) {
396  case 8:
397  return getSpeed();
398  case 9:
399  return getWaitingSeconds();
400  case 10:
402  case 11:
403  return getLastLaneChangeOffset();
404  case 12:
405  return getLane()->getVehicleMaxSpeed(this);
406  case 13:
407  return getCO2Emissions();
408  case 14:
409  return getCOEmissions();
410  case 15:
411  return getPMxEmissions();
412  case 16:
413  return getNOxEmissions();
414  case 17:
415  return getHCEmissions();
416  case 18:
417  return getFuelConsumption();
418  case 19:
420  case 20:
421  if (getNumberReroutes() == 0) {
422  return -1;
423  }
424  return getNumberReroutes();
425  case 21:
427  case 22:
428  return getBestLaneOffset();
429  case 23:
430  return getAcceleration();
431  case 24:
432  return getTimeGapOnLane();
433  case 25:
434  return STEPS2TIME(getDepartDelay());
435  case 26:
436  return getElectricityConsumption();
437  case 27:
438  return getTimeLossSeconds();
439  }
440  return 0;
441 }
442 
443 
444 void
446  myLock.lock();
447  std::vector<std::vector<MSVehicle::LaneQ> > bestLanes = myBestLanes;
448  myLock.unlock();
449  for (std::vector<std::vector<MSVehicle::LaneQ> >::iterator j = bestLanes.begin(); j != bestLanes.end(); ++j) {
450  std::vector<MSVehicle::LaneQ>& lanes = *j;
451  double gmax = -1;
452  double rmax = -1;
453  for (std::vector<MSVehicle::LaneQ>::const_iterator i = lanes.begin(); i != lanes.end(); ++i) {
454  gmax = MAX2((*i).length, gmax);
455  rmax = MAX2((*i).occupation, rmax);
456  }
457  for (std::vector<MSVehicle::LaneQ>::const_iterator i = lanes.begin(); i != lanes.end(); ++i) {
458  const PositionVector& shape = (*i).lane->getShape();
459  double g = (*i).length / gmax;
460  double r = (*i).occupation / rmax;
461  glColor3d(r, g, 0);
462  double width = 0.5 / (1 + abs((*i).bestLaneOffset));
463  GLHelper::drawBoxLines(shape, width);
464 
465  PositionVector s1 = shape;
466  s1.move2side((double) .1);
467  glColor3d(r, 0, 0);
468  GLHelper::drawLine(s1);
469  s1.move2side((double) - .2);
470  glColor3d(0, g, 0);
471  GLHelper::drawLine(s1);
472 
473  glColor3d(r, g, 0);
474  }
475  }
476 }
477 
478 
479 void
480 GUIVehicle::drawRouteHelper(const MSRoute& r, double exaggeration) const {
481  MSRouteIterator i = r.begin();
482  const std::vector<MSLane*>& bestLaneConts = getBestLanesContinuation();
483  // draw continuation lanes when drawing the current route where available
484  int bestLaneIndex = (&r == myRoute ? 0 : (int)bestLaneConts.size());
485  for (; i != r.end(); ++i) {
486  const GUILane* lane;
487  if (bestLaneIndex < (int)bestLaneConts.size() && bestLaneConts[bestLaneIndex] != 0 && (*i) == &(bestLaneConts[bestLaneIndex]->getEdge())) {
488  lane = static_cast<GUILane*>(bestLaneConts[bestLaneIndex]);
489  ++bestLaneIndex;
490  } else {
491  const std::vector<MSLane*>* allowed = (*i)->allowedLanes(getVClass());
492  if (allowed != 0 && allowed->size() != 0) {
493  lane = static_cast<GUILane*>((*allowed)[0]);
494  } else {
495  lane = static_cast<GUILane*>((*i)->getLanes()[0]);
496  }
497  }
498  GLHelper::drawBoxLines(lane->getShape(), lane->getShapeRotations(), lane->getShapeLengths(), exaggeration);
499  }
500 }
501 
502 
503 
504 MSLane*
505 GUIVehicle::getPreviousLane(MSLane* current, int& furtherIndex) const {
506  if (furtherIndex < (int)myFurtherLanes.size()) {
507  return myFurtherLanes[furtherIndex++];
508  } else {
509  return current;
510  }
511 }
512 
513 
514 void
515 GUIVehicle::drawAction_drawRailCarriages(const GUIVisualizationSettings& s, double defaultLength, double carriageGap, int firstPassengerCarriage, bool asImage) const {
516  RGBColor current = GLHelper::getColor();
517  RGBColor darker = current.changedBrightness(-51);
518  const double exaggeration = s.vehicleSize.getExaggeration(s);
519  defaultLength *= exaggeration;
520  if (exaggeration == 0) {
521  return;
522  }
523  carriageGap *= exaggeration;
524  const double length = getVehicleType().getLength() * exaggeration;
525  const double halfWidth = getVehicleType().getWidth() / 2.0 * exaggeration;
526  glPopMatrix(); // undo scaling and 90 degree rotation
527  glPopMatrix(); // undo initial translation and rotation
528  GLHelper::setColor(darker);
529  const double xCornerCut = 0.3 * exaggeration;
530  const double yCornerCut = 0.4 * exaggeration;
531  // round to closest integer
532  const int numCarriages = (int)(length / (defaultLength + carriageGap) + 0.5);
533  assert(numCarriages > 0);
534  const double carriageLengthWithGap = length / numCarriages;
535  const double carriageLength = carriageLengthWithGap - carriageGap;
536  // lane on which the carriage front is situated
537  MSLane* lane = myLane;
538  int furtherIndex = 0;
539  // lane on which the carriage back is situated
540  MSLane* backLane = myLane;
541  int backFurtherIndex = furtherIndex;
542  // offsets of front and back
543  double carriageOffset = myState.pos();
544  double carriageBackOffset = myState.pos() - carriageLength;
545  // handle seats
546  int requiredSeats = getNumPassengers();
547  if (requiredSeats > 0) {
548  mySeatPositions.clear();
549  }
550  Position front, back;
551  double angle = 0.;
552  // draw individual carriages
553  for (int i = 0; i < numCarriages; ++i) {
554  while (carriageOffset < 0) {
555  MSLane* prev = getPreviousLane(lane, furtherIndex);
556  if (prev != lane) {
557  carriageOffset += prev->getLength();
558  } else {
559  // no lane available for drawing.
560  carriageOffset = 0;
561  }
562  lane = prev;
563  }
564  while (carriageBackOffset < 0) {
565  MSLane* prev = getPreviousLane(backLane, backFurtherIndex);
566  if (prev != backLane) {
567  carriageBackOffset += prev->getLength();
568  } else {
569  // no lane available for drawing.
570  carriageBackOffset = 0;
571  }
572  backLane = prev;
573  }
574  front = lane->geometryPositionAtOffset(carriageOffset);
575  back = backLane->geometryPositionAtOffset(carriageBackOffset);
576  if (front == back) {
577  // no place for drawing available
578  continue;
579  }
580  const double drawnCarriageLength = front.distanceTo2D(back);
581  angle = atan2((front.x() - back.x()), (back.y() - front.y())) * (double) 180.0 / (double) M_PI;
582  if (i >= firstPassengerCarriage) {
583  computeSeats(front, back, requiredSeats);
584  }
585  glPushMatrix();
586  glTranslated(front.x(), front.y(), getType());
587  glRotated(angle, 0, 0, 1);
588  if (!asImage || !drawAction_drawVehicleAsImage(s, carriageLength)) {
589  glBegin(GL_TRIANGLE_FAN);
590  glVertex2d(-halfWidth + xCornerCut, 0);
591  glVertex2d(-halfWidth, yCornerCut);
592  glVertex2d(-halfWidth, drawnCarriageLength - yCornerCut);
593  glVertex2d(-halfWidth + xCornerCut, drawnCarriageLength);
594  glVertex2d(halfWidth - xCornerCut, drawnCarriageLength);
595  glVertex2d(halfWidth, drawnCarriageLength - yCornerCut);
596  glVertex2d(halfWidth, yCornerCut);
597  glVertex2d(halfWidth - xCornerCut, 0);
598  glEnd();
599  }
600  glPopMatrix();
601  carriageOffset -= carriageLengthWithGap;
602  carriageBackOffset -= carriageLengthWithGap;
603  GLHelper::setColor(current);
604  }
605  // restore matrices
606  glPushMatrix();
607  glTranslated(front.x(), front.y(), getType());
608  glRotated(angle, 0, 0, 1);
609  glPushMatrix();
610 }
611 
612 
613 int
615  if (myPersonDevice != 0) {
616  return (int)myPersonDevice->size();
617  }
618  return 0;
619 }
620 
621 
622 void
623 GUIVehicle::computeSeats(const Position& front, const Position& back, int& requiredSeats) const {
624  if (requiredSeats <= 0) {
625  return; // save some work
626  }
627  const double length = front.distanceTo2D(back);
628  if (length < 4) {
629  // small vehicle, sit at the center
630  mySeatPositions.push_back(PositionVector::positionAtOffset2D(front, back, length / 2));
631  requiredSeats--;
632  } else {
633  for (double p = 2; p <= length - 1; p += 1) {
634  mySeatPositions.push_back(PositionVector::positionAtOffset2D(front, back, p));
635  requiredSeats--;
636  }
637  }
638 }
639 
640 
641 double
644 }
645 
646 
647 std::string
649  std::string result = "";
650  if (isParking()) {
651  result += "parking";
652  } else if (isStopped()) {
653  result += "stopped";
654  } else {
655  return "";
656  }
657  if (myStops.front().triggered) {
658  result += ", triggered";
659  } else if (myStops.front().containerTriggered) {
660  result += ", containerTriggered";
661  } else {
662  result += ", duration=" + time2string(myStops.front().duration);
663  }
664  return result;
665 }
666 
667 
668 void
670  double dist = myLane->getLength() - getPositionOnLane();
671  for (DriveItemVector::const_iterator i = myLFLinkLanes.begin(); i != myLFLinkLanes.end(); ++i) {
672  const DriveProcessItem& dpi = *i;
673  if (dpi.myLink == 0) {
674  continue;
675  }
676  std::vector<const SUMOVehicle*> blockingFoes;
677  std::vector<const MSPerson*> blockingPersons;
678 #ifdef DEBUG_FOES
679  const bool isOpen =
680 #endif
683 #ifdef DEBUG_FOES
684  if (!isOpen) {
685  std::cout << SIMTIME << " veh=" << getID() << " foes at link=" << dpi.myLink->getViaLaneOrLane()->getID() << ":\n";
686  for (std::vector<const SUMOVehicle*>::const_iterator it = blockingFoes.begin(); it != blockingFoes.end(); ++it) {
687  std::cout << " " << (*it)->getID() << "\n";
688  }
689  }
690 #endif
691  if (getLaneChangeModel().getShadowLane() != 0) {
692  MSLink* parallelLink = dpi.myLink->getParallelLink(getLaneChangeModel().getShadowDirection());
693  if (parallelLink != 0) {
694  const double shadowLatPos = getLateralPositionOnLane() - getLaneChangeModel().getShadowDirection() * 0.5 * (
696 #ifdef DEBUG_FOES
697  const bool isShadowOpen =
698 #endif
699  parallelLink->opened(dpi.myArrivalTime, dpi.myArrivalSpeed, dpi.getLeaveSpeed(),
702  getWaitingTime(), shadowLatPos, &blockingFoes);
703 #ifdef DEBUG_FOES
704  if (!isShadowOpen) {
705  std::cout << SIMTIME << " veh=" << getID() << " foes at shadow link=" << parallelLink->getViaLaneOrLane()->getID() << ":\n";
706  for (std::vector<const SUMOVehicle*>::const_iterator it = blockingFoes.begin(); it != blockingFoes.end(); ++it) {
707  std::cout << " " << (*it)->getID() << "\n";
708  }
709  }
710 #endif
711  }
712  }
713  for (std::vector<const SUMOVehicle*>::const_iterator it = blockingFoes.begin(); it != blockingFoes.end(); ++it) {
714  gSelected.select(static_cast<const GUIVehicle*>(*it)->getGlID());
715  }
716  const MSLink::LinkLeaders linkLeaders = (dpi.myLink)->getLeaderInfo(this, dist, &blockingPersons);
717  for (MSLink::LinkLeaders::const_iterator it = linkLeaders.begin(); it != linkLeaders.end(); ++it) {
718  // the vehicle to enter the junction first has priority
719  const GUIVehicle* leader = dynamic_cast<const GUIVehicle*>(it->vehAndGap.first);
720  if (leader != 0) {
721  if (dpi.myLink->isLeader(this, leader)) {
722  gSelected.select(leader->getGlID());
723 #ifdef DEBUG_FOES
724  std::cout << SIMTIME << " veh=" << getID() << " linkLeader at link=" << dpi.myLink->getViaLaneOrLane()->getID() << " foe=" << leader->getID() << "\n";
725 #endif
726  }
727  } else {
728  for (std::vector<const MSPerson*>::iterator it_p = blockingPersons.begin(); it_p != blockingPersons.end(); ++it_p) {
729  const GUIPerson* foe = dynamic_cast<const GUIPerson*>(*it_p);
730  if (foe != 0) {
731  gSelected.select(foe->getGlID());
732  //std::cout << SIMTIME << " veh=" << getID() << " is blocked on link " << dpi.myLink->getRespondIndex() << " to " << dpi.myLink->getViaLaneOrLane()->getID() << " by pedestrian. dist=" << it->second << "\n";
733  }
734  }
735  }
736  }
737  dist += dpi.myLink->getViaLaneOrLane()->getLength();
738  }
739 }
740 
741 
742 void
745  GUISUMOAbstractView* view = mw->getActiveView();
746  if (view != 0) {
747  if (add) {
750  view->addAdditionalGLVisualisation(this);
751  }
752  } else {
755  }
756  }
757 }
758 
759 bool
762 }
763 
764 int
766  const double rightSide = getRightSideOnEdge();
767  const std::vector<double>& sublaneSides = myLane->getEdge().getSubLaneSides();
768  for (int i = 0; i < (int)sublaneSides.size(); ++i) {
769  if (sublaneSides[i] > rightSide) {
770  return MAX2(i - 1, 0);
771  }
772  }
773  return -1;
774 }
775 
776 int
778  const double leftSide = getLeftSideOnEdge();
779  const std::vector<double>& sublaneSides = myLane->getEdge().getSubLaneSides();
780  for (int i = (int)sublaneSides.size() - 1; i >= 0; --i) {
781  if (sublaneSides[i] < leftSide) {
782  return i;
783  }
784  }
785  return -1;
786 }
787 
788 /****************************************************************************/
789 
SUMOTime getBoardingDuration() const
Get this vehicle type&#39;s boarding duration.
std::map< GUISUMOAbstractView *, int > myAdditionalVisualizations
Enabled visualisations, per view.
bool signalSet(int which) const
Returns whether the given signal is on.
Definition: MSVehicle.h:1156
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Definition: GUIVehicle.cpp:101
const std::vector< double > & getShapeRotations() const
Definition: GUILane.cpp:829
double getMinGap() const
Get the free space in front of vehicles of this class.
static double gLateralResolution
Definition: MSGlobals.h:92
void selectBlockingFoes() const
adds the blocking foes to the current selection
Definition: GUIVehicle.cpp:669
static StringBijection< SumoXMLTag > CarFollowModels
car following models
SumoXMLTag
Numbers representing SUMO-XML - element names.
render as a rail
MSEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: MSLane.h:582
bool drawAction_drawCarriageClass(const GUIVisualizationSettings &s, SUMOVehicleShape guiShape, bool asImage) const
draws the given guiShape if it has distinct carriages/modules and returns true if so ...
Definition: GUIVehicle.cpp:301
double getWidth() const
Returns the lane&#39;s width.
Definition: MSLane.h:500
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
double scale
information about a lane&#39;s width (temporary, used for a single view)
SUMOVehicleClass getVehicleClass() const
Get this vehicle type&#39;s vehicle class.
bool drawAction_drawVehicleAsImage(const GUIVisualizationSettings &s, double length=-1) const
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:250
double getMaxSpeed() const
Returns the maximum speed.
static void drawBoxLines(const PositionVector &geom, const std::vector< double > &rots, const std::vector< double > &lengths, double width, int cornerDetail=0, double offset=0)
Draws thick lines.
Definition: GLHelper.cpp:172
int getRightSublaneOnEdge() const
return the righmost sublane on the edge occupied by the vehicle
Definition: GUIVehicle.cpp:765
std::vector< std::vector< LaneQ > > myBestLanes
Definition: MSVehicle.h:1550
const MSCFModel & getCarFollowModel() const
Returns the vehicle&#39;s car following model definition.
Definition: MSVehicle.h:796
std::vector< MSLane * > myFurtherLanes
The information into which lanes the vehicle laps into.
Definition: MSVehicle.h:1573
double getTimeLossSeconds() const
Returns the time loss in seconds.
Definition: MSVehicle.h:597
State myState
This Vehicles driving state (pos and speed)
Definition: MSVehicle.h:1535
a vehicles
DriveItemVector myLFLinkLanes
Definition: MSVehicle.h:1656
SUMOTime getLoadingDuration() const
Get this vehicle type&#39;s loading duration.
MFXMutex myLock
The mutex used to avoid concurrent updates of the vehicle buffer.
SUMOVehicleClass getVClass() const
Returns the vehicle&#39;s access class.
double getTimeGapOnLane() const
Returns the time gap in seconds to the leader of the vehicle on the same lane.
Definition: MSVehicle.cpp:3603
void drawBestLanes() const
Draws the vehicle&#39;s best lanes.
Definition: GUIVehicle.cpp:445
SUMOTime getWaitingTime() const
Returns the SUMOTime waited (speed was lesser than 0.1m/s)
Definition: MSVehicle.h:547
double x() const
Returns the x-position.
Definition: Position.h:63
Stores the information about how to visualize structures.
double getChosenSpeedFactor() const
Returns the precomputed factor by which the driver wants to be faster than the speed limit...
double getSpeedLat() const
return the lateral speed of the current lane change maneuver
void select(GUIGlID id, bool update=true)
Adds the object with the given id.
render as a flexible city bus
double getNaviDegree() const
return the current angle in navigational degrees
const Position & getSeatPosition(int personIndex) const
returns the seat position for the person with the given index
void drawAction_drawPersonsAndContainers(const GUIVisualizationSettings &s) const
Definition: GUIVehicle.cpp:233
int getShadowDirection() const
return the direction in which the current shadow lane lies
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:60
GUIVisualizationTextSettings vehicleName
MSDevice_Transportable * myPersonDevice
The passengers this vehicle may have.
Definition: MSVehicle.h:1564
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition: MSLane.h:448
double getCO2Emissions() const
Returns CO2 emission of the current state.
Definition: MSVehicle.cpp:3614
int getNumberReroutes() const
Returns the number of new routes this vehicle got.
double getRightSideOnEdge2() const
return right vehicle side on current edge (without argument)
Definition: GUIVehicle.h:143
double getLength() const
Returns the lane&#39;s length.
Definition: MSLane.h:484
T MAX2(T a, T b)
Definition: StdDefs.h:74
double getAcceleration() const
Returns the vehicle&#39;s acceleration in m/s (this is computed as the last step&#39;s mean acceleration in c...
Definition: MSVehicle.h:460
void drawOutsideNetwork(bool add)
register vehicle for drawing while outside the network
Definition: GUIVehicle.cpp:743
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
const MSRoute * myRoute
This vehicle&#39;s route.
static std::string getIDSecure(const T *obj, const std::string &fallBack="NULL")
get an identifier for Named-like object which may be Null
Definition: Named.h:59
bool isSelected() const
whether this vehicle is selected in the GUI
Definition: GUIVehicle.cpp:760
double getHCEmissions() const
Returns HC emission of the current state.
Definition: MSVehicle.cpp:3626
double getPositionOnLane() const
Get the vehicle&#39;s position along the lane.
Definition: MSVehicle.h:375
bool addAdditionalGLVisualisation(const GUIGlObject *const which)
Adds an object to call its additional visualisation method.
const std::map< std::string, std::string > & getMap() const
Returns the inner key/value map.
static void drawLinkItem(const Position &pos, SUMOTime arrivalTime, SUMOTime leaveTime, double exagerate)
const SUMOVehicleParameter * myParameter
This vehicle&#39;s parameter.
LateralAlignment getPreferredLateralAlignment() const
Get vehicle&#39;s preferred lateral alignment.
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:56
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:339
GUIGlID getGlID() const
Returns the numerical id of the object.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:40
#define abs(a)
Definition: polyfonts.c:67
bool removeAdditionalGLVisualisation(const GUIGlObject *const which)
Removes an object from the list of objects that show additional things.
The car-following model and parameter.
Definition: MSVehicleType.h:73
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:3144
void drawRouteHelper(const MSRoute &r, double exaggeration) const
Draws the route.
Definition: GUIVehicle.cpp:480
#define SIMTIME
Definition: SUMOTime.h:70
int getPersonCapacity() const
Get this vehicle type&#39;s person capacity.
std::string getStopInfo() const
retrieve information about the current stop state
Definition: GUIVehicle.cpp:648
Right blinker lights are switched on.
Definition: MSVehicle.h:1078
PositionVector mySeatPositions
positions of seats in the vehicle (updated at every drawing step)
double getSlope() const
Returns the slope of the road at vehicle&#39;s position.
Definition: MSVehicle.cpp:795
const std::vector< double > & getShapeLengths() const
Definition: GUILane.cpp:835
Representation of a lane in the micro simulation (gui-version)
Definition: GUILane.h:70
const std::vector< double > getSubLaneSides() const
Returns the right side offsets of this edge&#39;s sublanes.
Definition: MSEdge.h:553
double getImpatience() const
Returns this vehicles impatience.
int getContainerNumber() const
Returns the number of containers.
Definition: MSVehicle.cpp:3740
const std::string & getID() const
Returns the id.
Definition: Named.h:66
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
double getElectricityConsumption() const
Returns electricity consumption of the current state.
Definition: MSVehicle.cpp:3650
double getLeaveSpeed() const
Definition: MSVehicle.h:1649
Left blinker lights are switched on.
Definition: MSVehicle.h:1080
#define max(a, b)
Definition: polyfonts.c:65
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
GUISUMOAbstractView * getActiveView() const
get the active view or 0
const SUMOVTypeParameter & getParameter() const
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:438
PositionVector getBoundingBox() const
get bounding rectangle
Definition: MSVehicle.cpp:3982
double getColorValue(int activeScheme) const
gets the color value according to the current scheme index
Definition: GUIVehicle.cpp:394
double getHeight() const
Get the height which vehicles of this class shall have when being drawn.
double getMaxDecel() const
Get the vehicle type&#39;s maximal comfortable deceleration [m/s^2].
Definition: MSCFModel.h:212
const std::vector< MSLane * > & getBestLanesContinuation() const
Returns the best sequence of lanes to continue the route starting at myLane.
Definition: MSVehicle.cpp:3502
static GUIMainWindow * getInstance()
SUMOTime getDepartDelay() const
Returns the depart delay.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
GUIVehicle(SUMOVehicleParameter *pars, const MSRoute *route, MSVehicleType *type, const double speedFactor)
Constructor.
Definition: GUIVehicle.cpp:86
A list of positions.
int size() const
Returns the number of edges to pass.
Definition: MSRoute.cpp:86
std::list< Stop > myStops
The vehicle&#39;s list of stops.
Definition: MSVehicle.h:1561
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:65
double y() const
Returns the y-position.
Definition: Position.h:68
MSLane * getPreviousLane(MSLane *current, int &furtherIndex) const
Definition: GUIVehicle.cpp:505
PositionVector getBoundingPoly() const
get bounding polygon
Definition: MSVehicle.cpp:3995
const std::vector< MSTransportable * > & getTransportables() const
Returns the list of transportables using this vehicle.
bool isStopped() const
Returns whether the vehicle is at a stop.
Definition: MSVehicle.cpp:1240
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
MSLane * myLane
The lane the vehicle is on.
Definition: MSVehicle.h:1538
Blinker lights on both sides are switched on.
Definition: MSVehicle.h:1082
void drawAction_drawRailCarriages(const GUIVisualizationSettings &s, double defaultLength, double carriageGap, int firstPassengerCarriage, bool asImage) const
Definition: GUIVehicle.cpp:515
double length() const
Returns the length.
~GUIVehicle()
destructor
Definition: GUIVehicle.cpp:96
double getPMxEmissions() const
Returns PMx emission of the current state.
Definition: MSVehicle.cpp:3638
void setPositionInVehicle(const Position &pos)
Definition: GUIPerson.h:126
render as a (city) rail without locomotive
double getLastLaneChangeOffset() const
Returns the time since the last lane change in seconds.
Definition: GUIVehicle.cpp:642
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:157
A MSVehicle extended by some values for usage within the gui.
The brake lights are on.
Definition: MSVehicle.h:1084
A blue emergency light is on.
Definition: MSVehicle.h:1100
Position positionAtOffset2D(double pos, double lateralOffset=0) const
Returns the position at the given length.
int getNumPassengers() const
return the number of passengers
Definition: GUIVehicle.cpp:614
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
#define BLINKER_POS_BACK
Definition: GUIVehicle.cpp:325
MSLane * getShadowLane() const
Returns the lane the vehicles shadow is on during continuous/sublane lane change. ...
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
static void drawLine(const Position &beg, double rot, double visLength)
Draws a thin line.
Definition: GLHelper.cpp:265
double getWidth() const
Get the width which vehicles of this class shall have when being drawn.
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MSVehicle.h:581
void drawAction_drawVehicleBlinker(double length) const
Definition: GUIVehicle.cpp:342
bool isParking() const
Returns whether the vehicle is parking.
Definition: MSVehicle.cpp:1266
void move2side(double amount)
move position vector to side using certain ammount
int getPersonNumber() const
Returns the number of persons.
Definition: MSVehicle.cpp:3734
GUIParameterTableWindow * getTypeParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own type parameter window.
Definition: GUIVehicle.cpp:193
double getNOxEmissions() const
Returns NOx emission of the current state.
Definition: MSVehicle.cpp:3632
std::string line
The vehicle&#39;s line (mainly for public transport)
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GUIPerson.cpp:259
void setPositionInVehicle(const Position &pos)
Definition: GUIContainer.h:118
render as a cargo train
void computeSeats(const Position &front, const Position &back, int &requiredSeats) const
add seats to mySeatPositions and update requiredSeats
Definition: GUIVehicle.cpp:623
void unlock()
release mutex lock
Definition: MFXMutex.cpp:94
double getMinGapLat() const
Get the minimum lateral gap that vehicles of this type maintain.
double getLength() const
Get vehicle&#39;s length [m].
Structure representing possible vehicle parameter.
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:80
draw vehicle outside the road network
SUMOVehicleShape
Definition of vehicle classes to differ between different appearences.
#define M_PI
Definition: odrSpiral.cpp:40
int getLeftSublaneOnEdge() const
Definition: GUIVehicle.cpp:777
MSVehicleType * myType
This vehicle&#39;s type.
void drawAction_drawLinkItems(const GUIVisualizationSettings &s) const
Definition: GUIVehicle.cpp:273
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type definition.
double getLeftSideOnEdge() const
return left vehicle side on current edge
Definition: GUIVehicle.h:147
const std::string & getID() const
Returns the name of the vehicle type.
double getLateralPositionOnLane() const
Get the vehicle&#39;s lateral position on the lane.
Definition: MSVehicle.h:407
double getVehicleMaxSpeed(const SUMOVehicle *const veh) const
Returns the lane&#39;s maximum speed, given a vehicle&#39;s speed limit adaptation.
Definition: MSLane.h:462
const SUMOVehicleParameter & getParameter() const
Returns the vehicle&#39;s parameter (including departure definition)
void lock()
lock mutex
Definition: MFXMutex.cpp:84
double getAccumulatedWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s) within the last millisecs...
Definition: MSVehicle.h:591
static SUMOTime gWaitingTimeMemory
length of memory for waiting times (in millisecs)
Definition: MSGlobals.h:116
double pos() const
Position of this state.
Definition: MSVehicle.h:113
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:426
#define BLINKER_POS_FRONT
Definition: GUIVehicle.cpp:324
double getFuelConsumption() const
Returns fuel consumption of the current state.
Definition: MSVehicle.cpp:3644
double getCOEmissions() const
Returns CO emission of the current state.
Definition: MSVehicle.cpp:3620
double getRightSideOnEdge(const MSLane *lane=0) const
Get the vehicle&#39;s lateral position on the edge of the given lane (or its current edge if lane == 0) ...
Definition: MSVehicle.cpp:3824
GUIVisualizationSizeSettings vehicleSize
void drawAction_drawVehicleBrakeLight(double length, bool onlyOne=1) const
Definition: GUIVehicle.cpp:361
void drawAction_drawBlinker(double dir, double length)
Definition: GUIVehicle.cpp:328
long long int SUMOTime
Definition: TraCIDefs.h:52
int getContainerCapacity() const
Get this vehicle type&#39;s container capacity.
double getHarmonoise_NoiseEmissions() const
Returns noise emissions of the current state.
Definition: MSVehicle.cpp:3656
SUMOEmissionClass getEmissionClass() const
Get this vehicle type&#39;s emission class.
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:499
static SUMOTime gLaneChangeDuration
Definition: MSGlobals.h:89
void mkItem(const char *name, bool dynamic, ValueSource< unsigned > *src)
Adds a row which obtains its value from an unsigned-ValueSource.
GUISelectedStorage gSelected
A global holder of selected objects.
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
double getMaxSpeedLat() const
Get vehicle&#39;s maximum lateral speed [m/s].
std::vector< MSDevice * > myDevices
The devices this vehicle has.
A window containing a gl-object&#39;s parameter.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void drawAction_drawVehicleBlueLight() const
Definition: GUIVehicle.cpp:382
int getBestLaneOffset() const
Definition: MSVehicle.cpp:3531
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:74
MSDevice_Transportable * myContainerDevice
The containers this vehicle may have.
Definition: MSVehicle.h:1567
double getWidth() const
Returns the vehicle&#39;s width.
const std::string & getID() const
Returns the name of the vehicle.
int size() const
Return the number of passengers / containers.
const PositionVector & getShape() const
Definition: GUILane.cpp:823
double getSpeed() const
Returns the vehicle&#39;s current speed.
Definition: MSVehicle.h:443
static RGBColor getColor()
gets the gl-color
Definition: GLHelper.cpp:444
A MSVehicle extended by some values for usage within the gui.
Definition: GUIVehicle.h:61