Eclipse SUMO - Simulation of Urban MObility
GUIE2Collector.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 MSE2Collector
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
28 #include "GUIE2Collector.h"
29 #include <utils/gui/div/GLHelper.h>
30 #include <utils/geom/GeomHelper.h>
33 #include "GUIEdge.h"
35 
36 
37 // ===========================================================================
38 // method definitions
39 // ===========================================================================
40 /* -------------------------------------------------------------------------
41  * GUIE2Collector-methods
42  * ----------------------------------------------------------------------- */
43 GUIE2Collector::GUIE2Collector(const std::string& id, DetectorUsage usage,
44  MSLane* lane, double startPos, double endPos, double detLength,
45  SUMOTime haltingTimeThreshold, double haltingSpeedThreshold,
46  double jamDistThreshold, const std::string& vTypes, bool showDetector)
47  : MSE2Collector(id, usage, lane, startPos, endPos, detLength, haltingTimeThreshold,
48  haltingSpeedThreshold, jamDistThreshold, vTypes),
49  myShowDetectorInGUI(showDetector) {}
50 
51 GUIE2Collector::GUIE2Collector(const std::string& id, DetectorUsage usage,
52  std::vector<MSLane*> lanes, double startPos, double endPos,
53  SUMOTime haltingTimeThreshold, double haltingSpeedThreshold,
54  double jamDistThreshold, const std::string& vTypes, bool showDetector)
55  : MSE2Collector(id, usage, lanes, startPos, endPos, haltingTimeThreshold,
56  haltingSpeedThreshold, jamDistThreshold, vTypes),
57  myShowDetectorInGUI(showDetector) {}
58 
60 
61 
64  return new MyWrapper(*this);
65 }
66 
67 // -------------------------------------------------------------------------
68 // GUIE2Collector::MyWrapper-methods
69 // -------------------------------------------------------------------------
70 
72  GUIDetectorWrapper(GLO_E2DETECTOR, detector.getID()),
73  myDetector(detector) {
74  // collect detector shape into one vector (v)
76  const std::vector<MSLane*> lanes = detector.getLanes();
77  double detectorLength = detector.getLength();
78  for (std::vector<MSLane*>::const_iterator li = lanes.begin(); li != lanes.end(); ++li) {
79  const PositionVector& shape = (*li)->getShape();
80  // account for gaps between lanes (e.g. in networks without internal lanes)
81  if (v.size() > 0) {
82  detectorLength += v.back().distanceTo2D(shape.front());
83  }
84  v.insert(v.end(), shape.begin(), shape.end());
85  }
86  // build geometry
88  lanes.front()->interpolateLanePosToGeometryPos(detector.getStartPos()),
89  lanes.back()->interpolateLanePosToGeometryPos(detector.getStartPos() + detectorLength));
90  //
91  myShapeRotations.reserve(myFullGeometry.size() - 1);
92  myShapeLengths.reserve(myFullGeometry.size() - 1);
93  int e = (int) myFullGeometry.size() - 1;
94  for (int i = 0; i < e; ++i) {
95  const Position& f = myFullGeometry[i];
96  const Position& s = myFullGeometry[i + 1];
97  myShapeLengths.push_back(f.distanceTo(s));
98  myShapeRotations.push_back((double) atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double) M_PI);
99  }
100  //
102 }
103 
104 
106 
107 
108 Boundary
110  Boundary b(myBoundary);
111  b.grow(20);
112  return b;
113 }
114 
115 
120  new GUIParameterTableWindow(app, *this, 13);
121  // add items
122  // parameter
123  ret->mkItem("length [m]", false, myDetector.getLength());
124  ret->mkItem("position [m]", false, myDetector.getStartPos());
125  ret->mkItem("lane", false, myDetector.getLane()->getID());
126  // values
127  ret->mkItem("vehicles [#]", true,
129  ret->mkItem("occupancy [%]", true,
131  ret->mkItem("mean speed [m/s]", true,
133  ret->mkItem("mean vehicle length [m]", true,
135  ret->mkItem("jam number [#]", true,
137  ret->mkItem("max jam length [veh]", true,
139  ret->mkItem("max jam length [m]", true,
141  ret->mkItem("jam length sum [veh]", true,
143  ret->mkItem("jam length sum [m]", true,
145  ret->mkItem("started halts [#]", true,
147  // close building
148  ret->closeBuilding();
149  return ret;
150 }
151 
152 
153 void
155  if (!myDetector.myShowDetectorInGUI) {
156  return;
157  }
158  glPushName(getGlID());
159  glPushMatrix();
160  glTranslated(0, 0, getType());
161  double dwidth = 1;
162  const double exaggeration = s.addSize.getExaggeration(s, this);
163  if (exaggeration > 0) {
164  if (myDetector.getUsageType() == DU_TL_CONTROL) {
165  dwidth = (double) 0.3;
166  glColor3d(0, (double) .6, (double) .8);
167  } else {
168  glColor3d(0, (double) .8, (double) .8);
169  }
170  double width = (double) 2.0 * s.scale;
171  if (width * exaggeration > 1.0) {
172  GLHelper::drawBoxLines(myFullGeometry, myShapeRotations, myShapeLengths, dwidth * exaggeration);
173  } else {
174  int e = (int) myFullGeometry.size() - 1;
175  for (int i = 0; i < e; ++i) {
176  GLHelper::drawLine(myFullGeometry[i], myShapeRotations[i], myShapeLengths[i]);
177  }
178  }
179  }
180  glPopMatrix();
181  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
182  glPopName();
183 }
184 
185 
188  return myDetector;
189 }
190 
191 
192 
193 /****************************************************************************/
194 
GUIGlObject.h
GUIParameterTableWindow
A window containing a gl-object's parameter.
Definition: GUIParameterTableWindow.h:62
MSE2Collector::getCurrentJamLengthInVehicles
int getCurrentJamLengthInVehicles() const
Returns the length of all jams in vehicles.
Definition: MSE2Collector.h:450
GUISUMOAbstractView
Definition: GUISUMOAbstractView.h:72
MSE2Collector::getCurrentMeanLength
double getCurrentMeanLength() const
Returns the mean vehicle length of vehicles currently on the detector.
Definition: MSE2Collector.h:430
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
MSE2Collector::getCurrentOccupancy
double getCurrentOccupancy() const
Returns the current detector occupancy.
Definition: MSE2Collector.h:420
GUIParameterTableWindow.h
GUIDetectorWrapper
Definition: GUIDetectorWrapper.h:42
GLHelper::drawBoxLines
static void drawBoxLines(const PositionVector &geom, const std::vector< double > &rots, const std::vector< double > &lengths, double width, int cornerDetail=0, double offset=0)
Draws thick lines.
Definition: GLHelper.cpp:182
PositionVector::getSubpart
PositionVector getSubpart(double beginOffset, double endOffset) const
get subpart of a position vector
Definition: PositionVector.cpp:706
GUIE2Collector::MyWrapper::myBoundary
Boundary myBoundary
The detector's boundary.
Definition: GUIE2Collector.h:158
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
MSE2Collector
An areal detector corresponding to a sequence of consecutive lanes.
Definition: MSE2Collector.h:81
GLHelper.h
MSE2Collector::getLength
double getLength() const
Returns the length of the detector.
Definition: MSE2Collector.h:386
PositionVector
A list of positions.
Definition: PositionVector.h:45
GUIE2Collector::MyWrapper::myShapeLengths
std::vector< double > myShapeLengths
A sequence of lengths in full-geometry mode.
Definition: GUIE2Collector.h:164
GUIE2Collector::MyWrapper
Definition: GUIE2Collector.h:110
MSE2Collector::getStartPos
double getStartPos() const
Returns the begin position of the detector.
Definition: MSE2Collector.h:369
PositionVector::getBoxBoundary
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
Definition: PositionVector.cpp:390
GUIParameterTableWindow::closeBuilding
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
Definition: GUIParameterTableWindow.cpp:219
GUIE2Collector::MyWrapper::drawGL
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GUIE2Collector.cpp:154
MSE2Collector::getCurrentMeanSpeed
double getCurrentMeanSpeed() const
Returns the mean vehicle speed of vehicles currently on the detector.
Definition: MSE2Collector.h:425
GUIVisualizationSettings::addName
GUIVisualizationTextSettings addName
Definition: GUIVisualizationSettings.h:591
GUIE2Collector::GUIE2Collector
GUIE2Collector(const std::string &id, DetectorUsage usage, MSLane *lane, double startPos, double endPos, double detLength, SUMOTime haltingTimeThreshold, double haltingSpeedThreshold, double jamDistThreshold, const std::string &vTypes, bool showDetector)
Constructor with given end position and detector length.
Definition: GUIE2Collector.cpp:43
MSE2Collector::getCurrentJamNumber
int getCurrentJamNumber() const
Returns the current number of jams.
Definition: MSE2Collector.h:435
Position::distanceTo
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:233
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
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:41
GUIVisualizationSettings::scale
double scale
information about a lane's width (temporary, used for a single view)
Definition: GUIVisualizationSettings.h:632
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
Position::x
double x() const
Returns the x-position.
Definition: Position.h:56
GLHelper::drawLine
static void drawLine(const Position &beg, double rot, double visLength)
Draws a thin line.
Definition: GLHelper.cpp:274
MSE2Collector::getCurrentMaxJamLengthInVehicles
int getCurrentMaxJamLengthInVehicles() const
Returns the length in vehicles of the currently largest jam.
Definition: MSE2Collector.h:440
GUIE2Collector::~GUIE2Collector
~GUIE2Collector()
Destructor.
Definition: GUIE2Collector.cpp:59
DU_TL_CONTROL
@ DU_TL_CONTROL
Definition: MSDetectorFileOutput.h:53
GUIE2Collector::MyWrapper::getDetector
GUIE2Collector & getDetector()
Returns the detector itself.
Definition: GUIE2Collector.cpp:187
GUIE2Collector::buildDetectorGUIRepresentation
virtual GUIDetectorWrapper * buildDetectorGUIRepresentation()
Returns the wrapper for this detector.
Definition: GUIE2Collector.cpp:63
DetectorUsage
DetectorUsage
Definition: MSDetectorFileOutput.h:50
GLIncludes.h
MSE2Collector::getLanes
std::vector< MSLane * > getLanes()
Returns a vector containing pointers to the lanes covered by the detector ordered from its first to i...
Definition: MSE2Collector.cpp:591
FunctionBinding.h
GUIMainWindow
Definition: GUIMainWindow.h:46
Position::y
double y() const
Returns the y-position.
Definition: Position.h:61
M_PI
#define M_PI
Definition: odrSpiral.cpp:40
GUIE2Collector::MyWrapper::getParameterWindow
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Definition: GUIE2Collector.cpp:117
GUIE2Collector::MyWrapper::getCenteringBoundary
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GUIE2Collector.cpp:109
GUIEdge.h
MSE2Collector::getCurrentJamLengthInMeters
double getCurrentJamLengthInMeters() const
Returns the length of all jams in meters.
Definition: MSE2Collector.h:455
MSE2Collector::getCurrentMaxJamLengthInMeters
double getCurrentMaxJamLengthInMeters() const
Returns the length in meters of the currently largest jam.
Definition: MSE2Collector.h:445
config.h
GUIVisualizationSettings::addSize
GUIVisualizationSizeSettings addSize
Definition: GUIVisualizationSettings.h:589
MSE2Collector::getCurrentStartedHalts
int getCurrentStartedHalts() const
Returns the length of all jams in meters.
Definition: MSE2Collector.h:460
GUIE2Collector
The gui-version of the MSE2Collector.
Definition: GUIE2Collector.h:43
GeomHelper.h
MSE2Collector::getCurrentVehicleNumber
int getCurrentVehicleNumber() const
Returns the number of vehicles currently on the detector.
Definition: MSE2Collector.cpp:1399
Boundary::grow
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:300
GUIE2Collector.h
GUIVisualizationSettings
Stores the information about how to visualize structures.
Definition: GUIVisualizationSettings.h:345
FunctionBinding
Definition: FunctionBinding.h:40
GUIE2Collector::MyWrapper::myShapeRotations
std::vector< double > myShapeRotations
A sequence of rotations in full-geometry mode.
Definition: GUIE2Collector.h:167
GUIE2Collector::MyWrapper::~MyWrapper
~MyWrapper()
Destrutor.
Definition: GUIE2Collector.cpp:105
GUIE2Collector::MyWrapper::myFullGeometry
PositionVector myFullGeometry
A sequence of positions in full-geometry mode.
Definition: GUIE2Collector.h:161
PositionVector.h
GLO_E2DETECTOR
@ GLO_E2DETECTOR
a E2 detector
Definition: GUIGlObjectTypes.h:77
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
GUIE2Collector::MyWrapper::MyWrapper
MyWrapper(GUIE2Collector &detector)
Constructor.
Definition: GUIE2Collector.cpp:71