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, int vehicleIndex) :
251  MSVehicle(pars, route, type, speedFactor, vehicleIndex),
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, 21);
327  // add items
328  ret->mkItem("type [NAME]", false, myType->getID());
329  if (getParameter().repetitionNumber > 0) {
330  ret->mkItem("left same route [#]", false, (unsigned int) getParameter().repetitionNumber);
331  }
332  if (getParameter().repetitionOffset > 0) {
333  ret->mkItem("insertion period [s]", false, time2string(getParameter().repetitionOffset));
334  }
335  if (getChosenSpeedFactor() != 1) {
336  ret->mkItem("speed factor", false, getChosenSpeedFactor());
337  }
338  ret->mkItem("insertion period [s]", false, time2string(getParameter().repetitionOffset));
339  ret->mkItem("waiting time [s]", true,
341  ret->mkItem("last lane change [s]", true,
343  ret->mkItem("desired depart [s]", false, time2string(getParameter().depart));
344  ret->mkItem("position [m]", true,
346  ret->mkItem("speed [m/s]", true,
348  ret->mkItem("angle", true,
350  ret->mkItem("stop info", false, getStopInfo());
351  ret->mkItem("CO2 (HBEFA) [mg/s]", true,
353  ret->mkItem("CO (HBEFA) [mg/s]", true,
355  ret->mkItem("HC (HBEFA) [mg/s]", true,
357  ret->mkItem("NOx (HBEFA) [mg/s]", true,
359  ret->mkItem("PMx (HBEFA) [mg/s]", true,
361  ret->mkItem("fuel (HBEFA) [ml/s]", true,
363  ret->mkItem("noise (Harmonoise) [dB]", true,
365  // close building
366  ret->closeBuilding();
367  return ret;
368 }
369 
370 
371 Boundary
373  Boundary b;
374  b.add(getPosition());
375  b.grow(20);
376  return b;
377 }
378 
379 
380 void
382  glPushMatrix();
383  glScaled(getVehicleType().getWidth(), getVehicleType().getLength(), 1.);
384  glBegin(GL_TRIANGLE_STRIP);
385  glVertex2d(0., 0.);
386  glVertex2d(-.5, .15);
387  glVertex2d(.5, .15);
388  glVertex2d(-.5, 1.);
389  glVertex2d(.5, 1.);
390  glEnd();
391  glPopMatrix();
392 }
393 
394 
395 void
397  const SUMOReal length = getVehicleType().getLength();
398  if (length >= 8.) {
400  return;
401  }
402  glPushMatrix();
403  glScaled(getVehicleType().getWidth(), length, 1.);
404  glBegin(GL_TRIANGLES);
405  glVertex2d(0., 0.);
406  glVertex2d(-.5, 1.);
407  glVertex2d(.5, 1.);
408  glEnd();
409  glPopMatrix();
410 }
411 
412 
413 void
414 GUIVehicle::drawPoly(double* poses, SUMOReal offset) {
415  glPushMatrix();
416  glTranslated(0, 0, offset * .1);
417  glPolygonOffset(0, offset * -1);
418  glBegin(GL_TRIANGLE_FAN);
419  int i = 0;
420  while (poses[i] > -999) {
421  glVertex2d(poses[i], poses[i + 1]);
422  i = i + 2;
423  }
424  glEnd();
425  glPopMatrix();
426 }
427 
428 
429 void
431  RGBColor current = GLHelper::getColor();
432  RGBColor lighter = current.changedBrightness(51);
433  RGBColor darker = current.changedBrightness(-51);
434 
435  const SUMOReal length = getVehicleType().getLength();
436  const SUMOReal width = getVehicleType().getWidth();
437  glPushMatrix();
438  glRotated(90, 0, 0, 1);
439  glScaled(length, width, 1.);
441 
442  // draw main body
443  switch (shape) {
444  case SVS_UNKNOWN:
446  GLHelper::setColor(lighter);
447  drawPoly(vehiclePoly_PassengerCarBodyFront, 4.5);
448  glColor3d(0, 0, 0);
449  drawPoly(vehiclePoly_PassengerFrontGlass, 4.5);
450  break;
451  case SVS_PEDESTRIAN:
452  glTranslated(0, 0, .045);
454  glTranslated(0, 0, -.045);
455  glScaled(.7, 2, 1);
456  glTranslated(0, 0, .04);
457  GLHelper::setColor(lighter);
459  glTranslated(0, 0, -.04);
460  break;
461  case SVS_BICYCLE:
462  case SVS_MOTORCYCLE: {
463  glPushMatrix();
464  glTranslated(.5, 0, 0);
465  glScaled(.25 / (length), 1, 1.);
466  glTranslated(0, 0, .045);
468  glScaled(.7, 2, 1);
469  glTranslated(0, 0, -.045);
470  glTranslated(0, 0, .04);
471  GLHelper::setColor(lighter);
473  glTranslated(0, 0, -.04);
474  glPopMatrix();
475  }
476  break;
477  case SVS_PASSENGER:
478  case SVS_PASSENGER_SEDAN:
480  case SVS_PASSENGER_WAGON:
482  GLHelper::setColor(lighter);
483  drawPoly(vehiclePoly_PassengerCarBodyFront, 4.5);
484  glColor3d(0, 0, 0);
485  drawPoly(vehiclePoly_PassengerFrontGlass, 4.5);
486  break;
487  case SVS_PASSENGER_VAN:
488  drawPoly(vehiclePoly_PassengerVanBody, 4);
489  GLHelper::setColor(lighter);
490  drawPoly(vehiclePoly_PassengerVanBodyFront, 4.5);
491  glColor3d(0, 0, 0);
492  drawPoly(vehiclePoly_PassengerVanFrontGlass, 4.5);
493  drawPoly(vehiclePoly_PassengerVanRightGlass, 4.5);
494  drawPoly(vehiclePoly_PassengerVanLeftGlass, 4.5);
495  drawPoly(vehiclePoly_PassengerVanBackGlass, 4.5);
496  break;
497  case SVS_DELIVERY:
498  drawPoly(vehiclePoly_PassengerVanBody, 4);
499  GLHelper::setColor(lighter);
500  drawPoly(vehiclePoly_PassengerVanBodyFront, 4.5);
501  glColor3d(0, 0, 0);
502  drawPoly(vehiclePoly_PassengerVanFrontGlass, 4.5);
503  drawPoly(vehiclePoly_DeliveryMediumRightGlass, 4.5);
504  drawPoly(vehiclePoly_DeliveryMediumLeftGlass, 4.5);
505  break;
506  case SVS_TRANSPORT:
509  glScaled(1. / (length), 1, 1.);
510  drawPoly(vehiclePoly_TransportBody, 4);
511  glColor3d(0, 0, 0);
512  drawPoly(vehiclePoly_TransportFrontGlass, 4.5);
513  drawPoly(vehiclePoly_TransportRightGlass, 4.5);
514  drawPoly(vehiclePoly_TransportLeftGlass, 4.5);
515  break;
516  case SVS_BUS:
517  case SVS_BUS_TROLLEY:
519  case SVS_BUS_CITY: {
520  SUMOReal ml = length;
521  glScaled(1. / (length), 1, 1.);
522  glTranslated(0, 0, .04);
523  glBegin(GL_TRIANGLE_FAN);
524  glVertex2d(ml / 2., 0);
525  glVertex2d(0, 0);
526  glVertex2d(0, -.45);
527  glVertex2d(0 + .05, -.5);
528  glVertex2d(ml - .05, -.5);
529  glVertex2d(ml, -.45);
530  glVertex2d(ml, .45);
531  glVertex2d(ml - .05, .5);
532  glVertex2d(0 + .05, .5);
533  glVertex2d(0, .45);
534  glVertex2d(0, 0);
535  glEnd();
536  glTranslated(0, 0, -.04);
537 
538  glTranslated(0, 0, .045);
539  glColor3d(0, 0, 0);
540  glBegin(GL_QUADS);
541  glVertex2d(0 + .05, .48);
542  glVertex2d(0 + .05, -.48);
543  glVertex2d(0 + .15, -.48);
544  glVertex2d(0 + .15, .48);
545 
546  glVertex2d(ml - .1, .45);
547  glVertex2d(ml - .1, -.45);
548  glVertex2d(ml - .05, -.45);
549  glVertex2d(ml - .05, .45);
550 
551  glVertex2d(0 + .20, .49);
552  glVertex2d(0 + .20, .45);
553  glVertex2d(ml - .20, .45);
554  glVertex2d(ml - .20, .49);
555 
556  glVertex2d(0 + .20, -.49);
557  glVertex2d(0 + .20, -.45);
558  glVertex2d(ml - .20, -.45);
559  glVertex2d(ml - .20, -.49);
560 
561  glEnd();
562  glTranslated(0, 0, -.045);
563  }
564  break;
565  case SVS_BUS_OVERLAND:
566  case SVS_RAIL:
567  drawAction_drawRailCarriages(s, 25.0, 1);
568  break;
569  case SVS_RAIL_LIGHT:
571  break;
572  case SVS_RAIL_CITY:
574  break;
575  case SVS_RAIL_SLOW:
576  drawAction_drawRailCarriages(s, 15.0, 1);
577  break;
578  case SVS_RAIL_FAST:
579  drawAction_drawRailCarriages(s, 40.0, 1);
580  break;
581  case SVS_RAIL_CARGO:
583  break;
584  case SVS_E_VEHICLE:
585  drawPoly(vehiclePoly_EVehicleBody, 4);
586  glColor3d(0, 0, 0);
587  drawPoly(vehiclePoly_EVehicleFrontGlass, 4.5);
588  glTranslated(0, 0, .048);
589  GLHelper::setColor(current);
590  glBegin(GL_QUADS);
591  glVertex2d(.3, .5);
592  glVertex2d(.35, .5);
593  glVertex2d(.35, -.5);
594  glVertex2d(.3, -.5);
595 
596  glVertex2d(.3, -.05);
597  glVertex2d(.7, -.05);
598  glVertex2d(.7, .05);
599  glVertex2d(.3, .05);
600 
601  glVertex2d(.7, .5);
602  glVertex2d(.65, .5);
603  glVertex2d(.65, -.5);
604  glVertex2d(.7, -.5);
605  glEnd();
606  glTranslated(0, 0, -.048);
607  //drawPoly(vehiclePoly_EVehicleBackGlass, 4.5);
608  break;
609  case SVS_ANT:
610  glPushMatrix();
611  // ant is stretched via vehicle length
612  GLHelper::setColor(darker);
613  // draw left side
614  GLHelper::drawBoxLine(Position(-0.2, -.10), 350, 0.5, .02);
615  GLHelper::drawBoxLine(Position(-0.3, -.50), 240, 0.4, .03);
616  GLHelper::drawBoxLine(Position(0.3, -.10), 340, 0.8, .03);
617  GLHelper::drawBoxLine(Position(0.05, -.80), 290, 0.6, .04);
618  GLHelper::drawBoxLine(Position(0.4, -.10), 20, 0.8, .03);
619  GLHelper::drawBoxLine(Position(0.65, -.80), 75, 0.6, .04);
620  GLHelper::drawBoxLine(Position(0.5, -.10), 55, 0.8, .04);
621  GLHelper::drawBoxLine(Position(1.1, -.55), 90, 0.6, .04);
622  // draw right side
623  GLHelper::drawBoxLine(Position(-0.2, .10), 190, 0.5, .02);
624  GLHelper::drawBoxLine(Position(-0.3, .50), 300, 0.4, .03);
625  GLHelper::drawBoxLine(Position(0.3, .10), 200, 0.8, .03);
626  GLHelper::drawBoxLine(Position(0.05, .80), 250, 0.6, .04);
627  GLHelper::drawBoxLine(Position(0.4, .10), 160, 0.8, .03);
628  GLHelper::drawBoxLine(Position(0.65, .80), 105, 0.6, .04);
629  GLHelper::drawBoxLine(Position(0.5, .10), 125, 0.8, .04);
630  GLHelper::drawBoxLine(Position(1.1, .55), 90, 0.6, .04);
631  // draw body
632  GLHelper::setColor(current);
633  glTranslated(0, 0, 0.1);
635  glTranslated(.4, 0, 0);
637  glTranslated(.4, 0, 0);
639  glPopMatrix();
640  break;
641  default: // same as passenger
643  glColor3d(1, 1, 1);
644  drawPoly(vehiclePoly_PassengerCarBodyFront, 4.5);
645  glColor3d(0, 0, 0);
646  drawPoly(vehiclePoly_PassengerFrontGlass, 4.5);
647  break;
648  }
649 
650  // draw decorations
651  switch (shape) {
652  case SVS_PEDESTRIAN:
653  break;
654  case SVS_BICYCLE:
655  //glScaled(length, 1, 1.);
656  glBegin(GL_TRIANGLE_FAN);
657  glVertex2d(1 / 2., 0);
658  glVertex2d(0, 0);
659  glVertex2d(0, -.03);
660  glVertex2d(0 + .05, -.05);
661  glVertex2d(1 - .05, -.05);
662  glVertex2d(1, -.03);
663  glVertex2d(1, .03);
664  glVertex2d(1 - .05, .05);
665  glVertex2d(0 + .05, .05);
666  glVertex2d(0, .03);
667  glVertex2d(0, 0);
668  glEnd();
669  break;
670  case SVS_MOTORCYCLE:
671  //glScaled(length, 1, 1.);
672  glBegin(GL_TRIANGLE_FAN);
673  glVertex2d(1 / 2., 0);
674  glVertex2d(0, 0);
675  glVertex2d(0, -.03);
676  glVertex2d(0 + .05, -.2);
677  glVertex2d(1 - .05, -.2);
678  glVertex2d(1, -.03);
679  glVertex2d(1, .03);
680  glVertex2d(1 - .05, .2);
681  glVertex2d(0 + .05, .2);
682  glVertex2d(0, .03);
683  glVertex2d(0, 0);
684  glEnd();
685  break;
686  case SVS_PASSENGER:
687  case SVS_PASSENGER_SEDAN:
688  drawPoly(vehiclePoly_PassengerSedanRightGlass, 4.5);
689  drawPoly(vehiclePoly_PassengerSedanLeftGlass, 4.5);
690  drawPoly(vehiclePoly_PassengerSedanBackGlass, 4.5);
691  break;
693  drawPoly(vehiclePoly_PassengerHatchbackRightGlass, 4.5);
694  drawPoly(vehiclePoly_PassengerHatchbackLeftGlass, 4.5);
695  drawPoly(vehiclePoly_PassengerHatchbackBackGlass, 4.5);
696  break;
697  case SVS_PASSENGER_WAGON:
698  drawPoly(vehiclePoly_PassengerWagonRightGlass, 4.5);
699  drawPoly(vehiclePoly_PassengerWagonLeftGlass, 4.5);
700  drawPoly(vehiclePoly_PassengerWagonBackGlass, 4.5);
701  break;
702  case SVS_PASSENGER_VAN:
703  case SVS_DELIVERY:
704  break;
705  case SVS_TRANSPORT:
706  GLHelper::setColor(current);
707  GLHelper::drawBoxLine(Position(2.3, 0), 90., length - 2.3, .5);
708  break;
710  GLHelper::setColor(current);
711  GLHelper::drawBoxLine(Position(2.8, 0), 90., length - 2.8, .5);
712  break;
713  case SVS_TRANSPORT_1TRAILER: {
714  GLHelper::setColor(current);
715  SUMOReal l = length - 2.3;
716  l = l / 2.;
717  GLHelper::drawBoxLine(Position(2.3, 0), 90., l, .5);
718  GLHelper::drawBoxLine(Position(2.3 + l + .5, 0), 90., l - .5, .5);
719  break;
720  }
721  case SVS_BUS_TROLLEY:
722  glPushMatrix();
723  glTranslated(0, 0, .1);
724  GLHelper::setColor(darker);
725  GLHelper::drawBoxLine(Position(3.8, 0), 90., 1, .3);
726  glTranslated(0, 0, .1);
727  glColor3d(0, 0, 0);
728  GLHelper::drawBoxLine(Position(4.3, .2), 90., 1, .06);
729  GLHelper::drawBoxLine(Position(4.3, -.2), 90., 1, .06);
730  GLHelper::drawBoxLine(Position(5.3, .2), 90., 3, .03);
731  GLHelper::drawBoxLine(Position(5.3, -.2), 90., 3, .03);
732  glPopMatrix();
733  break;
734  case SVS_BUS:
735  case SVS_BUS_CITY:
737  case SVS_BUS_OVERLAND:
738  case SVS_RAIL:
739  case SVS_RAIL_LIGHT:
740  case SVS_RAIL_CITY:
741  case SVS_RAIL_SLOW:
742  case SVS_RAIL_FAST:
743  case SVS_RAIL_CARGO:
744  case SVS_E_VEHICLE:
745  case SVS_ANT:
746  break;
747  default: // same as passenger/sedan
748  drawPoly(vehiclePoly_PassengerSedanRightGlass, 4.5);
749  drawPoly(vehiclePoly_PassengerSedanLeftGlass, 4.5);
750  drawPoly(vehiclePoly_PassengerSedanBackGlass, 4.5);
751  break;
752  }
753  /*
754  glBegin(GL_TRIANGLE_FAN);
755  glVertex2d(.5,.5); // center - strip begin
756  glVertex2d(0, .5); // center, front
757  glVertex2d(0, .8); // ... clockwise ... (vehicle right side)
758  glVertex2d(0.08, .94);
759  glVertex2d(0.25, 1.);
760  glVertex2d(0.95, 1.);
761  glVertex2d(1., .9);
762  glVertex2d(1., .1); // (vehicle left side)
763  glVertex2d(0.95, 0.);
764  glVertex2d(0.25, 0.);
765  glVertex2d(0.08, .06);
766  glVertex2d(0, .2); //
767  glVertex2d(0, .5); // center, front (close)
768  glEnd();
769 
770  glPolygonOffset(0, -4.5);
771  glColor3d(1, 1, 1); // front
772  glBegin(GL_TRIANGLE_FAN);
773  glVertex2d(0.1,0.5);
774  glVertex2d(0.025,0.5);
775  glVertex2d(0.025,0.75);
776  glVertex2d(0.27,0.9);
777  glVertex2d(0.27,0.1);
778  glVertex2d(0.025,0.25);
779  glVertex2d(0.025,0.5);
780  glEnd();
781 
782  glColor3d(0, 0, 0); // front glass
783  glBegin(GL_TRIANGLE_FAN);
784  glVertex2d(0.35,0.5);
785  glVertex2d(0.3,0.5);
786  glVertex2d(0.3,0.9);
787  glVertex2d(0.43,0.8);
788  glVertex2d(0.43,0.2);
789  glVertex2d(0.3,0.1);
790  glVertex2d(0.3,0.5);
791  glEnd();
792 
793  glBegin(GL_TRIANGLE_FAN); // back glass
794  glVertex2d(0.92,0.5);
795  glVertex2d(0.90,0.5);
796  glVertex2d(0.90,0.8);
797  glVertex2d(0.95,0.9);
798  glVertex2d(0.95,0.1);
799  glVertex2d(0.90,0.2);
800  glVertex2d(0.90,0.5);
801  glEnd();
802 
803  glBegin(GL_TRIANGLE_FAN); // right glass
804  glVertex2d(0.36,0.07);
805  glVertex2d(0.34,0.03);
806  glVertex2d(0.94,0.03);
807  glVertex2d(0.87,0.13);
808  glVertex2d(0.45,0.13);
809  glVertex2d(0.34,0.03);
810  glEnd();
811 
812  glBegin(GL_TRIANGLE_FAN); // left glass
813  glVertex2d(0.36,1.-0.07);
814  glVertex2d(0.34,1.-0.03);
815  glVertex2d(0.94,1.-0.03);
816  glVertex2d(0.87,1.-0.13);
817  glVertex2d(0.45,1.-0.13);
818  glVertex2d(0.34,1.-0.03);
819  glEnd();
820  */
821 
822  glPopMatrix();
823 }
824 
825 
826 bool
828  const std::string& file = getVehicleType().getImgFile();
829  if (file != "") {
830  int textureID = GUITexturesHelper::getTextureID(file);
831  if (textureID > 0) {
832  if (length < 0) {
834  }
835  const SUMOReal halfWidth = getVehicleType().getWidth() / 2.0 * s.vehicleExaggeration;
836  GUITexturesHelper::drawTexturedBox(textureID, -halfWidth, 0, halfWidth, length);
837  return true;
838  }
839  }
840  return false;
841 }
842 
843 
844 #define BLINKER_POS_FRONT .5
845 #define BLINKER_POS_BACK .5
846 
847 inline void
848 drawAction_drawBlinker(const GUIVehicle& veh, double dir) {
849  glColor3d(1.f, .8f, 0);
850  glPushMatrix();
851  glTranslated(dir, BLINKER_POS_FRONT, -0.1);
853  glPopMatrix();
854  glPushMatrix();
855  glTranslated(dir, veh.getVehicleType().getLength() - BLINKER_POS_BACK, -0.1);
857  glPopMatrix();
858 }
859 
860 
861 inline void
864  return;
865  }
866  const double offset = MAX2(.5 * veh.getVehicleType().getWidth(), .4);
868  drawAction_drawBlinker(veh, -offset);
869  }
871  drawAction_drawBlinker(veh, offset);;
872  }
874  drawAction_drawBlinker(veh, -offset);
875  drawAction_drawBlinker(veh, offset);
876  }
877 }
878 
879 
880 inline void
883  return;
884  }
885  glColor3f(1.f, .2f, 0);
886  glPushMatrix();
887  glTranslated(-veh.getVehicleType().getWidth() * 0.5, veh.getVehicleType().getLength(), -0.1);
889  glPopMatrix();
890  glPushMatrix();
891  glTranslated(veh.getVehicleType().getWidth() * 0.5, veh.getVehicleType().getLength(), -0.1);
893  glPopMatrix();
894 }
895 
896 
897 void
899  glPushName(getGlID());
900  glPushMatrix();
901  Position p1 = getPosition();
902  // one seat in the center of the vehicle by default
904  glTranslated(p1.x(), p1.y(), getType());
905  glRotated(getAngle(), 0, 0, 1);
906  // set lane color
907  setColor(s);
908  // scale
909  SUMOReal upscale = s.vehicleExaggeration;
910  glScaled(upscale, upscale, 1);
911  /*
912  MSLCM_DK2004 &m2 = static_cast<MSLCM_DK2004&>(veh->getLaneChangeModel());
913  if((m2.getState()&LCA_URGENT)!=0) {
914  glColor3d(1, .4, .4);
915  } else if((m2.getState()&LCA_SPEEDGAIN)!=0) {
916  glColor3d(.4, .4, 1);
917  } else {
918  glColor3d(.4, 1, .4);
919  }
920  */
921  // draw the vehicle
922  switch (s.vehicleQuality) {
923  case 0:
925  break;
926  case 1:
928  break;
929  case 2:
931  break;
932  case 3:
933  default:
934  // draw as image but take special care for drawing trains
935  // XXX handle default carriage lenghts someplace else
936  switch (getVehicleType().getGuiShape()) {
937  case SVS_RAIL:
938  drawAction_drawRailCarriages(s, 25.0, 1, true);
939  break;
940  case SVS_RAIL_LIGHT:
941  drawAction_drawRailCarriages(s, 38.0, true);
942  break;
943  case SVS_RAIL_CITY:
944  drawAction_drawRailCarriages(s, 25.0, true);
945  break;
946  case SVS_RAIL_SLOW:
947  drawAction_drawRailCarriages(s, 15.0, 1, true);
948  break;
949  case SVS_RAIL_FAST:
950  drawAction_drawRailCarriages(s, 40.0, 1, true);
951  break;
952  case SVS_RAIL_CARGO:
953  drawAction_drawRailCarriages(s, 20.0, true);
954  break;
955  default:
956  // draw normal vehicle
959  };
960  };
961  break;
962  }
963  if (s.drawMinGap) {
964  SUMOReal minGap = -getVehicleType().getMinGap();
965  glColor3d(0., 1., 0.);
966  glBegin(GL_LINES);
967  glVertex2d(0., 0);
968  glVertex2d(0., minGap);
969  glVertex2d(-.5, minGap);
970  glVertex2d(.5, minGap);
971  glEnd();
972  }
973  // draw the blinker and brakelights if wished
974  if (s.showBlinker) {
975  glTranslated(0, 0, .1);
976  switch (getVehicleType().getGuiShape()) {
977  case SVS_PEDESTRIAN:
978  case SVS_BICYCLE:
979  case SVS_ANT:
980  case SVS_RAIL:
981  case SVS_RAIL_LIGHT:
982  case SVS_RAIL_SLOW:
983  case SVS_RAIL_FAST:
984  case SVS_RAIL_CARGO:
985  // only SVS_RAIL_CITY has blinkers and brake lights
986  break;
987  default:
990  break;
991  }
992  }
993  // draw the wish to change the lane
994  if (s.drawLaneChangePreference) {
995  /*
996  if(gSelected.isSelected(GLO_VEHICLE, veh->getGlID())) {
997  MSLCM_DK2004 &m = static_cast<MSLCM_DK2004&>(veh->getLaneChangeModel());
998  glColor3d(.5, .5, 1);
999  glBegin(GL_LINES);
1000  glVertex2f(0, 0);
1001  glVertex2f(m.getChangeProbability(), .5);
1002  glEnd();
1003 
1004  glColor3d(1, 0, 0);
1005  glBegin(GL_LINES);
1006  glVertex2f(0.1, 0);
1007  glVertex2f(0.1, m.myMaxJam1);
1008  glEnd();
1009 
1010  glColor3d(0, 1, 0);
1011  glBegin(GL_LINES);
1012  glVertex2f(-0.1, 0);
1013  glVertex2f(-0.1, m.myTDist);
1014  glEnd();
1015  }
1016  */
1017  }
1018  // draw best lanes
1019  /*
1020  if (true) {
1021  const MSLane &l = veh->getLane();
1022  SUMOReal r1 = veh->allowedContinuationsLength(&l, 0);
1023  SUMOReal r2 = l.getLeftLane()!=0 ? veh->allowedContinuationsLength(l.getLeftLane(), 0) : 0;
1024  SUMOReal r3 = l.getRightLane()!=0 ? veh->allowedContinuationsLength(l.getRightLane(), 0) : 0;
1025  SUMOReal mmax = MAX3(r1, r2, r3);
1026  glBegin(GL_LINES);
1027  glVertex2f(0, 0);
1028  glVertex2f(0, r1/mmax/2.);
1029  glEnd();
1030  glBegin(GL_LINES);
1031  glVertex2f(.4, 0);
1032  glVertex2f(.4, r2/mmax/2.);
1033  glEnd();
1034  glBegin(GL_LINES);
1035  glVertex2f(-.4, 0);
1036  glVertex2f(-.4, r3/mmax/2.);
1037  glEnd();
1038  }
1039  */
1040  glPopMatrix();
1041  drawName(getPosition(-MIN2(getVehicleType().getLength() / 2, SUMOReal(5))),
1042  s.scale,
1043  getVehicleType().getGuiShape() == SVS_PEDESTRIAN ? s.personName : s.vehicleName);
1044  glPopName();
1045  if (myPersonDevice != 0) {
1046  const std::vector<MSPerson*>& ps = myPersonDevice->getPersons();
1047  size_t personIndex = 0;
1048  for (std::vector<MSPerson*>::const_iterator i = ps.begin(); i != ps.end(); ++i) {
1049  GUIPerson* person = dynamic_cast<GUIPerson*>(*i);
1050  assert(person != 0);
1051  person->setPositionInVehicle(getSeatPosition(personIndex++));
1052  person->drawGL(s);
1053  }
1054  }
1055 }
1056 
1057 
1058 void
1060  glPushName(getGlID());
1061  glPushMatrix();
1062  glTranslated(0, 0, getType() - .1); // don't draw on top of other cars
1064  drawBestLanes();
1065  }
1067  drawRoute(s, 0, 0.25);
1068  }
1070  if (getNumberReroutes() > 0) {
1071  const int noReroutePlus1 = getNumberReroutes() + 1;
1072  for (int i = noReroutePlus1 - 1; i >= 0; i--) {
1073  SUMOReal darken = SUMOReal(0.4) / SUMOReal(noReroutePlus1) * SUMOReal(i);
1074  drawRoute(s, i, darken);
1075  }
1076  } else {
1077  drawRoute(s, 0, 0.25);
1078  }
1079  }
1081  for (DriveItemVector::const_iterator i = myLFLinkLanes.begin(); i != myLFLinkLanes.end(); ++i) {
1082  if ((*i).myLink == 0) {
1083  continue;
1084  }
1085  MSLink* link = (*i).myLink;
1086  MSLane* via = link->getViaLaneOrLane();
1087  if (via != 0) {
1088  Position p = via->getShape()[0];
1089  if ((*i).mySetRequest) {
1090  glColor3d(0, .8, 0);
1091  } else {
1092  glColor3d(.8, 0, 0);
1093  }
1094  const SUMOTime leaveTime = (*i).myLink->getLeaveTime(
1095  (*i).myArrivalTime, (*i).myArrivalSpeed, (*i).getLeaveSpeed(), getVehicleType().getLengthWithGap());
1096  drawLinkItem(p, (*i).myArrivalTime, leaveTime, s.addExaggeration);
1097  // the time slot that ego vehicle uses when checking opened may
1098  // differ from the one it requests in setApproaching
1099  MSLink::ApproachingVehicleInformation avi = (*i).myLink->getApproaching(this);
1100  assert(avi.arrivalTime == (*i).myArrivalTime && avi.leavingTime == leaveTime);
1101  }
1102  }
1103  }
1104  glPopMatrix();
1105  glPopName();
1106 }
1107 
1108 
1109 void
1110 GUIVehicle::drawLinkItem(const Position& pos, SUMOTime arrivalTime, SUMOTime leaveTime, SUMOReal exagerate) {
1111  glTranslated(pos.x(), pos.y(), -.1);
1113  std::string times = toString(STEPS2TIME(arrivalTime)) + "/" + toString(STEPS2TIME(leaveTime));
1114  GLHelper::drawText(times.c_str(), Position(), .1, 1.6 * exagerate, RGBColor::GREEN, 0);
1115  glTranslated(-pos.x(), -pos.y(), .1);
1116 }
1117 
1118 const std::vector<MSVehicle::LaneQ>&
1120  myLock.lock();
1121  const std::vector<MSVehicle::LaneQ>& ret = MSVehicle::getBestLanes();
1122  myLock.unlock();
1123  return ret;
1124 }
1125 
1126 
1127 void
1129  const GUIColorer& c = s.vehicleColorer;
1130  if (!setFunctionalColor(c.getActive())) {
1132  }
1133 }
1134 
1135 
1136 bool
1137 GUIVehicle::setFunctionalColor(size_t activeScheme) const {
1138  switch (activeScheme) {
1139  case 0: {
1140  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
1142  return true;
1143  }
1144  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
1145  GLHelper::setColor(getVehicleType().getColor());
1146  return true;
1147  }
1148  if (&getRoute().getColor() != &RGBColor::DEFAULT_COLOR) {
1149  GLHelper::setColor(getRoute().getColor());
1150  return true;
1151  }
1152  return false;
1153  }
1154  case 2: {
1155  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
1157  return true;
1158  }
1159  return false;
1160  }
1161  case 3: {
1162  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
1163  GLHelper::setColor(getVehicleType().getColor());
1164  return true;
1165  }
1166  return false;
1167  }
1168  case 4: {
1169  if (&getRoute().getColor() != &RGBColor::DEFAULT_COLOR) {
1170  GLHelper::setColor(getRoute().getColor());
1171  return true;
1172  }
1173  return false;
1174  }
1175  case 5: {
1176  Position p = getRoute().getEdges()[0]->getLanes()[0]->getShape()[0];
1177  const Boundary& b = ((GUINet*) MSNet::getInstance())->getBoundary();
1178  Position center = b.getCenter();
1179  SUMOReal hue = 180. + atan2(center.x() - p.x(), center.y() - p.y()) * 180. / PI;
1180  SUMOReal sat = p.distanceTo(center) / center.distanceTo(Position(b.xmin(), b.ymin()));
1181  GLHelper::setColor(RGBColor::fromHSV(hue, sat, 1.));
1182  return true;
1183  }
1184  case 6: {
1185  Position p = getRoute().getEdges().back()->getLanes()[0]->getShape()[-1];
1186  const Boundary& b = ((GUINet*) MSNet::getInstance())->getBoundary();
1187  Position center = b.getCenter();
1188  SUMOReal hue = 180. + atan2(center.x() - p.x(), center.y() - p.y()) * 180. / PI;
1189  SUMOReal sat = p.distanceTo(center) / center.distanceTo(Position(b.xmin(), b.ymin()));
1190  GLHelper::setColor(RGBColor::fromHSV(hue, sat, 1.));
1191  return true;
1192  }
1193  case 7: {
1194  Position pb = getRoute().getEdges()[0]->getLanes()[0]->getShape()[0];
1195  Position pe = getRoute().getEdges().back()->getLanes()[0]->getShape()[-1];
1196  const Boundary& b = ((GUINet*) MSNet::getInstance())->getBoundary();
1197  SUMOReal hue = 180. + atan2(pb.x() - pe.x(), pb.y() - pe.y()) * 180. / PI;
1198  Position minp(b.xmin(), b.ymin());
1199  Position maxp(b.xmax(), b.ymax());
1200  SUMOReal sat = pb.distanceTo(pe) / minp.distanceTo(maxp);
1201  GLHelper::setColor(RGBColor::fromHSV(hue, sat, 1.));
1202  return true;
1203  }
1204  }
1205  return false;
1206 }
1207 
1208 
1209 SUMOReal
1210 GUIVehicle::getColorValue(size_t activeScheme) const {
1211  switch (activeScheme) {
1212  case 8:
1213  return getSpeed();
1214  case 9:
1215  return getWaitingSeconds();
1216  case 10:
1217  return getLastLaneChangeOffset();
1218  case 11:
1219  return getMaxSpeed();
1220  case 12:
1221  return getHBEFA_CO2Emissions();
1222  case 13:
1223  return getHBEFA_COEmissions();
1224  case 14:
1225  return getHBEFA_PMxEmissions();
1226  case 15:
1227  return getHBEFA_NOxEmissions();
1228  case 16:
1229  return getHBEFA_HCEmissions();
1230  case 17:
1231  return getHBEFA_FuelConsumption();
1232  case 18:
1234  case 19:
1235  if (getNumberReroutes() == 0) {
1236  return -1;
1237  }
1238  return getNumberReroutes();
1239  case 20:
1241  }
1242  return 0;
1243 }
1244 
1245 
1246 // ------------ Additional visualisations
1247 bool
1249  return myAdditionalVisualizations.find(parent) != myAdditionalVisualizations.end() && (myAdditionalVisualizations.find(parent)->second & which) != 0;
1250 }
1251 
1252 
1253 void
1255  if (myAdditionalVisualizations.find(parent) == myAdditionalVisualizations.end()) {
1256  myAdditionalVisualizations[parent] = 0;
1257  }
1258  myAdditionalVisualizations[parent] |= which;
1259  parent->addAdditionalGLVisualisation(this);
1260 }
1261 
1262 
1263 void
1265  myAdditionalVisualizations[parent] &= ~which;
1266  parent->removeAdditionalGLVisualisation(this);
1267 }
1268 
1269 
1270 void
1271 GUIVehicle::drawRoute(const GUIVisualizationSettings& s, int routeNo, SUMOReal darken) const {
1272  setColor(s);
1273  GLdouble colors[4];
1274  glGetDoublev(GL_CURRENT_COLOR, colors);
1275  colors[0] -= darken;
1276  if (colors[0] < 0) {
1277  colors[0] = 0;
1278  }
1279  colors[1] -= darken;
1280  if (colors[1] < 0) {
1281  colors[1] = 0;
1282  }
1283  colors[2] -= darken;
1284  if (colors[2] < 0) {
1285  colors[2] = 0;
1286  }
1287  colors[3] -= darken;
1288  if (colors[3] < 0) {
1289  colors[3] = 0;
1290  }
1291  glColor3dv(colors);
1292  if (routeNo == 0) {
1294  return;
1295  }
1296  --routeNo; // only prior routes are stored
1298 }
1299 
1300 
1301 void
1303  myLock.lock();
1304  std::vector<std::vector<MSVehicle::LaneQ> > bestLanes = myBestLanes;
1305  myLock.unlock();
1306  SUMOReal width = 0.5;
1307  for (std::vector<std::vector<MSVehicle::LaneQ> >::iterator j = bestLanes.begin(); j != bestLanes.end(); ++j) {
1308  std::vector<MSVehicle::LaneQ>& lanes = *j;
1309  SUMOReal gmax = -1;
1310  SUMOReal rmax = -1;
1311  for (std::vector<MSVehicle::LaneQ>::const_iterator i = lanes.begin(); i != lanes.end(); ++i) {
1312  gmax = MAX2((*i).length, gmax);
1313  rmax = MAX2((*i).occupation, rmax);
1314  }
1315  for (std::vector<MSVehicle::LaneQ>::const_iterator i = lanes.begin(); i != lanes.end(); ++i) {
1316  const PositionVector& shape = (*i).lane->getShape();
1317  SUMOReal g = (*i).length / gmax;
1318  SUMOReal r = (*i).occupation / rmax;
1319  glColor3d(r, g, 0);
1320  GLHelper::drawBoxLines(shape, width);
1321 
1322  PositionVector s1 = shape;
1323  s1.move2side((SUMOReal) .1);
1324  glColor3d(r, 0, 0);
1325  GLHelper::drawLine(s1);
1326  s1.move2side((SUMOReal) - .2);
1327  glColor3d(0, g, 0);
1328  GLHelper::drawLine(s1);
1329 
1330  glColor3d(r, g, 0);
1331  Position lastPos = shape[-1];
1332  }
1333  width = .2;
1334  }
1335 }
1336 
1337 
1338 void
1339 GUIVehicle::drawRouteHelper(const MSRoute& r, SUMOReal exaggeration) const {
1340  MSRouteIterator i = r.begin();
1341  for (; i != r.end(); ++i) {
1342  const GUILane* lane = static_cast<GUILane*>((*i)->getLanes()[0]);
1343  GLHelper::drawBoxLines(lane->getShape(), lane->getShapeRotations(), lane->getShapeLengths(), exaggeration);
1344  }
1345 }
1346 
1347 
1348 MSLane*
1349 GUIVehicle::getPreviousLane(MSLane* current, int& routeIndex) const {
1350  const bool isInternal = current->getEdge().getPurpose() == MSEdge::EDGEFUNCTION_INTERNAL;
1351  if (isInternal) {
1352  // route pointer still points to the previous lane
1353  return myRoute->getEdges()[routeIndex]->getLanes()[0];
1354  } else if (routeIndex == 0) {
1355  // there is no previous lane because the route has just begun
1356  return current;
1357  } else {
1358  // retrieve the previous internal edge
1359  routeIndex -= 1;
1360  const MSEdge* previous = myRoute->getEdges()[routeIndex];
1361 #ifdef HAVE_INTERNAL_LANES
1362  const MSEdge* previousInternal = previous->getInternalFollowingEdge(&current->getEdge());
1363 #else
1364  const MSEdge* previousInternal = 0;
1365 #endif
1366  if (previousInternal != 0) {
1367  return previousInternal->getLanes()[0];
1368  } else {
1369  // network without internal links, use previous edge instead
1370  return previous->getLanes()[0];
1371  }
1372  }
1373 }
1374 
1375 
1376 void
1377 GUIVehicle::drawAction_drawRailCarriages(const GUIVisualizationSettings& s, SUMOReal defaultLength, int firstPassengerCarriage, bool asImage) const {
1378  RGBColor current = GLHelper::getColor();
1379  RGBColor darker = current.changedBrightness(-51);
1380  const SUMOReal length = getVehicleType().getLength() * s.vehicleExaggeration;
1381  const SUMOReal halfWidth = getVehicleType().getWidth() / 2.0 * s.vehicleExaggeration;
1382  glPopMatrix(); // undo scaling and 90 degree rotation
1383  glPopMatrix(); // undo initial translation and rotation
1384  glPushMatrix();
1385  glPushMatrix();
1386  GLHelper::setColor(darker);
1387  const SUMOReal carriageGap = 1;
1388  const SUMOReal xCornerCut = 0.3;
1389  const SUMOReal yCornerCut = 0.4;
1390  // round to closest integer
1391  const int numCarriages = floor(length / (defaultLength + carriageGap) + 0.5);
1392  assert(numCarriages > 0);
1393  const SUMOReal carriageLengthWithGap = length / numCarriages;
1394  const SUMOReal carriageLength = carriageLengthWithGap - carriageGap;
1395  // lane on which the carriage front is situated
1396  MSLane* lane = myLane;
1397  int routeIndex = myCurrEdge - myRoute->begin();
1398  // lane on which the carriage back is situated
1399  MSLane* backLane = myLane;
1400  int backRouteIndex = routeIndex;
1401  // offsets of front and back
1402  SUMOReal carriageOffset = myState.pos();
1403  SUMOReal carriageBackOffset = myState.pos() - carriageLength;
1404  // handle seats
1405  int requiredSeats = getNumPassengers();
1406  if (requiredSeats > 0) {
1407  mySeatPositions.clear();
1408  }
1409  // draw individual carriages
1410  for (int i = 0; i < numCarriages; ++i) {
1411  while (carriageOffset < 0) {
1412  lane = getPreviousLane(lane, routeIndex);
1413  carriageOffset += lane->getLength();
1414  }
1415  while (carriageBackOffset < 0) {
1416  backLane = getPreviousLane(backLane, backRouteIndex);
1417  carriageBackOffset += backLane->getLength();
1418  }
1419  const Position front = lane->getShape().positionAtOffset2D(carriageOffset);
1420  const Position back = backLane->getShape().positionAtOffset2D(carriageBackOffset);
1421  const SUMOReal angle = atan2((front.x() - back.x()), (back.y() - front.y())) * (SUMOReal) 180.0 / (SUMOReal) PI;
1422  if (i >= firstPassengerCarriage) {
1423  computeSeats(front, back, requiredSeats);
1424  }
1425  glPushMatrix();
1426  glTranslated(front.x(), front.y(), getType());
1427  glRotated(angle, 0, 0, 1);
1428  if (!asImage || !drawAction_drawVehicleAsImage(s, carriageLength)) {
1429  glBegin(GL_TRIANGLE_FAN);
1430  glVertex2d(-halfWidth + xCornerCut, 0);
1431  glVertex2d(-halfWidth, yCornerCut);
1432  glVertex2d(-halfWidth, carriageLength - yCornerCut);
1433  glVertex2d(-halfWidth + xCornerCut, carriageLength);
1434  glVertex2d(halfWidth - xCornerCut, carriageLength);
1435  glVertex2d(halfWidth, carriageLength - yCornerCut);
1436  glVertex2d(halfWidth, yCornerCut);
1437  glVertex2d(halfWidth - xCornerCut, 0);
1438  glEnd();
1439  }
1440  glPopMatrix();
1441  carriageOffset -= carriageLengthWithGap;
1442  carriageBackOffset -= carriageLengthWithGap;
1443  GLHelper::setColor(current);
1444  }
1445 }
1446 
1447 
1448 const Position&
1449 GUIVehicle::getSeatPosition(size_t personIndex) const {
1451  return mySeatPositions[(int)MIN2(personIndex, mySeatPositions.size() - 1)];
1452 }
1453 
1454 
1455 int
1457  if (myPersonDevice != 0) {
1458  return (int)myPersonDevice->getPersons().size();
1459  }
1460  return 0;
1461 }
1462 
1463 
1464 void
1465 GUIVehicle::computeSeats(const Position& front, const Position& back, int& requiredSeats) const {
1466  if (requiredSeats <= 0) {
1467  return; // save some work
1468  }
1469  const Line l(front, back);
1470  const SUMOReal length = l.length2D();
1471  if (length < 4) {
1472  // small vehicle, sit at the center
1474  requiredSeats--;
1475  } else {
1476  for (SUMOReal p = 2; p <= length - 1; p += 1) {
1478  requiredSeats--;
1479  }
1480  }
1481 }
1482 
1483 
1484 SUMOReal
1487 }
1488 
1489 
1490 std::string
1492  std::string result = "";
1493  if (isParking()) {
1494  result += "parking";
1495  } else if (isStopped()) {
1496  result += "stopped";
1497  } else {
1498  return "";
1499  }
1500  if (myStops.front().triggered) {
1501  result += ", triggered";
1502  } else {
1503  result += ", duration=" + time2string(myStops.front().duration);
1504  }
1505  return result;
1506 }
1507 
1508 
1509 void
1511  if (myLFLinkLanes.size() == 0) {
1512  return;
1513  }
1514  const DriveProcessItem& dpi = myLFLinkLanes[0];
1515  if (dpi.myLink == 0) {
1516  return;
1517  }
1518  std::vector<const SUMOVehicle*> blockingFoes;
1520  getImpatience(), getCarFollowModel().getMaxDecel(), getWaitingTime(), &blockingFoes);
1521  for (std::vector<const SUMOVehicle*>::const_iterator it = blockingFoes.begin(); it != blockingFoes.end(); ++it) {
1522  gSelected.select(static_cast<const GUIVehicle*>(*it)->getGlID());
1523  }
1524 #ifdef HAVE_INTERNAL_LANES
1525  const MSLink::LinkLeaders linkLeaders = (dpi.myLink)->getLeaderInfo(myLane->getLength() - getPositionOnLane() - getVehicleType().getMinGap());
1526  for (MSLink::LinkLeaders::const_iterator it = linkLeaders.begin(); it != linkLeaders.end(); ++it) {
1527  // the vehicle to enter the junction first has priority
1528  const MSVehicle* leader = it->first;
1529  if ((static_cast<const GUIVehicle*>(leader))->myLinkLeaders.count(getID()) == 0) {
1530  // leader isn't already following us, now we follow it
1531  gSelected.select(static_cast<const GUIVehicle*>(leader)->getGlID());
1532  }
1533  }
1534 #endif
1535 }
1536 
1537 
1538 #ifdef HAVE_OSG
1539 void
1540 GUIVehicle::updateColor(GUIOSGView* view) {
1541  const GUIVisualizationSettings* s = view->getVisualisationSettings();
1543  myGeom[view]->setColor(osg::Vec4(col.red() / 255., col.green() / 255., col.blue() / 255., col.alpha() / 255.));
1544 }
1545 #endif
1546 
1547 /****************************************************************************/
1548