Eclipse 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-2019 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, bool show) :
46  MSInductLoop(id, lane, position, vTypes),
47  myWrapper(nullptr),
48  myShow(show)
49 {}
50 
51 
53 
54 
57  // caller (GUINet) takes responsibility for pointer
58  myWrapper = new MyWrapper(*this, myPosition);
59  return myWrapper;
60 }
61 
62 
63 void
65  FXMutexLock locker(myLock);
67 }
68 
69 
70 void
72  FXMutexLock locker(myLock);
73  MSInductLoop::enterDetectorByMove(veh, entryTimestep);
74 }
75 
76 void
78  FXMutexLock locker(myLock);
79  MSInductLoop::leaveDetectorByMove(veh, leaveTimestep);
80 }
81 
82 void
84  FXMutexLock locker(myLock);
86 }
87 
88 
89 std::vector<MSInductLoop::VehicleData>
91  FXMutexLock locker(myLock);
92  return MSInductLoop::collectVehiclesOnDet(t, leaveTime);
93 }
94 
95 
96 void
98  if (myWrapper != nullptr) {
99  myWrapper->setSpecialColor(color);
100  }
101 }
102 
103 
104 // -------------------------------------------------------------------------
105 // GUIInductLoop::MyWrapper-methods
106 // -------------------------------------------------------------------------
107 
110  myDetector(detector), myPosition(pos),
111  mySpecialColor(nullptr) {
112  myFGPosition = detector.getLane()->geometryPositionAtOffset(pos);
113  myBoundary.add(myFGPosition.x() + (double) 5.5, myFGPosition.y() + (double) 5.5);
114  myBoundary.add(myFGPosition.x() - (double) 5.5, myFGPosition.y() - (double) 5.5);
115  myFGRotation = -detector.getLane()->getShape().rotationDegreeAtOffset(pos);
116 }
117 
118 
120 
121 
122 Boundary
124  Boundary b(myBoundary);
125  b.grow(20);
126  return b;
127 }
128 
129 
130 
133  GUISUMOAbstractView& /*parent !!! recheck this - never needed?*/) {
134  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this, 7);
135  // add items
136  // parameter
137  ret->mkItem("position [m]", false, myPosition);
138  ret->mkItem("lane", false, myDetector.getLane()->getID());
139  // values
140  ret->mkItem("passed vehicles [#]", true,
142  ret->mkItem("speed [m/s]", true,
144  ret->mkItem("occupancy [%]", true,
146  ret->mkItem("vehicle length [m]", true,
148  ret->mkItem("empty time [s]", true,
150  // close building
151  ret->closeBuilding();
152  return ret;
153 }
154 
155 
156 void
158  if (!myDetector.isVisible()) {
159  return;
160  }
161  glPushName(getGlID());
162  double width = (double) 2.0 * s.scale;
163  glLineWidth(1.0);
164  const double exaggeration = s.addSize.getExaggeration(s, this);
165  // shape
166  glColor3d(1, 1, 0);
167  glPushMatrix();
168  glTranslated(0, 0, getType());
169  glTranslated(myFGPosition.x(), myFGPosition.y(), 0);
170  glRotated(myFGRotation, 0, 0, 1);
171  glScaled(exaggeration, exaggeration, 1);
172  glBegin(GL_QUADS);
173  glVertex2d(0 - 1.0, 2);
174  glVertex2d(-1.0, -2);
175  glVertex2d(1.0, -2);
176  glVertex2d(1.0, 2);
177  glEnd();
178  glTranslated(0, 0, .01);
179  glBegin(GL_LINES);
180  glVertex2d(0, 2 - .1);
181  glVertex2d(0, -2 + .1);
182  glEnd();
183 
184  if (mySpecialColor == nullptr) {
185  glColor3d(1, 1, 1);
186  } else {
188  }
189 
190  // outline
191  if (width * exaggeration > 1) {
192  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
193  glBegin(GL_QUADS);
194  glVertex2f(0 - 1.0, 2);
195  glVertex2f(-1.0, -2);
196  glVertex2f(1.0, -2);
197  glVertex2f(1.0, 2);
198  glEnd();
199  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
200  }
201 
202  // position indicator
203  if (width * exaggeration > 1) {
204  glRotated(90, 0, 0, -1);
205  glBegin(GL_LINES);
206  glVertex2d(0, 1.7);
207  glVertex2d(0, -1.7);
208  glEnd();
209  }
210  glPopMatrix();
211  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
212  glPopName();
213 }
214 
215 
218  return myDetector;
219 }
220 
221 
222 
223 /****************************************************************************/
224 
const double myPosition
Detector&#39;s position on lane [m].
Definition: MSInductLoop.h:339
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:35
double scale
information about a lane&#39;s width (temporary, used for a single view)
virtual void leaveDetectorByMove(SUMOTrafficObject &veh, double leaveTimestep)
Processes a vehicle that leaves the detector.
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
virtual void leaveDetectorByLaneChange(SUMOTrafficObject &veh, double lastPos)
Removes a vehicle from the detector&#39;s map myVehiclesOnDet.
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 reset()
Resets all generated values to allow computation of next interval.
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
void setSpecialColor(const RGBColor *color)
sets special caller for myWrapper
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:478
Position myFGPosition
The position in full-geometry mode.
GUIInductLoop & myDetector
The wrapped detector.
const std::string & getID() const
Returns the id.
Definition: Named.h:77
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
GUIVisualizationSizeSettings addSize
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.
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:616
virtual GUIDetectorWrapper * buildDetectorGUIRepresentation()
Returns this detector&#39;s visualisation-wrapper.
const RGBColor * mySpecialColor
color for extra visualization
double getCurrentSpeed() const
Returns the speed of the vehicle on the detector.
FXMutex myLock
Mutex preventing parallel read/write access to internal MSInductLoop state.
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.
void setSpecialColor(const RGBColor *color)
set (outline) color for extra visualiaztion
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
virtual void enterDetectorByMove(SUMOTrafficObject &veh, double entryTimestep)
Introduces a vehicle to the detector&#39;s map myVehiclesOnDet.
int getCurrentPassedNumber() const
Returns the number of vehicles that have passed the detector.
bool isVisible() const
whether the induction loop shall be visible
Definition: GUIInductLoop.h:95
Representation of a vehicle or person.
void leaveDetectorByLaneChange(SUMOTrafficObject &veh, double lastPos)
Removes a vehicle from the detector&#39;s map myVehiclesOnDet.
a E1 detector
MyWrapper * myWrapper
the glObject wrapper for this induction loop
void enterDetectorByMove(SUMOTrafficObject &veh, double entryTimestep)
Introduces a vehicle to the detector&#39;s map myVehiclesOnDet.
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition: MSLane.h:505
~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...
GUIInductLoop & getLoop()
Returns the detector itself.
void leaveDetectorByMove(SUMOTrafficObject &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:83
A window containing a gl-object&#39;s parameter.
GUIInductLoop(const std::string &id, MSLane *const lane, double position, const std::string &vTypes, bool show)
Constructor.
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