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