Eclipse SUMO - Simulation of Urban MObility
GUIMEInductLoop.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 /****************************************************************************/
18 // The gui-version of the MEInductLoop
19 /****************************************************************************/
20 #include <config.h>
21 
22 
26 #include <guisim/GUILane.h>
27 #include <utils/gui/div/GLHelper.h>
31 #include <mesosim/MEInductLoop.h>
32 #include <mesosim/MESegment.h>
33 #include "GUIMEInductLoop.h"
34 
35 
36 // ===========================================================================
37 // method definitions
38 // ===========================================================================
39 /* -------------------------------------------------------------------------
40  * GUIMEInductLoop-methods
41  * ----------------------------------------------------------------------- */
42 GUIMEInductLoop::GUIMEInductLoop(const std::string& id, MESegment* s,
43  double position, const std::string& vTypes)
44  : MEInductLoop(id, s, position, vTypes) {}
45 
46 
48 
49 
52  return new MyWrapper(*this, myPosition);
53 }
54 
55 // -----------------------------------------------------------------------
56 // GUIMEInductLoop::MyWrapper-methods
57 // -----------------------------------------------------------------------
58 
60  : GUIDetectorWrapper(GLO_E1DETECTOR_ME, detector.getID()),
61  myDetector(detector), myPosition(pos) {
62  const MSLane* lane = detector.mySegment->getEdge().getLanes()[0];
64  myBoundary.add(myFGPosition.x() + (double) 5.5, myFGPosition.y() + (double) 5.5);
65  myBoundary.add(myFGPosition.x() - (double) 5.5, myFGPosition.y() - (double) 5.5);
67 }
68 
69 
71 
72 
75  Boundary b(myBoundary);
76  b.grow(20);
77  return b;
78 }
79 
80 
81 
84  GUISUMOAbstractView& /* parent */) {
85  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
86  // add items
87  /*
88  ret->mkItem("flow [veh/h]", true,
89  new FuncBinding_IntParam<GUIMEInductLoop, double>(
90  &(getLoop()), &GUIMEInductLoop::getFlow, 1));
91  ret->mkItem("mean speed [m/s]", true,
92  new FuncBinding_IntParam<GUIMEInductLoop, double>(
93  &(getLoop()), &GUIMEInductLoop::getMeanSpeed, 1));
94  ret->mkItem("occupancy [%]", true,
95  new FuncBinding_IntParam<GUIMEInductLoop, double>(
96  &(getLoop()), &GUIMEInductLoop::getOccupancy, 1));
97  ret->mkItem("mean vehicle length [m]", true,
98  new FuncBinding_IntParam<GUIMEInductLoop, double>(
99  &(getLoop()), &GUIMEInductLoop::getMeanVehicleLength, 1));
100  ret->mkItem("empty time [s]", true,
101  new FunctionBinding<GUIMEInductLoop, double>(
102  &(getLoop()), &GUIMEInductLoop::getTimeSinceLastDetection));
103  */
104  //
105  ret->mkItem("position [m]", false, myPosition);
106  ret->mkItem("lane", false, myDetector.mySegment->getID());
107  // close building
108  ret->closeBuilding();
109  return ret;
110 }
111 
112 
113 void
115  glPushName(getGlID());
116  glPolygonOffset(0, -2);
117  double width = (double) 2.0 * s.scale;
118  glLineWidth(1.0);
119  const double exaggeration = s.addSize.getExaggeration(s, this);
120  // shape
121  glColor3d(1, 1, 0);
122  glPushMatrix();
123  glTranslated(myFGPosition.x(), myFGPosition.y(), getType());
124  glRotated(myFGRotation, 0, 0, 1);
125  glScaled(exaggeration, exaggeration, exaggeration);
126  glBegin(GL_QUADS);
127  glVertex2d(0 - 1.0, 2);
128  glVertex2d(-1.0, -2);
129  glVertex2d(1.0, -2);
130  glVertex2d(1.0, 2);
131  glEnd();
132  glBegin(GL_LINES);
133  // without the substracted offsets, lines are partially longer
134  // than the boxes
135  glVertex2d(0, 2 - .1);
136  glVertex2d(0, -2 + .1);
137  glEnd();
138 
139  // outline
140  if (width * exaggeration > 1) {
141  glColor3d(1, 1, 1);
142  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
143  glBegin(GL_QUADS);
144  glVertex2f(0 - 1.0, 2);
145  glVertex2f(-1.0, -2);
146  glVertex2f(1.0, -2);
147  glVertex2f(1.0, 2);
148  glEnd();
149  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
150  }
151 
152  // position indicator
153  if (width * exaggeration > 1) {
154  glRotated(90, 0, 0, -1);
155  glColor3d(1, 1, 1);
156  glBegin(GL_LINES);
157  glVertex2d(0, 1.7);
158  glVertex2d(0, -1.7);
159  glEnd();
160  }
161  glPopMatrix();
162  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
163  glPopName();
164 }
165 
166 
169  return myDetector;
170 }
171 
172 
173 /****************************************************************************/
@ GLO_E1DETECTOR_ME
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
Boundary myBoundary
The detector's boundary.
Position myFGPosition
The position in full-geometry mode.
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
GUIMEInductLoop & getLoop()
Returns the detector itself.
double myFGRotation
The rotation in full-geometry mode.
MyWrapper(GUIMEInductLoop &detector, double pos)
Constructor.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
GUIMEInductLoop(const std::string &id, MESegment *s, double position, const std::string &vTypes)
Construtor.
virtual GUIDetectorWrapper * buildDetectorGUIRepresentation()
Returns this detector's visualisation-wrapper.
~GUIMEInductLoop()
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 induction loop for mesoscopic simulation.
Definition: MEInductLoop.h:45
MESegment *const mySegment
mesoscopic edge segment the loop lies on
Definition: MEInductLoop.h:89
const double myPosition
position from the start of the edge / lane
Definition: MEInductLoop.h:92
A single mesoscopic segment (cell)
Definition: MESegment.h:47
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:325
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:166
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
const PositionVector & getShape() const
Returns this lane's shape.
Definition: MSLane.h:476
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition: MSLane.h:503
double x() const
Returns the x-position.
Definition: Position.h:54
double y() const
Returns the y-position.
Definition: Position.h:59
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