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 /****************************************************************************/
16 // The gui-version of the MSInductLoop, together with the according
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
27 #include "GUIInductLoop.h"
28 #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 
109  GUIDetectorWrapper(GLO_E1DETECTOR, detector.getID()),
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 {
187  GLHelper::setColor(*mySpecialColor);
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 
216 /****************************************************************************/
GUIInductLoop::MyWrapper::getCenteringBoundary
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GUIInductLoop.cpp:123
GUIInductLoop::leaveDetectorByLaneChange
void leaveDetectorByLaneChange(SUMOTrafficObject &veh, double lastPos)
Removes a vehicle from the detector's map myVehiclesOnDet.
Definition: GUIInductLoop.cpp:83
SUMOTrafficObject
Representation of a vehicle or person.
Definition: SUMOTrafficObject.h:47
GUIGlObject.h
GUIParameterTableWindow
A window containing a gl-object's parameter.
Definition: GUIParameterTableWindow.h:62
GUISUMOAbstractView
Definition: GUISUMOAbstractView.h:72
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
MSInductLoop::getVehicleLength
double getVehicleLength(const int offset) const
Returns the length of the vehicle on the detector.
Definition: MSInductLoop.cpp:157
GUIParameterTableWindow.h
MSInductLoop::enterDetectorByMove
virtual void enterDetectorByMove(SUMOTrafficObject &veh, double entryTimestep)
Introduces a vehicle to the detector's map myVehiclesOnDet.
Definition: MSInductLoop.cpp:253
GUIDetectorWrapper
Definition: GUIDetectorWrapper.h:42
FuncBinding_IntParam
Definition: FuncBinding_IntParam.h:38
GUIInductLoop::MyWrapper::setSpecialColor
void setSpecialColor(const RGBColor *color)
set (outline) color for extra visualiaztion
Definition: GUIInductLoop.h:187
GUIInductLoop::MyWrapper::drawGL
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GUIInductLoop.cpp:157
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
MSInductLoop
An unextended detector measuring at a fixed position on a fixed lane.
Definition: MSInductLoop.h:63
GLHelper.h
MSInductLoop::getTimeSinceLastDetection
double getTimeSinceLastDetection() const
Returns the time since the last vehicle left the detector.
Definition: MSInductLoop.cpp:195
GLHelper::setColor
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:621
MSInductLoop::leaveDetectorByLaneChange
virtual void leaveDetectorByLaneChange(SUMOTrafficObject &veh, double lastPos)
Removes a vehicle from the detector's map myVehiclesOnDet.
Definition: MSInductLoop.cpp:274
GUIParameterTableWindow::closeBuilding
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
Definition: GUIParameterTableWindow.cpp:219
GUIInductLoop::MyWrapper::myFGPosition
Position myFGPosition
The position in full-geometry mode.
Definition: GUIInductLoop.h:199
GUIInductLoop::leaveDetectorByMove
void leaveDetectorByMove(SUMOTrafficObject &veh, double leaveTimestep)
Processes a vehicle that leaves the detector.
Definition: GUIInductLoop.cpp:77
RGBColor
Definition: RGBColor.h:39
GUIVisualizationSettings::addName
GUIVisualizationTextSettings addName
Definition: GUIVisualizationSettings.h:591
MSInductLoop::leaveDetectorByMove
virtual void leaveDetectorByMove(SUMOTrafficObject &veh, double leaveTimestep)
Processes a vehicle that leaves the detector.
Definition: MSInductLoop.cpp:260
GUIInductLoop::~GUIInductLoop
~GUIInductLoop()
Destructor.
Definition: GUIInductLoop.cpp:52
GUIInductLoop::GUIInductLoop
GUIInductLoop(const std::string &id, MSLane *const lane, double position, const std::string &vTypes, bool show)
Constructor.
Definition: GUIInductLoop.cpp:44
GUIParameterTableWindow::mkItem
void mkItem(const char *name, bool dynamic, ValueSource< T > *src)
Adds a row which obtains its value from a ValueSource.
Definition: GUIParameterTableWindow.h:108
GUIInductLoop::myLock
FXMutex myLock
Mutex preventing parallel read/write access to internal MSInductLoop state.
Definition: GUIInductLoop.h:228
PositionVector::rotationDegreeAtOffset
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
Definition: PositionVector.cpp:319
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:41
GUIInductLoop::buildDetectorGUIRepresentation
virtual GUIDetectorWrapper * buildDetectorGUIRepresentation()
Returns this detector's visualisation-wrapper.
Definition: GUIInductLoop.cpp:56
GUIVisualizationSettings::scale
double scale
information about a lane's width (temporary, used for a single view)
Definition: GUIVisualizationSettings.h:632
GLO_E1DETECTOR
a E1 detector
Definition: GUIGlObjectTypes.h:71
GUIInductLoop::MyWrapper::myFGRotation
double myFGRotation
The rotation in full-geometry mode.
Definition: GUIInductLoop.h:202
Position::x
double x() const
Returns the x-position.
Definition: Position.h:56
Boundary::add
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:78
GUIInductLoop.h
GUIInductLoop::reset
void reset()
Resets all generated values to allow computation of next interval.
Definition: GUIInductLoop.cpp:64
GUIInductLoop::MyWrapper::myBoundary
Boundary myBoundary
The detector's boundary.
Definition: GUIInductLoop.h:196
MSInductLoop::collectVehiclesOnDet
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.
Definition: MSInductLoop.cpp:281
GUIInductLoop::MyWrapper::~MyWrapper
~MyWrapper()
Destructor.
Definition: GUIInductLoop.cpp:119
GUIInductLoop
The gui-version of the MSInductLoop.
Definition: GUIInductLoop.h:47
GLIncludes.h
MSMoveReminder::getLane
const MSLane * getLane() const
Returns the lane the reminder works on.
Definition: MSMoveReminder.h:85
GUIInductLoop::myWrapper
MyWrapper * myWrapper
the glObject wrapper for this induction loop
Definition: GUIInductLoop.h:222
MSInductLoop::getPassedNumber
double getPassedNumber(const int offset) const
Returns the number of vehicles that have passed the detector.
Definition: MSInductLoop.cpp:178
MSLane::getShape
const PositionVector & getShape() const
Returns this lane's shape.
Definition: MSLane.h:477
FunctionBinding.h
GUIMainWindow
Definition: GUIMainWindow.h:46
Position::y
double y() const
Returns the y-position.
Definition: Position.h:61
GUIInductLoop::setSpecialColor
void setSpecialColor(const RGBColor *color)
sets special caller for myWrapper
Definition: GUIInductLoop.cpp:97
GUIEdge.h
GUIInductLoop::MyWrapper::MyWrapper
MyWrapper(GUIInductLoop &detector, double pos)
Constructor.
Definition: GUIInductLoop.cpp:108
MSInductLoop::getSpeed
double getSpeed(const int offset) const
Returns the speed of the vehicle on the detector.
Definition: MSInductLoop.cpp:150
config.h
GUIVisualizationSettings::addSize
GUIVisualizationSizeSettings addSize
Definition: GUIVisualizationSettings.h:589
MSInductLoop::myPosition
const double myPosition
Detector's position on lane [m].
Definition: MSInductLoop.h:341
Boundary::grow
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:300
MSLane::geometryPositionAtOffset
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition: MSLane.h:504
FuncBinding_IntParam.h
MSLane.h
MSInductLoop::getOccupancy
double getOccupancy() const
Returns the current occupancy.
Definition: MSInductLoop.cpp:164
GUIVisualizationSettings
Stores the information about how to visualize structures.
Definition: GUIVisualizationSettings.h:345
GUIInductLoop::MyWrapper
A MSInductLoop-visualiser.
Definition: GUIInductLoop.h:147
FunctionBinding
Definition: FunctionBinding.h:40
MSInductLoop.h
GUIInductLoop::enterDetectorByMove
void enterDetectorByMove(SUMOTrafficObject &veh, double entryTimestep)
Introduces a vehicle to the detector's map myVehiclesOnDet.
Definition: GUIInductLoop.cpp:71
MSInductLoop::reset
virtual void reset()
Resets all generated values to allow computation of next interval.
Definition: MSInductLoop.cpp:67
PositionVector.h
GUIInductLoop::MyWrapper::getParameterWindow
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Definition: GUIInductLoop.cpp:132
GUIVisualizationSizeSettings::getExaggeration
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
Definition: GUIVisualizationSettings.cpp:212
GUIInductLoop::collectVehiclesOnDet
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.
Definition: GUIInductLoop.cpp:90