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.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 /****************************************************************************/
20 // The gui-version of the MSInductLoop, together with the according
21 /****************************************************************************/
22 #include <config.h>
23 
27 #include <utils/gui/div/GLHelper.h>
33 #include <microsim/MSLane.h>
35 #include "GUIEdge.h"
37 #include "GUIInductLoop.h"
38 
39 
40 // ===========================================================================
41 // method definitions
42 // ===========================================================================
43 /* -------------------------------------------------------------------------
44  * GUIInductLoop-methods
45  * ----------------------------------------------------------------------- */
46 GUIInductLoop::GUIInductLoop(const std::string& id, MSLane* const lane,
47  double position, double length,
48  std::string name, const std::string& vTypes,
49  const std::string& nextEdges,
50  int detectPersons, bool show) :
51  MSInductLoop(id, lane, position, length, name, vTypes, nextEdges, detectPersons, true),
52  myWrapper(nullptr),
53  myShow(show) {
54 }
55 
56 
58 
59 
62  if (hasParameter("hotkey")) {
64  }
65  // caller (GUINet) takes responsibility for pointer
66  myWrapper = new MyWrapper(*this, myPosition);
67  return myWrapper;
68 }
69 
70 
71 void
73  if (myWrapper != nullptr) {
74  myWrapper->setSpecialColor(color);
75  }
76 }
77 
78 
79 // -------------------------------------------------------------------------
80 // GUIInductLoop::MyWrapper-methods
81 // -------------------------------------------------------------------------
82 
84  GUIDetectorWrapper(GLO_E1DETECTOR, detector.getID(), GUIIconSubSys::getIcon(GUIIcon::E1)),
85  myDetector(detector), myPosition(pos),
86  myHaveLength(myPosition != detector.getEndPosition()),
87  mySpecialColor(nullptr) {
88  mySupportsOverride = true;
90  myBoundary.add(myFGPosition.x() + (double) 5.5, myFGPosition.y() + (double) 5.5);
91  myBoundary.add(myFGPosition.x() - (double) 5.5, myFGPosition.y() - (double) 5.5);
93 
94  if (myHaveLength) {
95  const MSLane& lane = *detector.getLane();
96  const double endPos = detector.getEndPosition();
97  myFGShape = lane.getShape();
100  lane.interpolateLanePosToGeometryPos(endPos));
101  myFGShapeRotations.reserve(myFGShape.size() - 1);
102  myFGShapeLengths.reserve(myFGShape.size() - 1);
103  int e = (int) myFGShape.size() - 1;
104  for (int i = 0; i < e; ++i) {
105  const Position& f = myFGShape[i];
106  const Position& s = myFGShape[i + 1];
107  myFGShapeLengths.push_back(f.distanceTo(s));
108  myFGShapeRotations.push_back((double) atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double) PI);
109  }
110  myOutline.push_back(lane.geometryPositionAtOffset(pos, -1));
111  myOutline.push_back(lane.geometryPositionAtOffset(pos, 1));
112  myOutline.push_back(lane.geometryPositionAtOffset(endPos, 1));
113  myOutline.push_back(lane.geometryPositionAtOffset(endPos, -1));
114  myIndicators.push_back(lane.geometryPositionAtOffset(pos, -1.7));
115  myIndicators.push_back(lane.geometryPositionAtOffset(pos, 1.7));
116  myIndicators.push_back(lane.geometryPositionAtOffset(endPos, 1.7));
117  myIndicators.push_back(lane.geometryPositionAtOffset(endPos, -1.7));
118  }
119 }
120 
121 
123 
124 
125 Boundary
127  Boundary b(myBoundary);
128  b.grow(20);
129  return b;
130 }
131 
132 
133 
136  GUISUMOAbstractView& /*parent !!! recheck this - never needed?*/) {
137  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
138  // add items
139  // parameter
140  ret->mkItem(TL("name"), false, myDetector.getName());
141  ret->mkItem(TL("position [m]"), false, myPosition);
142  if (myDetector.getEndPosition() != myPosition) {
143  ret->mkItem(TL("end position [m]"), false, myDetector.getEndPosition());
144  }
145  ret->mkItem(TL("lane"), false, myDetector.getLane()->getID());
146  if (myDetector.isTyped()) {
147  ret->mkItem(TL("vTypes"), false, toString(myDetector.getVehicleTypes()));
148  }
149  // values
150  ret->mkItem(TL("entered vehicles [-]"), true,
152  ret->mkItem(TL("speed [m/s]"), true,
154  ret->mkItem(TL("occupancy [%]"), true,
156  ret->mkItem(TL("vehicle length [m]"), true,
158  ret->mkItem(TL("empty time [s]"), true,
160  ret->mkItem(TL("occupied time [s]"), true,
162  ret->mkItem(TL("interval entered vehicles [#]"), true,
164  ret->mkItem(TL("interval speed [m/s]"), true,
166  ret->mkItem(TL("interval occupancy [%]"), true,
168  ret->mkItem(TL("last interval entered vehicles [#]"), true,
170  ret->mkItem(TL("last interval speed [m/s]"), true,
172  ret->mkItem(TL("last interval occupancy [%]"), true,
174  // close building
175  ret->closeBuilding(&myDetector);
176  return ret;
177 }
178 
179 
180 void
182  if (!myDetector.isVisible()) {
183  return;
184  }
185  GLHelper::pushName(getGlID());
186  double width = (double) 2.0 * s.scale;
187  glLineWidth(1.0);
188  const double exaggeration = getExaggeration(s);
189  glColor3d(1, 1, 0);
190  if (myHaveLength) {
192  glTranslated(0, 0, GLO_JUNCTION + 0.4); // do not draw on top of linkRules
193  GLHelper::drawBoxLines(myFGShape, myFGShapeRotations, myFGShapeLengths, MIN2(1.0, exaggeration), 0, 0);
194  if (width * exaggeration > 1) {
195 
196  // outline
197  setOutlineColor();
198  glTranslated(0, 0, .01);
199  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
200  glBegin(GL_QUADS);
201  for (const Position& p : myOutline) {
202  glVertex2d(p.x(), p.y());
203  }
204  glEnd();
205  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
206 
207  // position indicator
208  glBegin(GL_LINES);
209  glVertex2d(myIndicators[0].x(), myIndicators[0].y());
210  glVertex2d(myIndicators[1].x(), myIndicators[1].y());
211  glEnd();
212  glBegin(GL_LINES);
213  glVertex2d(myIndicators[2].x(), myIndicators[2].y());
214  glVertex2d(myIndicators[3].x(), myIndicators[3].y());
215  glEnd();
216 
217  // jammed actuated-tls detector, draw crossed-out:
218  if (mySpecialColor != nullptr && *mySpecialColor == RGBColor::ORANGE) {
219  glBegin(GL_LINES);
220  glVertex2d(myOutline[0].x(), myOutline[0].y());
221  glVertex2d(myOutline[2].x(), myOutline[2].y());
222  glEnd();
223  glBegin(GL_LINES);
224  glVertex2d(myOutline[1].x(), myOutline[1].y());
225  glVertex2d(myOutline[3].x(), myOutline[3].y());
226  glEnd();
227  }
228  }
230  } else {
231  // classic shape
233  glTranslated(0, 0, GLO_JUNCTION + 0.4); // do not draw on top of linkRules
234  glTranslated(myFGPosition.x(), myFGPosition.y(), 0);
235  glRotated(myFGRotation, 0, 0, 1);
236  glScaled(exaggeration, exaggeration, 1);
237  glBegin(GL_QUADS);
238  glVertex2d(0 - 1.0, 2);
239  glVertex2d(-1.0, -2);
240  glVertex2d(1.0, -2);
241  glVertex2d(1.0, 2);
242  glEnd();
243  glTranslated(0, 0, .01);
244  setOutlineColor();
245 
246  if (width * exaggeration > 1) {
247  // outline
248  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
249  glBegin(GL_QUADS);
250  glVertex2d(0 - 1.0, 2);
251  glVertex2d(-1.0, -2);
252  glVertex2d(1.0, -2);
253  glVertex2d(1.0, 2);
254  glEnd();
255  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
256 
257  // position indicator
258  glRotated(90, 0, 0, -1);
259  glBegin(GL_LINES);
260  glVertex2d(0, 1.7);
261  glVertex2d(0, -1.7);
262  glEnd();
263 
264  // jammed actuated-tls detector, draw crossed-out:
265  if (mySpecialColor != nullptr && *mySpecialColor == RGBColor::ORANGE) {
266  glBegin(GL_LINES);
267  glVertex2d(-1.0, 2);
268  glVertex2d(1.0, -2);
269  glEnd();
270  glBegin(GL_LINES);
271  glVertex2d(-1.0, -2);
272  glVertex2d(1.0, 2);
273  glEnd();
274  }
275  }
277  }
278  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
280 }
281 
282 
283 void
285  if (haveOverride()) {
286  glColor3d(1, 0, 1);
287  } else if (mySpecialColor == nullptr) {
288  glColor3d(1, 1, 1);
289  } else {
290  GLHelper::setColor(*mySpecialColor);
291  }
292 }
293 
294 bool
296  return myDetector.getOverrideTime() >= 0;
297 }
298 
299 
300 void
302  if (haveOverride()) {
303  myDetector.overrideTimeSinceDetection(-1);
304  } else {
305  myDetector.overrideTimeSinceDetection(0);
306  }
307 }
308 
309 /****************************************************************************/
@ GLO_E1DETECTOR
a E1 detector
@ GLO_JUNCTION
a junction
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
#define TL(string)
Definition: MsgHandler.h:315
T MIN2(T a, T b)
Definition: StdDefs.h:76
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
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:78
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:319
static bool registerHotkey(const std::string &key, MSInductLoop *det)
register hotkey actions
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:654
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
A MSInductLoop-visualiser.
Definition: GUIInductLoop.h:86
PositionVector myOutline
void drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
bool haveOverride() const override
whether this detector has an active virtual detector call
bool myHaveLength
Whether this detector has defined a length.
void toggleOverride() const override
toggle virtual detector call
void setSpecialColor(const RGBColor *color)
set (outline) color for extra visualization
PositionVector myIndicators
Boundary myBoundary
The detector's boundary.
std::vector< double > myFGShapeLengths
The lengths of the shape parts.
Boundary getCenteringBoundary() const override
Returns the boundary to which the view shall be centered in order to show the object.
double myFGRotation
The rotation in full-geometry mode.
PositionVector myFGShape
The shape.
MyWrapper(GUIInductLoop &detector, double pos)
Constructor.
Position myFGPosition
The position in full-geometry mode.
std::vector< double > myFGShapeRotations
The rotations of the shape parts.
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent) override
Returns an own parameter window.
The gui-version of the MSInductLoop.
Definition: GUIInductLoop.h:45
MyWrapper * myWrapper
the glObject wrapper for this induction loop
virtual GUIDetectorWrapper * buildDetectorGUIRepresentation()
Returns this detector's visualisation-wrapper.
~GUIInductLoop()
Destructor.
void setSpecialColor(const RGBColor *color)
sets special caller for myWrapper
GUIInductLoop(const std::string &id, MSLane *const lane, double position, double length, std::string name, const std::string &vTypes, const std::string &nextEdges, int detectPersons, bool show)
Constructor.
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
double scale
information about a lane's width (temporary, used for a single view)
An unextended detector measuring at a fixed position on a fixed lane.
Definition: MSInductLoop.h:63
double getOccupancyTime() const
Returns the time of continous occupation by the same vehicle in seconds or 0 if there is no vehicle o...
double getOccupancy() const
Returns the current occupancy.
double getIntervalOccupancy(bool lastInterval=false) const
double getEnteredNumber(const int offset) const
Returns the number of vehicles that have passed the detector.
int getIntervalVehicleNumber(bool lastInterval=false) const
double getEndPosition() const
Returns the end position of the detector on the lane.
Definition: MSInductLoop.h:107
double getSpeed(const int offset) const
Returns the speed of the vehicle on the detector.
double getVehicleLength(const int offset) const
Returns the length of the vehicle on the detector.
const double myPosition
Detector's position on lane [m].
Definition: MSInductLoop.h:357
double getTimeSinceLastDetection() const
Returns the time since the last vehicle left the detector.
double getIntervalMeanSpeed(bool lastInterval=false) const
Representation of a lane in the micro simulation.
Definition: MSLane.h:84
double interpolateLanePosToGeometryPos(double lanePos) const
Definition: MSLane.h:546
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition: MSLane.h:552
virtual const PositionVector & getShape(bool) const
Definition: MSLane.h:294
const MSLane * getLane() const
Returns the lane the reminder works on.
bool hasParameter(const std::string &key) const
Returns whether the parameter is set.
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
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 dimensions
Definition: Position.h:266
double x() const
Returns the x-position.
Definition: Position.h:55
double y() const
Returns the y-position.
Definition: Position.h:60
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
PositionVector getSubpart(double beginOffset, double endOffset) const
get subpart of a position vector
static const RGBColor ORANGE
Definition: RGBColor.h:191