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