SUMO - Simulation of Urban MObility
GUIVehicle.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00009 // A MSVehicle extended by some values for usage within the gui
00010 /****************************************************************************/
00011 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00012 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00013 /****************************************************************************/
00014 //
00015 //   This file is part of SUMO.
00016 //   SUMO is free software: you can redistribute it and/or modify
00017 //   it under the terms of the GNU General Public License as published by
00018 //   the Free Software Foundation, either version 3 of the License, or
00019 //   (at your option) any later version.
00020 //
00021 /****************************************************************************/
00022 
00023 
00024 // ===========================================================================
00025 // included modules
00026 // ===========================================================================
00027 #ifdef _MSC_VER
00028 #include <windows_config.h>
00029 #else
00030 #include <config.h>
00031 #endif
00032 
00033 #ifdef WIN32
00034 #include <windows.h>
00035 #endif
00036 
00037 #include <GL/gl.h>
00038 
00039 #include <cmath>
00040 #include <vector>
00041 #include <string>
00042 #include <foreign/polyfonts/polyfonts.h>
00043 #include <utils/common/StringUtils.h>
00044 #include <utils/common/SUMOVehicleParameter.h>
00045 #include <utils/gui/windows/GUISUMOAbstractView.h>
00046 #include <utils/gui/windows/GUIAppEnum.h>
00047 #include <utils/gui/div/GUIParameterTableWindow.h>
00048 #include <utils/gui/div/GUIGlobalSelection.h>
00049 #include <utils/gui/div/GLHelper.h>
00050 #include <utils/gui/div/GLObjectValuePassConnector.h>
00051 #include <microsim/MSVehicle.h>
00052 #include <microsim/logging/CastingFunctionBinding.h>
00053 #include <microsim/logging/FunctionBinding.h>
00054 #include <microsim/MSVehicleControl.h>
00055 #include <microsim/MSAbstractLaneChangeModel.h>
00056 #include <microsim/devices/MSDevice_Vehroutes.h>
00057 #include <gui/GUIApplicationWindow.h>
00058 #include <gui/GUIGlobals.h>
00059 #include "GUIVehicle.h"
00060 #include "GUINet.h"
00061 #include "GUIEdge.h"
00062 
00063 
00064 #ifdef CHECK_MEMORY_LEAKS
00065 #include <foreign/nvwa/debug_new.h>
00066 #endif // CHECK_MEMORY_LEAKS
00067 
00068 
00069 // ===========================================================================
00070 // FOX callback mapping
00071 // ===========================================================================
00072 FXDEFMAP(GUIVehicle::GUIVehiclePopupMenu) GUIVehiclePopupMenuMap[] = {
00073     FXMAPFUNC(SEL_COMMAND, MID_SHOW_ALLROUTES, GUIVehicle::GUIVehiclePopupMenu::onCmdShowAllRoutes),
00074     FXMAPFUNC(SEL_COMMAND, MID_HIDE_ALLROUTES, GUIVehicle::GUIVehiclePopupMenu::onCmdHideAllRoutes),
00075     FXMAPFUNC(SEL_COMMAND, MID_SHOW_CURRENTROUTE, GUIVehicle::GUIVehiclePopupMenu::onCmdShowCurrentRoute),
00076     FXMAPFUNC(SEL_COMMAND, MID_HIDE_CURRENTROUTE, GUIVehicle::GUIVehiclePopupMenu::onCmdHideCurrentRoute),
00077     FXMAPFUNC(SEL_COMMAND, MID_SHOW_BEST_LANES, GUIVehicle::GUIVehiclePopupMenu::onCmdShowBestLanes),
00078     FXMAPFUNC(SEL_COMMAND, MID_HIDE_BEST_LANES, GUIVehicle::GUIVehiclePopupMenu::onCmdHideBestLanes),
00079     FXMAPFUNC(SEL_COMMAND, MID_START_TRACK, GUIVehicle::GUIVehiclePopupMenu::onCmdStartTrack),
00080     FXMAPFUNC(SEL_COMMAND, MID_STOP_TRACK, GUIVehicle::GUIVehiclePopupMenu::onCmdStopTrack),
00081     FXMAPFUNC(SEL_COMMAND, MID_SHOW_LFLINKITEMS, GUIVehicle::GUIVehiclePopupMenu::onCmdShowLFLinkItems),
00082     FXMAPFUNC(SEL_COMMAND, MID_HIDE_LFLINKITEMS, GUIVehicle::GUIVehiclePopupMenu::onCmdHideLFLinkItems),
00083 };
00084 
00085 // Object implementation
00086 FXIMPLEMENT(GUIVehicle::GUIVehiclePopupMenu, GUIGLObjectPopupMenu, GUIVehiclePopupMenuMap, ARRAYNUMBER(GUIVehiclePopupMenuMap))
00087 
00088 
00089 
00090 // ===========================================================================
00091 // data definitions
00092 // ===========================================================================
00093 /* -------------------------------------------------------------------------
00094  * drawed shapes
00095  * ----------------------------------------------------------------------- */
00096 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 };
00097 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 };
00098 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 };
00099 double vehiclePoly_PassengerSedanRightGlass[] = { 0.36, -.43,  0.34, -.47,  0.77, -.47,  0.67, -.37,  0.45, -.37,  0.34, -.47,  -10000 };
00100 double vehiclePoly_PassengerSedanLeftGlass[] = { 0.36, .43,  0.34, .47,  0.77, .47,  0.67, .37,  0.45, .37,  0.34, .47,  -10000 };
00101 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 };
00102 double vehiclePoly_PassengerHatchbackRightGlass[] = { 0.36, -.43,  0.34, -.47,  0.94, -.47,  0.80, -.37,  0.45, -.37,  0.34, -.47,  -10000 };
00103 double vehiclePoly_PassengerHatchbackLeftGlass[] = { 0.36, .43,  0.34, .47,  0.94, .47,  0.80, .37,  0.45, .37,  0.34, .47,  -10000 };
00104 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 };
00105 double vehiclePoly_PassengerWagonRightGlass[] = { 0.36, -.43,  0.34, -.47,  0.94, -.47,  0.87, -.37,  0.45, -.37,  0.34, -.47,  -10000 };
00106 double vehiclePoly_PassengerWagonLeftGlass[] = { 0.36, .43,  0.34, .47,  0.94, .47,  0.87, .37,  0.45, .37,  0.34, .47,  -10000 };
00107 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 };
00108 
00109 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 };
00110 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 };
00111 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 };
00112 double vehiclePoly_PassengerVanRightGlass[] = { 0.36, -.43,  0.20, -.47,  0.98, -.47,  0.91, -.37,  0.31, -.37,  0.20, -.47,  -10000 };
00113 double vehiclePoly_PassengerVanLeftGlass[] = { 0.36, .43,  0.20, .47,  0.98, .47,  0.91, .37,  0.31, .37,  0.20, .47,  -10000 };
00114 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 };
00115 
00116 double vehiclePoly_DeliveryMediumRightGlass[] = { 0.21, -.43,  0.20, -.47,  0.38, -.47,  0.38, -.37,  0.31, -.37,  0.20, -.47,  -10000 };
00117 double vehiclePoly_DeliveryMediumLeftGlass[] = { 0.21, .43,  0.20, .47,  0.38, .47,  0.38, .37,  0.31, .37,  0.20, .47,  -10000 };
00118 
00119 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 };
00120 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 };
00121 double vehiclePoly_TransportRightGlass[] = { 0.36, -.47,  0.10, -.48,  1.25, -.48,  1.25, -.4,  0.3, -.4,  0.10, -.48,  -10000 };
00122 double vehiclePoly_TransportLeftGlass[] = { 0.36, .47,  0.10, .48,  1.25, .48,  1.25, .4,  0.3, .4,  0.10, .48,  -10000 };
00123 
00124 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 };
00125 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 };
00126 //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 };
00127 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 };
00128 
00129 
00130 // ===========================================================================
00131 // method definitions
00132 // ===========================================================================
00133 /* -------------------------------------------------------------------------
00134  * GUIVehicle::GUIVehiclePopupMenu - methods
00135  * ----------------------------------------------------------------------- */
00136 GUIVehicle::GUIVehiclePopupMenu::GUIVehiclePopupMenu(
00137     GUIMainWindow& app, GUISUMOAbstractView& parent,
00138     GUIGlObject& o, std::map<GUISUMOAbstractView*, int> &additionalVisualizations)
00139     : GUIGLObjectPopupMenu(app, parent, o), myVehiclesAdditionalVisualizations(additionalVisualizations) {
00140 }
00141 
00142 
00143 GUIVehicle::GUIVehiclePopupMenu::~GUIVehiclePopupMenu() {}
00144 
00145 
00146 long
00147 GUIVehicle::GUIVehiclePopupMenu::onCmdShowAllRoutes(FXObject*, FXSelector, void*) {
00148     assert(myObject->getType() == GLO_VEHICLE);
00149     if (!static_cast<GUIVehicle*>(myObject)->hasActiveAddVisualisation(myParent, VO_SHOW_ALL_ROUTES)) {
00150         static_cast<GUIVehicle*>(myObject)->addActiveAddVisualisation(myParent, VO_SHOW_ALL_ROUTES);
00151     }
00152     return 1;
00153 }
00154 
00155 long
00156 GUIVehicle::GUIVehiclePopupMenu::onCmdHideAllRoutes(FXObject*, FXSelector, void*) {
00157     assert(myObject->getType() == GLO_VEHICLE);
00158     static_cast<GUIVehicle*>(myObject)->removeActiveAddVisualisation(myParent, VO_SHOW_ALL_ROUTES);
00159     return 1;
00160 }
00161 
00162 
00163 long
00164 GUIVehicle::GUIVehiclePopupMenu::onCmdShowCurrentRoute(FXObject*, FXSelector, void*) {
00165     assert(myObject->getType() == GLO_VEHICLE);
00166     if (!static_cast<GUIVehicle*>(myObject)->hasActiveAddVisualisation(myParent, VO_SHOW_ROUTE)) {
00167         static_cast<GUIVehicle*>(myObject)->addActiveAddVisualisation(myParent, VO_SHOW_ROUTE);
00168     }
00169     return 1;
00170 }
00171 
00172 long
00173 GUIVehicle::GUIVehiclePopupMenu::onCmdHideCurrentRoute(FXObject*, FXSelector, void*) {
00174     assert(myObject->getType() == GLO_VEHICLE);
00175     static_cast<GUIVehicle*>(myObject)->removeActiveAddVisualisation(myParent, VO_SHOW_ROUTE);
00176     return 1;
00177 }
00178 
00179 
00180 long
00181 GUIVehicle::GUIVehiclePopupMenu::onCmdShowBestLanes(FXObject*, FXSelector, void*) {
00182     assert(myObject->getType() == GLO_VEHICLE);
00183     if (!static_cast<GUIVehicle*>(myObject)->hasActiveAddVisualisation(myParent, VO_SHOW_BEST_LANES)) {
00184         static_cast<GUIVehicle*>(myObject)->addActiveAddVisualisation(myParent, VO_SHOW_BEST_LANES);
00185     }
00186     return 1;
00187 }
00188 
00189 long
00190 GUIVehicle::GUIVehiclePopupMenu::onCmdHideBestLanes(FXObject*, FXSelector, void*) {
00191     assert(myObject->getType() == GLO_VEHICLE);
00192     static_cast<GUIVehicle*>(myObject)->removeActiveAddVisualisation(myParent, VO_SHOW_BEST_LANES);
00193     return 1;
00194 }
00195 
00196 
00197 long
00198 GUIVehicle::GUIVehiclePopupMenu::onCmdStartTrack(FXObject*, FXSelector, void*) {
00199     assert(myObject->getType() == GLO_VEHICLE);
00200     if (!static_cast<GUIVehicle*>(myObject)->hasActiveAddVisualisation(myParent, VO_TRACKED)) {
00201         myParent->startTrack(static_cast<GUIVehicle*>(myObject)->getGlID());
00202         static_cast<GUIVehicle*>(myObject)->addActiveAddVisualisation(myParent, VO_TRACKED);
00203     }
00204     return 1;
00205 }
00206 
00207 long
00208 GUIVehicle::GUIVehiclePopupMenu::onCmdStopTrack(FXObject*, FXSelector, void*) {
00209     assert(myObject->getType() == GLO_VEHICLE);
00210     static_cast<GUIVehicle*>(myObject)->removeActiveAddVisualisation(myParent, VO_TRACKED);
00211     myParent->stopTrack();
00212     return 1;
00213 }
00214 
00215 
00216 long
00217 GUIVehicle::GUIVehiclePopupMenu::onCmdShowLFLinkItems(FXObject*, FXSelector, void*) {
00218     assert(myObject->getType() == GLO_VEHICLE);
00219     if (!static_cast<GUIVehicle*>(myObject)->hasActiveAddVisualisation(myParent, VO_SHOW_LFLINKITEMS)) {
00220         static_cast<GUIVehicle*>(myObject)->addActiveAddVisualisation(myParent, VO_SHOW_LFLINKITEMS);
00221     }
00222     return 1;
00223 }
00224 
00225 long
00226 GUIVehicle::GUIVehiclePopupMenu::onCmdHideLFLinkItems(FXObject*, FXSelector, void*) {
00227     assert(myObject->getType() == GLO_VEHICLE);
00228     static_cast<GUIVehicle*>(myObject)->removeActiveAddVisualisation(myParent, VO_SHOW_LFLINKITEMS);
00229     return 1;
00230 }
00231 
00232 
00233 /* -------------------------------------------------------------------------
00234  * GUIVehicle - methods
00235  * ----------------------------------------------------------------------- */
00236 GUIVehicle::GUIVehicle(SUMOVehicleParameter* pars, const MSRoute* route,
00237                        const MSVehicleType* type,
00238                        int vehicleIndex)
00239     : MSVehicle(pars, route, type, vehicleIndex),
00240       GUIGlObject(GLO_VEHICLE, pars->id) {
00241     // as it is possible to show all vehicle routes, we have to store them... (bug [ 2519761 ])
00242     myRoutes = MSDevice_Vehroutes::buildVehicleDevices(*this, myDevices, 5);
00243     myMoveReminders.push_back(std::make_pair(myRoutes, 0.));
00244 }
00245 
00246 
00247 GUIVehicle::~GUIVehicle() {
00248     myLock.lock();
00249     for (std::map<GUISUMOAbstractView*, int>::iterator i = myAdditionalVisualizations.begin(); i != myAdditionalVisualizations.end(); ++i) {
00250         while (i->first->removeAdditionalGLVisualisation(this));
00251     }
00252     myLock.unlock();
00253     GLObjectValuePassConnector<SUMOReal>::removeObject(*this);
00254     delete myRoutes;
00255 }
00256 
00257 
00258 GUIGLObjectPopupMenu*
00259 GUIVehicle::getPopUpMenu(GUIMainWindow& app,
00260                          GUISUMOAbstractView& parent) {
00261     GUIGLObjectPopupMenu* ret = new GUIVehiclePopupMenu(app, parent, *this, myAdditionalVisualizations);
00262     buildPopupHeader(ret, app);
00263     buildCenterPopupEntry(ret);
00264     buildNameCopyPopupEntry(ret);
00265     buildSelectionPopupEntry(ret);
00266     //
00267     if (hasActiveAddVisualisation(&parent, VO_SHOW_ROUTE)) {
00268         new FXMenuCommand(ret, "Hide Current Route", 0, ret, MID_HIDE_CURRENTROUTE);
00269     } else {
00270         new FXMenuCommand(ret, "Show Current Route", 0, ret, MID_SHOW_CURRENTROUTE);
00271     }
00272     if (hasActiveAddVisualisation(&parent, VO_SHOW_ALL_ROUTES)) {
00273         new FXMenuCommand(ret, "Hide All Routes", 0, ret, MID_HIDE_ALLROUTES);
00274     } else {
00275         new FXMenuCommand(ret, "Show All Routes", 0, ret, MID_SHOW_ALLROUTES);
00276     }
00277     if (hasActiveAddVisualisation(&parent, VO_SHOW_BEST_LANES)) {
00278         new FXMenuCommand(ret, "Hide Best Lanes", 0, ret, MID_HIDE_BEST_LANES);
00279     } else {
00280         new FXMenuCommand(ret, "Show Best Lanes", 0, ret, MID_SHOW_BEST_LANES);
00281     }
00282     if (hasActiveAddVisualisation(&parent, VO_SHOW_LFLINKITEMS)) {
00283         new FXMenuCommand(ret, "Hide Link Items", 0, ret, MID_HIDE_LFLINKITEMS);
00284     } else {
00285         new FXMenuCommand(ret, "Show Link Items", 0, ret, MID_SHOW_LFLINKITEMS);
00286     }
00287     new FXMenuSeparator(ret);
00288     int trackedID = parent.getTrackedID();
00289     if (trackedID < 0 || (size_t)trackedID != getGlID()) {
00290         new FXMenuCommand(ret, "Start Tracking", 0, ret, MID_START_TRACK);
00291     } else {
00292         new FXMenuCommand(ret, "Stop Tracking", 0, ret, MID_STOP_TRACK);
00293     }
00294     new FXMenuSeparator(ret);
00295     //
00296     buildShowParamsPopupEntry(ret);
00297     buildPositionCopyEntry(ret, false);
00298     return ret;
00299 }
00300 
00301 
00302 GUIParameterTableWindow*
00303 GUIVehicle::getParameterWindow(GUIMainWindow& app,
00304                                GUISUMOAbstractView&) {
00305     GUIParameterTableWindow* ret =
00306         new GUIParameterTableWindow(app, *this, 15);
00307     // add items
00308     ret->mkItem("type [NAME]", false, myType->getID());
00309     if (getParameter().repetitionNumber > 0) {
00310         ret->mkItem("left same route [#]", false, (unsigned int) getParameter().repetitionNumber);
00311     }
00312     if (getParameter().repetitionOffset > 0) {
00313         ret->mkItem("insertion period [s]", false, time2string(getParameter().repetitionOffset));
00314     }
00315     ret->mkItem("waiting time [s]", true,
00316                 new FunctionBinding<GUIVehicle, SUMOReal>(this, &MSVehicle::getWaitingSeconds));
00317     ret->mkItem("last lane change [s]", true,
00318                 new FunctionBinding<GUIVehicle, SUMOReal>(this, &GUIVehicle::getLastLaneChangeOffset));
00319     ret->mkItem("desired depart [s]", false, time2string(getParameter().depart));
00320     ret->mkItem("position [m]", true,
00321                 new FunctionBinding<GUIVehicle, SUMOReal>(this, &GUIVehicle::getPositionOnLane));
00322     ret->mkItem("speed [m/s]", true,
00323                 new FunctionBinding<GUIVehicle, SUMOReal>(this, &GUIVehicle::getSpeed));
00324     ret->mkItem("angle", true,
00325                 new FunctionBinding<GUIVehicle, SUMOReal>(this, &MSVehicle::getAngle));
00326     ret->mkItem("CO2 (HBEFA) [g/s]", true,
00327                 new FunctionBinding<GUIVehicle, SUMOReal>(this, &GUIVehicle::getHBEFA_CO2Emissions));
00328     ret->mkItem("CO (HBEFA) [g/s]", true,
00329                 new FunctionBinding<GUIVehicle, SUMOReal>(this, &GUIVehicle::getHBEFA_COEmissions));
00330     ret->mkItem("HC (HBEFA) [g/s]", true,
00331                 new FunctionBinding<GUIVehicle, SUMOReal>(this, &GUIVehicle::getHBEFA_HCEmissions));
00332     ret->mkItem("NOx (HBEFA) [g/s]", true,
00333                 new FunctionBinding<GUIVehicle, SUMOReal>(this, &GUIVehicle::getHBEFA_NOxEmissions));
00334     ret->mkItem("PMx (HBEFA) [g/s]", true,
00335                 new FunctionBinding<GUIVehicle, SUMOReal>(this, &GUIVehicle::getHBEFA_PMxEmissions));
00336     ret->mkItem("fuel (HBEFA) [l/s]", true,
00337                 new FunctionBinding<GUIVehicle, SUMOReal>(this, &GUIVehicle::getHBEFA_FuelConsumption));
00338     ret->mkItem("noise (Harmonoise) [dB]", true,
00339                 new FunctionBinding<GUIVehicle, SUMOReal>(this, &GUIVehicle::getHarmonoise_NoiseEmissions));
00340     // close building
00341     ret->closeBuilding();
00342     return ret;
00343 }
00344 
00345 
00346 Boundary
00347 GUIVehicle::getCenteringBoundary() const {
00348     Boundary b;
00349     b.add(getPosition());
00350     b.grow(20);
00351     return b;
00352 }
00353 
00354 
00355 inline void
00356 drawAction_drawVehicleAsBoxPlus(const GUIVehicle& veh) {
00357     glPushMatrix();
00358     glScaled(veh.getVehicleType().getWidth(), veh.getVehicleType().getLength(), 1.);
00359     glBegin(GL_TRIANGLE_STRIP);
00360     glVertex2d(0., 0.);
00361     glVertex2d(-.5, .15);
00362     glVertex2d( .5, .15);
00363     glVertex2d(-.5, 1.);
00364     glVertex2d( .5, 1.);
00365     glEnd();
00366     glPopMatrix();
00367 }
00368 
00369 
00370 inline void
00371 drawAction_drawVehicleAsTrianglePlus(const GUIVehicle& veh) {
00372     const SUMOReal length = veh.getVehicleType().getLength();
00373     if (length >= 8.) {
00374         drawAction_drawVehicleAsBoxPlus(veh);
00375         return;
00376     }
00377     glPushMatrix();
00378     glScaled(veh.getVehicleType().getWidth(), length, 1.);
00379     glBegin(GL_TRIANGLES);
00380     glVertex2d(0., 0.);
00381     glVertex2d(-.5, 1.);
00382     glVertex2d( .5, 1.);
00383     glEnd();
00384     glPopMatrix();
00385 }
00386 
00387 
00388 void
00389 drawPoly(double* poses, SUMOReal offset) {
00390     glPushMatrix();
00391     glTranslated(0, 0, offset * .1);
00392     glPolygonOffset(0, offset * -1);
00393     glBegin(GL_TRIANGLE_FAN);
00394     int i = 0;
00395     while (poses[i] > -999) {
00396         glVertex2d(poses[i], poses[i + 1]);
00397         i = i + 2;
00398     }
00399     glEnd();
00400     glPopMatrix();
00401 }
00402 
00403 
00404 inline void
00405 drawAction_drawVehicleAsPoly(const GUIVehicle& veh) {
00406     RGBColor current = GLHelper::getColor();
00407     RGBColor lighter = current.changedBrightness(.2);
00408     RGBColor darker = current.changedBrightness(-.2);
00409 
00410     SUMOReal length = veh.getVehicleType().getLength();
00411     glPushMatrix();
00412     glRotated(90, 0, 0, 1);
00413     glScaled(length, veh.getVehicleType().getWidth(), 1.);
00414     SUMOVehicleShape shape = veh.getVehicleType().getGuiShape();
00415 
00416     // draw main body
00417     switch (shape) {
00418         case SVS_UNKNOWN:
00419             drawPoly(vehiclePoly_PassengerCarBody, 4);
00420             GLHelper::setColor(lighter);
00421             drawPoly(vehiclePoly_PassengerCarBodyFront, 4.5);
00422             glColor3d(0, 0, 0);
00423             drawPoly(vehiclePoly_PassengerFrontGlass, 4.5);
00424             break;
00425         case SVS_PEDESTRIAN:
00426             //glScaled(1./(lenght)), 1, 1.);
00427             glTranslated(0, 0, .045);
00428             GLHelper::drawFilledCircle(1);
00429             glTranslated(0, 0, -.045);
00430             glScaled(.7, 2, 1);
00431             glTranslated(0, 0, .04);
00432             GLHelper::setColor(lighter);
00433             GLHelper::drawFilledCircle(1);
00434             glTranslated(0, 0, -.04);
00435             break;
00436         case SVS_BICYCLE:
00437         case SVS_MOTORCYCLE: {
00438             glPushMatrix();
00439             glTranslated(.5, 0, 0);
00440             glScaled(.25 / (length), 1, 1.);
00441             glTranslated(0, 0, .045);
00442             GLHelper::drawFilledCircle(1);
00443             glScaled(.7, 2, 1);
00444             glTranslated(0, 0, -.045);
00445             glTranslated(0, 0, .04);
00446             GLHelper::setColor(lighter);
00447             GLHelper::drawFilledCircle(1);
00448             glTranslated(0, 0, -.04);
00449             glPopMatrix();
00450         }
00451         break;
00452         case SVS_PASSENGER:
00453         case SVS_PASSENGER_SEDAN:
00454         case SVS_PASSENGER_HATCHBACK:
00455         case SVS_PASSENGER_WAGON:
00456             drawPoly(vehiclePoly_PassengerCarBody, 4);
00457             GLHelper::setColor(lighter);
00458             drawPoly(vehiclePoly_PassengerCarBodyFront, 4.5);
00459             glColor3d(0, 0, 0);
00460             drawPoly(vehiclePoly_PassengerFrontGlass, 4.5);
00461             break;
00462         case SVS_PASSENGER_VAN:
00463             drawPoly(vehiclePoly_PassengerVanBody, 4);
00464             GLHelper::setColor(lighter);
00465             drawPoly(vehiclePoly_PassengerVanBodyFront, 4.5);
00466             glColor3d(0, 0, 0);
00467             drawPoly(vehiclePoly_PassengerVanFrontGlass, 4.5);
00468             drawPoly(vehiclePoly_PassengerVanRightGlass, 4.5);
00469             drawPoly(vehiclePoly_PassengerVanLeftGlass, 4.5);
00470             drawPoly(vehiclePoly_PassengerVanBackGlass, 4.5);
00471             break;
00472         case SVS_DELIVERY:
00473             drawPoly(vehiclePoly_PassengerVanBody, 4);
00474             GLHelper::setColor(lighter);
00475             drawPoly(vehiclePoly_PassengerVanBodyFront, 4.5);
00476             glColor3d(0, 0, 0);
00477             drawPoly(vehiclePoly_PassengerVanFrontGlass, 4.5);
00478             drawPoly(vehiclePoly_DeliveryMediumRightGlass, 4.5);
00479             drawPoly(vehiclePoly_DeliveryMediumLeftGlass, 4.5);
00480             break;
00481         case SVS_TRANSPORT:
00482         case SVS_TRANSPORT_SEMITRAILER:
00483         case SVS_TRANSPORT_1TRAILER:
00484             glScaled(1. / (length), 1, 1.);
00485             drawPoly(vehiclePoly_TransportBody, 4);
00486             glColor3d(0, 0, 0);
00487             drawPoly(vehiclePoly_TransportFrontGlass, 4.5);
00488             drawPoly(vehiclePoly_TransportRightGlass, 4.5);
00489             drawPoly(vehiclePoly_TransportLeftGlass, 4.5);
00490             break;
00491         case SVS_BUS:
00492         case SVS_BUS_TROLLEY:
00493         case SVS_BUS_CITY_FLEXIBLE:
00494         case SVS_BUS_CITY: {
00495             SUMOReal ml = length;
00496             glScaled(1. / (length), 1, 1.);
00497             glTranslated(0, 0, .04);
00498             glBegin(GL_TRIANGLE_FAN);
00499             glVertex2d(ml / 2., 0);
00500             glVertex2d(0, 0);
00501             glVertex2d(0, -.45);
00502             glVertex2d(0 + .05, -.5);
00503             glVertex2d(ml - .05, -.5);
00504             glVertex2d(ml, -.45);
00505             glVertex2d(ml, .45);
00506             glVertex2d(ml - .05, .5);
00507             glVertex2d(0 + .05, .5);
00508             glVertex2d(0, .45);
00509             glVertex2d(0, 0);
00510             glEnd();
00511             glTranslated(0, 0, -.04);
00512 
00513             glTranslated(0, 0, .045);
00514             glColor3d(0, 0, 0);
00515             glBegin(GL_QUADS);
00516             glVertex2d(0 + .05, .48);
00517             glVertex2d(0 + .05, -.48);
00518             glVertex2d(0 + .15, -.48);
00519             glVertex2d(0 + .15, .48);
00520 
00521             glVertex2d(ml - .1, .45);
00522             glVertex2d(ml - .1, -.45);
00523             glVertex2d(ml - .05, -.45);
00524             glVertex2d(ml - .05, .45);
00525 
00526             glVertex2d(0 + .20, .49);
00527             glVertex2d(0 + .20, .45);
00528             glVertex2d(ml - .20, .45);
00529             glVertex2d(ml - .20, .49);
00530 
00531             glVertex2d(0 + .20, -.49);
00532             glVertex2d(0 + .20, -.45);
00533             glVertex2d(ml - .20, -.45);
00534             glVertex2d(ml - .20, -.49);
00535 
00536             glEnd();
00537             glTranslated(0, 0, -.045);
00538         }
00539         break;
00540         case SVS_BUS_OVERLAND:
00541         case SVS_RAIL:
00542         case SVS_RAIL_LIGHT:
00543         case SVS_RAIL_CITY:
00544         case SVS_RAIL_SLOW:
00545         case SVS_RAIL_FAST:
00546         case SVS_RAIL_CARGO:
00547             glScaled(1. / (length), 1, 1.);
00548             glTranslated(0, 0, .04);
00549             glBegin(GL_TRIANGLE_FAN);
00550             glVertex2d(length/ 2., 0);
00551             glVertex2d(0, 0);
00552             glVertex2d(0, -.45);
00553             glVertex2d(.05, -.5);
00554             glVertex2d(length - .05, -.5);
00555             glVertex2d(length, -.45);
00556             glVertex2d(length, .45);
00557             glVertex2d(length - .05, .5);
00558             glVertex2d(.05, .5);
00559             glVertex2d(0, .45);
00560             glVertex2d(0, 0);
00561             glEnd();
00562             glTranslated(0, 0, -.04);
00563             break;
00564         case SVS_E_VEHICLE:
00565             drawPoly(vehiclePoly_EVehicleBody, 4);
00566             glColor3d(0, 0, 0);
00567             drawPoly(vehiclePoly_EVehicleFrontGlass, 4.5);
00568             glTranslated(0, 0, .048);
00569             GLHelper::setColor(current);
00570             glBegin(GL_QUADS);
00571             glVertex2d(.3, .5);
00572             glVertex2d(.35, .5);
00573             glVertex2d(.35, -.5);
00574             glVertex2d(.3, -.5);
00575 
00576             glVertex2d(.3, -.05);
00577             glVertex2d(.7, -.05);
00578             glVertex2d(.7, .05);
00579             glVertex2d(.3, .05);
00580 
00581             glVertex2d(.7, .5);
00582             glVertex2d(.65, .5);
00583             glVertex2d(.65, -.5);
00584             glVertex2d(.7, -.5);
00585             glEnd();
00586             glTranslated(0, 0, -.048);
00587             //drawPoly(vehiclePoly_EVehicleBackGlass, 4.5);
00588             break;
00589         case SVS_ANT:
00590             glPushMatrix();
00591             // ant is stretched via vehicle length
00592             GLHelper::setColor(darker);
00593             // draw left side
00594             GLHelper::drawBoxLine(Position(-0.2, -.10), 350, 0.5, .02);
00595             GLHelper::drawBoxLine(Position(-0.3, -.50), 240, 0.4, .03);
00596             GLHelper::drawBoxLine(Position(0.3, -.10), 340, 0.8, .03);
00597             GLHelper::drawBoxLine(Position(0.05, -.80), 290, 0.6, .04);
00598             GLHelper::drawBoxLine(Position(0.4, -.10),  20, 0.8, .03);
00599             GLHelper::drawBoxLine(Position(0.65, -.80),  75, 0.6, .04);
00600             GLHelper::drawBoxLine(Position(0.5, -.10),  55, 0.8, .04);
00601             GLHelper::drawBoxLine(Position(1.1, -.55),  90, 0.6, .04);
00602             // draw right side
00603             GLHelper::drawBoxLine(Position(-0.2,  .10), 190, 0.5, .02);
00604             GLHelper::drawBoxLine(Position(-0.3,  .50), 300, 0.4, .03);
00605             GLHelper::drawBoxLine(Position(0.3,  .10), 200, 0.8, .03);
00606             GLHelper::drawBoxLine(Position(0.05, .80), 250, 0.6, .04);
00607             GLHelper::drawBoxLine(Position(0.4,  .10), 160, 0.8, .03);
00608             GLHelper::drawBoxLine(Position(0.65, .80), 105, 0.6, .04);
00609             GLHelper::drawBoxLine(Position(0.5,  .10), 125, 0.8, .04);
00610             GLHelper::drawBoxLine(Position(1.1,  .55),  90, 0.6, .04);
00611             // draw body
00612             GLHelper::setColor(current);
00613             glTranslated(0, 0, 0.1);
00614             GLHelper::drawFilledCircle(.25, 16);
00615             glTranslated(.4, 0, 0);
00616             GLHelper::drawFilledCircle(.2, 16);
00617             glTranslated(.4, 0, 0);
00618             GLHelper::drawFilledCircle(.3, 16);
00619             glPopMatrix();
00620             break;
00621         default: // same as passenger
00622             drawPoly(vehiclePoly_PassengerCarBody, 4);
00623             glColor3d(1, 1, 1);
00624             drawPoly(vehiclePoly_PassengerCarBodyFront, 4.5);
00625             glColor3d(0, 0, 0);
00626             drawPoly(vehiclePoly_PassengerFrontGlass, 4.5);
00627             break;
00628     }
00629 
00630     // draw decorations
00631     switch (shape) {
00632         case SVS_PEDESTRIAN:
00633             break;
00634         case SVS_BICYCLE:
00635             //glScaled(length, 1, 1.);
00636             glBegin(GL_TRIANGLE_FAN);
00637             glVertex2d(1 / 2., 0);
00638             glVertex2d(0, 0);
00639             glVertex2d(0, -.03);
00640             glVertex2d(0 + .05, -.05);
00641             glVertex2d(1 - .05, -.05);
00642             glVertex2d(1, -.03);
00643             glVertex2d(1, .03);
00644             glVertex2d(1 - .05, .05);
00645             glVertex2d(0 + .05, .05);
00646             glVertex2d(0, .03);
00647             glVertex2d(0, 0);
00648             glEnd();
00649             break;
00650         case SVS_MOTORCYCLE:
00651             //glScaled(length, 1, 1.);
00652             glBegin(GL_TRIANGLE_FAN);
00653             glVertex2d(1 / 2., 0);
00654             glVertex2d(0, 0);
00655             glVertex2d(0, -.03);
00656             glVertex2d(0 + .05, -.2);
00657             glVertex2d(1 - .05, -.2);
00658             glVertex2d(1, -.03);
00659             glVertex2d(1, .03);
00660             glVertex2d(1 - .05, .2);
00661             glVertex2d(0 + .05, .2);
00662             glVertex2d(0, .03);
00663             glVertex2d(0, 0);
00664             glEnd();
00665             break;
00666         case SVS_PASSENGER:
00667         case SVS_PASSENGER_SEDAN:
00668             drawPoly(vehiclePoly_PassengerSedanRightGlass, 4.5);
00669             drawPoly(vehiclePoly_PassengerSedanLeftGlass, 4.5);
00670             drawPoly(vehiclePoly_PassengerSedanBackGlass, 4.5);
00671             break;
00672         case SVS_PASSENGER_HATCHBACK:
00673             drawPoly(vehiclePoly_PassengerHatchbackRightGlass, 4.5);
00674             drawPoly(vehiclePoly_PassengerHatchbackLeftGlass, 4.5);
00675             drawPoly(vehiclePoly_PassengerHatchbackBackGlass, 4.5);
00676             break;
00677         case SVS_PASSENGER_WAGON:
00678             drawPoly(vehiclePoly_PassengerWagonRightGlass, 4.5);
00679             drawPoly(vehiclePoly_PassengerWagonLeftGlass, 4.5);
00680             drawPoly(vehiclePoly_PassengerWagonBackGlass, 4.5);
00681             break;
00682         case SVS_PASSENGER_VAN:
00683         case SVS_DELIVERY:
00684             break;
00685         case SVS_TRANSPORT:
00686             GLHelper::setColor(current);
00687             GLHelper::drawBoxLine(Position(2.3, 0), 90., length - 2.3, .5);
00688             break;
00689         case SVS_TRANSPORT_SEMITRAILER:
00690             GLHelper::setColor(current);
00691             GLHelper::drawBoxLine(Position(2.8, 0), 90., length - 2.8, .5);
00692             break;
00693         case SVS_TRANSPORT_1TRAILER: {
00694             GLHelper::setColor(current);
00695             SUMOReal l = length - 2.3;
00696             l = l / 2.;
00697             GLHelper::drawBoxLine(Position(2.3, 0), 90., l, .5);
00698             GLHelper::drawBoxLine(Position(2.3 + l + .5, 0), 90., l - .5, .5);
00699             break;
00700         }
00701         case SVS_BUS_TROLLEY:
00702             glPushMatrix();
00703             glTranslated(0, 0, .1);
00704             GLHelper::setColor(darker);
00705             GLHelper::drawBoxLine(Position(3.8, 0), 90., 1, .3);
00706             glTranslated(0, 0, .1);
00707             glColor3d(0, 0, 0);
00708             GLHelper::drawBoxLine(Position(4.3, .2), 90., 1, .06);
00709             GLHelper::drawBoxLine(Position(4.3, -.2), 90., 1, .06);
00710             GLHelper::drawBoxLine(Position(5.3, .2), 90., 3, .03);
00711             GLHelper::drawBoxLine(Position(5.3, -.2), 90., 3, .03);
00712             glPopMatrix();
00713             break;
00714         case SVS_BUS:
00715         case SVS_BUS_CITY:
00716         case SVS_BUS_CITY_FLEXIBLE:
00717         case SVS_BUS_OVERLAND:
00718         case SVS_RAIL:
00719         case SVS_RAIL_LIGHT:
00720         case SVS_RAIL_CITY:
00721         case SVS_RAIL_SLOW:
00722         case SVS_RAIL_FAST:
00723         case SVS_RAIL_CARGO:
00724         case SVS_E_VEHICLE:
00725         case SVS_ANT:
00726             break;
00727         default: // same as passenger/sedan
00728             drawPoly(vehiclePoly_PassengerSedanRightGlass, 4.5);
00729             drawPoly(vehiclePoly_PassengerSedanLeftGlass, 4.5);
00730             drawPoly(vehiclePoly_PassengerSedanBackGlass, 4.5);
00731             break;
00732     }
00733     /*
00734     glBegin(GL_TRIANGLE_FAN);
00735     glVertex2d(.5,.5); // center - strip begin
00736     glVertex2d(0,    .5); // center, front
00737     glVertex2d(0,    .8); // ... clockwise ... (vehicle right side)
00738     glVertex2d(0.08, .94);
00739     glVertex2d(0.25, 1.);
00740     glVertex2d(0.95, 1.);
00741     glVertex2d(1.,   .9);
00742     glVertex2d(1.,   .1); // (vehicle left side)
00743     glVertex2d(0.95, 0.);
00744     glVertex2d(0.25, 0.);
00745     glVertex2d(0.08, .06);
00746     glVertex2d(0,    .2); //
00747     glVertex2d(0,    .5); // center, front (close)
00748     glEnd();
00749 
00750     glPolygonOffset(0, -4.5);
00751     glColor3d(1, 1, 1); // front
00752     glBegin(GL_TRIANGLE_FAN);
00753     glVertex2d(0.1,0.5);
00754     glVertex2d(0.025,0.5);
00755     glVertex2d(0.025,0.75);
00756     glVertex2d(0.27,0.9);
00757     glVertex2d(0.27,0.1);
00758     glVertex2d(0.025,0.25);
00759     glVertex2d(0.025,0.5);
00760     glEnd();
00761 
00762     glColor3d(0, 0, 0); // front glass
00763     glBegin(GL_TRIANGLE_FAN);
00764     glVertex2d(0.35,0.5);
00765     glVertex2d(0.3,0.5);
00766     glVertex2d(0.3,0.9);
00767     glVertex2d(0.43,0.8);
00768     glVertex2d(0.43,0.2);
00769     glVertex2d(0.3,0.1);
00770     glVertex2d(0.3,0.5);
00771     glEnd();
00772 
00773     glBegin(GL_TRIANGLE_FAN); // back glass
00774     glVertex2d(0.92,0.5);
00775     glVertex2d(0.90,0.5);
00776     glVertex2d(0.90,0.8);
00777     glVertex2d(0.95,0.9);
00778     glVertex2d(0.95,0.1);
00779     glVertex2d(0.90,0.2);
00780     glVertex2d(0.90,0.5);
00781     glEnd();
00782 
00783     glBegin(GL_TRIANGLE_FAN); // right glass
00784     glVertex2d(0.36,0.07);
00785     glVertex2d(0.34,0.03);
00786     glVertex2d(0.94,0.03);
00787     glVertex2d(0.87,0.13);
00788     glVertex2d(0.45,0.13);
00789     glVertex2d(0.34,0.03);
00790     glEnd();
00791 
00792     glBegin(GL_TRIANGLE_FAN); // left glass
00793     glVertex2d(0.36,1.-0.07);
00794     glVertex2d(0.34,1.-0.03);
00795     glVertex2d(0.94,1.-0.03);
00796     glVertex2d(0.87,1.-0.13);
00797     glVertex2d(0.45,1.-0.13);
00798     glVertex2d(0.34,1.-0.03);
00799     glEnd();
00800     */
00801 
00802     glPopMatrix();
00803 }
00804 
00805 
00806 #define BLINKER_POS_FRONT .5
00807 #define BLINKER_POS_BACK .5
00808 
00809 inline void
00810 drawAction_drawBlinker(const GUIVehicle& veh, double dir) {
00811     glColor3d(1.f, .8f, 0);
00812     glPushMatrix();
00813     glTranslated(dir, BLINKER_POS_FRONT, -0.1);
00814     GLHelper::drawFilledCircle(.5, 6);
00815     glPopMatrix();
00816     glPushMatrix();
00817     glTranslated(dir, veh.getVehicleType().getLength() - BLINKER_POS_BACK, -0.1);
00818     GLHelper::drawFilledCircle(.5, 6);
00819     glPopMatrix();
00820 }
00821 
00822 
00823 inline void
00824 drawAction_drawVehicleBlinker(const GUIVehicle& veh) {
00825     if (!veh.signalSet(MSVehicle::VEH_SIGNAL_BLINKER_RIGHT | MSVehicle::VEH_SIGNAL_BLINKER_LEFT | MSVehicle::VEH_SIGNAL_BLINKER_EMERGENCY)) {
00826         return;
00827     }
00828     const double offset = MAX2(.5 * veh.getVehicleType().getWidth(), .4);
00829     if (veh.signalSet(MSVehicle::VEH_SIGNAL_BLINKER_RIGHT)) {
00830         drawAction_drawBlinker(veh, -offset);
00831     }
00832     if (veh.signalSet(MSVehicle::VEH_SIGNAL_BLINKER_LEFT)) {
00833         drawAction_drawBlinker(veh, offset);;
00834     }
00835     if (veh.signalSet(MSVehicle::VEH_SIGNAL_BLINKER_EMERGENCY)) {
00836         drawAction_drawBlinker(veh, -offset);
00837         drawAction_drawBlinker(veh, offset);
00838     }
00839 }
00840 
00841 
00842 inline void
00843 drawAction_drawVehicleBrakeLight(const GUIVehicle& veh) {
00844     if (!veh.signalSet(MSVehicle::VEH_SIGNAL_BRAKELIGHT)) {
00845         return;
00846     }
00847     glColor3f(1.f, .2f, 0);
00848     glPushMatrix();
00849     glTranslated(-veh.getVehicleType().getWidth() * 0.5, veh.getVehicleType().getLength(), -0.1);
00850     GLHelper::drawFilledCircle(.5, 6);
00851     glPopMatrix();
00852     glPushMatrix();
00853     glTranslated(veh.getVehicleType().getWidth() * 0.5, veh.getVehicleType().getLength(), -0.1);
00854     GLHelper::drawFilledCircle(.5, 6);
00855     glPopMatrix();
00856 }
00857 
00858 
00859 void
00860 GUIVehicle::drawGL(const GUIVisualizationSettings& s) const {
00861     glPushName(getGlID());
00862     glPushMatrix();
00863     Position p1 = myLane->getShape().positionAtLengthPosition(myState.pos());
00864     glTranslated(p1.x(), p1.y(), getType());
00865     glRotated(getAngle(), 0, 0, 1);
00866     // set lane color
00867     setColor(s);
00868     // scale
00869     SUMOReal upscale = s.vehicleExaggeration;
00870     glScaled(upscale, upscale, 1);
00871     /*
00872         MSLCM_DK2004 &m2 = static_cast<MSLCM_DK2004&>(veh->getLaneChangeModel());
00873         if((m2.getState()&LCA_URGENT)!=0) {
00874             glColor3d(1, .4, .4);
00875         } else if((m2.getState()&LCA_SPEEDGAIN)!=0) {
00876             glColor3d(.4, .4, 1);
00877         } else {
00878             glColor3d(.4, 1, .4);
00879         }
00880         */
00881     // draw the vehicle
00882     switch (s.vehicleQuality) {
00883         case 0:
00884             drawAction_drawVehicleAsTrianglePlus(*this);
00885             break;
00886         case 1:
00887             drawAction_drawVehicleAsBoxPlus(*this);
00888             break;
00889         case 2:
00890         default:
00891             drawAction_drawVehicleAsPoly(*this);
00892             break;
00893     }
00894     if (s.drawMinGap) {
00895         SUMOReal minGap = -getVehicleType().getMinGap();
00896         glColor3d(0., 1., 0.);
00897         glBegin(GL_LINES);
00898         glVertex2d(0., 0);
00899         glVertex2d(0., minGap);
00900         glVertex2d(-.5, minGap);
00901         glVertex2d(.5, minGap);
00902         glEnd();
00903     }
00904     // draw the blinker and brakelights if wished
00905     if (s.showBlinker) {
00906         glTranslated(0, 0, .1);
00907         switch (getVehicleType().getGuiShape()) {
00908             case SVS_PEDESTRIAN:
00909             case SVS_BICYCLE:
00910             case SVS_ANT:
00911             case SVS_RAIL:
00912             case SVS_RAIL_LIGHT:
00913             case SVS_RAIL_SLOW:
00914             case SVS_RAIL_FAST:
00915             case SVS_RAIL_CARGO:
00916             // only SVS_RAIL_CITY has blinkers and brake lights
00917                 break;
00918             default:
00919                 drawAction_drawVehicleBlinker(*this);
00920                 drawAction_drawVehicleBrakeLight(*this);
00921                 break;
00922         }
00923     }
00924     // draw the wish to change the lane
00925     if (s.drawLaneChangePreference) {
00926         /*
00927                 if(gSelected.isSelected(GLO_VEHICLE, veh->getGlID())) {
00928                 MSLCM_DK2004 &m = static_cast<MSLCM_DK2004&>(veh->getLaneChangeModel());
00929                 glColor3d(.5, .5, 1);
00930                 glBegin(GL_LINES);
00931                 glVertex2f(0, 0);
00932                 glVertex2f(m.getChangeProbability(), .5);
00933                 glEnd();
00934 
00935                 glColor3d(1, 0, 0);
00936                 glBegin(GL_LINES);
00937                 glVertex2f(0.1, 0);
00938                 glVertex2f(0.1, m.myMaxJam1);
00939                 glEnd();
00940 
00941                 glColor3d(0, 1, 0);
00942                 glBegin(GL_LINES);
00943                 glVertex2f(-0.1, 0);
00944                 glVertex2f(-0.1, m.myTDist);
00945                 glEnd();
00946                 }
00947                 */
00948     }
00949     // draw best lanes
00950     if (true) {
00951         /*
00952         const MSLane &l = veh->getLane();
00953         SUMOReal r1 = veh->allowedContinuationsLength(&l, 0);
00954         SUMOReal r2 = l.getLeftLane()!=0 ? veh->allowedContinuationsLength(l.getLeftLane(), 0) : 0;
00955         SUMOReal r3 = l.getRightLane()!=0 ? veh->allowedContinuationsLength(l.getRightLane(), 0) : 0;
00956         SUMOReal mmax = MAX3(r1, r2, r3);
00957         glBegin(GL_LINES);
00958         glVertex2f(0, 0);
00959         glVertex2f(0, r1/mmax/2.);
00960         glEnd();
00961         glBegin(GL_LINES);
00962         glVertex2f(.4, 0);
00963         glVertex2f(.4, r2/mmax/2.);
00964         glEnd();
00965         glBegin(GL_LINES);
00966         glVertex2f(-.4, 0);
00967         glVertex2f(-.4, r3/mmax/2.);
00968         glEnd();
00969         */
00970     }
00971     glPopMatrix();
00972     drawName(myLane->getShape().positionAtLengthPosition(myState.pos() - getVehicleType().getLength() / 2),
00973              s.scale, s.vehicleName);
00974     glPopName();
00975 }
00976 
00977 
00978 void
00979 GUIVehicle::drawGLAdditional(GUISUMOAbstractView* const parent, const GUIVisualizationSettings& s) const {
00980     glPushName(getGlID());
00981     glPushMatrix();
00982     glTranslated(0, 0, getType() - .1); // don't draw on top of other cars
00983     if (hasActiveAddVisualisation(parent, VO_SHOW_BEST_LANES)) {
00984         drawBestLanes();
00985     }
00986     if (hasActiveAddVisualisation(parent, VO_SHOW_ROUTE)) {
00987         drawRoute(s, 0, 0.25);
00988     }
00989     if (hasActiveAddVisualisation(parent, VO_SHOW_ALL_ROUTES)) {
00990         if (getNumberReroutes() > 0) {
00991             const int noReroutePlus1 = getNumberReroutes() + 1;
00992             for (int i = noReroutePlus1 - 1; i >= 0; i--) {
00993                 SUMOReal darken = SUMOReal(0.4) / SUMOReal(noReroutePlus1) * SUMOReal(i);
00994                 drawRoute(s, i, darken);
00995             }
00996         } else {
00997             drawRoute(s, 0, 0.25);
00998         }
00999     }
01000     if (hasActiveAddVisualisation(parent, VO_SHOW_LFLINKITEMS)) {
01001         for (DriveItemVector::const_iterator i = myLFLinkLanes.begin(); i != myLFLinkLanes.end(); ++i) {
01002             if((*i).myLink==0) {
01003                 continue;
01004             }
01005             MSLink* link = (*i).myLink;
01006 #ifdef HAVE_INTERNAL_LANES
01007             MSLane *via = link->getViaLane();
01008             if (via == 0) {
01009                 via = link->getLane();
01010             }
01011 #else
01012             MSLane *via = link->getLane();
01013 #endif
01014             if (via != 0) {
01015                 Position p = via->getShape()[0];
01016                 if((*i).mySetRequest) {
01017                     glColor3f(0, 1, 0);
01018                 } else {
01019                     glColor3f(1, 0, 0);
01020                 }
01021                 glTranslated(p.x(), p.y(), -.1);
01022                 GLHelper::drawFilledCircle(1);
01023                 glTranslated(-p.x(), -p.y(), .1);
01024             }
01025         }
01026     }
01027     glPopMatrix();
01028     glPopName();
01029 }
01030 
01031 
01032 const std::vector<MSVehicle::LaneQ> &
01033 GUIVehicle::getBestLanes() const {
01034     myLock.lock();
01035     const std::vector<MSVehicle::LaneQ> &ret = MSVehicle::getBestLanes();
01036     myLock.unlock();
01037     return ret;
01038 }
01039 
01040 
01041 void
01042 GUIVehicle::setColor(const GUIVisualizationSettings& s) const {
01043     const GUIColorer& c = s.vehicleColorer;
01044     if (!setFunctionalColor(c.getActive())) {
01045         GLHelper::setColor(c.getScheme().getColor(getColorValue(c.getActive())));
01046     }
01047 }
01048 
01049 
01050 bool
01051 GUIVehicle::setFunctionalColor(size_t activeScheme) const {
01052     switch (activeScheme) {
01053         case 1: {
01054             GLHelper::setColor(getParameter().color);
01055             return true;
01056         }
01057         case 2: {
01058             GLHelper::setColor(getVehicleType().getColor());
01059             return true;
01060         }
01061         case 3: {
01062             GLHelper::setColor(getRoute().getColor());
01063             return true;
01064         }
01065         case 4: {
01066             Position p = getRoute().getEdges()[0]->getLanes()[0]->getShape()[0];
01067             const Boundary& b = ((GUINet*) MSNet::getInstance())->getBoundary();
01068             Position center = b.getCenter();
01069             SUMOReal hue = 180. + atan2(center.x() - p.x(), center.y() - p.y()) * 180. / PI;
01070             SUMOReal sat = p.distanceTo(center) / center.distanceTo(Position(b.xmin(), b.ymin()));
01071             GLHelper::setColor(RGBColor::fromHSV(hue, sat, 1.));
01072             return true;
01073         }
01074         case 5: {
01075             Position p = getRoute().getEdges().back()->getLanes()[0]->getShape()[-1];
01076             const Boundary& b = ((GUINet*) MSNet::getInstance())->getBoundary();
01077             Position center = b.getCenter();
01078             SUMOReal hue = 180. + atan2(center.x() - p.x(), center.y() - p.y()) * 180. / PI;
01079             SUMOReal sat = p.distanceTo(center) / center.distanceTo(Position(b.xmin(), b.ymin()));
01080             GLHelper::setColor(RGBColor::fromHSV(hue, sat, 1.));
01081             return true;
01082         }
01083         case 6: {
01084             Position pb = getRoute().getEdges()[0]->getLanes()[0]->getShape()[0];
01085             Position pe = getRoute().getEdges().back()->getLanes()[0]->getShape()[-1];
01086             const Boundary& b = ((GUINet*) MSNet::getInstance())->getBoundary();
01087             SUMOReal hue = 180. + atan2(pb.x() - pe.x(), pb.y() - pe.y()) * 180. / PI;
01088             Position minp(b.xmin(), b.ymin());
01089             Position maxp(b.xmax(), b.ymax());
01090             SUMOReal sat = pb.distanceTo(pe) / minp.distanceTo(maxp);
01091             GLHelper::setColor(RGBColor::fromHSV(hue, sat, 1.));
01092             return true;
01093         }
01094     }
01095     return false;
01096 }
01097 
01098 
01099 SUMOReal
01100 GUIVehicle::getColorValue(size_t activeScheme) const {
01101     switch (activeScheme) {
01102         case 7:
01103             return getSpeed();
01104         case 8:
01105             return getWaitingSeconds();
01106         case 9:
01107             return getLastLaneChangeOffset();
01108         case 10:
01109             return getMaxSpeed();
01110         case 11:
01111             return getHBEFA_CO2Emissions();
01112         case 12:
01113             return getHBEFA_COEmissions();
01114         case 13:
01115             return getHBEFA_PMxEmissions();
01116         case 14:
01117             return getHBEFA_NOxEmissions();
01118         case 15:
01119             return getHBEFA_HCEmissions();
01120         case 16:
01121             return getHBEFA_FuelConsumption();
01122         case 17:
01123             return getHarmonoise_NoiseEmissions();
01124         case 18:
01125             if (getNumberReroutes() == 0) {
01126                 return -1;
01127             }
01128             return getNumberReroutes();
01129     }
01130     return 0;
01131 }
01132 
01133 
01134 // ------------ Additional visualisations
01135 bool
01136 GUIVehicle::hasActiveAddVisualisation(GUISUMOAbstractView* const parent, int which) const {
01137     return myAdditionalVisualizations.find(parent) != myAdditionalVisualizations.end() && (myAdditionalVisualizations.find(parent)->second & which) != 0;
01138 }
01139 
01140 
01141 bool
01142 GUIVehicle::addActiveAddVisualisation(GUISUMOAbstractView* const parent, int which) {
01143     if (myAdditionalVisualizations.find(parent) == myAdditionalVisualizations.end()) {
01144         myAdditionalVisualizations[parent] = 0;
01145     }
01146     myAdditionalVisualizations[parent] |= which;
01147     return parent->addAdditionalGLVisualisation(this);
01148 }
01149 
01150 
01151 bool
01152 GUIVehicle::removeActiveAddVisualisation(GUISUMOAbstractView* const parent, int which) {
01153     myAdditionalVisualizations[parent] &= ~which;
01154     return parent->removeAdditionalGLVisualisation(this);
01155 }
01156 
01157 
01158 void
01159 GUIVehicle::drawRoute(const GUIVisualizationSettings& s, int routeNo, SUMOReal darken) const {
01160     setColor(s);
01161     GLdouble colors[4];
01162     glGetDoublev(GL_CURRENT_COLOR, colors);
01163     colors[0] -= darken;
01164     if (colors[0] < 0) {
01165         colors[0] = 0;
01166     }
01167     colors[1] -= darken;
01168     if (colors[1] < 0) {
01169         colors[1] = 0;
01170     }
01171     colors[2] -= darken;
01172     if (colors[2] < 0) {
01173         colors[2] = 0;
01174     }
01175     colors[3] -= darken;
01176     if (colors[3] < 0) {
01177         colors[3] = 0;
01178     }
01179     glColor3dv(colors);
01180     if (routeNo == 0) {
01181         draw(*myRoute);
01182         return;
01183     }
01184     --routeNo; // only prior routes are stored
01185     draw(*myRoutes->getRoute(routeNo));
01186 }
01187 
01188 
01189 void
01190 GUIVehicle::drawBestLanes() const {
01191     myLock.lock();
01192     std::vector<std::vector<MSVehicle::LaneQ> > bestLanes = myBestLanes;
01193     myLock.unlock();
01194     SUMOReal width = 0.5;
01195     for (std::vector<std::vector<MSVehicle::LaneQ> >::iterator j = bestLanes.begin(); j != bestLanes.end(); ++j) {
01196         std::vector<MSVehicle::LaneQ> &lanes = *j;
01197         SUMOReal gmax = -1;
01198         SUMOReal rmax = -1;
01199         for (std::vector<MSVehicle::LaneQ>::const_iterator i = lanes.begin(); i != lanes.end(); ++i) {
01200             gmax = MAX2((*i).length, gmax);
01201             rmax = MAX2((*i).occupation, rmax);
01202         }
01203         for (std::vector<MSVehicle::LaneQ>::const_iterator i = lanes.begin(); i != lanes.end(); ++i) {
01204             const PositionVector& shape = (*i).lane->getShape();
01205             SUMOReal g = (*i).length / gmax;
01206             SUMOReal r = (*i).occupation / rmax;
01207             glColor3d(r, g, 0);
01208             GLHelper::drawBoxLines(shape, width);
01209 
01210             PositionVector s1 = shape;
01211             s1.move2side((SUMOReal) .1);
01212             glColor3d(r, 0, 0);
01213             GLHelper::drawLine(s1);
01214             s1.move2side((SUMOReal) - .2);
01215             glColor3d(0, g, 0);
01216             GLHelper::drawLine(s1);
01217 
01218             glColor3d(r, g, 0);
01219             Position lastPos = shape[-1];
01220         }
01221         width = .2;
01222     }
01223 }
01224 
01225 
01226 void
01227 GUIVehicle::draw(const MSRoute& r) const {
01228     MSRouteIterator i = r.begin();
01229     for (; i != r.end(); ++i) {
01230         const MSEdge* e = *i;
01231         const GUIEdge* ge = static_cast<const GUIEdge*>(e);
01232         const GUILaneWrapper& lane = ge->getLaneGeometry((size_t) 0);
01233         GLHelper::drawBoxLines(lane.getShape(), lane.getShapeRotations(), lane.getShapeLengths(), 1.0);
01234     }
01235 }
01236 
01237 
01238 /****************************************************************************/
01239 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines