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