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