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-2022 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 
26 #include "GUIInductLoop.h"
27 #include <utils/gui/div/GLHelper.h>
31 #include <microsim/MSLane.h>
33 #include "GUIEdge.h"
35 
36 
37 // ===========================================================================
38 // method definitions
39 // ===========================================================================
40 /* -------------------------------------------------------------------------
41  * GUIInductLoop-methods
42  * ----------------------------------------------------------------------- */
43 GUIInductLoop::GUIInductLoop(const std::string& id, MSLane* const lane,
44  double position, const std::string& vTypes,
45  int detectPersons, bool show) :
46  MSInductLoop(id, lane, position, vTypes, detectPersons, true),
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  if (myWrapper != nullptr) {
66  myWrapper->setSpecialColor(color);
67  }
68 }
69 
70 
71 // -------------------------------------------------------------------------
72 // GUIInductLoop::MyWrapper-methods
73 // -------------------------------------------------------------------------
74 
76  GUIDetectorWrapper(GLO_E1DETECTOR, detector.getID()),
77  myDetector(detector), myPosition(pos),
78  mySpecialColor(nullptr) {
80  myBoundary.add(myFGPosition.x() + (double) 5.5, myFGPosition.y() + (double) 5.5);
81  myBoundary.add(myFGPosition.x() - (double) 5.5, myFGPosition.y() - (double) 5.5);
83 }
84 
85 
87 
88 
89 double
91  return s.addSize.getExaggeration(s, this);
92 }
93 
94 
97  Boundary b(myBoundary);
98  b.grow(20);
99  return b;
100 }
101 
102 
103 
106  GUISUMOAbstractView& /*parent !!! recheck this - never needed?*/) {
107  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
108  // add items
109  // parameter
110  ret->mkItem("position [m]", false, myPosition);
111  ret->mkItem("lane", false, myDetector.getLane()->getID());
112  // values
113  ret->mkItem("entered vehicles [#]", true,
115  ret->mkItem("speed [m/s]", true,
117  ret->mkItem("occupancy [%]", true,
119  ret->mkItem("vehicle length [m]", true,
121  ret->mkItem("empty time [s]", true,
123  // close building
124  ret->closeBuilding(&myDetector);
125  return ret;
126 }
127 
128 
129 void
131  if (!myDetector.isVisible()) {
132  return;
133  }
134  GLHelper::pushName(getGlID());
135  double width = (double) 2.0 * s.scale;
136  glLineWidth(1.0);
137  const double exaggeration = getExaggeration(s);
138  // shape
139  glColor3d(1, 1, 0);
141  glTranslated(0, 0, getType());
142  glTranslated(myFGPosition.x(), myFGPosition.y(), 0);
143  glRotated(myFGRotation, 0, 0, 1);
144  glScaled(exaggeration, exaggeration, 1);
145  glBegin(GL_QUADS);
146  glVertex2d(0 - 1.0, 2);
147  glVertex2d(-1.0, -2);
148  glVertex2d(1.0, -2);
149  glVertex2d(1.0, 2);
150  glEnd();
151  glTranslated(0, 0, .01);
152  glBegin(GL_LINES);
153  glVertex2d(0, 2 - .1);
154  glVertex2d(0, -2 + .1);
155  glEnd();
156 
157  if (mySpecialColor == nullptr) {
158  glColor3d(1, 1, 1);
159  } else {
160  GLHelper::setColor(*mySpecialColor);
161  }
162 
163  // outline
164  if (width * exaggeration > 1) {
165  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
166  glBegin(GL_QUADS);
167  glVertex2d(0 - 1.0, 2);
168  glVertex2d(-1.0, -2);
169  glVertex2d(1.0, -2);
170  glVertex2d(1.0, 2);
171  glEnd();
172  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
173  }
174 
175  // position indicator
176  if (width * exaggeration > 1) {
177  glRotated(90, 0, 0, -1);
178  glBegin(GL_LINES);
179  glVertex2d(0, 1.7);
180  glVertex2d(0, -1.7);
181  glEnd();
182  }
184  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
186 }
187 
188 
189 /****************************************************************************/
@ GLO_E1DETECTOR
a E1 detector
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:77
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:299
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:507
static void pushName(unsigned int name)
push Name
Definition: GLHelper.cpp:132
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:123
static void popName()
pop Name
Definition: GLHelper.cpp:141
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:114
A MSInductLoop-visualiser.
Definition: GUIInductLoop.h:85
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
void setSpecialColor(const RGBColor *color)
set (outline) color for extra visualiaztion
Boundary myBoundary
The detector's boundary.
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration asociated with this GLObject
double myFGRotation
The rotation in full-geometry mode.
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
MyWrapper(GUIInductLoop &detector, double pos)
Constructor.
Position myFGPosition
The position in full-geometry mode.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
The gui-version of the MSInductLoop.
Definition: GUIInductLoop.h:45
MyWrapper * myWrapper
the glObject wrapper for this induction loop
GUIInductLoop(const std::string &id, MSLane *const lane, double position, const std::string &vTypes, int detectPersons, bool show)
Constructor.
virtual GUIDetectorWrapper * buildDetectorGUIRepresentation()
Returns this detector's visualisation-wrapper.
~GUIInductLoop()
Destructor.
void setSpecialColor(const RGBColor *color)
sets special caller for myWrapper
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 unextended detector measuring at a fixed position on a fixed lane.
Definition: MSInductLoop.h:62
double getOccupancy() const
Returns the current occupancy.
double getEnteredNumber(const int offset) const
Returns the number of vehicles that have passed the detector.
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:322
double getTimeSinceLastDetection() const
Returns the time since the last vehicle left the detector.
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
const PositionVector & getShape() const
Returns this lane's shape.
Definition: MSLane.h:478
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition: MSLane.h:505
const MSLane * getLane() const
Returns the lane the reminder works on.
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.
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values