|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // A MSVehicle extended by some values for usage within the gui 00008 /****************************************************************************/ 00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors 00011 /****************************************************************************/ 00012 // 00013 // This program is free software; you can redistribute it and/or modify 00014 // it under the terms of the GNU General Public License as published by 00015 // the Free Software Foundation; either version 2 of the License, or 00016 // (at your option) any later version. 00017 // 00018 /****************************************************************************/ 00019 00020 00021 // =========================================================================== 00022 // included modules 00023 // =========================================================================== 00024 #ifdef _MSC_VER 00025 #include <windows_config.h> 00026 #else 00027 #include <config.h> 00028 #endif 00029 00030 #ifdef WIN32 00031 #include <windows.h> 00032 #endif 00033 00034 #include <GL/gl.h> 00035 00036 #include <cmath> 00037 #include <vector> 00038 #include <string> 00039 #include <foreign/polyfonts/polyfonts.h> 00040 #include <utils/common/StringUtils.h> 00041 #include <utils/common/SUMOVehicleParameter.h> 00042 #include <utils/gui/windows/GUISUMOAbstractView.h> 00043 #include <utils/gui/windows/GUIAppEnum.h> 00044 #include <utils/gui/div/GUIParameterTableWindow.h> 00045 #include <utils/gui/div/GUIGlobalSelection.h> 00046 #include <utils/gui/div/GLHelper.h> 00047 #include <utils/gui/div/GLObjectValuePassConnector.h> 00048 #include <microsim/MSVehicle.h> 00049 #include <microsim/logging/CastingFunctionBinding.h> 00050 #include <microsim/logging/FunctionBinding.h> 00051 #include <microsim/MSVehicleControl.h> 00052 #include <microsim/MSAbstractLaneChangeModel.h> 00053 #include <microsim/devices/MSDevice_Vehroutes.h> 00054 #include <gui/GUIApplicationWindow.h> 00055 #include <gui/GUIGlobals.h> 00056 #include "GUIVehicle.h" 00057 #include "GUINet.h" 00058 #include "GUIEdge.h" 00059 00060 00061 #ifdef CHECK_MEMORY_LEAKS 00062 #include <foreign/nvwa/debug_new.h> 00063 #endif // CHECK_MEMORY_LEAKS 00064 00065 00066 // =========================================================================== 00067 // FOX callback mapping 00068 // =========================================================================== 00069 FXDEFMAP(GUIVehicle::GUIVehiclePopupMenu) GUIVehiclePopupMenuMap[]= { 00070 FXMAPFUNC(SEL_COMMAND, MID_SHOW_ALLROUTES, GUIVehicle::GUIVehiclePopupMenu::onCmdShowAllRoutes), 00071 FXMAPFUNC(SEL_COMMAND, MID_HIDE_ALLROUTES, GUIVehicle::GUIVehiclePopupMenu::onCmdHideAllRoutes), 00072 FXMAPFUNC(SEL_COMMAND, MID_SHOW_CURRENTROUTE, GUIVehicle::GUIVehiclePopupMenu::onCmdShowCurrentRoute), 00073 FXMAPFUNC(SEL_COMMAND, MID_HIDE_CURRENTROUTE, GUIVehicle::GUIVehiclePopupMenu::onCmdHideCurrentRoute), 00074 FXMAPFUNC(SEL_COMMAND, MID_SHOW_BEST_LANES, GUIVehicle::GUIVehiclePopupMenu::onCmdShowBestLanes), 00075 FXMAPFUNC(SEL_COMMAND, MID_HIDE_BEST_LANES, GUIVehicle::GUIVehiclePopupMenu::onCmdHideBestLanes), 00076 FXMAPFUNC(SEL_COMMAND, MID_START_TRACK, GUIVehicle::GUIVehiclePopupMenu::onCmdStartTrack), 00077 FXMAPFUNC(SEL_COMMAND, MID_STOP_TRACK, GUIVehicle::GUIVehiclePopupMenu::onCmdStopTrack), 00078 }; 00079 00080 // Object implementation 00081 FXIMPLEMENT(GUIVehicle::GUIVehiclePopupMenu, GUIGLObjectPopupMenu, GUIVehiclePopupMenuMap, ARRAYNUMBER(GUIVehiclePopupMenuMap)) 00082 00083 00084 00085 // =========================================================================== 00086 // data definitions 00087 // =========================================================================== 00088 /* ------------------------------------------------------------------------- 00089 * drawed shapes 00090 * ----------------------------------------------------------------------- */ 00091 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 }; 00092 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 }; 00093 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 }; 00094 double vehiclePoly_PassengerSedanRightGlass[] = { 0.36,-.43, 0.34,-.47, 0.77,-.47, 0.67,-.37, 0.45,-.37, 0.34,-.47, -10000 }; 00095 double vehiclePoly_PassengerSedanLeftGlass[] = { 0.36,.43, 0.34,.47, 0.77,.47, 0.67,.37, 0.45,.37, 0.34,.47, -10000 }; 00096 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 }; 00097 double vehiclePoly_PassengerHatchbackRightGlass[] = { 0.36,-.43, 0.34,-.47, 0.94,-.47, 0.80,-.37, 0.45,-.37, 0.34,-.47, -10000 }; 00098 double vehiclePoly_PassengerHatchbackLeftGlass[] = { 0.36,.43, 0.34,.47, 0.94,.47, 0.80,.37, 0.45,.37, 0.34,.47, -10000 }; 00099 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 }; 00100 double vehiclePoly_PassengerWagonRightGlass[] = { 0.36,-.43, 0.34,-.47, 0.94,-.47, 0.87,-.37, 0.45,-.37, 0.34,-.47, -10000 }; 00101 double vehiclePoly_PassengerWagonLeftGlass[] = { 0.36,.43, 0.34,.47, 0.94,.47, 0.87,.37, 0.45,.37, 0.34,.47, -10000 }; 00102 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 }; 00103 00104 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 }; 00105 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 }; 00106 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 }; 00107 double vehiclePoly_PassengerVanRightGlass[] = { 0.36,-.43, 0.20,-.47, 0.98,-.47, 0.91,-.37, 0.31,-.37, 0.20,-.47, -10000 }; 00108 double vehiclePoly_PassengerVanLeftGlass[] = { 0.36,.43, 0.20,.47, 0.98,.47, 0.91,.37, 0.31,.37, 0.20,.47, -10000 }; 00109 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 }; 00110 00111 double vehiclePoly_DeliveryMediumRightGlass[] = { 0.21,-.43, 0.20,-.47, 0.38,-.47, 0.38,-.37, 0.31,-.37, 0.20,-.47, -10000 }; 00112 double vehiclePoly_DeliveryMediumLeftGlass[] = { 0.21,.43, 0.20,.47, 0.38,.47, 0.38,.37, 0.31,.37, 0.20,.47, -10000 }; 00113 00114 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 }; 00115 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 }; 00116 double vehiclePoly_TransportRightGlass[] = { 0.36,-.47, 0.10,-.48, 1.25,-.48, 1.25,-.4, 0.3,-.4, 0.10,-.48, -10000 }; 00117 double vehiclePoly_TransportLeftGlass[] = { 0.36,.47, 0.10,.48, 1.25,.48, 1.25,.4, 0.3,.4, 0.10,.48, -10000 }; 00118 00119 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 }; 00120 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 }; 00121 //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 }; 00122 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 }; 00123 00124 00125 // =========================================================================== 00126 // method definitions 00127 // =========================================================================== 00128 /* ------------------------------------------------------------------------- 00129 * GUIVehicle::GUIVehiclePopupMenu - methods 00130 * ----------------------------------------------------------------------- */ 00131 GUIVehicle::GUIVehiclePopupMenu::GUIVehiclePopupMenu( 00132 GUIMainWindow& app, GUISUMOAbstractView& parent, 00133 GUIGlObject& o, std::map<GUISUMOAbstractView*, int> &additionalVisualizations) 00134 : GUIGLObjectPopupMenu(app, parent, o), myVehiclesAdditionalVisualizations(additionalVisualizations) { 00135 } 00136 00137 00138 GUIVehicle::GUIVehiclePopupMenu::~GUIVehiclePopupMenu() throw() {} 00139 00140 00141 long 00142 GUIVehicle::GUIVehiclePopupMenu::onCmdShowAllRoutes(FXObject*,FXSelector,void*) { 00143 assert(myObject->getType()==GLO_VEHICLE); 00144 if (!static_cast<GUIVehicle*>(myObject)->hasActiveAddVisualisation(myParent, VO_SHOW_ALL_ROUTES)) { 00145 static_cast<GUIVehicle*>(myObject)->addActiveAddVisualisation(myParent, VO_SHOW_ALL_ROUTES); 00146 } 00147 return 1; 00148 } 00149 00150 00151 long 00152 GUIVehicle::GUIVehiclePopupMenu::onCmdHideAllRoutes(FXObject*,FXSelector,void*) { 00153 assert(myObject->getType()==GLO_VEHICLE); 00154 static_cast<GUIVehicle*>(myObject)->removeActiveAddVisualisation(myParent, VO_SHOW_ALL_ROUTES); 00155 return 1; 00156 } 00157 00158 00159 long 00160 GUIVehicle::GUIVehiclePopupMenu::onCmdShowCurrentRoute(FXObject*,FXSelector,void*) { 00161 assert(myObject->getType()==GLO_VEHICLE); 00162 if (!static_cast<GUIVehicle*>(myObject)->hasActiveAddVisualisation(myParent, VO_SHOW_ROUTE)) { 00163 static_cast<GUIVehicle*>(myObject)->addActiveAddVisualisation(myParent, VO_SHOW_ROUTE); 00164 } 00165 return 1; 00166 } 00167 00168 00169 long 00170 GUIVehicle::GUIVehiclePopupMenu::onCmdShowBestLanes(FXObject*,FXSelector,void*) { 00171 assert(myObject->getType()==GLO_VEHICLE); 00172 if (!static_cast<GUIVehicle*>(myObject)->hasActiveAddVisualisation(myParent, VO_SHOW_BEST_LANES)) { 00173 static_cast<GUIVehicle*>(myObject)->addActiveAddVisualisation(myParent, VO_SHOW_BEST_LANES); 00174 } 00175 return 1; 00176 } 00177 00178 00179 long 00180 GUIVehicle::GUIVehiclePopupMenu::onCmdHideCurrentRoute(FXObject*,FXSelector,void*) { 00181 assert(myObject->getType()==GLO_VEHICLE); 00182 static_cast<GUIVehicle*>(myObject)->removeActiveAddVisualisation(myParent, VO_SHOW_ROUTE); 00183 return 1; 00184 } 00185 00186 long 00187 GUIVehicle::GUIVehiclePopupMenu::onCmdHideBestLanes(FXObject*,FXSelector,void*) { 00188 assert(myObject->getType()==GLO_VEHICLE); 00189 static_cast<GUIVehicle*>(myObject)->removeActiveAddVisualisation(myParent, VO_SHOW_BEST_LANES); 00190 return 1; 00191 } 00192 00193 00194 long 00195 GUIVehicle::GUIVehiclePopupMenu::onCmdStartTrack(FXObject*,FXSelector,void*) { 00196 assert(myObject->getType()==GLO_VEHICLE); 00197 if (!static_cast<GUIVehicle*>(myObject)->hasActiveAddVisualisation(myParent, VO_TRACKED)) { 00198 myParent->startTrack(static_cast<GUIVehicle*>(myObject)->getGlID()); 00199 static_cast<GUIVehicle*>(myObject)->addActiveAddVisualisation(myParent, VO_TRACKED); 00200 } 00201 return 1; 00202 } 00203 00204 long 00205 GUIVehicle::GUIVehiclePopupMenu::onCmdStopTrack(FXObject*,FXSelector,void*) { 00206 assert(myObject->getType()==GLO_VEHICLE); 00207 static_cast<GUIVehicle*>(myObject)->removeActiveAddVisualisation(myParent, VO_TRACKED); 00208 myParent->stopTrack(); 00209 return 1; 00210 } 00211 00212 00213 /* ------------------------------------------------------------------------- 00214 * GUIVehicle - methods 00215 * ----------------------------------------------------------------------- */ 00216 GUIVehicle::GUIVehicle(SUMOVehicleParameter* pars, const MSRoute* route, 00217 const MSVehicleType* type, 00218 int vehicleIndex) throw(ProcessError) 00219 : MSVehicle(pars, route, type, vehicleIndex), 00220 GUIGlObject(GLO_VEHICLE, pars->id) { 00221 // as it is possible to show all vehicle routes, we have to store them... (bug [ 2519761 ]) 00222 myRoutes = MSDevice_Vehroutes::buildVehicleDevices(*this, myDevices, 5); 00223 myMoveReminders.push_back(std::make_pair(myRoutes, 0.)); 00224 } 00225 00226 00227 GUIVehicle::~GUIVehicle() throw() { 00228 myLock.lock(); 00229 for (std::map<GUISUMOAbstractView*, int>::iterator i=myAdditionalVisualizations.begin(); i!=myAdditionalVisualizations.end(); ++i) { 00230 while (i->first->removeAdditionalGLVisualisation(this)); 00231 } 00232 myLock.unlock(); 00233 GLObjectValuePassConnector<SUMOReal>::removeObject(*this); 00234 delete myRoutes; 00235 } 00236 00237 00238 GUIGLObjectPopupMenu* 00239 GUIVehicle::getPopUpMenu(GUIMainWindow& app, 00240 GUISUMOAbstractView& parent) throw() { 00241 GUIGLObjectPopupMenu* ret = new GUIVehiclePopupMenu(app, parent, *this, myAdditionalVisualizations); 00242 buildPopupHeader(ret, app); 00243 buildCenterPopupEntry(ret); 00244 buildNameCopyPopupEntry(ret); 00245 buildSelectionPopupEntry(ret); 00246 // 00247 if (hasActiveAddVisualisation(&parent, VO_SHOW_ROUTE)) { 00248 new FXMenuCommand(ret, "Hide Current Route", 0, ret, MID_HIDE_CURRENTROUTE); 00249 } else { 00250 new FXMenuCommand(ret, "Show Current Route", 0, ret, MID_SHOW_CURRENTROUTE); 00251 } 00252 if (hasActiveAddVisualisation(&parent, VO_SHOW_ALL_ROUTES)) { 00253 new FXMenuCommand(ret, "Hide All Routes", 0, ret, MID_HIDE_ALLROUTES); 00254 } else { 00255 new FXMenuCommand(ret, "Show All Routes", 0, ret, MID_SHOW_ALLROUTES); 00256 } 00257 if (hasActiveAddVisualisation(&parent, VO_SHOW_BEST_LANES)) { 00258 new FXMenuCommand(ret, "Hide Best Lanes", 0, ret, MID_HIDE_BEST_LANES); 00259 } else { 00260 new FXMenuCommand(ret, "Show Best Lanes", 0, ret, MID_SHOW_BEST_LANES); 00261 } 00262 new FXMenuSeparator(ret); 00263 int trackedID = parent.getTrackedID(); 00264 if (trackedID<0||(size_t)trackedID!=getGlID()) { 00265 new FXMenuCommand(ret, "Start Tracking", 0, ret, MID_START_TRACK); 00266 } else { 00267 new FXMenuCommand(ret, "Stop Tracking", 0, ret, MID_STOP_TRACK); 00268 } 00269 new FXMenuSeparator(ret); 00270 // 00271 buildShowParamsPopupEntry(ret); 00272 buildPositionCopyEntry(ret, false); 00273 return ret; 00274 } 00275 00276 00277 GUIParameterTableWindow* 00278 GUIVehicle::getParameterWindow(GUIMainWindow& app, 00279 GUISUMOAbstractView&) throw() { 00280 GUIParameterTableWindow* ret = 00281 new GUIParameterTableWindow(app, *this, 15); 00282 // add items 00283 ret->mkItem("type [NAME]", false, myType->getID()); 00284 if (getParameter().repetitionNumber>0) { 00285 ret->mkItem("left same route [#]", false, (unsigned int) getParameter().repetitionNumber); 00286 } 00287 if (getParameter().repetitionOffset>0) { 00288 ret->mkItem("insertion period [s]", false, time2string(getParameter().repetitionOffset)); 00289 } 00290 ret->mkItem("waiting time [s]", true, 00291 new FunctionBinding<GUIVehicle, SUMOReal>(this, &MSVehicle::getWaitingSeconds)); 00292 ret->mkItem("last lane change [s]", true, 00293 new FunctionBinding<GUIVehicle, SUMOReal>(this, &GUIVehicle::getLastLaneChangeOffset)); 00294 ret->mkItem("desired depart [s]", false, time2string(getParameter().depart)); 00295 ret->mkItem("position [m]", true, 00296 new FunctionBinding<GUIVehicle, SUMOReal>(this, &GUIVehicle::getPositionOnLane)); 00297 ret->mkItem("speed [m/s]", true, 00298 new FunctionBinding<GUIVehicle, SUMOReal>(this, &GUIVehicle::getSpeed)); 00299 ret->mkItem("angle", true, 00300 new FunctionBinding<GUIVehicle, SUMOReal>(this, &MSVehicle::getAngle)); 00301 ret->mkItem("CO2 (HBEFA) [g/s]", true, 00302 new FunctionBinding<GUIVehicle, SUMOReal>(this, &GUIVehicle::getHBEFA_CO2Emissions)); 00303 ret->mkItem("CO (HBEFA) [g/s]", true, 00304 new FunctionBinding<GUIVehicle, SUMOReal>(this, &GUIVehicle::getHBEFA_COEmissions)); 00305 ret->mkItem("HC (HBEFA) [g/s]", true, 00306 new FunctionBinding<GUIVehicle, SUMOReal>(this, &GUIVehicle::getHBEFA_HCEmissions)); 00307 ret->mkItem("NOx (HBEFA) [g/s]", true, 00308 new FunctionBinding<GUIVehicle, SUMOReal>(this, &GUIVehicle::getHBEFA_NOxEmissions)); 00309 ret->mkItem("PMx (HBEFA) [g/s]", true, 00310 new FunctionBinding<GUIVehicle, SUMOReal>(this, &GUIVehicle::getHBEFA_PMxEmissions)); 00311 ret->mkItem("fuel (HBEFA) [l/s]", true, 00312 new FunctionBinding<GUIVehicle, SUMOReal>(this, &GUIVehicle::getHBEFA_FuelConsumption)); 00313 ret->mkItem("noise (Harmonoise) [dB]", true, 00314 new FunctionBinding<GUIVehicle, SUMOReal>(this, &GUIVehicle::getHarmonoise_NoiseEmissions)); 00315 // close building 00316 ret->closeBuilding(); 00317 return ret; 00318 } 00319 00320 00321 Boundary 00322 GUIVehicle::getCenteringBoundary() const throw() { 00323 Boundary b; 00324 b.add(getPosition()); 00325 b.grow(20); 00326 return b; 00327 } 00328 00329 00330 inline void 00331 drawAction_drawVehicleAsTrianglePlus(const GUIVehicle& veh, SUMOReal upscale) { 00332 SUMOReal length = veh.getVehicleType().getLengthWithGap(); 00333 glPushMatrix(); 00334 glScaled(upscale, upscale, 1); 00335 if (length<8) { 00336 glScaled(1, length, 1); 00337 glBegin(GL_TRIANGLES); 00338 glVertex2d(0, 0); 00339 glVertex2d(0-1.25, 1); 00340 glVertex2d(0+1.25, 1); 00341 glEnd(); 00342 } else { 00343 glBegin(GL_TRIANGLES); 00344 glVertex2d(0, 0); 00345 glVertex2d(0-1.25, 0+2); 00346 glVertex2d(0+1.25, 0+2); 00347 glVertex2d(0-1.25, 2); 00348 glVertex2d(0-1.25, length); 00349 glVertex2d(0+1.25, length); 00350 glVertex2d(0+1.25, 2); 00351 glVertex2d(0-1.25, 2); 00352 glVertex2d(0+1.25, length); 00353 glEnd(); 00354 } 00355 glPopMatrix(); 00356 } 00357 00358 inline void 00359 drawAction_drawVehicleAsBoxPlus(const GUIVehicle& veh, SUMOReal upscale) { 00360 SUMOReal length = veh.getVehicleType().getLengthWithGap(); 00361 SUMOReal offset = veh.getVehicleType().getMinGap(); 00362 glPushMatrix(); 00363 glRotated(90, 0, 0, 1); 00364 //glTranslated(veh.getVehicleType().getMinGap(), 0, 0); 00365 glScaled(1, veh.getVehicleType().getGuiWidth(), 1.); 00366 glScaled(upscale, upscale, 1); 00367 glBegin(GL_TRIANGLE_FAN); 00368 glVertex2d((length-offset)/2., 0); 00369 glVertex2d(offset, 0); 00370 glVertex2d(offset, -.4); 00371 glVertex2d(offset+.1, -.5); 00372 glVertex2d(length, -.5); 00373 glVertex2d(length, .5); 00374 glVertex2d(offset+.1, .5); 00375 glVertex2d(offset, .4); 00376 glVertex2d(offset, 0); 00377 glEnd(); 00378 glPopMatrix(); 00379 } 00380 00381 00382 void 00383 drawPoly(double* poses, SUMOReal offset) { 00384 glPushMatrix(); 00385 glTranslated(0, 0, offset*.1); 00386 glPolygonOffset(0, offset*-1); 00387 glBegin(GL_TRIANGLE_FAN); 00388 int i = 0; 00389 while (poses[i]>-999) { 00390 glVertex2d(poses[i],poses[i+1]); 00391 i = i + 2; 00392 } 00393 glEnd(); 00394 glPopMatrix(); 00395 } 00396 00397 00398 inline void 00399 drawAction_drawVehicleAsPoly(const GUIVehicle& veh, SUMOReal upscale) { 00400 RGBColor current = GLHelper::getColor(); 00401 RGBColor lighter = current.changedBrightness(.2); 00402 RGBColor darker = current.changedBrightness(-.2); 00403 00404 SUMOReal length = veh.getVehicleType().getLengthWithGap(); 00405 glPushMatrix(); 00406 glRotated(90, 0, 0, 1); 00407 glTranslated(veh.getVehicleType().getMinGap(), 0, 0); 00408 glScaled(length-veh.getVehicleType().getMinGap(), veh.getVehicleType().getGuiWidth(), 1.); 00409 glScaled(upscale, upscale, 1); 00410 SUMOVehicleShape shape = veh.getVehicleType().getGuiShape(); 00411 00412 // draw main body 00413 switch (shape) { 00414 case SVS_UNKNOWN: 00415 drawPoly(vehiclePoly_PassengerCarBody, 4); 00416 GLHelper::setColor(lighter); 00417 drawPoly(vehiclePoly_PassengerCarBodyFront, 4.5); 00418 glColor3d(0, 0, 0); 00419 drawPoly(vehiclePoly_PassengerFrontGlass, 4.5); 00420 break; 00421 case SVS_PEDESTRIAN: 00422 //glScaled(1./(length-veh.getVehicleType().getMinGap()), 1, 1.); 00423 glTranslated(0, 0, .045); 00424 GLHelper::drawFilledCircle(1); 00425 glTranslated(0, 0, -.045); 00426 glScaled(.7, 2, 1); 00427 glTranslated(0, 0, .04); 00428 GLHelper::setColor(lighter); 00429 GLHelper::drawFilledCircle(1); 00430 glTranslated(0, 0, -.04); 00431 break; 00432 case SVS_BICYCLE: 00433 case SVS_MOTORCYCLE: { 00434 glPushMatrix(); 00435 glTranslated(.5, 0, 0); 00436 glScaled(.25/(length-veh.getVehicleType().getMinGap()), 1, 1.); 00437 glTranslated(0, 0, .045); 00438 GLHelper::drawFilledCircle(1); 00439 glScaled(.7, 2, 1); 00440 glTranslated(0, 0, -.045); 00441 glTranslated(0, 0, .04); 00442 GLHelper::setColor(lighter); 00443 GLHelper::drawFilledCircle(1); 00444 glTranslated(0, 0, -.04); 00445 glPopMatrix(); 00446 } 00447 break; 00448 case SVS_PASSENGER: 00449 case SVS_PASSENGER_SEDAN: 00450 case SVS_PASSENGER_HATCHBACK: 00451 case SVS_PASSENGER_WAGON: 00452 drawPoly(vehiclePoly_PassengerCarBody, 4); 00453 GLHelper::setColor(lighter); 00454 drawPoly(vehiclePoly_PassengerCarBodyFront, 4.5); 00455 glColor3d(0, 0, 0); 00456 drawPoly(vehiclePoly_PassengerFrontGlass, 4.5); 00457 break; 00458 case SVS_PASSENGER_VAN: 00459 drawPoly(vehiclePoly_PassengerVanBody, 4); 00460 GLHelper::setColor(lighter); 00461 drawPoly(vehiclePoly_PassengerVanBodyFront, 4.5); 00462 glColor3d(0, 0, 0); 00463 drawPoly(vehiclePoly_PassengerVanFrontGlass, 4.5); 00464 drawPoly(vehiclePoly_PassengerVanRightGlass, 4.5); 00465 drawPoly(vehiclePoly_PassengerVanLeftGlass, 4.5); 00466 drawPoly(vehiclePoly_PassengerVanBackGlass, 4.5); 00467 break; 00468 case SVS_DELIVERY: 00469 drawPoly(vehiclePoly_PassengerVanBody, 4); 00470 GLHelper::setColor(lighter); 00471 drawPoly(vehiclePoly_PassengerVanBodyFront, 4.5); 00472 glColor3d(0, 0, 0); 00473 drawPoly(vehiclePoly_PassengerVanFrontGlass, 4.5); 00474 drawPoly(vehiclePoly_DeliveryMediumRightGlass, 4.5); 00475 drawPoly(vehiclePoly_DeliveryMediumLeftGlass, 4.5); 00476 break; 00477 case SVS_TRANSPORT: 00478 case SVS_TRANSPORT_SEMITRAILER: 00479 case SVS_TRANSPORT_1TRAILER: 00480 glScaled(1./(length-veh.getVehicleType().getMinGap()), 1, 1.); 00481 drawPoly(vehiclePoly_TransportBody, 4); 00482 glColor3d(0, 0, 0); 00483 drawPoly(vehiclePoly_TransportFrontGlass, 4.5); 00484 drawPoly(vehiclePoly_TransportRightGlass, 4.5); 00485 drawPoly(vehiclePoly_TransportLeftGlass, 4.5); 00486 break; 00487 case SVS_BUS: 00488 case SVS_BUS_TROLLEY: 00489 case SVS_BUS_CITY: { 00490 SUMOReal ml = length - veh.getVehicleType().getMinGap(); 00491 glScaled(1./(length-veh.getVehicleType().getMinGap()), 1, 1.); 00492 glTranslated(0, 0, .04); 00493 glBegin(GL_TRIANGLE_FAN); 00494 glVertex2d(ml/2., 0); 00495 glVertex2d(0, 0); 00496 glVertex2d(0, -.45); 00497 glVertex2d(0+.05, -.5); 00498 glVertex2d(ml-.05, -.5); 00499 glVertex2d(ml, -.45); 00500 glVertex2d(ml, .45); 00501 glVertex2d(ml-.05, .5); 00502 glVertex2d(0+.05, .5); 00503 glVertex2d(0, .45); 00504 glVertex2d(0, 0); 00505 glEnd(); 00506 glTranslated(0, 0, -.04); 00507 00508 glTranslated(0, 0, .045); 00509 glColor3d(0, 0, 0); 00510 glBegin(GL_QUADS); 00511 glVertex2d(0+.05, .48); 00512 glVertex2d(0+.05, -.48); 00513 glVertex2d(0+.15, -.48); 00514 glVertex2d(0+.15, .48); 00515 00516 glVertex2d(ml-.1, .45); 00517 glVertex2d(ml-.1, -.45); 00518 glVertex2d(ml-.05, -.45); 00519 glVertex2d(ml-.05, .45); 00520 00521 glVertex2d(0+.20, .49); 00522 glVertex2d(0+.20, .45); 00523 glVertex2d(ml-.20, .45); 00524 glVertex2d(ml-.20, .49); 00525 00526 glVertex2d(0+.20, -.49); 00527 glVertex2d(0+.20, -.45); 00528 glVertex2d(ml-.20, -.45); 00529 glVertex2d(ml-.20, -.49); 00530 00531 glEnd(); 00532 glTranslated(0, 0, -.045); 00533 } 00534 break; 00535 case SVS_BUS_OVERLAND: 00536 case SVS_RAIL: 00537 case SVS_RAIL_LIGHT: 00538 case SVS_RAIL_CITY: 00539 case SVS_RAIL_SLOW: 00540 case SVS_RAIL_FAST: 00541 case SVS_RAIL_CARGO: 00542 glScaled(1./(length-veh.getVehicleType().getMinGap()), 1, 1.); 00543 glTranslated(0, 0, .04); 00544 glBegin(GL_TRIANGLE_FAN); 00545 glVertex2d(length/2., 0); 00546 glVertex2d(0, 0); 00547 glVertex2d(0, -.45); 00548 glVertex2d(.05, -.5); 00549 glVertex2d(length-.05, -.5); 00550 glVertex2d(length, -.45); 00551 glVertex2d(length, .45); 00552 glVertex2d(length-.05, .5); 00553 glVertex2d(.05, .5); 00554 glVertex2d(0, .45); 00555 glVertex2d(0, 0); 00556 glEnd(); 00557 glTranslated(0, 0, -.04); 00558 break; 00559 case SVS_E_VEHICLE: 00560 drawPoly(vehiclePoly_EVehicleBody, 4); 00561 glColor3d(0, 0, 0); 00562 drawPoly(vehiclePoly_EVehicleFrontGlass, 4.5); 00563 glTranslated(0, 0, .048); 00564 GLHelper::setColor(current); 00565 glBegin(GL_QUADS); 00566 glVertex2d(.3, .5); 00567 glVertex2d(.35, .5); 00568 glVertex2d(.35, -.5); 00569 glVertex2d(.3, -.5); 00570 00571 glVertex2d(.3, -.05); 00572 glVertex2d(.7, -.05); 00573 glVertex2d(.7, .05); 00574 glVertex2d(.3, .05); 00575 00576 glVertex2d(.7, .5); 00577 glVertex2d(.65, .5); 00578 glVertex2d(.65, -.5); 00579 glVertex2d(.7, -.5); 00580 glEnd(); 00581 glTranslated(0, 0, -.048); 00582 //drawPoly(vehiclePoly_EVehicleBackGlass, 4.5); 00583 break; 00584 case SVS_ANT: 00585 glPushMatrix(); 00586 // ant is stretched via vehicle length 00587 GLHelper::setColor(darker); 00588 // draw left side 00589 GLHelper::drawBoxLine(Position(-0.2, -.10), 350, 0.5, .02); 00590 GLHelper::drawBoxLine(Position(-0.3, -.50), 240, 0.4, .03); 00591 GLHelper::drawBoxLine(Position(0.3, -.10), 340, 0.8, .03); 00592 GLHelper::drawBoxLine(Position(0.05,-.80), 290, 0.6, .04); 00593 GLHelper::drawBoxLine(Position(0.4, -.10), 20, 0.8, .03); 00594 GLHelper::drawBoxLine(Position(0.65,-.80), 75, 0.6, .04); 00595 GLHelper::drawBoxLine(Position(0.5, -.10), 55, 0.8, .04); 00596 GLHelper::drawBoxLine(Position(1.1, -.55), 90, 0.6, .04); 00597 // draw right side 00598 GLHelper::drawBoxLine(Position(-0.2, .10), 190, 0.5, .02); 00599 GLHelper::drawBoxLine(Position(-0.3, .50), 300, 0.4, .03); 00600 GLHelper::drawBoxLine(Position(0.3, .10), 200, 0.8, .03); 00601 GLHelper::drawBoxLine(Position(0.05, .80), 250, 0.6, .04); 00602 GLHelper::drawBoxLine(Position(0.4, .10), 160, 0.8, .03); 00603 GLHelper::drawBoxLine(Position(0.65, .80), 105, 0.6, .04); 00604 GLHelper::drawBoxLine(Position(0.5, .10), 125, 0.8, .04); 00605 GLHelper::drawBoxLine(Position(1.1, .55), 90, 0.6, .04); 00606 // draw body 00607 GLHelper::setColor(current); 00608 glTranslated(0,0,0.1); 00609 GLHelper::drawFilledCircle(.25,16); 00610 glTranslated(.4,0,0); 00611 GLHelper::drawFilledCircle(.2,16); 00612 glTranslated(.4,0,0); 00613 GLHelper::drawFilledCircle(.3,16); 00614 glPopMatrix(); 00615 break; 00616 default: // same as passenger 00617 drawPoly(vehiclePoly_PassengerCarBody, 4); 00618 glColor3d(1, 1, 1); 00619 drawPoly(vehiclePoly_PassengerCarBodyFront, 4.5); 00620 glColor3d(0, 0, 0); 00621 drawPoly(vehiclePoly_PassengerFrontGlass, 4.5); 00622 break; 00623 } 00624 00625 // draw decorations 00626 switch (shape) { 00627 case SVS_PEDESTRIAN: 00628 break; 00629 case SVS_BICYCLE: 00630 //glScaled(length-veh.getVehicleType().getMinGap(), 1, 1.); 00631 glBegin(GL_TRIANGLE_FAN); 00632 glVertex2d(1/2., 0); 00633 glVertex2d(0, 0); 00634 glVertex2d(0, -.03); 00635 glVertex2d(0+.05, -.05); 00636 glVertex2d(1-.05, -.05); 00637 glVertex2d(1, -.03); 00638 glVertex2d(1, .03); 00639 glVertex2d(1-.05, .05); 00640 glVertex2d(0+.05, .05); 00641 glVertex2d(0, .03); 00642 glVertex2d(0, 0); 00643 glEnd(); 00644 break; 00645 case SVS_MOTORCYCLE: 00646 //glScaled(length-veh.getVehicleType().getMinGap(), 1, 1.); 00647 glBegin(GL_TRIANGLE_FAN); 00648 glVertex2d(1/2., 0); 00649 glVertex2d(0, 0); 00650 glVertex2d(0, -.03); 00651 glVertex2d(0+.05, -.2); 00652 glVertex2d(1-.05, -.2); 00653 glVertex2d(1, -.03); 00654 glVertex2d(1, .03); 00655 glVertex2d(1-.05, .2); 00656 glVertex2d(0+.05, .2); 00657 glVertex2d(0, .03); 00658 glVertex2d(0, 0); 00659 glEnd(); 00660 break; 00661 case SVS_PASSENGER: 00662 case SVS_PASSENGER_SEDAN: 00663 drawPoly(vehiclePoly_PassengerSedanRightGlass, 4.5); 00664 drawPoly(vehiclePoly_PassengerSedanLeftGlass, 4.5); 00665 drawPoly(vehiclePoly_PassengerSedanBackGlass, 4.5); 00666 break; 00667 case SVS_PASSENGER_HATCHBACK: 00668 drawPoly(vehiclePoly_PassengerHatchbackRightGlass, 4.5); 00669 drawPoly(vehiclePoly_PassengerHatchbackLeftGlass, 4.5); 00670 drawPoly(vehiclePoly_PassengerHatchbackBackGlass, 4.5); 00671 break; 00672 case SVS_PASSENGER_WAGON: 00673 drawPoly(vehiclePoly_PassengerWagonRightGlass, 4.5); 00674 drawPoly(vehiclePoly_PassengerWagonLeftGlass, 4.5); 00675 drawPoly(vehiclePoly_PassengerWagonBackGlass, 4.5); 00676 break; 00677 case SVS_PASSENGER_VAN: 00678 case SVS_DELIVERY: 00679 break; 00680 case SVS_TRANSPORT: 00681 GLHelper::setColor(current); 00682 GLHelper::drawBoxLine(Position(2.3, 0), 90., length-veh.getVehicleType().getMinGap()-2.3, .5); 00683 break; 00684 case SVS_TRANSPORT_SEMITRAILER: 00685 GLHelper::setColor(current); 00686 GLHelper::drawBoxLine(Position(2.8, 0), 90., length-veh.getVehicleType().getMinGap()-2.8, .5); 00687 break; 00688 case SVS_TRANSPORT_1TRAILER: { 00689 GLHelper::setColor(current); 00690 SUMOReal l = length-veh.getVehicleType().getMinGap()-2.3; 00691 l = l/2.; 00692 GLHelper::drawBoxLine(Position(2.3, 0), 90., l, .5); 00693 GLHelper::drawBoxLine(Position(2.3+l+.5, 0), 90., l-.5, .5); 00694 break; 00695 } 00696 case SVS_BUS_TROLLEY: 00697 glPushMatrix(); 00698 glTranslated(0,0,.1); 00699 GLHelper::setColor(darker); 00700 GLHelper::drawBoxLine(Position(3.8, 0), 90., 1, .3); 00701 glTranslated(0,0,.1); 00702 glColor3d(0,0,0); 00703 GLHelper::drawBoxLine(Position(4.3, .2), 90., 1, .06); 00704 GLHelper::drawBoxLine(Position(4.3, -.2), 90., 1, .06); 00705 GLHelper::drawBoxLine(Position(5.3, .2), 90., 3, .03); 00706 GLHelper::drawBoxLine(Position(5.3, -.2), 90., 3, .03); 00707 glPopMatrix(); 00708 break; 00709 case SVS_BUS: 00710 case SVS_BUS_CITY: 00711 case SVS_BUS_CITY_FLEXIBLE: 00712 case SVS_BUS_OVERLAND: 00713 case SVS_RAIL: 00714 case SVS_RAIL_LIGHT: 00715 case SVS_RAIL_CITY: 00716 case SVS_RAIL_SLOW: 00717 case SVS_RAIL_FAST: 00718 case SVS_RAIL_CARGO: 00719 case SVS_E_VEHICLE: 00720 case SVS_ANT: 00721 break; 00722 default: // same as passenger/sedan 00723 drawPoly(vehiclePoly_PassengerSedanRightGlass, 4.5); 00724 drawPoly(vehiclePoly_PassengerSedanLeftGlass, 4.5); 00725 drawPoly(vehiclePoly_PassengerSedanBackGlass, 4.5); 00726 break; 00727 } 00728 /* 00729 glBegin(GL_TRIANGLE_FAN); 00730 glVertex2d(.5,.5); // center - strip begin 00731 glVertex2d(0, .5); // center, front 00732 glVertex2d(0, .8); // ... clockwise ... (vehicle right side) 00733 glVertex2d(0.08, .94); 00734 glVertex2d(0.25, 1.); 00735 glVertex2d(0.95, 1.); 00736 glVertex2d(1., .9); 00737 glVertex2d(1., .1); // (vehicle left side) 00738 glVertex2d(0.95, 0.); 00739 glVertex2d(0.25, 0.); 00740 glVertex2d(0.08, .06); 00741 glVertex2d(0, .2); // 00742 glVertex2d(0, .5); // center, front (close) 00743 glEnd(); 00744 00745 glPolygonOffset(0, -4.5); 00746 glColor3d(1, 1, 1); // front 00747 glBegin(GL_TRIANGLE_FAN); 00748 glVertex2d(0.1,0.5); 00749 glVertex2d(0.025,0.5); 00750 glVertex2d(0.025,0.75); 00751 glVertex2d(0.27,0.9); 00752 glVertex2d(0.27,0.1); 00753 glVertex2d(0.025,0.25); 00754 glVertex2d(0.025,0.5); 00755 glEnd(); 00756 00757 glColor3d(0, 0, 0); // front glass 00758 glBegin(GL_TRIANGLE_FAN); 00759 glVertex2d(0.35,0.5); 00760 glVertex2d(0.3,0.5); 00761 glVertex2d(0.3,0.9); 00762 glVertex2d(0.43,0.8); 00763 glVertex2d(0.43,0.2); 00764 glVertex2d(0.3,0.1); 00765 glVertex2d(0.3,0.5); 00766 glEnd(); 00767 00768 glBegin(GL_TRIANGLE_FAN); // back glass 00769 glVertex2d(0.92,0.5); 00770 glVertex2d(0.90,0.5); 00771 glVertex2d(0.90,0.8); 00772 glVertex2d(0.95,0.9); 00773 glVertex2d(0.95,0.1); 00774 glVertex2d(0.90,0.2); 00775 glVertex2d(0.90,0.5); 00776 glEnd(); 00777 00778 glBegin(GL_TRIANGLE_FAN); // right glass 00779 glVertex2d(0.36,0.07); 00780 glVertex2d(0.34,0.03); 00781 glVertex2d(0.94,0.03); 00782 glVertex2d(0.87,0.13); 00783 glVertex2d(0.45,0.13); 00784 glVertex2d(0.34,0.03); 00785 glEnd(); 00786 00787 glBegin(GL_TRIANGLE_FAN); // left glass 00788 glVertex2d(0.36,1.-0.07); 00789 glVertex2d(0.34,1.-0.03); 00790 glVertex2d(0.94,1.-0.03); 00791 glVertex2d(0.87,1.-0.13); 00792 glVertex2d(0.45,1.-0.13); 00793 glVertex2d(0.34,1.-0.03); 00794 glEnd(); 00795 */ 00796 00797 glPopMatrix(); 00798 } 00799 00800 00801 #define BLINKER_POS_FRONT .5 00802 #define BLINKER_POS_BACK .5 00803 #define BRAKELIGHT_POS 1.2 00804 00805 inline void 00806 drawAction_drawBlinker(const GUIVehicle& veh, double dir) { 00807 glColor3d(1.f, .8f, 0); 00808 glPushMatrix(); 00809 glTranslated(dir, BLINKER_POS_FRONT+veh.getVehicleType().getMinGap(), 0); 00810 GLHelper::drawFilledCircle(.5, 6); 00811 glPopMatrix(); 00812 glPushMatrix(); 00813 glTranslated(dir, veh.getVehicleType().getLengthWithGap()-BLINKER_POS_BACK, 0); 00814 GLHelper::drawFilledCircle(.5, 6); 00815 glPopMatrix(); 00816 } 00817 00818 00819 inline void 00820 drawAction_drawVehicleBlinker(const GUIVehicle& veh) { 00821 if (veh.getVehicleType().getGuiWidth()<.5) { 00822 return; 00823 } 00824 if (!veh.signalSet(MSVehicle::VEH_SIGNAL_BLINKER_RIGHT|MSVehicle::VEH_SIGNAL_BLINKER_LEFT|MSVehicle::VEH_SIGNAL_BLINKER_EMERGENCY)) { 00825 return; 00826 } 00827 if (veh.signalSet(MSVehicle::VEH_SIGNAL_BLINKER_RIGHT)) { 00828 drawAction_drawBlinker(veh, (double) -1.*veh.getVehicleType().getGuiWidth()*.5); 00829 } 00830 if (veh.signalSet(MSVehicle::VEH_SIGNAL_BLINKER_LEFT)) { 00831 drawAction_drawBlinker(veh, (double) 1.*veh.getVehicleType().getGuiWidth()*.5); 00832 } 00833 if (veh.signalSet(MSVehicle::VEH_SIGNAL_BLINKER_EMERGENCY)) { 00834 drawAction_drawBlinker(veh, (double) -1.*veh.getVehicleType().getGuiWidth()*.5); 00835 drawAction_drawBlinker(veh, (double) 1.*veh.getVehicleType().getGuiWidth()*.5); 00836 } 00837 } 00838 00839 00840 inline void 00841 drawAction_drawVehicleBrakeLight(const GUIVehicle& veh) { 00842 if (!veh.signalSet(MSVehicle::VEH_SIGNAL_BRAKELIGHT)) { 00843 return; 00844 } 00845 glColor3f(1.f, .2f, 0); 00846 glPushMatrix(); 00847 glTranslated(-veh.getVehicleType().getGuiWidth()+BRAKELIGHT_POS, veh.getVehicleType().getLengthWithGap(), 0); 00848 GLHelper::drawFilledCircle(.5, 6); 00849 glPopMatrix(); 00850 glPushMatrix(); 00851 glTranslated(veh.getVehicleType().getGuiWidth()-BRAKELIGHT_POS, veh.getVehicleType().getLengthWithGap(), 0); 00852 GLHelper::drawFilledCircle(.5, 6); 00853 glPopMatrix(); 00854 } 00855 00856 00857 void 00858 GUIVehicle::drawGL(const GUIVisualizationSettings& s) const throw() { 00859 glPushName(getGlID()); 00860 glPushMatrix(); 00861 Position p1 = myLane->getShape().positionAtLengthPosition(myState.pos()); 00862 glTranslated(p1.x(), p1.y(), getType()); 00863 glRotated(getAngle(), 0, 0, 1); 00864 // set lane color 00865 setColor(s); 00866 /* 00867 MSLCM_DK2004 &m2 = static_cast<MSLCM_DK2004&>(veh->getLaneChangeModel()); 00868 if((m2.getState()&LCA_URGENT)!=0) { 00869 glColor3d(1, .4, .4); 00870 } else if((m2.getState()&LCA_SPEEDGAIN)!=0) { 00871 glColor3d(.4, .4, 1); 00872 } else { 00873 glColor3d(.4, 1, .4); 00874 } 00875 */ 00876 // draw the vehicle 00877 SUMOReal upscale = s.vehicleExaggeration; 00878 switch (s.vehicleQuality) { 00879 case 0: 00880 drawAction_drawVehicleAsTrianglePlus(*this, upscale); 00881 break; 00882 case 1: 00883 drawAction_drawVehicleAsBoxPlus(*this, upscale); 00884 break; 00885 case 2: 00886 default: 00887 drawAction_drawVehicleAsPoly(*this, upscale); 00888 break; 00889 } 00890 // draw the blinker if wished 00891 if (s.showBlinker) { 00892 glTranslated(0, 0, .1); 00893 switch (getVehicleType().getGuiShape()) { 00894 case SVS_PEDESTRIAN: 00895 case SVS_BICYCLE: 00896 case SVS_ANT: 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 throw() { 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 throw() { 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 throw() { 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) throw() { 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) throw() { 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 throw() { 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 throw() { 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 throw() { 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