SUMO - Simulation of Urban MObility
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.dlr.de/
12 // Copyright (C) 2001-2016 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>
39 #include <microsim/MSLane.h>
41 #include "GUIEdge.h"
43 
44 #ifdef CHECK_MEMORY_LEAKS
45 #include <foreign/nvwa/debug_new.h>
46 #endif // CHECK_MEMORY_LEAKS
47 
48 
49 // ===========================================================================
50 // method definitions
51 // ===========================================================================
52 /* -------------------------------------------------------------------------
53  * GUIInductLoop-methods
54  * ----------------------------------------------------------------------- */
55 GUIInductLoop::GUIInductLoop(const std::string& id, MSLane* const lane,
56  SUMOReal position, const std::string& vTypes)
57  : MSInductLoop(id, lane, position, vTypes) {}
58 
59 
61 
62 
65  return new MyWrapper(*this, myPosition);
66 }
67 
68 
69 void
73 }
74 
75 
76 void
79  MSInductLoop::enterDetectorByMove(veh, entryTimestep);
80 }
81 
82 void
85  MSInductLoop::leaveDetectorByMove(veh, leaveTimestep);
86 }
87 
88 void
92 }
93 
94 
95 std::vector<MSInductLoop::VehicleData>
98  return MSInductLoop::collectVehiclesOnDet(t, leaveTime);
99 }
100 
101 
102 /* -------------------------------------------------------------------------
103  * GUIInductLoop::MyWrapper-methods
104  * ----------------------------------------------------------------------- */
106  : GUIDetectorWrapper("induct loop", detector.getID()),
107  myDetector(detector), myPosition(pos) {
108  myFGPosition = detector.getLane()->geometryPositionAtOffset(pos);
109  myBoundary.add(myFGPosition.x() + (SUMOReal) 5.5, myFGPosition.y() + (SUMOReal) 5.5);
110  myBoundary.add(myFGPosition.x() - (SUMOReal) 5.5, myFGPosition.y() - (SUMOReal) 5.5);
111  myFGRotation = -detector.getLane()->getShape().rotationDegreeAtOffset(pos);
112 }
113 
114 
116 
117 
118 Boundary
120  Boundary b(myBoundary);
121  b.grow(20);
122  return b;
123 }
124 
125 
126 
129  GUISUMOAbstractView& /*parent !!! recheck this - never needed?*/) {
130  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this, 7);
131  // add items
132  // parameter
133  ret->mkItem("position [m]", false, myPosition);
134  ret->mkItem("lane", false, myDetector.getLane()->getID());
135  // values
136  ret->mkItem("passed vehicles [#]", true,
138  ret->mkItem("speed [m/s]", true,
140  ret->mkItem("occupancy [%]", true,
142  ret->mkItem("vehicle length [m]", true,
144  ret->mkItem("empty time [s]", true,
146  // close building
147  ret->closeBuilding();
148  return ret;
149 }
150 
151 
152 void
154  glPushName(getGlID());
155  SUMOReal width = (SUMOReal) 2.0 * s.scale;
156  glLineWidth(1.0);
157  const SUMOReal exaggeration = s.addSize.getExaggeration(s);
158  // shape
159  glColor3d(1, 1, 0);
160  glPushMatrix();
161  glTranslated(0, 0, getType());
162  glTranslated(myFGPosition.x(), myFGPosition.y(), 0);
163  glRotated(myFGRotation, 0, 0, 1);
164  glScaled(exaggeration, exaggeration, 1);
165  glBegin(GL_QUADS);
166  glVertex2d(0 - 1.0, 2);
167  glVertex2d(-1.0, -2);
168  glVertex2d(1.0, -2);
169  glVertex2d(1.0, 2);
170  glEnd();
171  glTranslated(0, 0, .01);
172  glBegin(GL_LINES);
173  glVertex2d(0, 2 - .1);
174  glVertex2d(0, -2 + .1);
175  glEnd();
176 
177  // outline
178  if (width * exaggeration > 1) {
179  glColor3d(1, 1, 1);
180  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
181  glBegin(GL_QUADS);
182  glVertex2f(0 - 1.0, 2);
183  glVertex2f(-1.0, -2);
184  glVertex2f(1.0, -2);
185  glVertex2f(1.0, 2);
186  glEnd();
187  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
188  }
189 
190  // position indicator
191  if (width * exaggeration > 1) {
192  glRotated(90, 0, 0, -1);
193  glColor3d(1, 1, 1);
194  glBegin(GL_LINES);
195  glVertex2d(0, 1.7);
196  glVertex2d(0, -1.7);
197  glEnd();
198  }
199  glPopMatrix();
200  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
201  glPopName();
202 }
203 
204 
207  return myDetector;
208 }
209 
210 
211 
212 /****************************************************************************/
213 
void drawName(const Position &pos, const SUMOReal scale, const GUIVisualizationTextSettings &settings, const SUMOReal angle=0) const
draw name of item
void leaveDetectorByMove(SUMOVehicle &veh, SUMOReal leaveTimestep)
Processes a vehicle that leaves the detector.
GUIInductLoop(const std::string &id, MSLane *const lane, SUMOReal position, const std::string &vTypes)
Constructor.
MyWrapper(GUIInductLoop &detector, SUMOReal pos)
Constructor.
const MSLane * getLane() const
Returns the lane the reminder works on.
SUMOReal getTimestepsSinceLastDetection() const
Returns the time since the last vehicle left the detector.
long long int SUMOTime
Definition: SUMOTime.h:43
Boundary myBoundary
The detector&#39;s boundary.
A MSInductLoop-visualiser.
void reset()
Resets all generated values to allow computation of next interval.
GUIVisualizationTextSettings addName
Stores the information about how to visualize structures.
virtual void reset()
Resets all generated values to allow computation of next interval.
SUMOReal myPosition
The position on the lane.
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:427
Position myFGPosition
The position in full-geometry mode.
SUMOReal getCurrentOccupancy() const
Returns the current occupancy.
GUIInductLoop & myDetector
The wrapped detector.
const std::string & getID() const
Returns the id.
Definition: Named.h:66
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
const SUMOReal myPosition
Detector&#39;s position on lane [m].
Definition: MSInductLoop.h:342
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
SUMOReal scale
information about a lane&#39;s width (temporary, used for a single view)
MFXMutex myLock
Mutex preventing parallel read/write access to internal MSInductLoop state.
GUIVisualizationSizeSettings addSize
The gui-version of the MSInductLoop.
Definition: GUIInductLoop.h:55
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Representation of a vehicle.
Definition: SUMOVehicle.h:66
virtual GUIDetectorWrapper * buildDetectorGUIRepresentation()
Returns this detector&#39;s visualisation-wrapper.
virtual void enterDetectorByMove(SUMOVehicle &veh, SUMOReal entryTimestep)
Introduces a vehicle to the detector&#39;s map myVehiclesOnDet.
void enterDetectorByMove(SUMOVehicle &veh, SUMOReal entryTimestep)
Introduces a vehicle to the detector&#39;s map myVehiclesOnDet.
SUMOReal rotationDegreeAtOffset(SUMOReal pos) const
Returns the rotation at the given length.
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
std::vector< VehicleData > collectVehiclesOnDet(SUMOTime t, bool leaveTime=false) const
Returns vehicle data for vehicles that have been on the detector starting at the given time...
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
int getCurrentPassedNumber() const
Returns the number of vehicles that have passed the detector.
Boundary & grow(SUMOReal by)
extends the boundary by the given amount
Definition: Boundary.cpp:232
SUMOReal myFGRotation
The rotation in full-geometry mode.
void add(SUMOReal x, SUMOReal y, SUMOReal z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:90
A mutex encapsulator which locks/unlocks the given mutex on construction/destruction, respectively.
Definition: AbstractMutex.h:71
virtual void leaveDetectorByLaneChange(SUMOVehicle &veh, SUMOReal lastPos)
Removes a vehicle from the detector&#39;s map myVehiclesOnDet.
~GUIInductLoop()
Destructor.
GUIGlID getGlID() const
Returns the numerical id of the object.
#define SUMOReal
Definition: config.h:213
virtual std::vector< VehicleData > collectVehiclesOnDet(SUMOTime t, bool leaveTime=false) const
Returns vehicle data for vehicles that have been on the detector starting at the given time...
SUMOReal getExaggeration(const GUIVisualizationSettings &s, SUMOReal factor=20) const
return the drawing size including exaggeration and constantSize values
GUIInductLoop & getLoop()
Returns the detector itself.
virtual void leaveDetectorByMove(SUMOVehicle &veh, SUMOReal leaveTimestep)
Processes a vehicle that leaves the detector.
SUMOReal getCurrentSpeed() const
Returns the speed of the vehicle on the detector.
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
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:79
A window containing a gl-object&#39;s parameter.
SUMOReal getCurrentLength() const
Returns the length of the vehicle on the detector.
const Position geometryPositionAtOffset(SUMOReal offset, SUMOReal lateralOffset=0) const
Definition: MSLane.h:444
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
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&#39;s map myVehiclesOnDet.