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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // The gui-version of the MEInductLoop
16 /****************************************************************************/
17 
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
24 
28 #include <guisim/GUILane.h>
29 #include <utils/gui/div/GLHelper.h>
33 #include <mesosim/MEInductLoop.h>
34 #include <mesosim/MESegment.h>
35 #include "GUIMEInductLoop.h"
36 
37 
38 // ===========================================================================
39 // method definitions
40 // ===========================================================================
41 /* -------------------------------------------------------------------------
42  * GUIMEInductLoop-methods
43  * ----------------------------------------------------------------------- */
44 GUIMEInductLoop::GUIMEInductLoop(const std::string& id, MESegment* s,
45  double position, const std::string& vTypes)
46  : MEInductLoop(id, s, position, vTypes) {}
47 
48 
50 
51 
54  return new MyWrapper(*this, myPosition);
55 }
56 
57 // -----------------------------------------------------------------------
58 // GUIMEInductLoop::MyWrapper-methods
59 // -----------------------------------------------------------------------
60 
63  myDetector(detector), myPosition(pos) {
64  const MSLane* lane = detector.mySegment->getEdge().getLanes()[0];
66  myBoundary.add(myFGPosition.x() + (double) 5.5, myFGPosition.y() + (double) 5.5);
67  myBoundary.add(myFGPosition.x() - (double) 5.5, myFGPosition.y() - (double) 5.5);
69 }
70 
71 
73 
74 
78  b.grow(20);
79  return b;
80 }
81 
82 
83 
86  GUISUMOAbstractView& /* parent */) {
88  new GUIParameterTableWindow(app, *this, 2);
89  // add items
90  /*
91  ret->mkItem("flow [veh/h]", true,
92  new FuncBinding_IntParam<GUIMEInductLoop, double>(
93  &(getLoop()), &GUIMEInductLoop::getFlow, 1));
94  ret->mkItem("mean speed [m/s]", true,
95  new FuncBinding_IntParam<GUIMEInductLoop, double>(
96  &(getLoop()), &GUIMEInductLoop::getMeanSpeed, 1));
97  ret->mkItem("occupancy [%]", true,
98  new FuncBinding_IntParam<GUIMEInductLoop, double>(
99  &(getLoop()), &GUIMEInductLoop::getOccupancy, 1));
100  ret->mkItem("mean vehicle length [m]", true,
101  new FuncBinding_IntParam<GUIMEInductLoop, double>(
102  &(getLoop()), &GUIMEInductLoop::getMeanVehicleLength, 1));
103  ret->mkItem("empty time [s]", true,
104  new FunctionBinding<GUIMEInductLoop, double>(
105  &(getLoop()), &GUIMEInductLoop::getTimeSinceLastDetection));
106  */
107  //
108  ret->mkItem("position [m]", false, myPosition);
109  ret->mkItem("lane", false, myDetector.mySegment->getID());
110  // close building
111  ret->closeBuilding();
112  return ret;
113 }
114 
115 
116 void
118  glPushName(getGlID());
119  glPolygonOffset(0, -2);
120  double width = (double) 2.0 * s.scale;
121  glLineWidth(1.0);
122  const double exaggeration = s.addSize.getExaggeration(s, this);
123  // shape
124  glColor3d(1, 1, 0);
125  glPushMatrix();
126  glTranslated(myFGPosition.x(), myFGPosition.y(), getType());
127  glRotated(myFGRotation, 0, 0, 1);
128  glScaled(exaggeration, exaggeration, exaggeration);
129  glBegin(GL_QUADS);
130  glVertex2d(0 - 1.0, 2);
131  glVertex2d(-1.0, -2);
132  glVertex2d(1.0, -2);
133  glVertex2d(1.0, 2);
134  glEnd();
135  glBegin(GL_LINES);
136  // without the substracted offsets, lines are partially longer
137  // than the boxes
138  glVertex2d(0, 2 - .1);
139  glVertex2d(0, -2 + .1);
140  glEnd();
141 
142  // outline
143  if (width * exaggeration > 1) {
144  glColor3d(1, 1, 1);
145  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
146  glBegin(GL_QUADS);
147  glVertex2f(0 - 1.0, 2);
148  glVertex2f(-1.0, -2);
149  glVertex2f(1.0, -2);
150  glVertex2f(1.0, 2);
151  glEnd();
152  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
153  }
154 
155  // position indicator
156  if (width * exaggeration > 1) {
157  glRotated(90, 0, 0, -1);
158  glColor3d(1, 1, 1);
159  glBegin(GL_LINES);
160  glVertex2d(0, 1.7);
161  glVertex2d(0, -1.7);
162  glEnd();
163  }
164  glPopMatrix();
165  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
166  glPopName();
167 }
168 
169 
172  return myDetector;
173 }
174 
175 
176 /****************************************************************************/
177 
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
const double myPosition
position from the start of the edge / lane
Definition: MEInductLoop.h:95
double myFGRotation
The rotation in full-geometry mode.
double scale
information about a lane&#39;s width (temporary, used for a single view)
Position myFGPosition
The position in full-geometry mode.
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
GUIVisualizationTextSettings addName
~GUIMEInductLoop()
Destructor.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Stores the information about how to visualize structures.
double y() const
Returns the y-position.
Definition: Position.h:62
void mkItem(const char *name, bool dynamic, ValueSource< T > *src)
Adds a row which obtains its value from a ValueSource.
double x() const
Returns the x-position.
Definition: Position.h:57
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:165
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:478
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
const std::string & getID() const
Returns the id.
Definition: Named.h:77
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
GUIMEInductLoop(const std::string &id, MESegment *s, double position, const std::string &vTypes)
Construtor.
Boundary myBoundary
The detector&#39;s boundary.
GUIVisualizationSizeSettings addSize
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
GUIMEInductLoop & getLoop()
Returns the detector itself.
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:301
MyWrapper(GUIMEInductLoop &detector, double pos)
Constructor.
a E1 detector
double myPosition
The position on the lane.
A single mesoscopic segment (cell)
Definition: MESegment.h:50
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition: MSLane.h:505
GUIGlID getGlID() const
Returns the numerical id of the object.
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:79
virtual GUIDetectorWrapper * buildDetectorGUIRepresentation()
Returns this detector&#39;s visualisation-wrapper.
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:266
Representation of a lane in the micro simulation.
Definition: MSLane.h:83
A window containing a gl-object&#39;s parameter.
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
An induction loop for mesoscopic simulation.
Definition: MEInductLoop.h:48
MESegment *const mySegment
mesoscopic edge segment the loop lies on
Definition: MEInductLoop.h:92
GUIMEInductLoop & myDetector
The wrapped detector.