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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // The gui-version of the MSInductLoop, together with the according
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
34 #include "GUIInductLoop.h"
35 #include <utils/gui/div/GLHelper.h>
38 #include <microsim/MSLane.h>
40 #include "GUIEdge.h"
42 
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
47 /* -------------------------------------------------------------------------
48  * GUIInductLoop-methods
49  * ----------------------------------------------------------------------- */
50 GUIInductLoop::GUIInductLoop(const std::string& id, MSLane* const lane,
51  double position, const std::string& vTypes)
52  : MSInductLoop(id, lane, position, vTypes) {}
53 
54 
56 
57 
60  return new MyWrapper(*this, myPosition);
61 }
62 
63 
64 void
68 }
69 
70 
71 void
72 GUIInductLoop::enterDetectorByMove(SUMOVehicle& veh, double entryTimestep) {
74  MSInductLoop::enterDetectorByMove(veh, entryTimestep);
75 }
76 
77 void
78 GUIInductLoop::leaveDetectorByMove(SUMOVehicle& veh, double leaveTimestep) {
80  MSInductLoop::leaveDetectorByMove(veh, leaveTimestep);
81 }
82 
83 void
87 }
88 
89 
90 std::vector<MSInductLoop::VehicleData>
93  return MSInductLoop::collectVehiclesOnDet(t, leaveTime);
94 }
95 
96 
97 /* -------------------------------------------------------------------------
98  * GUIInductLoop::MyWrapper-methods
99  * ----------------------------------------------------------------------- */
101  : GUIDetectorWrapper("induct loop", detector.getID()),
102  myDetector(detector), myPosition(pos) {
103  myFGPosition = detector.getLane()->geometryPositionAtOffset(pos);
104  myBoundary.add(myFGPosition.x() + (double) 5.5, myFGPosition.y() + (double) 5.5);
105  myBoundary.add(myFGPosition.x() - (double) 5.5, myFGPosition.y() - (double) 5.5);
106  myFGRotation = -detector.getLane()->getShape().rotationDegreeAtOffset(pos);
107 }
108 
109 
111 
112 
113 Boundary
115  Boundary b(myBoundary);
116  b.grow(20);
117  return b;
118 }
119 
120 
121 
124  GUISUMOAbstractView& /*parent !!! recheck this - never needed?*/) {
125  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this, 7);
126  // add items
127  // parameter
128  ret->mkItem("position [m]", false, myPosition);
129  ret->mkItem("lane", false, myDetector.getLane()->getID());
130  // values
131  ret->mkItem("passed vehicles [#]", true,
133  ret->mkItem("speed [m/s]", true,
135  ret->mkItem("occupancy [%]", true,
137  ret->mkItem("vehicle length [m]", true,
139  ret->mkItem("empty time [s]", true,
141  // close building
142  ret->closeBuilding();
143  return ret;
144 }
145 
146 
147 void
149  glPushName(getGlID());
150  double width = (double) 2.0 * s.scale;
151  glLineWidth(1.0);
152  const double exaggeration = s.addSize.getExaggeration(s);
153  // shape
154  glColor3d(1, 1, 0);
155  glPushMatrix();
156  glTranslated(0, 0, getType());
157  glTranslated(myFGPosition.x(), myFGPosition.y(), 0);
158  glRotated(myFGRotation, 0, 0, 1);
159  glScaled(exaggeration, exaggeration, 1);
160  glBegin(GL_QUADS);
161  glVertex2d(0 - 1.0, 2);
162  glVertex2d(-1.0, -2);
163  glVertex2d(1.0, -2);
164  glVertex2d(1.0, 2);
165  glEnd();
166  glTranslated(0, 0, .01);
167  glBegin(GL_LINES);
168  glVertex2d(0, 2 - .1);
169  glVertex2d(0, -2 + .1);
170  glEnd();
171 
172  // outline
173  if (width * exaggeration > 1) {
174  glColor3d(1, 1, 1);
175  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
176  glBegin(GL_QUADS);
177  glVertex2f(0 - 1.0, 2);
178  glVertex2f(-1.0, -2);
179  glVertex2f(1.0, -2);
180  glVertex2f(1.0, 2);
181  glEnd();
182  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
183  }
184 
185  // position indicator
186  if (width * exaggeration > 1) {
187  glRotated(90, 0, 0, -1);
188  glColor3d(1, 1, 1);
189  glBegin(GL_LINES);
190  glVertex2d(0, 1.7);
191  glVertex2d(0, -1.7);
192  glEnd();
193  }
194  glPopMatrix();
195  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
196  glPopName();
197 }
198 
199 
202  return myDetector;
203 }
204 
205 
206 
207 /****************************************************************************/
208 
const double myPosition
Detector&#39;s position on lane [m].
Definition: MSInductLoop.h:341
const MSLane * getLane() const
Returns the lane the reminder works on.
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
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:67
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.
double x() const
Returns the x-position.
Definition: Position.h:62
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:439
Position myFGPosition
The position in full-geometry mode.
GUIInductLoop & myDetector
The wrapped detector.
const std::string & getID() const
Returns the id.
Definition: Named.h:74
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:47
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:54
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:66
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:70
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition: MSLane.h:461
~GUIInductLoop()
Destructor.
GUIGlID getGlID() const
Returns the numerical id of the object.
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
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...
long long int SUMOTime
Definition: TraCIDefs.h:51
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:85
double getCurrentOccupancy() const
Returns the current occupancy.
void mkItem(const char *name, bool dynamic, ValueSource< unsigned > *src)
Adds a row which obtains its value from an unsigned-ValueSource.
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
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:70