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