SUMO - Simulation of Urban MObility
GUIMEInductLoop.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // The gui-version of the MEInductLoop
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 
35 #include <guisim/GUILane.h>
36 #include <utils/gui/div/GLHelper.h>
40 #include <mesosim/MEInductLoop.h>
41 #include <mesosim/MESegment.h>
42 #include "GUIMEInductLoop.h"
43 
44 #ifdef CHECK_MEMORY_LEAKS
45 #include <foreign/nvwa/debug_new.h>
46 #endif // CHECK_MEMORY_LEAKS
47 
48 
49 // ===========================================================================
50 // method definitions
51 // ===========================================================================
52 /* -------------------------------------------------------------------------
53  * GUIMEInductLoop-methods
54  * ----------------------------------------------------------------------- */
55 GUIMEInductLoop::GUIMEInductLoop(const std::string& id, MESegment* s,
56  SUMOReal position, const std::string& vTypes)
57  : MEInductLoop(id, s, position, vTypes) {}
58 
59 
61 
62 
65  return new MyWrapper(*this, myPosition);
66 }
67 
68 
69 /* -------------------------------------------------------------------------
70  * GUIMEInductLoop::MyWrapper-methods
71  * ----------------------------------------------------------------------- */
73  : GUIDetectorWrapper("induct loop", detector.getID()),
74  myDetector(detector), myPosition(pos) {
75  const MSLane* lane = detector.mySegment->getEdge().getLanes()[0];
80 }
81 
82 
84 
85 
89  b.grow(20);
90  return b;
91 }
92 
93 
94 
97  GUISUMOAbstractView& /* parent */) {
99  new GUIParameterTableWindow(app, *this, 2);
100  // add items
101  /*
102  ret->mkItem("flow [veh/h]", true,
103  new FuncBinding_IntParam<GUIMEInductLoop, SUMOReal>(
104  &(getLoop()), &GUIMEInductLoop::getFlow, 1));
105  ret->mkItem("mean speed [m/s]", true,
106  new FuncBinding_IntParam<GUIMEInductLoop, SUMOReal>(
107  &(getLoop()), &GUIMEInductLoop::getMeanSpeed, 1));
108  ret->mkItem("occupancy [%]", true,
109  new FuncBinding_IntParam<GUIMEInductLoop, SUMOReal>(
110  &(getLoop()), &GUIMEInductLoop::getOccupancy, 1));
111  ret->mkItem("mean vehicle length [m]", true,
112  new FuncBinding_IntParam<GUIMEInductLoop, SUMOReal>(
113  &(getLoop()), &GUIMEInductLoop::getMeanVehicleLength, 1));
114  ret->mkItem("empty time [s]", true,
115  new FunctionBinding<GUIMEInductLoop, SUMOReal>(
116  &(getLoop()), &GUIMEInductLoop::getTimestepsSinceLastDetection));
117  */
118  //
119  ret->mkItem("position [m]", false, myPosition);
120  ret->mkItem("lane", false, myDetector.mySegment->getID());
121  // close building
122  ret->closeBuilding();
123  return ret;
124 }
125 
126 
127 void
129  glPushName(getGlID());
130  glPolygonOffset(0, -2);
131  SUMOReal width = (SUMOReal) 2.0 * s.scale;
132  glLineWidth(1.0);
133  const SUMOReal exaggeration = s.addSize.getExaggeration(s);
134  // shape
135  glColor3d(1, 1, 0);
136  glPushMatrix();
137  glTranslated(myFGPosition.x(), myFGPosition.y(), getType());
138  glRotated(myFGRotation, 0, 0, 1);
139  glScaled(exaggeration, exaggeration, exaggeration);
140  glBegin(GL_QUADS);
141  glVertex2d(0 - 1.0, 2);
142  glVertex2d(-1.0, -2);
143  glVertex2d(1.0, -2);
144  glVertex2d(1.0, 2);
145  glEnd();
146  glBegin(GL_LINES);
147  // without the substracted offsets, lines are partially longer
148  // than the boxes
149  glVertex2d(0, 2 - .1);
150  glVertex2d(0, -2 + .1);
151  glEnd();
152 
153  // outline
154  if (width * exaggeration > 1) {
155  glColor3d(1, 1, 1);
156  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
157  glBegin(GL_QUADS);
158  glVertex2f(0 - 1.0, 2);
159  glVertex2f(-1.0, -2);
160  glVertex2f(1.0, -2);
161  glVertex2f(1.0, 2);
162  glEnd();
163  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
164  }
165 
166  // position indicator
167  if (width * exaggeration > 1) {
168  glRotated(90, 0, 0, -1);
169  glColor3d(1, 1, 1);
170  glBegin(GL_LINES);
171  glVertex2d(0, 1.7);
172  glVertex2d(0, -1.7);
173  glEnd();
174  }
175  glPopMatrix();
176  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
177  glPopName();
178 }
179 
180 
183  return myDetector;
184 }
185 
186 
187 /****************************************************************************/
188 
void drawName(const Position &pos, const SUMOReal scale, const GUIVisualizationTextSettings &settings, const SUMOReal angle=0) const
draw name of item
Position myFGPosition
The position in full-geometry mode.
MyWrapper(GUIMEInductLoop &detector, SUMOReal pos)
Constructor.
GUIVisualizationTextSettings addName
const SUMOReal myPosition
position from the start of the edge / lane
Definition: MEInductLoop.h:102
~GUIMEInductLoop()
Destructor.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Stores the information about how to visualize structures.
SUMOReal myFGRotation
The rotation in full-geometry mode.
SUMOReal myPosition
The position on the lane.
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:192
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:427
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:66
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
SUMOReal scale
information about a lane&#39;s width (temporary, used for a single view)
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.
SUMOReal rotationDegreeAtOffset(SUMOReal pos) const
Returns the rotation at the given length.
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
GUIMEInductLoop(const std::string &id, MESegment *s, SUMOReal position, const std::string &vTypes)
Construtor.
Boundary & grow(SUMOReal by)
extends the boundary by the given amount
Definition: Boundary.cpp:232
void add(SUMOReal x, SUMOReal y, SUMOReal z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:90
A single mesoscopic segment (cell)
Definition: MESegment.h:57
GUIGlID getGlID() const
Returns the numerical id of the object.
#define SUMOReal
Definition: config.h:213
SUMOReal getExaggeration(const GUIVisualizationSettings &s, SUMOReal factor=20) const
return the drawing size including exaggeration and constantSize values
virtual GUIDetectorWrapper * buildDetectorGUIRepresentation()
Returns this detector&#39;s visualisation-wrapper.
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
void mkItem(const char *name, bool dynamic, ValueSource< unsigned > *src)
Adds a row which obtains its value from an unsigned-ValueSource.
void closeBuilding()
Closes the building of the table.
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:272
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
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:55
const Position geometryPositionAtOffset(SUMOReal offset, SUMOReal lateralOffset=0) const
Definition: MSLane.h:444
MESegment *const mySegment
mesoscopic edge segment the loop lies on
Definition: MEInductLoop.h:99
GUIMEInductLoop & myDetector
The wrapped detector.