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-2015 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>
40 #include <microsim/MSLane.h>
42 #include "GUIEdge.h"
44 
45 #ifdef CHECK_MEMORY_LEAKS
46 #include <foreign/nvwa/debug_new.h>
47 #endif // CHECK_MEMORY_LEAKS
48 
49 
50 // ===========================================================================
51 // method definitions
52 // ===========================================================================
53 /* -------------------------------------------------------------------------
54  * GUIInductLoop-methods
55  * ----------------------------------------------------------------------- */
56 GUIInductLoop::GUIInductLoop(const std::string& id, MSLane* const lane,
57  SUMOReal position, bool splitByType)
58  : MSInductLoop(id, lane, position, splitByType) {}
59 
60 
62 
63 
66  return new MyWrapper(*this, myPosition);
67 }
68 
69 
70 void
74 }
75 
76 
77 void
80  MSInductLoop::enterDetectorByMove(veh, entryTimestep);
81 }
82 
83 void
86  MSInductLoop::leaveDetectorByMove(veh, leaveTimestep);
87 }
88 
89 void
93 }
94 
95 
96 std::vector<MSInductLoop::VehicleData>
100 }
101 
102 
103 /* -------------------------------------------------------------------------
104  * GUIInductLoop::MyWrapper-methods
105  * ----------------------------------------------------------------------- */
107  : GUIDetectorWrapper("induct loop", detector.getID()),
108  myDetector(detector), myPosition(pos) {
109  myFGPosition = detector.getLane()->geometryPositionAtOffset(pos);
110  myBoundary.add(myFGPosition.x() + (SUMOReal) 5.5, myFGPosition.y() + (SUMOReal) 5.5);
111  myBoundary.add(myFGPosition.x() - (SUMOReal) 5.5, myFGPosition.y() - (SUMOReal) 5.5);
112  myFGRotation = -detector.getLane()->getShape().rotationDegreeAtOffset(pos);
113 }
114 
115 
117 
118 
119 Boundary
121  Boundary b(myBoundary);
122  b.grow(20);
123  return b;
124 }
125 
126 
127 
130  GUISUMOAbstractView& /*parent !!! recheck this - never needed?*/) {
131  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this, 7);
132  // add items
133  // parameter
134  ret->mkItem("position [m]", false, myPosition);
135  ret->mkItem("lane", false, myDetector.getLane()->getID());
136  // values
137  ret->mkItem("passed vehicles [#]", true,
139  ret->mkItem("speed [m/s]", true,
141  ret->mkItem("occupancy [%]", true,
143  ret->mkItem("vehicle length [m]", true,
145  ret->mkItem("empty time [s]", true,
147  // close building
148  ret->closeBuilding();
149  return ret;
150 }
151 
152 
153 void
155  glPushName(getGlID());
156  SUMOReal width = (SUMOReal) 2.0 * s.scale;
157  glLineWidth(1.0);
158  const SUMOReal exaggeration = s.addSize.getExaggeration(s);
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(exaggeration, exaggeration, 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 * exaggeration > 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 * exaggeration > 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.
GUIVisualizationSizeSettings addSize
The gui-version of the MSInductLoop.
Definition: GUIInductLoop.h:55
Representation of a vehicle.
Definition: SUMOVehicle.h:65
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.
int SUMOTime
Definition: SUMOTime.h:43
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:218
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.
SUMOReal getExaggeration(const GUIVisualizationSettings &s) const
return the drawing size including exaggeration and constantSize values
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.