|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // The gui-version of a MSE3Collector 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 #include "GUIE3Collector.h" 00031 #include "GUIEdge.h" 00032 #include <utils/geom/Line.h> 00033 #include <utils/gui/div/GUIParameterTableWindow.h> 00034 #include <utils/gui/div/GLHelper.h> 00035 #include <microsim/logging/FunctionBinding.h> 00036 #include <microsim/MSLane.h> 00037 00038 #ifdef _WIN32 00039 #include <windows.h> 00040 #endif 00041 00042 #include <GL/gl.h> 00043 00044 #ifdef CHECK_MEMORY_LEAKS 00045 #include <foreign/nvwa/debug_new.h> 00046 #endif // CHECK_MEMORY_LEAKS 00047 00048 00049 // =========================================================================== 00050 // method definitions 00051 // =========================================================================== 00052 /* ------------------------------------------------------------------------- 00053 * GUIE3Collector::MyWrapper-methods 00054 * ----------------------------------------------------------------------- */ 00055 GUIE3Collector::MyWrapper::MyWrapper(GUIE3Collector& detector) throw() 00056 : GUIDetectorWrapper("E3 detector", detector.getID()), 00057 myDetector(detector) { 00058 const CrossSectionVector& entries = detector.getEntries(); 00059 const CrossSectionVector& exits = detector.getExits(); 00060 CrossSectionVectorConstIt i; 00061 for (i=entries.begin(); i!=entries.end(); ++i) { 00062 SingleCrossingDefinition def = buildDefinition(*i); 00063 myBoundary.add(def.myFGPosition); 00064 myEntryDefinitions.push_back(def); 00065 } 00066 for (i=exits.begin(); i!=exits.end(); ++i) { 00067 SingleCrossingDefinition def = buildDefinition(*i); 00068 myBoundary.add(def.myFGPosition); 00069 myExitDefinitions.push_back(def); 00070 } 00071 } 00072 00073 00074 GUIE3Collector::MyWrapper::~MyWrapper() throw() {} 00075 00076 00077 GUIE3Collector::MyWrapper::SingleCrossingDefinition 00078 GUIE3Collector::MyWrapper::buildDefinition(const MSCrossSection& section) { 00079 const MSLane* lane = section.myLane; 00080 SUMOReal pos = section.myPosition; 00081 const PositionVector& v = lane->getShape(); 00082 Line l(v.getBegin(), v.getEnd()); 00083 SingleCrossingDefinition def; 00084 def.myFGPosition = v.positionAtLengthPosition(pos); 00085 def.myFGRotation = -v.rotationDegreeAtLengthPosition(pos); 00086 return def; 00087 } 00088 00089 00090 GUIParameterTableWindow* 00091 GUIE3Collector::MyWrapper::getParameterWindow(GUIMainWindow& app, 00092 GUISUMOAbstractView&) throw() { 00093 GUIParameterTableWindow* ret = 00094 new GUIParameterTableWindow(app, *this, 3); 00095 // add items 00096 // values 00097 ret->mkItem("vehicles within [#]", true, 00098 new FunctionBinding<MSE3Collector, SUMOReal>(&myDetector, &MSE3Collector::getVehiclesWithin)); 00099 ret->mkItem("mean speed [m/s]", true, 00100 new FunctionBinding<MSE3Collector, SUMOReal>(&myDetector, &MSE3Collector::getCurrentMeanSpeed)); 00101 ret->mkItem("haltings [#]", true, 00102 new FunctionBinding<MSE3Collector, SUMOReal>(&myDetector, &MSE3Collector::getCurrentHaltingNumber)); 00103 // close building 00104 ret->closeBuilding(); 00105 return ret; 00106 } 00107 00108 00109 void 00110 GUIE3Collector::MyWrapper::drawGL(const GUIVisualizationSettings& s) const throw() { 00111 glPushName(getGlID()); 00112 glPushMatrix(); 00113 glTranslated(0, 0, getType()); 00114 typedef std::vector<SingleCrossingDefinition> CrossingDefinitions; 00115 CrossingDefinitions::const_iterator i; 00116 glColor3d(0, .8, 0); 00117 for (i=myEntryDefinitions.begin(); i!=myEntryDefinitions.end(); ++i) { 00118 drawSingleCrossing((*i).myFGPosition, (*i).myFGRotation, s.addExaggeration); 00119 } 00120 glColor3d(.8, 0, 0); 00121 for (i=myExitDefinitions.begin(); i!=myExitDefinitions.end(); ++i) { 00122 drawSingleCrossing((*i).myFGPosition, (*i).myFGRotation, s.addExaggeration); 00123 } 00124 glPopMatrix(); 00125 drawName(getCenteringBoundary().getCenter(), s.scale, s.addName); 00126 glPopName(); 00127 } 00128 00129 00130 void 00131 GUIE3Collector::MyWrapper::drawSingleCrossing(const Position& pos, 00132 SUMOReal rot, SUMOReal upscale) const { 00133 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 00134 glPushMatrix(); 00135 glScaled(upscale, upscale, 1); 00136 glTranslated(pos.x(), pos.y(), 0); 00137 glRotated(rot, 0, 0, 1); 00138 glBegin(GL_LINES); 00139 glVertex2d(1.7, 0); 00140 glVertex2d(-1.7, 0); 00141 glEnd(); 00142 glBegin(GL_QUADS); 00143 glVertex2d(-1.7, .5); 00144 glVertex2d(-1.7, -.5); 00145 glVertex2d(1.7, -.5); 00146 glVertex2d(1.7, .5); 00147 glEnd(); 00148 // arrows 00149 glTranslated(1.5, 0, 0); 00150 GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05); 00151 GLHelper::drawTriangleAtEnd(Line(Position(0, 4), Position(0, 1)), (SUMOReal) 1, (SUMOReal) .25); 00152 glTranslated(-3, 0, 0); 00153 GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05); 00154 GLHelper::drawTriangleAtEnd(Line(Position(0, 4), Position(0, 1)), (SUMOReal) 1, (SUMOReal) .25); 00155 glPopMatrix(); 00156 } 00157 00158 00159 Boundary 00160 GUIE3Collector::MyWrapper::getCenteringBoundary() const throw() { 00161 Boundary b(myBoundary); 00162 b.grow(20); 00163 return b; 00164 } 00165 00166 00167 GUIE3Collector& 00168 GUIE3Collector::MyWrapper::getDetector() { 00169 return myDetector; 00170 } 00171 00172 00173 /* ------------------------------------------------------------------------- 00174 * GUIE3Collector-methods 00175 * ----------------------------------------------------------------------- */ 00176 GUIE3Collector::GUIE3Collector(const std::string& id, 00177 const CrossSectionVector& entries, const CrossSectionVector& exits, 00178 SUMOReal haltingSpeedThreshold, 00179 SUMOTime haltingTimeThreshold) throw() 00180 : MSE3Collector(id, entries, exits, haltingSpeedThreshold, haltingTimeThreshold) {} 00181 00182 00183 GUIE3Collector::~GUIE3Collector() throw() {} 00184 00185 00186 const CrossSectionVector& 00187 GUIE3Collector::getEntries() const { 00188 return myEntries; 00189 } 00190 00191 00192 const CrossSectionVector& 00193 GUIE3Collector::getExits() const { 00194 return myExits; 00195 } 00196 00197 00198 00199 GUIDetectorWrapper* 00200 GUIE3Collector::buildDetectorGUIRepresentation() { 00201 return new MyWrapper(*this); 00202 } 00203 00204 00205 00206 /****************************************************************************/ 00207