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.dev/sumo
3 // Copyright (C) 2001-2024 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 
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,
47  const std::string name, const std::string& vTypes,
48  const std::string& nextEdges,
49  int detectPersons, bool showDetector)
50  : MSE2Collector(id, usage, lane, startPos, endPos, detLength, haltingTimeThreshold,
51  haltingSpeedThreshold, jamDistThreshold, name, vTypes, nextEdges, detectPersons),
52  myShow(showDetector) {}
53 
54 GUIE2Collector::GUIE2Collector(const std::string& id, DetectorUsage usage,
55  std::vector<MSLane*> lanes, double startPos, double endPos,
56  SUMOTime haltingTimeThreshold, double haltingSpeedThreshold,
57  double jamDistThreshold,
58  const std::string name, const std::string& vTypes,
59  const std::string& nextEdges,
60  int detectPersons, bool showDetector)
61  : MSE2Collector(id, usage, lanes, startPos, endPos, haltingTimeThreshold,
62  haltingSpeedThreshold, jamDistThreshold, name, vTypes, nextEdges, detectPersons),
63  myShow(showDetector) {}
64 
66 
67 
70  return new MyWrapper(*this);
71 }
72 
73 // -------------------------------------------------------------------------
74 // GUIE2Collector::MyWrapper-methods
75 // -------------------------------------------------------------------------
76 
78  GUIDetectorWrapper(GLO_E2DETECTOR, detector.getID(), GUIIconSubSys::getIcon(GUIIcon::E2)),
79  myDetector(detector) {
80  mySupportsOverride = true;
81  // collect detector shape into one vector (v)
82  const std::vector<MSLane*> lanes = detector.getLanes();
83  for (std::vector<MSLane*>::const_iterator li = lanes.begin(); li != lanes.end(); ++li) {
84  PositionVector shape = (*li)->getShape();
85  double start = (li == lanes.begin() ? lanes.front()->interpolateLanePosToGeometryPos(detector.getStartPos()) : 0);
86  double end = (li + 1 == lanes.end() ? lanes.back()->interpolateLanePosToGeometryPos(detector.getEndPos()) : shape.length());
87  shape = shape.getSubpart(start, end);
88  myFullGeometry.insert(myFullGeometry.end(), shape.begin(), shape.end());
89  }
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 double
110  return s.addSize.getExaggeration(s, this);
111 }
112 
113 
114 Boundary
116  Boundary b(myBoundary);
117  b.grow(20);
118  return b;
119 }
120 
121 
126  new GUIParameterTableWindow(app, *this);
127  // add items
128  // parameter
129  ret->mkItem(TL("name"), false, myDetector.getName());
130  ret->mkItem(TL("length [m]"), false, myDetector.getLength());
131  ret->mkItem(TL("position [m]"), false, myDetector.getStartPos());
132  ret->mkItem(TL("lane"), false, myDetector.getLane()->getID());
133  if (myDetector.isTyped()) {
134  ret->mkItem(TL("vTypes"), false, toString(myDetector.getVehicleTypes()));
135  }
136  // values
137  ret->mkItem(TL("vehicles [#]"), true,
139  ret->mkItem(TL("occupancy [%]"), true,
141  ret->mkItem(TL("mean speed [m/s]"), true,
143  ret->mkItem(TL("mean vehicle length [m]"), true,
145  ret->mkItem(TL("jam number [#]"), true,
147  ret->mkItem(TL("max jam length [veh]"), true,
149  ret->mkItem(TL("max jam length [m]"), true,
151  ret->mkItem(TL("jam length sum [veh]"), true,
153  ret->mkItem(TL("jam length sum [m]"), true,
155  ret->mkItem(TL("started halts [#]"), true,
157  ret->mkItem(TL("interval seen vehicles [#]"), true,
159  ret->mkItem(TL("interval speed [m/s]"), true,
161  ret->mkItem(TL("interval occupancy [%]"), true,
163  ret->mkItem(TL("interval max jam length [m]"), true,
165  ret->mkItem(TL("last interval seen vehicles [#]"), true,
167  ret->mkItem(TL("last interval speed [m/s]"), true,
169  ret->mkItem(TL("last interval occupancy [%]"), true,
171  ret->mkItem(TL("last interval max jam length [m]"), true,
173 
174 
175  // close building
176  ret->closeBuilding(&myDetector);
177  return ret;
178 }
179 
180 
181 void
183  if (!myDetector.myShow) {
184  return;
185  }
186  GLHelper::pushName(getGlID());
188  glTranslated(0, 0, GLO_JUNCTION + 0.4); // do not draw on top of linkRules
189  double dwidth = 1;
190  const double exaggeration = getExaggeration(s);
191  if (exaggeration > 0) {
192  if (haveOverride()) {
193  glColor3d(1, 0, 1);
194  } else if (myDetector.getUsageType() == DU_TL_CONTROL) {
195  glColor3d(0, (double) .6, (double) .8);
196  } else {
197  glColor3d(0, (double) .8, (double) .8);
198  }
199  if (myDetector.getUsageType() == DU_TL_CONTROL) {
200  dwidth = (double) 0.3;
201  }
202  double width = (double) 2.0 * s.scale;
203  if (width * exaggeration > 1.0) {
204  GLHelper::drawBoxLines(myFullGeometry, myShapeRotations, myShapeLengths, dwidth * exaggeration);
205  } else {
206  int e = (int) myFullGeometry.size() - 1;
207  for (int i = 0; i < e; ++i) {
208  GLHelper::drawLine(myFullGeometry[i], myShapeRotations[i], myShapeLengths[i]);
209  }
210  }
211  }
213  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
215 }
216 
217 
220  return myDetector;
221 }
222 
223 bool
225  return myDetector.getOverrideVehNumber() >= 0;
226 }
227 
228 
229 void
231  if (haveOverride()) {
232  myDetector.overrideVehicleNumber(-1);
233  } else {
234  myDetector.overrideVehicleNumber(1);
235  }
236 }
237 
238 
239 /****************************************************************************/
long long int SUMOTime
Definition: GUI.h:35
@ GLO_E2DETECTOR
a E2 detector
@ GLO_JUNCTION
a junction
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
@ DU_TL_CONTROL
#define TL(string)
Definition: MsgHandler.h:315
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
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:319
static void drawLine(const Position &beg, double rot, double visLength)
Draws a thin line.
Definition: GLHelper.cpp:439
static void pushName(unsigned int name)
push Name
Definition: GLHelper.cpp:139
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:130
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:347
static void popName()
pop Name
Definition: GLHelper.cpp:148
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:117
bool mySupportsOverride
whether this detector supports virtual detector calls
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent) override
Returns an own parameter window.
Boundary myBoundary
The detector's boundary.
Boundary getCenteringBoundary() const override
Returns the boundary to which the view shall be centered in order to show the object.
void drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
void toggleOverride() const override
toggle virtual detector call
bool haveOverride() const override
whether this detector has an active virtual detector call
std::vector< double > myShapeLengths
A sequence of lengths in full-geometry mode.
double getExaggeration(const GUIVisualizationSettings &s) const override
return exaggeration associated with this GLObject
MyWrapper(GUIE2Collector &detector)
Constructor.
GUIE2Collector & getDetector()
Returns the detector itself.
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.
virtual GUIDetectorWrapper * buildDetectorGUIRepresentation()
Returns the wrapper for this detector.
GUIE2Collector(const std::string &id, DetectorUsage usage, MSLane *lane, double startPos, double endPos, double detLength, SUMOTime haltingTimeThreshold, double haltingSpeedThreshold, double jamDistThreshold, const std::string name, const std::string &vTypes, const std::string &nextEdges, int detectPersons, bool showDetector)
Constructor with given end position and detector length.
~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 getIntervalMaxJamLengthInMeters() const
double getStartPos() const
Returns the begin position of the detector.
double getLastIntervalOccupancy() const
double getCurrentMeanLength() const
Returns the mean vehicle length of vehicles currently on the detector.
double getIntervalMeanSpeed() const
int getCurrentMaxJamLengthInVehicles() const
Returns the length in vehicles of the currently largest jam.
double getLastIntervalMeanSpeed() const
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.
int getIntervalVehicleNumber() const
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.
double getIntervalOccupancy() const
double getLastIntervalMaxJamLengthInMeters() const
int getCurrentJamNumber() const
Returns the current number of jams.
double getCurrentOccupancy() const
Returns the current detector occupancy.
int getLastIntervalVehicleNumber() const
Representation of a lane in the micro simulation.
Definition: MSLane.h:84
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:261
double x() const
Returns the x-position.
Definition: Position.h:55
double y() const
Returns the y-position.
Definition: Position.h:60
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:45
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values