GUI_E2_ZS_Collector.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // The gui-version of the MS_E2_ZS_Collector
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright 2001-2010 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 <utils/gui/globjects/GUIGlObject.h>
00031 #include <utils/geom/Position2DVector.h>
00032 #include "GUILaneWrapper.h"
00033 #include "GUI_E2_ZS_Collector.h"
00034 #include <utils/gui/div/GLHelper.h>
00035 #include <utils/geom/Line2D.h>
00036 #include <utils/geom/GeomHelper.h>
00037 #include <utils/gui/div/GUIParameterTableWindow.h>
00038 #include <microsim/logging/FunctionBinding.h>
00039 
00040 #ifdef _WIN32
00041 #include <windows.h>
00042 #endif
00043 
00044 #include <GL/gl.h>
00045 
00046 #ifdef CHECK_MEMORY_LEAKS
00047 #include <foreign/nvwa/debug_new.h>
00048 #endif // CHECK_MEMORY_LEAKS
00049 
00050 
00051 // ===========================================================================
00052 // method definitions
00053 // ===========================================================================
00054 /* -------------------------------------------------------------------------
00055  * GUI_E2_ZS_Collector-methods
00056  * ----------------------------------------------------------------------- */
00057 GUI_E2_ZS_Collector::GUI_E2_ZS_Collector(const std::string &id, DetectorUsage usage,
00058         MSLane * const lane, SUMOReal startPos, SUMOReal detLength,
00059         SUMOTime haltingTimeThreshold, SUMOReal haltingSpeedThreshold,
00060         SUMOReal jamDistThreshold) throw()
00061         : MSE2Collector(id, usage, lane, startPos, detLength, haltingTimeThreshold,
00062                         haltingSpeedThreshold, jamDistThreshold) {}
00063 
00064 
00065 
00066 GUI_E2_ZS_Collector::~GUI_E2_ZS_Collector() throw() {}
00067 
00068 
00069 GUIDetectorWrapper *
00070 GUI_E2_ZS_Collector::buildDetectorWrapper(GUIGlObjectStorage &idStorage,
00071         GUILaneWrapper &wrapper) {
00072     return new MyWrapper(*this, idStorage, wrapper);
00073 }
00074 
00075 GUIDetectorWrapper *
00076 GUI_E2_ZS_Collector::buildDetectorWrapper(GUIGlObjectStorage &idStorage,
00077         GUILaneWrapper &wrapper,
00078         GUI_E2_ZS_CollectorOverLanes& p,
00079         GLuint glID) {
00080     return new MyWrapper(*this, idStorage, glID, p, wrapper);
00081 }
00082 
00083 
00084 
00085 /* -------------------------------------------------------------------------
00086  * GUI_E2_ZS_Collector::MyWrapper-methods
00087  * ----------------------------------------------------------------------- */
00088 GUI_E2_ZS_Collector::MyWrapper::MyWrapper(GUI_E2_ZS_Collector &detector,
00089         GUIGlObjectStorage &idStorage,
00090         GUILaneWrapper &wrapper) throw()
00091         : GUIDetectorWrapper(idStorage, "E2 detector:"+detector.getID()),
00092         myDetector(detector) {
00093     myConstruct(detector, wrapper);
00094 }
00095 
00096 
00097 GUI_E2_ZS_Collector::MyWrapper::MyWrapper(
00098     GUI_E2_ZS_Collector &detector, GUIGlObjectStorage &idStorage,
00099     GLuint glID, GUI_E2_ZS_CollectorOverLanes &,
00100     GUILaneWrapper &wrapper) throw()
00101         : GUIDetectorWrapper("E2 detector:"+detector.getID(), glID),
00102         myDetector(detector) {
00103     myConstruct(detector, wrapper);
00104 }
00105 
00106 void
00107 GUI_E2_ZS_Collector::MyWrapper::myConstruct(GUI_E2_ZS_Collector &detector,
00108         GUILaneWrapper &wrapper) {
00109     const Position2DVector &v = wrapper.getShape();
00110     Line2D l(v.getBegin(), v.getEnd());
00111     // build geometry
00112     myFullGeometry = v.getSubpart(detector.getStartPos(), detector.getEndPos());
00113     //
00114     myShapeRotations.reserve(myFullGeometry.size()-1);
00115     myShapeLengths.reserve(myFullGeometry.size()-1);
00116     int e = (int) myFullGeometry.size() - 1;
00117     for (int i=0; i<e; ++i) {
00118         const Position2D &f = myFullGeometry[i];
00119         const Position2D &s = myFullGeometry[i+1];
00120         myShapeLengths.push_back(f.distanceTo(s));
00121         myShapeRotations.push_back((SUMOReal) atan2((s.x()-f.x()), (f.y()-s.y()))*(SUMOReal) 180.0/(SUMOReal) PI);
00122     }
00123     //
00124     myBoundary = myFullGeometry.getBoxBoundary();
00125 }
00126 
00127 
00128 GUI_E2_ZS_Collector::MyWrapper::~MyWrapper() throw() {}
00129 
00130 
00131 Boundary
00132 GUI_E2_ZS_Collector::MyWrapper::getCenteringBoundary() const throw() {
00133     Boundary b(myBoundary);
00134     b.grow(20);
00135     return b;
00136 }
00137 
00138 
00139 GUIParameterTableWindow *
00140 GUI_E2_ZS_Collector::MyWrapper::getParameterWindow(GUIMainWindow &app,
00141         GUISUMOAbstractView &) throw() {
00142     GUIParameterTableWindow *ret =
00143         new GUIParameterTableWindow(app, *this, 13);
00144     // add items
00145     // parameter
00146     ret->mkItem("length [m]", false, myDetector.getEndPos()-myDetector.getStartPos());
00147     ret->mkItem("position [m]", false, myDetector.getStartPos());
00148     ret->mkItem("lane", false, myDetector.getLane()->getID());
00149     // values
00150     ret->mkItem("vehicles [#]", true,
00151                 new FunctionBinding<MSE2Collector, unsigned>(&myDetector, &MSE2Collector::getCurrentVehicleNumber));
00152     ret->mkItem("occupancy [%]", true,
00153                 new FunctionBinding<MSE2Collector, SUMOReal>(&myDetector, &MSE2Collector::getCurrentOccupancy));
00154     ret->mkItem("mean speed [m/s]", true,
00155                 new FunctionBinding<MSE2Collector, SUMOReal>(&myDetector, &MSE2Collector::getCurrentMeanSpeed));
00156     ret->mkItem("mean vehicle length [m]", true,
00157                 new FunctionBinding<MSE2Collector, SUMOReal>(&myDetector, &MSE2Collector::getCurrentMeanLength));
00158     ret->mkItem("jam number [#]", true,
00159                 new FunctionBinding<MSE2Collector, unsigned>(&myDetector, &MSE2Collector::getCurrentJamNumber));
00160     ret->mkItem("max jam length [veh]", true,
00161                 new FunctionBinding<MSE2Collector, unsigned>(&myDetector, &MSE2Collector::getCurrentMaxJamLengthInVehicles));
00162     ret->mkItem("max jam length [m]", true,
00163                 new FunctionBinding<MSE2Collector, SUMOReal>(&myDetector, &MSE2Collector::getCurrentMaxJamLengthInMeters));
00164     ret->mkItem("jam length sum [veh]", true,
00165                 new FunctionBinding<MSE2Collector, unsigned>(&myDetector, &MSE2Collector::getCurrentJamLengthInVehicles));
00166     ret->mkItem("jam length sum [m]", true,
00167                 new FunctionBinding<MSE2Collector, SUMOReal>(&myDetector, &MSE2Collector::getCurrentJamLengthInMeters));
00168     ret->mkItem("started halts [#]", true,
00169                 new FunctionBinding<MSE2Collector, unsigned>(&myDetector, &MSE2Collector::getCurrentStartedHalts));
00170     // close building
00171     ret->closeBuilding();
00172     return ret;
00173 }
00174 
00175 
00176 const std::string &
00177 GUI_E2_ZS_Collector::MyWrapper::getMicrosimID() const throw() {
00178     return myDetector.getID();
00179 }
00180 
00181 
00182 void
00183 GUI_E2_ZS_Collector::MyWrapper::drawGL(const GUIVisualizationSettings &s) const throw() {
00184     // (optional) set id
00185     if (s.needsGlID) {
00186         glPushName(getGlID());
00187     }
00188     glTranslated(0, 0, -.03);
00189     SUMOReal dwidth = 1;
00190     if (myDetector.getUsageType()==DU_TL_CONTROL) {
00191         dwidth = (SUMOReal) 0.3;
00192         glColor3d(0, (SUMOReal) .6, (SUMOReal) .8);
00193     } else {
00194         glColor3d(0, (SUMOReal) .8, (SUMOReal) .8);
00195     }
00196     SUMOReal width=2; // !!!
00197     if (width*s.addExaggeration>1.0) {
00198         glScaled(s.addExaggeration, s.addExaggeration, 1);
00199         GLHelper::drawBoxLines(myFullGeometry, myShapeRotations, myShapeLengths, dwidth);
00200     } else {
00201         int e = (int) myFullGeometry.size() - 1;
00202         for (int i=0; i<e; ++i) {
00203             GLHelper::drawLine(myFullGeometry[i], myShapeRotations[i], myShapeLengths[i]);
00204         }
00205     }
00206     glTranslated(0, 0, .03);
00207     // (optional) draw name
00208     if (s.drawAddName) {
00209         drawGLName(getCenteringBoundary().getCenter(), getMicrosimID(), s.addNameSize / s.scale);
00210     }
00211     // (optional) clear id
00212     if (s.needsGlID) {
00213         glPopName();
00214     }
00215 }
00216 
00217 
00218 GUI_E2_ZS_Collector &
00219 GUI_E2_ZS_Collector::MyWrapper::getDetector() {
00220     return myDetector;
00221 }
00222 
00223 
00224 
00225 /****************************************************************************/
00226 

Generated on Wed May 5 00:06:29 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6