SUMO - Simulation of Urban MObility
GUIInductLoop.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // The gui-version of the MSInductLoop, together with the according
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
28 #include "GUIInductLoop.h"
29 #include <utils/gui/div/GLHelper.h>
32 #include <microsim/MSLane.h>
34 #include "GUIEdge.h"
36 
37 
38 // ===========================================================================
39 // method definitions
40 // ===========================================================================
41 /* -------------------------------------------------------------------------
42  * GUIInductLoop-methods
43  * ----------------------------------------------------------------------- */
44 GUIInductLoop::GUIInductLoop(const std::string& id, MSLane* const lane,
45  double position, const std::string& vTypes)
46  : MSInductLoop(id, lane, position, vTypes) {}
47 
48 
50 
51 
54  return new MyWrapper(*this, myPosition);
55 }
56 
57 
58 void
62 }
63 
64 
65 void
66 GUIInductLoop::enterDetectorByMove(SUMOVehicle& veh, double entryTimestep) {
68  MSInductLoop::enterDetectorByMove(veh, entryTimestep);
69 }
70 
71 void
72 GUIInductLoop::leaveDetectorByMove(SUMOVehicle& veh, double leaveTimestep) {
74  MSInductLoop::leaveDetectorByMove(veh, leaveTimestep);
75 }
76 
77 void
81 }
82 
83 
84 std::vector<MSInductLoop::VehicleData>
87  return MSInductLoop::collectVehiclesOnDet(t, leaveTime);
88 }
89 
90 // -------------------------------------------------------------------------
91 // GUIInductLoop::MyWrapper-methods
92 // -------------------------------------------------------------------------
93 
96  myDetector(detector), myPosition(pos) {
98  myBoundary.add(myFGPosition.x() + (double) 5.5, myFGPosition.y() + (double) 5.5);
99  myBoundary.add(myFGPosition.x() - (double) 5.5, myFGPosition.y() - (double) 5.5);
100  myFGRotation = -detector.getLane()->getShape().rotationDegreeAtOffset(pos);
101 }
102 
103 
105 
106 
107 Boundary
109  Boundary b(myBoundary);
110  b.grow(20);
111  return b;
112 }
113 
114 
115 
118  GUISUMOAbstractView& /*parent !!! recheck this - never needed?*/) {
119  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this, 7);
120  // add items
121  // parameter
122  ret->mkItem("position [m]", false, myPosition);
123  ret->mkItem("lane", false, myDetector.getLane()->getID());
124  // values
125  ret->mkItem("passed vehicles [#]", true,
127  ret->mkItem("speed [m/s]", true,
129  ret->mkItem("occupancy [%]", true,
131  ret->mkItem("vehicle length [m]", true,
133  ret->mkItem("empty time [s]", true,
135  // close building
136  ret->closeBuilding();
137  return ret;
138 }
139 
140 
141 void
143  glPushName(getGlID());
144  double width = (double) 2.0 * s.scale;
145  glLineWidth(1.0);
146  const double exaggeration = s.addSize.getExaggeration(s, this);
147  // shape
148  glColor3d(1, 1, 0);
149  glPushMatrix();
150  glTranslated(0, 0, getType());
151  glTranslated(myFGPosition.x(), myFGPosition.y(), 0);
152  glRotated(myFGRotation, 0, 0, 1);
153  glScaled(exaggeration, exaggeration, 1);
154  glBegin(GL_QUADS);
155  glVertex2d(0 - 1.0, 2);
156  glVertex2d(-1.0, -2);
157  glVertex2d(1.0, -2);
158  glVertex2d(1.0, 2);
159  glEnd();
160  glTranslated(0, 0, .01);
161  glBegin(GL_LINES);
162  glVertex2d(0, 2 - .1);
163  glVertex2d(0, -2 + .1);
164  glEnd();
165 
166  // outline
167  if (width * exaggeration > 1) {
168  glColor3d(1, 1, 1);
169  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
170  glBegin(GL_QUADS);
171  glVertex2f(0 - 1.0, 2);
172  glVertex2f(-1.0, -2);
173  glVertex2f(1.0, -2);
174  glVertex2f(1.0, 2);
175  glEnd();
176  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
177  }
178 
179  // position indicator
180  if (width * exaggeration > 1) {
181  glRotated(90, 0, 0, -1);
182  glColor3d(1, 1, 1);
183  glBegin(GL_LINES);
184  glVertex2d(0, 1.7);
185  glVertex2d(0, -1.7);
186  glEnd();
187  }
188  glPopMatrix();
189  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
190  glPopName();
191 }
192 
193 
196  return myDetector;
197 }
198 
199 
200 
201 /****************************************************************************/
202 
const double myPosition
Detector&#39;s position on lane [m].
Definition: MSInductLoop.h:335
const MSLane * getLane() const
Returns the lane the reminder works on.
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
long long int SUMOTime
Definition: SUMOTime.h:36
double scale
information about a lane&#39;s width (temporary, used for a single view)
Boundary myBoundary
The detector&#39;s boundary.
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
A MSInductLoop-visualiser.
void reset()
Resets all generated values to allow computation of next interval.
GUIVisualizationTextSettings addName
MyWrapper(GUIInductLoop &detector, double pos)
Constructor.
Stores the information about how to visualize structures.
double y() const
Returns the y-position.
Definition: Position.h:62
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.
void mkItem(const char *name, bool dynamic, ValueSource< T > *src)
Adds a row which obtains its value from a ValueSource.
double x() const
Returns the x-position.
Definition: Position.h:57
double getCurrentLength() const
Returns the length of the vehicle on the detector.
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:456
Position myFGPosition
The position in full-geometry mode.
GUIInductLoop & myDetector
The wrapped detector.
const std::string & getID() const
Returns the id.
Definition: Named.h:78
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
MFXMutex myLock
Mutex preventing parallel read/write access to internal MSInductLoop state.
GUIVisualizationSizeSettings addSize
GUIInductLoop(const std::string &id, MSLane *const lane, double position, const std::string &vTypes)
Constructor.
The gui-version of the MSInductLoop.
Definition: GUIInductLoop.h:48
double myPosition
The position on the lane.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Representation of a vehicle.
Definition: SUMOVehicle.h:60
virtual GUIDetectorWrapper * buildDetectorGUIRepresentation()
Returns this detector&#39;s visualisation-wrapper.
virtual void enterDetectorByMove(SUMOVehicle &veh, double entryTimestep)
Introduces a vehicle to the detector&#39;s map myVehiclesOnDet.
double getCurrentSpeed() const
Returns the speed of the vehicle on the detector.
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:301
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...
double getTimeSinceLastDetection() const
Returns the time since the last vehicle left the detector.
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.
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:59
a E1 detector
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition: MSLane.h:478
~GUIInductLoop()
Destructor.
GUIGlID getGlID() const
Returns the numerical id of the object.
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...
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:79
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
double getCurrentOccupancy() const
Returns the current occupancy.
Representation of a lane in the micro simulation.
Definition: MSLane.h:78
A window containing a gl-object&#39;s parameter.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
An unextended detector measuring at a fixed position on a fixed lane.
Definition: MSInductLoop.h:64