SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GUIInductLoop.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // The gui-version of the MSInductLoop, together with the according
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12 // Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
35 #include "GUIInductLoop.h"
36 #include <utils/gui/div/GLHelper.h>
37 #include <utils/geom/Line.h>
41 #include <microsim/MSLane.h>
43 #include "GUIEdge.h"
45 
46 #ifdef CHECK_MEMORY_LEAKS
47 #include <foreign/nvwa/debug_new.h>
48 #endif // CHECK_MEMORY_LEAKS
49 
50 
51 // ===========================================================================
52 // method definitions
53 // ===========================================================================
54 /* -------------------------------------------------------------------------
55  * GUIInductLoop-methods
56  * ----------------------------------------------------------------------- */
57 GUIInductLoop::GUIInductLoop(const std::string& id, MSLane* const lane,
58  SUMOReal position, bool splitByType)
59  : MSInductLoop(id, lane, position, splitByType) {}
60 
61 
63 
64 
67  return new MyWrapper(*this, myPosition);
68 }
69 
70 
71 void
75 }
76 
77 
78 void
81  MSInductLoop::enterDetectorByMove(veh, entryTimestep);
82 }
83 
84 void
87  MSInductLoop::leaveDetectorByMove(veh, leaveTimestep);
88 }
89 
90 void
94 }
95 
96 
97 std::vector<MSInductLoop::VehicleData>
101 }
102 
103 
104 /* -------------------------------------------------------------------------
105  * GUIInductLoop::MyWrapper-methods
106  * ----------------------------------------------------------------------- */
108  : GUIDetectorWrapper("induct loop", detector.getID()),
109  myDetector(detector), myPosition(pos) {
110  myFGPosition = detector.getLane()->geometryPositionAtOffset(pos);
111  myBoundary.add(myFGPosition.x() + (SUMOReal) 5.5, myFGPosition.y() + (SUMOReal) 5.5);
112  myBoundary.add(myFGPosition.x() - (SUMOReal) 5.5, myFGPosition.y() - (SUMOReal) 5.5);
113  myFGRotation = -detector.getLane()->getShape().rotationDegreeAtOffset(pos);
114 }
115 
116 
118 
119 
120 Boundary
122  Boundary b(myBoundary);
123  b.grow(20);
124  return b;
125 }
126 
127 
128 
131  GUISUMOAbstractView& /*parent !!! recheck this - never needed?*/) {
132  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this, 7);
133  // add items
134  // parameter
135  ret->mkItem("position [m]", false, myPosition);
136  ret->mkItem("lane", false, myDetector.getLane()->getID());
137  // values
138  ret->mkItem("passed vehicles [#]", true,
140  ret->mkItem("speed [m/s]", true,
142  ret->mkItem("occupancy [%]", true,
144  ret->mkItem("vehicle length [m]", true,
146  ret->mkItem("empty time [s]", true,
148  // close building
149  ret->closeBuilding();
150  return ret;
151 }
152 
153 
154 void
156  glPushName(getGlID());
157  SUMOReal width = (SUMOReal) 2.0 * s.scale;
158  glLineWidth(1.0);
159  // shape
160  glColor3d(1, 1, 0);
161  glPushMatrix();
162  glTranslated(0, 0, getType());
163  glTranslated(myFGPosition.x(), myFGPosition.y(), 0);
164  glRotated(myFGRotation, 0, 0, 1);
165  glScaled(s.addExaggeration, s.addExaggeration, 1);
166  glBegin(GL_QUADS);
167  glVertex2d(0 - 1.0, 2);
168  glVertex2d(-1.0, -2);
169  glVertex2d(1.0, -2);
170  glVertex2d(1.0, 2);
171  glEnd();
172  glTranslated(0, 0, .01);
173  glBegin(GL_LINES);
174  glVertex2d(0, 2 - .1);
175  glVertex2d(0, -2 + .1);
176  glEnd();
177 
178  // outline
179  if (width * s.addExaggeration > 1) {
180  glColor3d(1, 1, 1);
181  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
182  glBegin(GL_QUADS);
183  glVertex2f(0 - 1.0, 2);
184  glVertex2f(-1.0, -2);
185  glVertex2f(1.0, -2);
186  glVertex2f(1.0, 2);
187  glEnd();
188  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
189  }
190 
191  // position indicator
192  if (width * s.addExaggeration > 1) {
193  glRotated(90, 0, 0, -1);
194  glColor3d(1, 1, 1);
195  glBegin(GL_LINES);
196  glVertex2d(0, 1.7);
197  glVertex2d(0, -1.7);
198  glEnd();
199  }
200  glPopMatrix();
201  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
202  glPopName();
203 }
204 
205 
208  return myDetector;
209 }
210 
211 
212 
213 /****************************************************************************/
214 
void leaveDetectorByMove(SUMOVehicle &veh, SUMOReal leaveTimestep)
Processes a vehicle that leaves the detector.
MyWrapper(GUIInductLoop &detector, SUMOReal pos)
Constructor.
Boundary myBoundary
The detector's boundary.
A MSInductLoop-visualiser.
void reset()
Resets all generated values to allow computation of next interval.
GUIVisualizationTextSettings addName
std::vector< VehicleData > collectVehiclesOnDet(SUMOTime t) const
Returns vehicle data for vehicles that have been on the detector starting at the given time...
const Position geometryPositionAtOffset(SUMOReal offset) const
Definition: MSLane.h:340
Stores the information about how to visualize structures.
virtual void reset()
Resets all generated values to allow computation of next interval.
virtual std::vector< VehicleData > collectVehiclesOnDet(SUMOTime t) const
Returns vehicle data for vehicles that have been on the detector starting at the given time...
Position myFGPosition
The position in full-geometry mode.
SUMOReal getCurrentOccupancy() const
Returns the current occupancy.
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
const SUMOReal myPosition
Detector's position on lane [m].
Definition: MSInductLoop.h:328
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
const MSLane * getLane() const
Returns the lane the reminder works on.
SUMOReal scale
information about a lane's width (temporary, used for a single view)
MFXMutex myLock
Mutex preventing parallel read/write access to internal MSInductLoop state.
The gui-version of the MSInductLoop.
Definition: GUIInductLoop.h:55
float addExaggeration
The additional structures exaggeration (upscale)
Representation of a vehicle.
Definition: SUMOVehicle.h:64
virtual GUIDetectorWrapper * buildDetectorGUIRepresentation()
Returns this detector's visualisation-wrapper.
virtual void enterDetectorByMove(SUMOVehicle &veh, SUMOReal entryTimestep)
Introduces a vehicle to the detector's map myVehiclesOnDet.
GUIInductLoop(const std::string &id, MSLane *const lane, SUMOReal position, bool splitByType)
Constructor.
void enterDetectorByMove(SUMOVehicle &veh, SUMOReal entryTimestep)
Introduces a vehicle to the detector's map myVehiclesOnDet.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
SUMOReal getCurrentSpeed() const
Returns the speed of the vehicle on the detector.
unsigned int getCurrentPassedNumber() const
Returns the number of vehicles that have passed the detector.
SUMOReal rotationDegreeAtOffset(SUMOReal pos) const
Returns the rotation at the given length.
void add(SUMOReal x, SUMOReal y)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:76
Boundary & grow(SUMOReal by)
extends the boundary by the given amount
Definition: Boundary.cpp:200
SUMOReal myFGRotation
The rotation in full-geometry mode.
A mutex encapsulator which locks/unlocks the given mutex on construction/destruction, respectively.
Definition: AbstractMutex.h:71
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
virtual void leaveDetectorByLaneChange(SUMOVehicle &veh, SUMOReal lastPos)
Removes a vehicle from the detector's map myVehiclesOnDet.
~GUIInductLoop()
Destructor.
const PositionVector & getShape() const
Returns this lane's shape.
Definition: MSLane.h:323
SUMOReal getTimestepsSinceLastDetection() const
Returns the time since the last vehicle left the detector.
#define SUMOReal
Definition: config.h:215
GUIInductLoop & getLoop()
Returns the detector itself.
SUMOReal getCurrentLength() const
Returns the length of the vehicle on the detector.
virtual void leaveDetectorByMove(SUMOVehicle &veh, SUMOReal leaveTimestep)
Processes a vehicle that leaves the detector.
void mkItem(const char *name, bool dynamic, ValueSource< unsigned > *src)
Adds a row which obtains its value from an unsigned-ValueSource.
void closeBuilding()
Closes the building of the table.
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
A window containing a gl-object's parameter.
An unextended detector measuring at a fixed position on a fixed lane.
Definition: MSInductLoop.h:71
void leaveDetectorByLaneChange(SUMOVehicle &veh, SUMOReal lastPos)
Removes a vehicle from the detector's map myVehiclesOnDet.