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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
21 // The gui-version of the MSE2Collector
22 /****************************************************************************/
23 #include <config.h>
24 
27 #include "GUIE2Collector.h"
28 #include <utils/gui/div/GLHelper.h>
29 #include <utils/geom/GeomHelper.h>
32 #include "GUIEdge.h"
34 
35 
36 // ===========================================================================
37 // method definitions
38 // ===========================================================================
39 /* -------------------------------------------------------------------------
40  * GUIE2Collector-methods
41  * ----------------------------------------------------------------------- */
42 GUIE2Collector::GUIE2Collector(const std::string& id, DetectorUsage usage,
43  MSLane* lane, double startPos, double endPos, double detLength,
44  SUMOTime haltingTimeThreshold, double haltingSpeedThreshold,
45  double jamDistThreshold, const std::string& vTypes, bool showDetector)
46  : MSE2Collector(id, usage, lane, startPos, endPos, detLength, haltingTimeThreshold,
47  haltingSpeedThreshold, jamDistThreshold, vTypes),
48  myShow(showDetector) {}
49 
50 GUIE2Collector::GUIE2Collector(const std::string& id, DetectorUsage usage,
51  std::vector<MSLane*> lanes, double startPos, double endPos,
52  SUMOTime haltingTimeThreshold, double haltingSpeedThreshold,
53  double jamDistThreshold, const std::string& vTypes, bool showDetector)
54  : MSE2Collector(id, usage, lanes, startPos, endPos, haltingTimeThreshold,
55  haltingSpeedThreshold, jamDistThreshold, vTypes),
56  myShow(showDetector) {}
57 
59 
60 
63  return new MyWrapper(*this);
64 }
65 
66 // -------------------------------------------------------------------------
67 // GUIE2Collector::MyWrapper-methods
68 // -------------------------------------------------------------------------
69 
71  GUIDetectorWrapper(GLO_E2DETECTOR, detector.getID()),
72  myDetector(detector) {
73  // collect detector shape into one vector (v)
74  const std::vector<MSLane*> lanes = detector.getLanes();
75  for (std::vector<MSLane*>::const_iterator li = lanes.begin(); li != lanes.end(); ++li) {
76  PositionVector shape = (*li)->getShape();
77  double start = (li == lanes.begin() ? lanes.front()->interpolateLanePosToGeometryPos(detector.getStartPos()) : 0);
78  double end = (li + 1 == lanes.end() ? lanes.back()->interpolateLanePosToGeometryPos(detector.getEndPos()) : shape.length());
79  shape = shape.getSubpart(start, end);
80  myFullGeometry.insert(myFullGeometry.end(), shape.begin(), shape.end());
81  }
82  //
83  myShapeRotations.reserve(myFullGeometry.size() - 1);
84  myShapeLengths.reserve(myFullGeometry.size() - 1);
85  int e = (int) myFullGeometry.size() - 1;
86  for (int i = 0; i < e; ++i) {
87  const Position& f = myFullGeometry[i];
88  const Position& s = myFullGeometry[i + 1];
89  myShapeLengths.push_back(f.distanceTo(s));
90  myShapeRotations.push_back((double) atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double) M_PI);
91  }
92  //
94 }
95 
96 
98 
99 
100 Boundary
102  Boundary b(myBoundary);
103  b.grow(20);
104  return b;
105 }
106 
107 
112  new GUIParameterTableWindow(app, *this);
113  // add items
114  // parameter
115  ret->mkItem("length [m]", false, myDetector.getLength());
116  ret->mkItem("position [m]", false, myDetector.getStartPos());
117  ret->mkItem("lane", false, myDetector.getLane()->getID());
118  // values
119  ret->mkItem("vehicles [#]", true,
121  ret->mkItem("occupancy [%]", true,
123  ret->mkItem("mean speed [m/s]", true,
125  ret->mkItem("mean vehicle length [m]", true,
127  ret->mkItem("jam number [#]", true,
129  ret->mkItem("max jam length [veh]", true,
131  ret->mkItem("max jam length [m]", true,
133  ret->mkItem("jam length sum [veh]", true,
135  ret->mkItem("jam length sum [m]", true,
137  ret->mkItem("started halts [#]", true,
139  // close building
140  ret->closeBuilding();
141  return ret;
142 }
143 
144 
145 void
147  if (!myDetector.myShow) {
148  return;
149  }
150  glPushName(getGlID());
151  glPushMatrix();
152  glTranslated(0, 0, getType());
153  double dwidth = 1;
154  const double exaggeration = s.addSize.getExaggeration(s, this);
155  if (exaggeration > 0) {
156  if (myDetector.getUsageType() == DU_TL_CONTROL) {
157  dwidth = (double) 0.3;
158  glColor3d(0, (double) .6, (double) .8);
159  } else {
160  glColor3d(0, (double) .8, (double) .8);
161  }
162  double width = (double) 2.0 * s.scale;
163  if (width * exaggeration > 1.0) {
164  GLHelper::drawBoxLines(myFullGeometry, myShapeRotations, myShapeLengths, dwidth * exaggeration);
165  } else {
166  int e = (int) myFullGeometry.size() - 1;
167  for (int i = 0; i < e; ++i) {
168  GLHelper::drawLine(myFullGeometry[i], myShapeRotations[i], myShapeLengths[i]);
169  }
170  }
171  }
172  glPopMatrix();
173  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
174  glPopName();
175 }
176 
177 
180  return myDetector;
181 }
182 
183 
184 /****************************************************************************/
@ GLO_E2DETECTOR
a E2 detector
@ DU_TL_CONTROL
long long int SUMOTime
Definition: SUMOTime.h:31
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:39
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:299
static void drawLine(const Position &beg, double rot, double visLength)
Draws a thin line.
Definition: GLHelper.cpp:273
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:181
Boundary myBoundary
The detector's boundary.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
std::vector< double > myShapeLengths
A sequence of lengths in full-geometry mode.
MyWrapper(GUIE2Collector &detector)
Constructor.
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
GUIE2Collector & getDetector()
Returns the detector itself.
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
PositionVector myFullGeometry
A sequence of positions in full-geometry mode.
std::vector< double > myShapeRotations
A sequence of rotations in full-geometry mode.
The gui-version of the MSE2Collector.
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.
virtual GUIDetectorWrapper * buildDetectorGUIRepresentation()
Returns the wrapper for this detector.
~GUIE2Collector()
Destructor.
A window containing a gl-object's parameter.
void mkItem(const char *name, bool dynamic, ValueSource< T > *src)
Adds a row which obtains its value from a ValueSource.
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
Stores the information about how to visualize structures.
GUIVisualizationTextSettings addName
GUIVisualizationSizeSettings addSize
double scale
information about a lane's width (temporary, used for a single view)
An areal detector corresponding to a sequence of consecutive lanes.
Definition: MSE2Collector.h:79
std::vector< MSLane * > getLanes()
Returns a vector containing pointers to the lanes covered by the detector ordered from its first to i...
double getCurrentMaxJamLengthInMeters() const
Returns the length in meters of the currently largest jam.
double getStartPos() const
Returns the begin position of the detector.
double getCurrentMeanLength() const
Returns the mean vehicle length of vehicles currently on the detector.
int getCurrentMaxJamLengthInVehicles() const
Returns the length in vehicles of the currently largest jam.
int getCurrentVehicleNumber() const
Returns the number of vehicles currently on the detector.
int getCurrentJamLengthInVehicles() const
Returns the length of all jams in vehicles.
int getCurrentStartedHalts() const
Returns the length of all jams in meters.
double getEndPos() const
Returns the end position of the detector.
double getCurrentMeanSpeed() const
Returns the mean vehicle speed of vehicles currently on the detector.
double getCurrentJamLengthInMeters() const
Returns the length of all jams in meters.
int getCurrentJamNumber() const
Returns the current number of jams.
double getCurrentOccupancy() const
Returns the current detector occupancy.
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:231
double x() const
Returns the x-position.
Definition: Position.h:54
double y() const
Returns the y-position.
Definition: Position.h:59
A list of positions.
double length() const
Returns the length.
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
PositionVector getSubpart(double beginOffset, double endOffset) const
get subpart of a position vector
#define M_PI
Definition: odrSpiral.cpp:40
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values