SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-sim.org/
12 // Copyright (C) 2001-2013 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>
36 #ifdef HAVE_OSG
37 #include <osg/ShapeDrawable>
38 #include <osgview/GUIOSGView.h>
39 #endif
49 #include <utils/gui/div/GLHelper.h>
52 #include <microsim/MSVehicle.h>
53 #include <microsim/MSLane.h>
61 #include <gui/GUIGlobals.h>
62 #include "GUIVehicle.h"
63 #include "GUIPerson.h"
64 #include "GUINet.h"
65 #include "GUIEdge.h"
66 #include "GUILane.h"
67 
68 #ifdef CHECK_MEMORY_LEAKS
69 #include <foreign/nvwa/debug_new.h>
70 #endif // CHECK_MEMORY_LEAKS
71 
72 
73 // ===========================================================================
74 // FOX callback mapping
75 // ===========================================================================
76 FXDEFMAP(GUIVehicle::GUIVehiclePopupMenu) GUIVehiclePopupMenuMap[] = {
88 };
89 
90 // Object implementation
91 FXIMPLEMENT(GUIVehicle::GUIVehiclePopupMenu, GUIGLObjectPopupMenu, GUIVehiclePopupMenuMap, ARRAYNUMBER(GUIVehiclePopupMenuMap))
92 
93 
94 
95 // ===========================================================================
96 // data definitions
97 // ===========================================================================
98 /* -------------------------------------------------------------------------
99  * drawed shapes
100  * ----------------------------------------------------------------------- */
101 double vehiclePoly_PassengerCarBody[] = { .5, 0, 0, 0, 0, .3, 0.08, .44, 0.25, .5, 0.95, .5, 1., .4, 1., -.4, 0.95, -.5, 0.25, -.5, 0.08, -.44, 0, -.3, 0, 0, -10000 };
102 double vehiclePoly_PassengerCarBodyFront[] = { 0.1, 0, 0.025, 0, 0.025, 0.25, 0.27, 0.4, 0.27, -.4, 0.025, -0.25, 0.025, 0, -10000 };
103 double vehiclePoly_PassengerFrontGlass[] = { 0.35, 0, 0.3, 0, 0.3, 0.4, 0.43, 0.3, 0.43, -0.3, 0.3, -0.4, 0.3, 0, -10000 };
104 double vehiclePoly_PassengerSedanRightGlass[] = { 0.36, -.43, 0.34, -.47, 0.77, -.47, 0.67, -.37, 0.45, -.37, 0.34, -.47, -10000 };
105 double vehiclePoly_PassengerSedanLeftGlass[] = { 0.36, .43, 0.34, .47, 0.77, .47, 0.67, .37, 0.45, .37, 0.34, .47, -10000 };
106 double vehiclePoly_PassengerSedanBackGlass[] = { 0.80, 0, 0.70, 0, 0.70, 0.3, 0.83, 0.4, 0.83, -.4, 0.70, -.3, 0.70, 0, -10000 };
107 double vehiclePoly_PassengerHatchbackRightGlass[] = { 0.36, -.43, 0.34, -.47, 0.94, -.47, 0.80, -.37, 0.45, -.37, 0.34, -.47, -10000 };
108 double vehiclePoly_PassengerHatchbackLeftGlass[] = { 0.36, .43, 0.34, .47, 0.94, .47, 0.80, .37, 0.45, .37, 0.34, .47, -10000 };
109 double vehiclePoly_PassengerHatchbackBackGlass[] = { 0.92, 0, 0.80, 0, 0.80, 0.3, 0.95, 0.4, 0.95, -.4, 0.80, -.3, 0.80, 0, -10000 };
110 double vehiclePoly_PassengerWagonRightGlass[] = { 0.36, -.43, 0.34, -.47, 0.94, -.47, 0.87, -.37, 0.45, -.37, 0.34, -.47, -10000 };
111 double vehiclePoly_PassengerWagonLeftGlass[] = { 0.36, .43, 0.34, .47, 0.94, .47, 0.87, .37, 0.45, .37, 0.34, .47, -10000 };
112 double vehiclePoly_PassengerWagonBackGlass[] = { 0.92, 0, 0.90, 0, 0.90, 0.3, 0.95, 0.4, 0.95, -.4, 0.90, -.3, 0.90, 0, -10000 };
113 
114 double vehiclePoly_PassengerVanBody[] = { .5, 0, 0, 0, 0, .4, 0.1, .5, 0.97, .5, 1., .47, 1., -.47, 0.97, -.5, 0.1, -.5, 0, -.4, 0, 0, -10000 };
115 double vehiclePoly_PassengerVanBodyFront[] = { 0.1, 0, 0.025, 0, 0.025, 0.25, 0.13, 0.4, 0.13, -.4, 0.025, -0.25, 0.025, 0, -10000 };
116 double vehiclePoly_PassengerVanFrontGlass[] = { 0.21, 0, 0.16, 0, 0.16, 0.4, 0.29, 0.3, 0.29, -0.3, 0.16, -0.4, 0.16, 0, -10000 };
117 double vehiclePoly_PassengerVanRightGlass[] = { 0.36, -.43, 0.20, -.47, 0.98, -.47, 0.91, -.37, 0.31, -.37, 0.20, -.47, -10000 };
118 double vehiclePoly_PassengerVanLeftGlass[] = { 0.36, .43, 0.20, .47, 0.98, .47, 0.91, .37, 0.31, .37, 0.20, .47, -10000 };
119 double vehiclePoly_PassengerVanBackGlass[] = { 0.95, 0, 0.94, 0, 0.94, 0.3, 0.98, 0.4, 0.98, -.4, 0.94, -.3, 0.94, 0, -10000 };
120 
121 double vehiclePoly_DeliveryMediumRightGlass[] = { 0.21, -.43, 0.20, -.47, 0.38, -.47, 0.38, -.37, 0.31, -.37, 0.20, -.47, -10000 };
122 double vehiclePoly_DeliveryMediumLeftGlass[] = { 0.21, .43, 0.20, .47, 0.38, .47, 0.38, .37, 0.31, .37, 0.20, .47, -10000 };
123 
124 double vehiclePoly_TransportBody[] = { .5, 0, 0, 0, 0, .45, 0.05, .5, 2.25, .5, 2.25, -.5, 0.05, -.5, 0, -.45, 0, 0, -10000 };
125 double vehiclePoly_TransportFrontGlass[] = { 0.1, 0, 0.05, 0, 0.05, 0.45, 0.25, 0.4, 0.25, -.4, 0.05, -0.45, 0.05, 0, -10000 };
126 double vehiclePoly_TransportRightGlass[] = { 0.36, -.47, 0.10, -.48, 1.25, -.48, 1.25, -.4, 0.3, -.4, 0.10, -.48, -10000 };
127 double vehiclePoly_TransportLeftGlass[] = { 0.36, .47, 0.10, .48, 1.25, .48, 1.25, .4, 0.3, .4, 0.10, .48, -10000 };
128 
129 double vehiclePoly_EVehicleBody[] = { .5, 0, 0, 0, 0, .3, 0.08, .44, 0.25, .5, 0.75, .5, .92, .44, 1, .3, 1, -.3, .92, -.44, .75, -.5, .25, -.5, 0.08, -.44, 0, -.3, 0, 0, -1000 };
130 double vehiclePoly_EVehicleFrontGlass[] = { .5, 0, 0.05, .05, 0.05, .25, 0.13, .39, 0.3, .45, 0.70, .45, .87, .39, .95, .25, .95, -.25, .87, -.39, .70, -.45, .3, -.45, 0.13, -.39, 0.05, -.25, 0.05, 0.05, -1000 };
131 //double vehiclePoly_EVehicleFrontGlass[] = { 0.35,0, 0.1,0, 0.1,0.4, 0.43,0.3, 0.43,-0.3, 0.1,-0.4, 0.1,0, -10000 };
132 double vehiclePoly_EVehicleBackGlass[] = { 0.65, 0, 0.9, 0, 0.9, 0.4, 0.57, 0.3, 0.57, -0.3, 0.9, -0.4, 0.9, 0, -10000 };
133 
134 
135 // ===========================================================================
136 // method definitions
137 // ===========================================================================
138 /* -------------------------------------------------------------------------
139  * GUIVehicle::GUIVehiclePopupMenu - methods
140  * ----------------------------------------------------------------------- */
142  GUIMainWindow& app, GUISUMOAbstractView& parent,
143  GUIGlObject& o, std::map<GUISUMOAbstractView*, int>& additionalVisualizations)
144  : GUIGLObjectPopupMenu(app, parent, o), myVehiclesAdditionalVisualizations(additionalVisualizations) {
145 }
146 
147 
149 
150 
151 long
153  assert(myObject->getType() == GLO_VEHICLE);
154  if (!static_cast<GUIVehicle*>(myObject)->hasActiveAddVisualisation(myParent, VO_SHOW_ALL_ROUTES)) {
155  static_cast<GUIVehicle*>(myObject)->addActiveAddVisualisation(myParent, VO_SHOW_ALL_ROUTES);
156  }
157  return 1;
158 }
159 
160 long
162  assert(myObject->getType() == GLO_VEHICLE);
163  static_cast<GUIVehicle*>(myObject)->removeActiveAddVisualisation(myParent, VO_SHOW_ALL_ROUTES);
164  return 1;
165 }
166 
167 
168 long
170  assert(myObject->getType() == GLO_VEHICLE);
171  if (!static_cast<GUIVehicle*>(myObject)->hasActiveAddVisualisation(myParent, VO_SHOW_ROUTE)) {
172  static_cast<GUIVehicle*>(myObject)->addActiveAddVisualisation(myParent, VO_SHOW_ROUTE);
173  }
174  return 1;
175 }
176 
177 long
179  assert(myObject->getType() == GLO_VEHICLE);
180  static_cast<GUIVehicle*>(myObject)->removeActiveAddVisualisation(myParent, VO_SHOW_ROUTE);
181  return 1;
182 }
183 
184 
185 long
187  assert(myObject->getType() == GLO_VEHICLE);
188  if (!static_cast<GUIVehicle*>(myObject)->hasActiveAddVisualisation(myParent, VO_SHOW_BEST_LANES)) {
189  static_cast<GUIVehicle*>(myObject)->addActiveAddVisualisation(myParent, VO_SHOW_BEST_LANES);
190  }
191  return 1;
192 }
193 
194 long
196  assert(myObject->getType() == GLO_VEHICLE);
197  static_cast<GUIVehicle*>(myObject)->removeActiveAddVisualisation(myParent, VO_SHOW_BEST_LANES);
198  return 1;
199 }
200 
201 
202 long
204  assert(myObject->getType() == GLO_VEHICLE);
205  if (!static_cast<GUIVehicle*>(myObject)->hasActiveAddVisualisation(myParent, VO_TRACKED)) {
206  myParent->startTrack(static_cast<GUIVehicle*>(myObject)->getGlID());
207  static_cast<GUIVehicle*>(myObject)->addActiveAddVisualisation(myParent, VO_TRACKED);
208  }
209  return 1;
210 }
211 
212 long
214  assert(myObject->getType() == GLO_VEHICLE);
215  static_cast<GUIVehicle*>(myObject)->removeActiveAddVisualisation(myParent, VO_TRACKED);
216  myParent->stopTrack();
217  return 1;
218 }
219 
220 
221 long
223  assert(myObject->getType() == GLO_VEHICLE);
224  if (!static_cast<GUIVehicle*>(myObject)->hasActiveAddVisualisation(myParent, VO_SHOW_LFLINKITEMS)) {
225  static_cast<GUIVehicle*>(myObject)->addActiveAddVisualisation(myParent, VO_SHOW_LFLINKITEMS);
226  }
227  return 1;
228 }
229 
230 long
232  assert(myObject->getType() == GLO_VEHICLE);
233  static_cast<GUIVehicle*>(myObject)->removeActiveAddVisualisation(myParent, VO_SHOW_LFLINKITEMS);
234  return 1;
235 }
236 
237 long
239  assert(myObject->getType() == GLO_VEHICLE);
240  static_cast<GUIVehicle*>(myObject)->selectBlockingFoes();
241  return 1;
242 }
243 
244 
245 /* -------------------------------------------------------------------------
246  * GUIVehicle - methods
247  * ----------------------------------------------------------------------- */
249  const MSVehicleType* type,
250  SUMOReal speedFactor) :
251  MSVehicle(pars, route, type, speedFactor),
252  GUIGlObject(GLO_VEHICLE, pars->id) {
253  // as it is possible to show all vehicle routes, we have to store them... (bug [ 2519761 ])
255  myMoveReminders.push_back(std::make_pair(myRoutes, 0.));
256  mySeatPositions.push_back(Position(0, 0)); // ensure length 1
257 }
258 
259 
261  myLock.lock();
262  for (std::map<GUISUMOAbstractView*, int>::iterator i = myAdditionalVisualizations.begin(); i != myAdditionalVisualizations.end(); ++i) {
263  while (i->first->removeAdditionalGLVisualisation(this));
264  }
265 #ifdef HAVE_OSG
266  for (std::map<GUIOSGView*, osg::ShapeDrawable*>::iterator i = myGeom.begin(); i != myGeom.end(); ++i) {
267  i->first->remove(this);
268  }
269 #endif
270  myLock.unlock();
272  delete myRoutes;
273 }
274 
275 
278  GUISUMOAbstractView& parent) {
280  buildPopupHeader(ret, app);
284  //
286  new FXMenuCommand(ret, "Hide Current Route", 0, ret, MID_HIDE_CURRENTROUTE);
287  } else {
288  new FXMenuCommand(ret, "Show Current Route", 0, ret, MID_SHOW_CURRENTROUTE);
289  }
291  new FXMenuCommand(ret, "Hide All Routes", 0, ret, MID_HIDE_ALLROUTES);
292  } else {
293  new FXMenuCommand(ret, "Show All Routes", 0, ret, MID_SHOW_ALLROUTES);
294  }
296  new FXMenuCommand(ret, "Hide Best Lanes", 0, ret, MID_HIDE_BEST_LANES);
297  } else {
298  new FXMenuCommand(ret, "Show Best Lanes", 0, ret, MID_SHOW_BEST_LANES);
299  }
301  new FXMenuCommand(ret, "Hide Link Items", 0, ret, MID_HIDE_LFLINKITEMS);
302  } else {
303  new FXMenuCommand(ret, "Show Link Items", 0, ret, MID_SHOW_LFLINKITEMS);
304  }
305  new FXMenuSeparator(ret);
306  int trackedID = parent.getTrackedID();
307  if (trackedID < 0 || (size_t)trackedID != getGlID()) {
308  new FXMenuCommand(ret, "Start Tracking", 0, ret, MID_START_TRACK);
309  } else {
310  new FXMenuCommand(ret, "Stop Tracking", 0, ret, MID_STOP_TRACK);
311  }
312  new FXMenuCommand(ret, "Select Foes", 0, ret, MID_SHOW_FOES);
313 
314  new FXMenuSeparator(ret);
315  //
317  buildPositionCopyEntry(ret, false);
318  return ret;
319 }
320 
321 
326  new GUIParameterTableWindow(app, *this, 33);
327  // add items
328  ret->mkItem("lane [id]", false, myLane->getID());
329  ret->mkItem("position [m]", true,
331  ret->mkItem("speed [m/s]", true,
333  ret->mkItem("angle [degree]", true,
335  if (getChosenSpeedFactor() != 1) {
336  ret->mkItem("speed factor", false, getChosenSpeedFactor());
337  }
338  ret->mkItem("waiting time [s]", true,
340  ret->mkItem("impatience", true,
342  ret->mkItem("last lane change [s]", true,
344  ret->mkItem("desired depart [s]", false, time2string(getParameter().depart));
345  if (getParameter().repetitionNumber > 0) {
346  ret->mkItem("left same route [#]", false, (unsigned int) getParameter().repetitionNumber);
347  }
348  if (getParameter().repetitionOffset > 0) {
349  ret->mkItem("insertion period [s]", false, time2string(getParameter().repetitionOffset));
350  }
351  ret->mkItem("stop info", false, getStopInfo());
352  ret->mkItem("CO2 (HBEFA) [mg/s]", true,
354  ret->mkItem("CO (HBEFA) [mg/s]", true,
356  ret->mkItem("HC (HBEFA) [mg/s]", true,
358  ret->mkItem("NOx (HBEFA) [mg/s]", true,
360  ret->mkItem("PMx (HBEFA) [mg/s]", true,
362  ret->mkItem("fuel (HBEFA) [ml/s]", true,
364  ret->mkItem("noise (Harmonoise) [dB]", true,
366  ret->mkItem("parameters [key:val]", false, toString(getParameter().getMap()));
367  ret->mkItem("", false, "");
368  ret->mkItem("Type Information:", false, "");
369  ret->mkItem("type [id]", false, myType->getID());
370  ret->mkItem("length", false, myType->getLength());
371  ret->mkItem("minGap", false, myType->getMinGap());
372  ret->mkItem("vehicle class", false, SumoVehicleClassStrings.getString(myType->getVehicleClass()));
373  ret->mkItem("emission class", false, SumoEmissionClassStrings.getString(myType->getEmissionClass()));
374  ret->mkItem("maximum acceleration [m/s^2]", false, getCarFollowModel().getMaxAccel());
375  ret->mkItem("maximum deceleration [m/s^2]", false, getCarFollowModel().getMaxDecel());
376  ret->mkItem("imperfection (sigma)", false, getCarFollowModel().getImperfection());
377  ret->mkItem("reaction time (tau)", false, getCarFollowModel().getHeadwayTime());
378  ret->mkItem("type parameters [key:val]", false, toString(myType->getParameter().getMap()));
379  // close building
380  ret->closeBuilding();
381  return ret;
382 }
383 
384 
385 Boundary
387  Boundary b;
388  b.add(getPosition());
389  b.grow(20);
390  return b;
391 }
392 
393 
394 void
396  glPushMatrix();
397  glScaled(getVehicleType().getWidth(), getVehicleType().getLength(), 1.);
398  glBegin(GL_TRIANGLE_STRIP);
399  glVertex2d(0., 0.);
400  glVertex2d(-.5, .15);
401  glVertex2d(.5, .15);
402  glVertex2d(-.5, 1.);
403  glVertex2d(.5, 1.);
404  glEnd();
405  glPopMatrix();
406 }
407 
408 
409 void
411  const SUMOReal length = getVehicleType().getLength();
412  if (length >= 8.) {
414  return;
415  }
416  glPushMatrix();
417  glScaled(getVehicleType().getWidth(), length, 1.);
418  glBegin(GL_TRIANGLES);
419  glVertex2d(0., 0.);
420  glVertex2d(-.5, 1.);
421  glVertex2d(.5, 1.);
422  glEnd();
423  glPopMatrix();
424 }
425 
426 
427 void
428 GUIVehicle::drawPoly(double* poses, SUMOReal offset) {
429  glPushMatrix();
430  glTranslated(0, 0, offset * .1);
431  glPolygonOffset(0, offset * -1);
432  glBegin(GL_TRIANGLE_FAN);
433  int i = 0;
434  while (poses[i] > -999) {
435  glVertex2d(poses[i], poses[i + 1]);
436  i = i + 2;
437  }
438  glEnd();
439  glPopMatrix();
440 }
441 
442 
443 void
445  RGBColor current = GLHelper::getColor();
446  RGBColor lighter = current.changedBrightness(51);
447  RGBColor darker = current.changedBrightness(-51);
448 
449  const SUMOReal length = getVehicleType().getLength();
450  const SUMOReal width = getVehicleType().getWidth();
451  glPushMatrix();
452  glRotated(90, 0, 0, 1);
453  glScaled(length, width, 1.);
455 
456  // draw main body
457  switch (shape) {
458  case SVS_UNKNOWN:
460  GLHelper::setColor(lighter);
461  drawPoly(vehiclePoly_PassengerCarBodyFront, 4.5);
462  glColor3d(0, 0, 0);
463  drawPoly(vehiclePoly_PassengerFrontGlass, 4.5);
464  break;
465  case SVS_PEDESTRIAN:
466  glTranslated(0, 0, .045);
468  glTranslated(0, 0, -.045);
469  glScaled(.7, 2, 1);
470  glTranslated(0, 0, .04);
471  GLHelper::setColor(lighter);
473  glTranslated(0, 0, -.04);
474  break;
475  case SVS_BICYCLE:
476  case SVS_MOTORCYCLE: {
477  glPushMatrix();
478  glTranslated(.5, 0, 0);
479  glScaled(.25 / (length), 1, 1.);
480  glTranslated(0, 0, .045);
482  glScaled(.7, 2, 1);
483  glTranslated(0, 0, -.045);
484  glTranslated(0, 0, .04);
485  GLHelper::setColor(lighter);
487  glTranslated(0, 0, -.04);
488  glPopMatrix();
489  }
490  break;
491  case SVS_PASSENGER:
492  case SVS_PASSENGER_SEDAN:
494  case SVS_PASSENGER_WAGON:
496  GLHelper::setColor(lighter);
497  drawPoly(vehiclePoly_PassengerCarBodyFront, 4.5);
498  glColor3d(0, 0, 0);
499  drawPoly(vehiclePoly_PassengerFrontGlass, 4.5);
500  break;
501  case SVS_PASSENGER_VAN:
502  drawPoly(vehiclePoly_PassengerVanBody, 4);
503  GLHelper::setColor(lighter);
504  drawPoly(vehiclePoly_PassengerVanBodyFront, 4.5);
505  glColor3d(0, 0, 0);
506  drawPoly(vehiclePoly_PassengerVanFrontGlass, 4.5);
507  drawPoly(vehiclePoly_PassengerVanRightGlass, 4.5);
508  drawPoly(vehiclePoly_PassengerVanLeftGlass, 4.5);
509  drawPoly(vehiclePoly_PassengerVanBackGlass, 4.5);
510  break;
511  case SVS_DELIVERY:
512  drawPoly(vehiclePoly_PassengerVanBody, 4);
513  GLHelper::setColor(lighter);
514  drawPoly(vehiclePoly_PassengerVanBodyFront, 4.5);
515  glColor3d(0, 0, 0);
516  drawPoly(vehiclePoly_PassengerVanFrontGlass, 4.5);
517  drawPoly(vehiclePoly_DeliveryMediumRightGlass, 4.5);
518  drawPoly(vehiclePoly_DeliveryMediumLeftGlass, 4.5);
519  break;
520  case SVS_TRANSPORT:
523  glScaled(1. / (length), 1, 1.);
524  drawPoly(vehiclePoly_TransportBody, 4);
525  glColor3d(0, 0, 0);
526  drawPoly(vehiclePoly_TransportFrontGlass, 4.5);
527  drawPoly(vehiclePoly_TransportRightGlass, 4.5);
528  drawPoly(vehiclePoly_TransportLeftGlass, 4.5);
529  break;
530  case SVS_BUS:
531  case SVS_BUS_TROLLEY:
533  case SVS_BUS_CITY: {
534  SUMOReal ml = length;
535  glScaled(1. / (length), 1, 1.);
536  glTranslated(0, 0, .04);
537  glBegin(GL_TRIANGLE_FAN);
538  glVertex2d(ml / 2., 0);
539  glVertex2d(0, 0);
540  glVertex2d(0, -.45);
541  glVertex2d(0 + .05, -.5);
542  glVertex2d(ml - .05, -.5);
543  glVertex2d(ml, -.45);
544  glVertex2d(ml, .45);
545  glVertex2d(ml - .05, .5);
546  glVertex2d(0 + .05, .5);
547  glVertex2d(0, .45);
548  glVertex2d(0, 0);
549  glEnd();
550  glTranslated(0, 0, -.04);
551 
552  glTranslated(0, 0, .045);
553  glColor3d(0, 0, 0);
554  glBegin(GL_QUADS);
555  glVertex2d(0 + .05, .48);
556  glVertex2d(0 + .05, -.48);
557  glVertex2d(0 + .15, -.48);
558  glVertex2d(0 + .15, .48);
559 
560  glVertex2d(ml - .1, .45);
561  glVertex2d(ml - .1, -.45);
562  glVertex2d(ml - .05, -.45);
563  glVertex2d(ml - .05, .45);
564 
565  glVertex2d(0 + .20, .49);
566  glVertex2d(0 + .20, .45);
567  glVertex2d(ml - .20, .45);
568  glVertex2d(ml - .20, .49);
569 
570  glVertex2d(0 + .20, -.49);
571  glVertex2d(0 + .20, -.45);
572  glVertex2d(ml - .20, -.45);
573  glVertex2d(ml - .20, -.49);
574 
575  glEnd();
576  glTranslated(0, 0, -.045);
577  }
578  break;
579  case SVS_BUS_OVERLAND:
580  case SVS_RAIL:
581  drawAction_drawRailCarriages(s, 25.0, 1);
582  break;
583  case SVS_RAIL_LIGHT:
585  break;
586  case SVS_RAIL_CITY:
588  break;
589  case SVS_RAIL_SLOW:
590  drawAction_drawRailCarriages(s, 15.0, 1);
591  break;
592  case SVS_RAIL_FAST:
593  drawAction_drawRailCarriages(s, 40.0, 1);
594  break;
595  case SVS_RAIL_CARGO:
597  break;
598  case SVS_E_VEHICLE:
599  drawPoly(vehiclePoly_EVehicleBody, 4);
600  glColor3d(0, 0, 0);
601  drawPoly(vehiclePoly_EVehicleFrontGlass, 4.5);
602  glTranslated(0, 0, .048);
603  GLHelper::setColor(current);
604  glBegin(GL_QUADS);
605  glVertex2d(.3, .5);
606  glVertex2d(.35, .5);
607  glVertex2d(.35, -.5);
608  glVertex2d(.3, -.5);
609 
610  glVertex2d(.3, -.05);
611  glVertex2d(.7, -.05);
612  glVertex2d(.7, .05);
613  glVertex2d(.3, .05);
614 
615  glVertex2d(.7, .5);
616  glVertex2d(.65, .5);
617  glVertex2d(.65, -.5);
618  glVertex2d(.7, -.5);
619  glEnd();
620  glTranslated(0, 0, -.048);
621  //drawPoly(vehiclePoly_EVehicleBackGlass, 4.5);
622  break;
623  case SVS_ANT:
624  glPushMatrix();
625  // ant is stretched via vehicle length
626  GLHelper::setColor(darker);
627  // draw left side
628  GLHelper::drawBoxLine(Position(-0.2, -.10), 350, 0.5, .02);
629  GLHelper::drawBoxLine(Position(-0.3, -.50), 240, 0.4, .03);
630  GLHelper::drawBoxLine(Position(0.3, -.10), 340, 0.8, .03);
631  GLHelper::drawBoxLine(Position(0.05, -.80), 290, 0.6, .04);
632  GLHelper::drawBoxLine(Position(0.4, -.10), 20, 0.8, .03);
633  GLHelper::drawBoxLine(Position(0.65, -.80), 75, 0.6, .04);
634  GLHelper::drawBoxLine(Position(0.5, -.10), 55, 0.8, .04);
635  GLHelper::drawBoxLine(Position(1.1, -.55), 90, 0.6, .04);
636  // draw right side
637  GLHelper::drawBoxLine(Position(-0.2, .10), 190, 0.5, .02);
638  GLHelper::drawBoxLine(Position(-0.3, .50), 300, 0.4, .03);
639  GLHelper::drawBoxLine(Position(0.3, .10), 200, 0.8, .03);
640  GLHelper::drawBoxLine(Position(0.05, .80), 250, 0.6, .04);
641  GLHelper::drawBoxLine(Position(0.4, .10), 160, 0.8, .03);
642  GLHelper::drawBoxLine(Position(0.65, .80), 105, 0.6, .04);
643  GLHelper::drawBoxLine(Position(0.5, .10), 125, 0.8, .04);
644  GLHelper::drawBoxLine(Position(1.1, .55), 90, 0.6, .04);
645  // draw body
646  GLHelper::setColor(current);
647  glTranslated(0, 0, 0.1);
649  glTranslated(.4, 0, 0);
651  glTranslated(.4, 0, 0);
653  glPopMatrix();
654  break;
655  default: // same as passenger
657  glColor3d(1, 1, 1);
658  drawPoly(vehiclePoly_PassengerCarBodyFront, 4.5);
659  glColor3d(0, 0, 0);
660  drawPoly(vehiclePoly_PassengerFrontGlass, 4.5);
661  break;
662  }
663 
664  // draw decorations
665  switch (shape) {
666  case SVS_PEDESTRIAN:
667  break;
668  case SVS_BICYCLE:
669  //glScaled(length, 1, 1.);
670  glBegin(GL_TRIANGLE_FAN);
671  glVertex2d(1 / 2., 0);
672  glVertex2d(0, 0);
673  glVertex2d(0, -.03);
674  glVertex2d(0 + .05, -.05);
675  glVertex2d(1 - .05, -.05);
676  glVertex2d(1, -.03);
677  glVertex2d(1, .03);
678  glVertex2d(1 - .05, .05);
679  glVertex2d(0 + .05, .05);
680  glVertex2d(0, .03);
681  glVertex2d(0, 0);
682  glEnd();
683  break;
684  case SVS_MOTORCYCLE:
685  //glScaled(length, 1, 1.);
686  glBegin(GL_TRIANGLE_FAN);
687  glVertex2d(1 / 2., 0);
688  glVertex2d(0, 0);
689  glVertex2d(0, -.03);
690  glVertex2d(0 + .05, -.2);
691  glVertex2d(1 - .05, -.2);
692  glVertex2d(1, -.03);
693  glVertex2d(1, .03);
694  glVertex2d(1 - .05, .2);
695  glVertex2d(0 + .05, .2);
696  glVertex2d(0, .03);
697  glVertex2d(0, 0);
698  glEnd();
699  break;
700  case SVS_PASSENGER:
701  case SVS_PASSENGER_SEDAN:
702  drawPoly(vehiclePoly_PassengerSedanRightGlass, 4.5);
703  drawPoly(vehiclePoly_PassengerSedanLeftGlass, 4.5);
704  drawPoly(vehiclePoly_PassengerSedanBackGlass, 4.5);
705  break;
707  drawPoly(vehiclePoly_PassengerHatchbackRightGlass, 4.5);
708  drawPoly(vehiclePoly_PassengerHatchbackLeftGlass, 4.5);
709  drawPoly(vehiclePoly_PassengerHatchbackBackGlass, 4.5);
710  break;
711  case SVS_PASSENGER_WAGON:
712  drawPoly(vehiclePoly_PassengerWagonRightGlass, 4.5);
713  drawPoly(vehiclePoly_PassengerWagonLeftGlass, 4.5);
714  drawPoly(vehiclePoly_PassengerWagonBackGlass, 4.5);
715  break;
716  case SVS_PASSENGER_VAN:
717  case SVS_DELIVERY:
718  break;
719  case SVS_TRANSPORT:
720  GLHelper::setColor(current);
721  GLHelper::drawBoxLine(Position(2.3, 0), 90., length - 2.3, .5);
722  break;
724  GLHelper::setColor(current);
725  GLHelper::drawBoxLine(Position(2.8, 0), 90., length - 2.8, .5);
726  break;
727  case SVS_TRANSPORT_1TRAILER: {
728  GLHelper::setColor(current);
729  SUMOReal l = length - 2.3;
730  l = l / 2.;
731  GLHelper::drawBoxLine(Position(2.3, 0), 90., l, .5);
732  GLHelper::drawBoxLine(Position(2.3 + l + .5, 0), 90., l - .5, .5);
733  break;
734  }
735  case SVS_BUS_TROLLEY:
736  glPushMatrix();
737  glTranslated(0, 0, .1);
738  GLHelper::setColor(darker);
739  GLHelper::drawBoxLine(Position(3.8, 0), 90., 1, .3);
740  glTranslated(0, 0, .1);
741  glColor3d(0, 0, 0);
742  GLHelper::drawBoxLine(Position(4.3, .2), 90., 1, .06);
743  GLHelper::drawBoxLine(Position(4.3, -.2), 90., 1, .06);
744  GLHelper::drawBoxLine(Position(5.3, .2), 90., 3, .03);
745  GLHelper::drawBoxLine(Position(5.3, -.2), 90., 3, .03);
746  glPopMatrix();
747  break;
748  case SVS_BUS:
749  case SVS_BUS_CITY:
751  case SVS_BUS_OVERLAND:
752  case SVS_RAIL:
753  case SVS_RAIL_LIGHT:
754  case SVS_RAIL_CITY:
755  case SVS_RAIL_SLOW:
756  case SVS_RAIL_FAST:
757  case SVS_RAIL_CARGO:
758  case SVS_E_VEHICLE:
759  case SVS_ANT:
760  break;
761  default: // same as passenger/sedan
762  drawPoly(vehiclePoly_PassengerSedanRightGlass, 4.5);
763  drawPoly(vehiclePoly_PassengerSedanLeftGlass, 4.5);
764  drawPoly(vehiclePoly_PassengerSedanBackGlass, 4.5);
765  break;
766  }
767  /*
768  glBegin(GL_TRIANGLE_FAN);
769  glVertex2d(.5,.5); // center - strip begin
770  glVertex2d(0, .5); // center, front
771  glVertex2d(0, .8); // ... clockwise ... (vehicle right side)
772  glVertex2d(0.08, .94);
773  glVertex2d(0.25, 1.);
774  glVertex2d(0.95, 1.);
775  glVertex2d(1., .9);
776  glVertex2d(1., .1); // (vehicle left side)
777  glVertex2d(0.95, 0.);
778  glVertex2d(0.25, 0.);
779  glVertex2d(0.08, .06);
780  glVertex2d(0, .2); //
781  glVertex2d(0, .5); // center, front (close)
782  glEnd();
783 
784  glPolygonOffset(0, -4.5);
785  glColor3d(1, 1, 1); // front
786  glBegin(GL_TRIANGLE_FAN);
787  glVertex2d(0.1,0.5);
788  glVertex2d(0.025,0.5);
789  glVertex2d(0.025,0.75);
790  glVertex2d(0.27,0.9);
791  glVertex2d(0.27,0.1);
792  glVertex2d(0.025,0.25);
793  glVertex2d(0.025,0.5);
794  glEnd();
795 
796  glColor3d(0, 0, 0); // front glass
797  glBegin(GL_TRIANGLE_FAN);
798  glVertex2d(0.35,0.5);
799  glVertex2d(0.3,0.5);
800  glVertex2d(0.3,0.9);
801  glVertex2d(0.43,0.8);
802  glVertex2d(0.43,0.2);
803  glVertex2d(0.3,0.1);
804  glVertex2d(0.3,0.5);
805  glEnd();
806 
807  glBegin(GL_TRIANGLE_FAN); // back glass
808  glVertex2d(0.92,0.5);
809  glVertex2d(0.90,0.5);
810  glVertex2d(0.90,0.8);
811  glVertex2d(0.95,0.9);
812  glVertex2d(0.95,0.1);
813  glVertex2d(0.90,0.2);
814  glVertex2d(0.90,0.5);
815  glEnd();
816 
817  glBegin(GL_TRIANGLE_FAN); // right glass
818  glVertex2d(0.36,0.07);
819  glVertex2d(0.34,0.03);
820  glVertex2d(0.94,0.03);
821  glVertex2d(0.87,0.13);
822  glVertex2d(0.45,0.13);
823  glVertex2d(0.34,0.03);
824  glEnd();
825 
826  glBegin(GL_TRIANGLE_FAN); // left glass
827  glVertex2d(0.36,1.-0.07);
828  glVertex2d(0.34,1.-0.03);
829  glVertex2d(0.94,1.-0.03);
830  glVertex2d(0.87,1.-0.13);
831  glVertex2d(0.45,1.-0.13);
832  glVertex2d(0.34,1.-0.03);
833  glEnd();
834  */
835 
836  glPopMatrix();
837 }
838 
839 
840 bool
842  const std::string& file = getVehicleType().getImgFile();
843  if (file != "") {
844  int textureID = GUITexturesHelper::getTextureID(file);
845  if (textureID > 0) {
846  if (length < 0) {
848  }
849  const SUMOReal halfWidth = getVehicleType().getWidth() / 2.0 * s.vehicleExaggeration;
850  GUITexturesHelper::drawTexturedBox(textureID, -halfWidth, 0, halfWidth, length);
851  return true;
852  }
853  }
854  return false;
855 }
856 
857 
858 #define BLINKER_POS_FRONT .5
859 #define BLINKER_POS_BACK .5
860 
861 inline void
862 drawAction_drawBlinker(const GUIVehicle& veh, double dir) {
863  glColor3d(1.f, .8f, 0);
864  glPushMatrix();
865  glTranslated(dir, BLINKER_POS_FRONT, -0.1);
867  glPopMatrix();
868  glPushMatrix();
869  glTranslated(dir, veh.getVehicleType().getLength() - BLINKER_POS_BACK, -0.1);
871  glPopMatrix();
872 }
873 
874 
875 inline void
878  return;
879  }
880  const double offset = MAX2(.5 * veh.getVehicleType().getWidth(), .4);
882  drawAction_drawBlinker(veh, -offset);
883  }
885  drawAction_drawBlinker(veh, offset);;
886  }
888  drawAction_drawBlinker(veh, -offset);
889  drawAction_drawBlinker(veh, offset);
890  }
891 }
892 
893 
894 inline void
897  return;
898  }
899  glColor3f(1.f, .2f, 0);
900  glPushMatrix();
901  glTranslated(-veh.getVehicleType().getWidth() * 0.5, veh.getVehicleType().getLength(), -0.1);
903  glPopMatrix();
904  glPushMatrix();
905  glTranslated(veh.getVehicleType().getWidth() * 0.5, veh.getVehicleType().getLength(), -0.1);
907  glPopMatrix();
908 }
909 
910 
911 void
913  glPushName(getGlID());
914  glPushMatrix();
915  Position p1 = getPosition();
916  // one seat in the center of the vehicle by default
918  glTranslated(p1.x(), p1.y(), getType());
919  glRotated(getAngle(), 0, 0, 1);
920  // set lane color
921  setColor(s);
922  // scale
923  SUMOReal upscale = s.vehicleExaggeration;
924  glScaled(upscale, upscale, 1);
925  /*
926  MSLCM_DK2004 &m2 = static_cast<MSLCM_DK2004&>(veh->getLaneChangeModel());
927  if((m2.getState()&LCA_URGENT)!=0) {
928  glColor3d(1, .4, .4);
929  } else if((m2.getState()&LCA_SPEEDGAIN)!=0) {
930  glColor3d(.4, .4, 1);
931  } else {
932  glColor3d(.4, 1, .4);
933  }
934  */
935  // draw the vehicle
936  switch (s.vehicleQuality) {
937  case 0:
939  break;
940  case 1:
942  break;
943  case 2:
945  break;
946  case 3:
947  default:
948  // draw as image but take special care for drawing trains
949  // XXX handle default carriage lenghts someplace else
950  switch (getVehicleType().getGuiShape()) {
951  case SVS_RAIL:
952  drawAction_drawRailCarriages(s, 25.0, 1, true);
953  break;
954  case SVS_RAIL_LIGHT:
955  drawAction_drawRailCarriages(s, 38.0, true);
956  break;
957  case SVS_RAIL_CITY:
958  drawAction_drawRailCarriages(s, 25.0, true);
959  break;
960  case SVS_RAIL_SLOW:
961  drawAction_drawRailCarriages(s, 15.0, 1, true);
962  break;
963  case SVS_RAIL_FAST:
964  drawAction_drawRailCarriages(s, 40.0, 1, true);
965  break;
966  case SVS_RAIL_CARGO:
967  drawAction_drawRailCarriages(s, 20.0, true);
968  break;
969  default:
970  // draw normal vehicle
973  };
974  };
975  break;
976  }
977  if (s.drawMinGap) {
978  SUMOReal minGap = -getVehicleType().getMinGap();
979  glColor3d(0., 1., 0.);
980  glBegin(GL_LINES);
981  glVertex2d(0., 0);
982  glVertex2d(0., minGap);
983  glVertex2d(-.5, minGap);
984  glVertex2d(.5, minGap);
985  glEnd();
986  }
987  // draw the blinker and brakelights if wished
988  if (s.showBlinker) {
989  glTranslated(0, 0, .1);
990  switch (getVehicleType().getGuiShape()) {
991  case SVS_PEDESTRIAN:
992  case SVS_BICYCLE:
993  case SVS_ANT:
994  case SVS_RAIL:
995  case SVS_RAIL_LIGHT:
996  case SVS_RAIL_SLOW:
997  case SVS_RAIL_FAST:
998  case SVS_RAIL_CARGO:
999  // only SVS_RAIL_CITY has blinkers and brake lights
1000  break;
1001  default:
1004  break;
1005  }
1006  }
1007  // draw the wish to change the lane
1008  if (s.drawLaneChangePreference) {
1009  /*
1010  if(gSelected.isSelected(GLO_VEHICLE, veh->getGlID())) {
1011  MSLCM_DK2004 &m = static_cast<MSLCM_DK2004&>(veh->getLaneChangeModel());
1012  glColor3d(.5, .5, 1);
1013  glBegin(GL_LINES);
1014  glVertex2f(0, 0);
1015  glVertex2f(m.getChangeProbability(), .5);
1016  glEnd();
1017 
1018  glColor3d(1, 0, 0);
1019  glBegin(GL_LINES);
1020  glVertex2f(0.1, 0);
1021  glVertex2f(0.1, m.myMaxJam1);
1022  glEnd();
1023 
1024  glColor3d(0, 1, 0);
1025  glBegin(GL_LINES);
1026  glVertex2f(-0.1, 0);
1027  glVertex2f(-0.1, m.myTDist);
1028  glEnd();
1029  }
1030  */
1031  }
1032  // draw best lanes
1033  /*
1034  if (true) {
1035  const MSLane &l = veh->getLane();
1036  SUMOReal r1 = veh->allowedContinuationsLength(&l, 0);
1037  SUMOReal r2 = l.getLeftLane()!=0 ? veh->allowedContinuationsLength(l.getLeftLane(), 0) : 0;
1038  SUMOReal r3 = l.getRightLane()!=0 ? veh->allowedContinuationsLength(l.getRightLane(), 0) : 0;
1039  SUMOReal mmax = MAX3(r1, r2, r3);
1040  glBegin(GL_LINES);
1041  glVertex2f(0, 0);
1042  glVertex2f(0, r1/mmax/2.);
1043  glEnd();
1044  glBegin(GL_LINES);
1045  glVertex2f(.4, 0);
1046  glVertex2f(.4, r2/mmax/2.);
1047  glEnd();
1048  glBegin(GL_LINES);
1049  glVertex2f(-.4, 0);
1050  glVertex2f(-.4, r3/mmax/2.);
1051  glEnd();
1052  }
1053  */
1054  glPopMatrix();
1055  drawName(getPosition(-MIN2(getVehicleType().getLength() / 2, SUMOReal(5))),
1056  s.scale,
1057  getVehicleType().getGuiShape() == SVS_PEDESTRIAN ? s.personName : s.vehicleName);
1058  glPopName();
1059  if (myPersonDevice != 0) {
1060  const std::vector<MSPerson*>& ps = myPersonDevice->getPersons();
1061  size_t personIndex = 0;
1062  for (std::vector<MSPerson*>::const_iterator i = ps.begin(); i != ps.end(); ++i) {
1063  GUIPerson* person = dynamic_cast<GUIPerson*>(*i);
1064  assert(person != 0);
1065  person->setPositionInVehicle(getSeatPosition(personIndex++));
1066  person->drawGL(s);
1067  }
1068  }
1069 }
1070 
1071 
1072 void
1074  glPushName(getGlID());
1075  glPushMatrix();
1076  glTranslated(0, 0, getType() - .1); // don't draw on top of other cars
1078  drawBestLanes();
1079  }
1081  drawRoute(s, 0, 0.25);
1082  }
1084  if (getNumberReroutes() > 0) {
1085  const int noReroutePlus1 = getNumberReroutes() + 1;
1086  for (int i = noReroutePlus1 - 1; i >= 0; i--) {
1087  SUMOReal darken = SUMOReal(0.4) / SUMOReal(noReroutePlus1) * SUMOReal(i);
1088  drawRoute(s, i, darken);
1089  }
1090  } else {
1091  drawRoute(s, 0, 0.25);
1092  }
1093  }
1095  for (DriveItemVector::const_iterator i = myLFLinkLanes.begin(); i != myLFLinkLanes.end(); ++i) {
1096  if ((*i).myLink == 0) {
1097  continue;
1098  }
1099  MSLink* link = (*i).myLink;
1100  MSLane* via = link->getViaLaneOrLane();
1101  if (via != 0) {
1102  Position p = via->getShape()[0];
1103  if ((*i).mySetRequest) {
1104  glColor3d(0, .8, 0);
1105  } else {
1106  glColor3d(.8, 0, 0);
1107  }
1108  const SUMOTime leaveTime = (*i).myLink->getLeaveTime(
1109  (*i).myArrivalTime, (*i).myArrivalSpeed, (*i).getLeaveSpeed(), getVehicleType().getLengthWithGap());
1110  drawLinkItem(p, (*i).myArrivalTime, leaveTime, s.addExaggeration);
1111  // the time slot that ego vehicle uses when checking opened may
1112  // differ from the one it requests in setApproaching
1113  MSLink::ApproachingVehicleInformation avi = (*i).myLink->getApproaching(this);
1114  assert(avi.arrivalTime == (*i).myArrivalTime && avi.leavingTime == leaveTime);
1115  }
1116  }
1117  }
1118  glPopMatrix();
1119  glPopName();
1120 }
1121 
1122 
1123 void
1124 GUIVehicle::drawLinkItem(const Position& pos, SUMOTime arrivalTime, SUMOTime leaveTime, SUMOReal exagerate) {
1125  glTranslated(pos.x(), pos.y(), -.1);
1127  std::string times = toString(STEPS2TIME(arrivalTime)) + "/" + toString(STEPS2TIME(leaveTime));
1128  GLHelper::drawText(times.c_str(), Position(), .1, 1.6 * exagerate, RGBColor::GREEN, 0);
1129  glTranslated(-pos.x(), -pos.y(), .1);
1130 }
1131 
1132 const std::vector<MSVehicle::LaneQ>&
1134  myLock.lock();
1135  const std::vector<MSVehicle::LaneQ>& ret = MSVehicle::getBestLanes();
1136  myLock.unlock();
1137  return ret;
1138 }
1139 
1140 
1141 void
1143  const GUIColorer& c = s.vehicleColorer;
1144  if (!setFunctionalColor(c.getActive())) {
1146  }
1147 }
1148 
1149 
1150 bool
1151 GUIVehicle::setFunctionalColor(size_t activeScheme) const {
1152  switch (activeScheme) {
1153  case 0: {
1154  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
1156  return true;
1157  }
1158  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
1159  GLHelper::setColor(getVehicleType().getColor());
1160  return true;
1161  }
1162  if (&getRoute().getColor() != &RGBColor::DEFAULT_COLOR) {
1163  GLHelper::setColor(getRoute().getColor());
1164  return true;
1165  }
1166  return false;
1167  }
1168  case 2: {
1169  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
1171  return true;
1172  }
1173  return false;
1174  }
1175  case 3: {
1176  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
1177  GLHelper::setColor(getVehicleType().getColor());
1178  return true;
1179  }
1180  return false;
1181  }
1182  case 4: {
1183  if (&getRoute().getColor() != &RGBColor::DEFAULT_COLOR) {
1184  GLHelper::setColor(getRoute().getColor());
1185  return true;
1186  }
1187  return false;
1188  }
1189  case 5: {
1190  Position p = getRoute().getEdges()[0]->getLanes()[0]->getShape()[0];
1191  const Boundary& b = ((GUINet*) MSNet::getInstance())->getBoundary();
1192  Position center = b.getCenter();
1193  SUMOReal hue = 180. + atan2(center.x() - p.x(), center.y() - p.y()) * 180. / PI;
1194  SUMOReal sat = p.distanceTo(center) / center.distanceTo(Position(b.xmin(), b.ymin()));
1195  GLHelper::setColor(RGBColor::fromHSV(hue, sat, 1.));
1196  return true;
1197  }
1198  case 6: {
1199  Position p = getRoute().getEdges().back()->getLanes()[0]->getShape()[-1];
1200  const Boundary& b = ((GUINet*) MSNet::getInstance())->getBoundary();
1201  Position center = b.getCenter();
1202  SUMOReal hue = 180. + atan2(center.x() - p.x(), center.y() - p.y()) * 180. / PI;
1203  SUMOReal sat = p.distanceTo(center) / center.distanceTo(Position(b.xmin(), b.ymin()));
1204  GLHelper::setColor(RGBColor::fromHSV(hue, sat, 1.));
1205  return true;
1206  }
1207  case 7: {
1208  Position pb = getRoute().getEdges()[0]->getLanes()[0]->getShape()[0];
1209  Position pe = getRoute().getEdges().back()->getLanes()[0]->getShape()[-1];
1210  const Boundary& b = ((GUINet*) MSNet::getInstance())->getBoundary();
1211  SUMOReal hue = 180. + atan2(pb.x() - pe.x(), pb.y() - pe.y()) * 180. / PI;
1212  Position minp(b.xmin(), b.ymin());
1213  Position maxp(b.xmax(), b.ymax());
1214  SUMOReal sat = pb.distanceTo(pe) / minp.distanceTo(maxp);
1215  GLHelper::setColor(RGBColor::fromHSV(hue, sat, 1.));
1216  return true;
1217  }
1218  }
1219  return false;
1220 }
1221 
1222 
1223 SUMOReal
1224 GUIVehicle::getColorValue(size_t activeScheme) const {
1225  switch (activeScheme) {
1226  case 8:
1227  return getSpeed();
1228  case 9:
1229  return getWaitingSeconds();
1230  case 10:
1231  return getLastLaneChangeOffset();
1232  case 11:
1233  return getMaxSpeed();
1234  case 12:
1235  return getHBEFA_CO2Emissions();
1236  case 13:
1237  return getHBEFA_COEmissions();
1238  case 14:
1239  return getHBEFA_PMxEmissions();
1240  case 15:
1241  return getHBEFA_NOxEmissions();
1242  case 16:
1243  return getHBEFA_HCEmissions();
1244  case 17:
1245  return getHBEFA_FuelConsumption();
1246  case 18:
1248  case 19:
1249  if (getNumberReroutes() == 0) {
1250  return -1;
1251  }
1252  return getNumberReroutes();
1253  case 20:
1255  case 21:
1256  return getBestLaneOffset();
1257  case 22:
1258  return getAcceleration();
1259  }
1260  return 0;
1261 }
1262 
1263 
1264 // ------------ Additional visualisations
1265 bool
1267  return myAdditionalVisualizations.find(parent) != myAdditionalVisualizations.end() && (myAdditionalVisualizations.find(parent)->second & which) != 0;
1268 }
1269 
1270 
1271 void
1273  if (myAdditionalVisualizations.find(parent) == myAdditionalVisualizations.end()) {
1274  myAdditionalVisualizations[parent] = 0;
1275  }
1276  myAdditionalVisualizations[parent] |= which;
1277  parent->addAdditionalGLVisualisation(this);
1278 }
1279 
1280 
1281 void
1283  myAdditionalVisualizations[parent] &= ~which;
1284  parent->removeAdditionalGLVisualisation(this);
1285 }
1286 
1287 
1288 void
1289 GUIVehicle::drawRoute(const GUIVisualizationSettings& s, int routeNo, SUMOReal darken) const {
1290  setColor(s);
1291  GLdouble colors[4];
1292  glGetDoublev(GL_CURRENT_COLOR, colors);
1293  colors[0] -= darken;
1294  if (colors[0] < 0) {
1295  colors[0] = 0;
1296  }
1297  colors[1] -= darken;
1298  if (colors[1] < 0) {
1299  colors[1] = 0;
1300  }
1301  colors[2] -= darken;
1302  if (colors[2] < 0) {
1303  colors[2] = 0;
1304  }
1305  colors[3] -= darken;
1306  if (colors[3] < 0) {
1307  colors[3] = 0;
1308  }
1309  glColor3dv(colors);
1310  if (routeNo == 0) {
1312  return;
1313  }
1314  --routeNo; // only prior routes are stored
1316 }
1317 
1318 
1319 void
1321  myLock.lock();
1322  std::vector<std::vector<MSVehicle::LaneQ> > bestLanes = myBestLanes;
1323  myLock.unlock();
1324  SUMOReal width = 0.5;
1325  for (std::vector<std::vector<MSVehicle::LaneQ> >::iterator j = bestLanes.begin(); j != bestLanes.end(); ++j) {
1326  std::vector<MSVehicle::LaneQ>& lanes = *j;
1327  SUMOReal gmax = -1;
1328  SUMOReal rmax = -1;
1329  for (std::vector<MSVehicle::LaneQ>::const_iterator i = lanes.begin(); i != lanes.end(); ++i) {
1330  gmax = MAX2((*i).length, gmax);
1331  rmax = MAX2((*i).occupation, rmax);
1332  }
1333  for (std::vector<MSVehicle::LaneQ>::const_iterator i = lanes.begin(); i != lanes.end(); ++i) {
1334  const PositionVector& shape = (*i).lane->getShape();
1335  SUMOReal g = (*i).length / gmax;
1336  SUMOReal r = (*i).occupation / rmax;
1337  glColor3d(r, g, 0);
1338  GLHelper::drawBoxLines(shape, width);
1339 
1340  PositionVector s1 = shape;
1341  s1.move2side((SUMOReal) .1);
1342  glColor3d(r, 0, 0);
1343  GLHelper::drawLine(s1);
1344  s1.move2side((SUMOReal) - .2);
1345  glColor3d(0, g, 0);
1346  GLHelper::drawLine(s1);
1347 
1348  glColor3d(r, g, 0);
1349  Position lastPos = shape[-1];
1350  }
1351  width = .2;
1352  }
1353 }
1354 
1355 
1356 void
1357 GUIVehicle::drawRouteHelper(const MSRoute& r, SUMOReal exaggeration) const {
1358  MSRouteIterator i = r.begin();
1359  const std::vector<MSLane*>& bestLaneConts = getBestLanesContinuation();
1360  // draw continuation lanes when drawing the current route where available
1361  size_t bestLaneIndex = (&r == myRoute ? 0 : bestLaneConts.size());
1362  for (; i != r.end(); ++i) {
1363  const GUILane* lane;
1364  if (bestLaneIndex < bestLaneConts.size() && bestLaneConts[bestLaneIndex] != 0 && (*i) == &(bestLaneConts[bestLaneIndex]->getEdge())) {
1365  lane = static_cast<GUILane*>(bestLaneConts[bestLaneIndex]);
1366  ++bestLaneIndex;
1367  } else {
1368  lane = static_cast<GUILane*>((*i)->getLanes()[0]);
1369  }
1370  GLHelper::drawBoxLines(lane->getShape(), lane->getShapeRotations(), lane->getShapeLengths(), exaggeration);
1371  }
1372 }
1373 
1374 
1375 MSLane*
1376 GUIVehicle::getPreviousLane(MSLane* current, int& routeIndex) const {
1377  const bool isInternal = current->getEdge().getPurpose() == MSEdge::EDGEFUNCTION_INTERNAL;
1378  if (isInternal) {
1379  // route pointer still points to the previous lane
1380  return myRoute->getEdges()[routeIndex]->getLanes()[0];
1381  } else if (routeIndex == 0) {
1382  // there is no previous lane because the route has just begun
1383  return current;
1384  } else {
1385  // retrieve the previous internal edge
1386  routeIndex -= 1;
1387  const MSEdge* previous = myRoute->getEdges()[routeIndex];
1388 #ifdef HAVE_INTERNAL_LANES
1389  const MSEdge* previousInternal = previous->getInternalFollowingEdge(&current->getEdge());
1390 #else
1391  const MSEdge* previousInternal = 0;
1392 #endif
1393  if (previousInternal != 0) {
1394  return previousInternal->getLanes()[0];
1395  } else {
1396  // network without internal links, use previous edge instead
1397  return previous->getLanes()[0];
1398  }
1399  }
1400 }
1401 
1402 
1403 void
1404 GUIVehicle::drawAction_drawRailCarriages(const GUIVisualizationSettings& s, SUMOReal defaultLength, int firstPassengerCarriage, bool asImage) const {
1405  RGBColor current = GLHelper::getColor();
1406  RGBColor darker = current.changedBrightness(-51);
1407  const SUMOReal length = getVehicleType().getLength() * s.vehicleExaggeration;
1408  const SUMOReal halfWidth = getVehicleType().getWidth() / 2.0 * s.vehicleExaggeration;
1409  glPopMatrix(); // undo scaling and 90 degree rotation
1410  glPopMatrix(); // undo initial translation and rotation
1411  glPushMatrix();
1412  glPushMatrix();
1413  GLHelper::setColor(darker);
1414  const SUMOReal carriageGap = 1;
1415  const SUMOReal xCornerCut = 0.3;
1416  const SUMOReal yCornerCut = 0.4;
1417  // round to closest integer
1418  const int numCarriages = floor(length / (defaultLength + carriageGap) + 0.5);
1419  assert(numCarriages > 0);
1420  const SUMOReal carriageLengthWithGap = length / numCarriages;
1421  const SUMOReal carriageLength = carriageLengthWithGap - carriageGap;
1422  // lane on which the carriage front is situated
1423  MSLane* lane = myLane;
1424  int routeIndex = myCurrEdge - myRoute->begin();
1425  // lane on which the carriage back is situated
1426  MSLane* backLane = myLane;
1427  int backRouteIndex = routeIndex;
1428  // offsets of front and back
1429  SUMOReal carriageOffset = myState.pos();
1430  SUMOReal carriageBackOffset = myState.pos() - carriageLength;
1431  // handle seats
1432  int requiredSeats = getNumPassengers();
1433  if (requiredSeats > 0) {
1434  mySeatPositions.clear();
1435  }
1436  // draw individual carriages
1437  for (int i = 0; i < numCarriages; ++i) {
1438  while (carriageOffset < 0) {
1439  lane = getPreviousLane(lane, routeIndex);
1440  carriageOffset += lane->getLength();
1441  }
1442  while (carriageBackOffset < 0) {
1443  backLane = getPreviousLane(backLane, backRouteIndex);
1444  carriageBackOffset += backLane->getLength();
1445  }
1446  const Position front = lane->getShape().positionAtOffset2D(carriageOffset);
1447  const Position back = backLane->getShape().positionAtOffset2D(carriageBackOffset);
1448  const SUMOReal angle = atan2((front.x() - back.x()), (back.y() - front.y())) * (SUMOReal) 180.0 / (SUMOReal) PI;
1449  if (i >= firstPassengerCarriage) {
1450  computeSeats(front, back, requiredSeats);
1451  }
1452  glPushMatrix();
1453  glTranslated(front.x(), front.y(), getType());
1454  glRotated(angle, 0, 0, 1);
1455  if (!asImage || !drawAction_drawVehicleAsImage(s, carriageLength)) {
1456  glBegin(GL_TRIANGLE_FAN);
1457  glVertex2d(-halfWidth + xCornerCut, 0);
1458  glVertex2d(-halfWidth, yCornerCut);
1459  glVertex2d(-halfWidth, carriageLength - yCornerCut);
1460  glVertex2d(-halfWidth + xCornerCut, carriageLength);
1461  glVertex2d(halfWidth - xCornerCut, carriageLength);
1462  glVertex2d(halfWidth, carriageLength - yCornerCut);
1463  glVertex2d(halfWidth, yCornerCut);
1464  glVertex2d(halfWidth - xCornerCut, 0);
1465  glEnd();
1466  }
1467  glPopMatrix();
1468  carriageOffset -= carriageLengthWithGap;
1469  carriageBackOffset -= carriageLengthWithGap;
1470  GLHelper::setColor(current);
1471  }
1472 }
1473 
1474 
1475 const Position&
1476 GUIVehicle::getSeatPosition(size_t personIndex) const {
1478  return mySeatPositions[(int)MIN2(personIndex, mySeatPositions.size() - 1)];
1479 }
1480 
1481 
1482 int
1484  if (myPersonDevice != 0) {
1485  return (int)myPersonDevice->getPersons().size();
1486  }
1487  return 0;
1488 }
1489 
1490 
1491 void
1492 GUIVehicle::computeSeats(const Position& front, const Position& back, int& requiredSeats) const {
1493  if (requiredSeats <= 0) {
1494  return; // save some work
1495  }
1496  const Line l(front, back);
1497  const SUMOReal length = l.length2D();
1498  if (length < 4) {
1499  // small vehicle, sit at the center
1501  requiredSeats--;
1502  } else {
1503  for (SUMOReal p = 2; p <= length - 1; p += 1) {
1505  requiredSeats--;
1506  }
1507  }
1508 }
1509 
1510 
1511 SUMOReal
1514 }
1515 
1516 
1517 std::string
1519  std::string result = "";
1520  if (isParking()) {
1521  result += "parking";
1522  } else if (isStopped()) {
1523  result += "stopped";
1524  } else {
1525  return "";
1526  }
1527  if (myStops.front().triggered) {
1528  result += ", triggered";
1529  } else {
1530  result += ", duration=" + time2string(myStops.front().duration);
1531  }
1532  return result;
1533 }
1534 
1535 
1536 void
1538  if (myLFLinkLanes.size() == 0) {
1539  return;
1540  }
1541  const DriveProcessItem& dpi = myLFLinkLanes[0];
1542  if (dpi.myLink == 0) {
1543  return;
1544  }
1545  std::vector<const SUMOVehicle*> blockingFoes;
1547  getImpatience(), getCarFollowModel().getMaxDecel(), getWaitingTime(), &blockingFoes);
1548  for (std::vector<const SUMOVehicle*>::const_iterator it = blockingFoes.begin(); it != blockingFoes.end(); ++it) {
1549  gSelected.select(static_cast<const GUIVehicle*>(*it)->getGlID());
1550  }
1551 #ifdef HAVE_INTERNAL_LANES
1552  const MSLink::LinkLeaders linkLeaders = (dpi.myLink)->getLeaderInfo(myLane->getLength() - getPositionOnLane(), getVehicleType().getMinGap());
1553  for (MSLink::LinkLeaders::const_iterator it = linkLeaders.begin(); it != linkLeaders.end(); ++it) {
1554  // the vehicle to enter the junction first has priority
1555  const MSVehicle* leader = it->first;
1556  if ((static_cast<const GUIVehicle*>(leader))->myLinkLeaders.count(getID()) == 0) {
1557  // leader isn't already following us, now we follow it
1558  gSelected.select(static_cast<const GUIVehicle*>(leader)->getGlID());
1559  }
1560  }
1561 #endif
1562 }
1563 
1564 
1565 #ifdef HAVE_OSG
1566 void
1567 GUIVehicle::updateColor(GUIOSGView* view) {
1568  const GUIVisualizationSettings* s = view->getVisualisationSettings();
1570  myGeom[view]->setColor(osg::Vec4(col.red() / 255., col.green() / 255., col.blue() / 255., col.alpha() / 255.));
1571 }
1572 #endif
1573 
1574 /****************************************************************************/
1575