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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // The gui-version of the MEInductLoop
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
30 
34 #include <guisim/GUILane.h>
35 #include <utils/gui/div/GLHelper.h>
39 #include <mesosim/MEInductLoop.h>
40 #include <mesosim/MESegment.h>
41 #include "GUIMEInductLoop.h"
42 
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
47 /* -------------------------------------------------------------------------
48  * GUIMEInductLoop-methods
49  * ----------------------------------------------------------------------- */
50 GUIMEInductLoop::GUIMEInductLoop(const std::string& id, MESegment* s,
51  double position, const std::string& vTypes)
52  : MEInductLoop(id, s, position, vTypes) {}
53 
54 
56 
57 
60  return new MyWrapper(*this, myPosition);
61 }
62 
63 
64 /* -------------------------------------------------------------------------
65  * GUIMEInductLoop::MyWrapper-methods
66  * ----------------------------------------------------------------------- */
68  : GUIDetectorWrapper("induct loop", detector.getID()),
69  myDetector(detector), myPosition(pos) {
70  const MSLane* lane = detector.mySegment->getEdge().getLanes()[0];
72  myBoundary.add(myFGPosition.x() + (double) 5.5, myFGPosition.y() + (double) 5.5);
73  myBoundary.add(myFGPosition.x() - (double) 5.5, myFGPosition.y() - (double) 5.5);
75 }
76 
77 
79 
80 
84  b.grow(20);
85  return b;
86 }
87 
88 
89 
92  GUISUMOAbstractView& /* parent */) {
94  new GUIParameterTableWindow(app, *this, 2);
95  // add items
96  /*
97  ret->mkItem("flow [veh/h]", true,
98  new FuncBinding_IntParam<GUIMEInductLoop, double>(
99  &(getLoop()), &GUIMEInductLoop::getFlow, 1));
100  ret->mkItem("mean speed [m/s]", true,
101  new FuncBinding_IntParam<GUIMEInductLoop, double>(
102  &(getLoop()), &GUIMEInductLoop::getMeanSpeed, 1));
103  ret->mkItem("occupancy [%]", true,
104  new FuncBinding_IntParam<GUIMEInductLoop, double>(
105  &(getLoop()), &GUIMEInductLoop::getOccupancy, 1));
106  ret->mkItem("mean vehicle length [m]", true,
107  new FuncBinding_IntParam<GUIMEInductLoop, double>(
108  &(getLoop()), &GUIMEInductLoop::getMeanVehicleLength, 1));
109  ret->mkItem("empty time [s]", true,
110  new FunctionBinding<GUIMEInductLoop, double>(
111  &(getLoop()), &GUIMEInductLoop::getTimeSinceLastDetection));
112  */
113  //
114  ret->mkItem("position [m]", false, myPosition);
115  ret->mkItem("lane", false, myDetector.mySegment->getID());
116  // close building
117  ret->closeBuilding();
118  return ret;
119 }
120 
121 
122 void
124  glPushName(getGlID());
125  glPolygonOffset(0, -2);
126  double width = (double) 2.0 * s.scale;
127  glLineWidth(1.0);
128  const double exaggeration = s.addSize.getExaggeration(s);
129  // shape
130  glColor3d(1, 1, 0);
131  glPushMatrix();
132  glTranslated(myFGPosition.x(), myFGPosition.y(), getType());
133  glRotated(myFGRotation, 0, 0, 1);
134  glScaled(exaggeration, exaggeration, exaggeration);
135  glBegin(GL_QUADS);
136  glVertex2d(0 - 1.0, 2);
137  glVertex2d(-1.0, -2);
138  glVertex2d(1.0, -2);
139  glVertex2d(1.0, 2);
140  glEnd();
141  glBegin(GL_LINES);
142  // without the substracted offsets, lines are partially longer
143  // than the boxes
144  glVertex2d(0, 2 - .1);
145  glVertex2d(0, -2 + .1);
146  glEnd();
147 
148  // outline
149  if (width * exaggeration > 1) {
150  glColor3d(1, 1, 1);
151  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
152  glBegin(GL_QUADS);
153  glVertex2f(0 - 1.0, 2);
154  glVertex2f(-1.0, -2);
155  glVertex2f(1.0, -2);
156  glVertex2f(1.0, 2);
157  glEnd();
158  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
159  }
160 
161  // position indicator
162  if (width * exaggeration > 1) {
163  glRotated(90, 0, 0, -1);
164  glColor3d(1, 1, 1);
165  glBegin(GL_LINES);
166  glVertex2d(0, 1.7);
167  glVertex2d(0, -1.7);
168  glEnd();
169  }
170  glPopMatrix();
171  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
172  glPopName();
173 }
174 
175 
178  return myDetector;
179 }
180 
181 
182 /****************************************************************************/
183 
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:101
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:67
double x() const
Returns the x-position.
Definition: Position.h:62
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:167
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:439
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:74
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:47
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.
double myPosition
The position on the lane.
A single mesoscopic segment (cell)
Definition: MESegment.h:56
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition: MSLane.h:461
GUIGlID getGlID() const
Returns the numerical id of the object.
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:85
virtual GUIDetectorWrapper * buildDetectorGUIRepresentation()
Returns this detector&#39;s visualisation-wrapper.
void mkItem(const char *name, bool dynamic, ValueSource< unsigned > *src)
Adds a row which obtains its value from an unsigned-ValueSource.
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:270
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
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:54
MESegment *const mySegment
mesoscopic edge segment the loop lies on
Definition: MEInductLoop.h:98
GUIMEInductLoop & myDetector
The wrapped detector.