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-2022 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  int detectPersons,
45  bool /*show*/):
46  MEInductLoop(id, s, position, vTypes, detectPersons)
47 {}
48 
49 
51 
52 
55  return new MyWrapper(*this, myPosition);
56 }
57 
58 // -----------------------------------------------------------------------
59 // GUIMEInductLoop::MyWrapper-methods
60 // -----------------------------------------------------------------------
61 
63  : GUIDetectorWrapper(GLO_E1DETECTOR_ME, detector.getID()),
64  myDetector(detector), myPosition(pos) {
65  const MSLane* lane = detector.mySegment->getEdge().getLanes()[0];
67  myBoundary.add(myFGPosition.x() + (double) 5.5, myFGPosition.y() + (double) 5.5);
68  myBoundary.add(myFGPosition.x() - (double) 5.5, myFGPosition.y() - (double) 5.5);
70 }
71 
72 
74 
75 
76 double
78  return s.addSize.getExaggeration(s, this);
79 }
80 
81 
84  Boundary b(myBoundary);
85  b.grow(20);
86  return b;
87 }
88 
89 
90 
93  GUISUMOAbstractView& /* parent */) {
94  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
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  GLHelper::pushName(getGlID());
125  glPolygonOffset(0, -2);
126  double width = (double) 2.0 * s.scale;
127  glLineWidth(1.0);
128  const double exaggeration = getExaggeration(s);
129  // shape
130  glColor3d(1, 1, 0);
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  glVertex2d(0 - 1.0, 2);
154  glVertex2d(-1.0, -2);
155  glVertex2d(1.0, -2);
156  glVertex2d(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  }
171  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
173 }
174 
175 
178  return myDetector;
179 }
180 
181 
182 /****************************************************************************/
@ 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
static void pushName(unsigned int name)
push Name
Definition: GLHelper.cpp:132
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:123
static void popName()
pop Name
Definition: GLHelper.cpp:141
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:114
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration asociated with this GLObject
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, int detectPersons, bool show)
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:90
const double myPosition
position from the start of the edge / lane
Definition: MEInductLoop.h:93
A single mesoscopic segment (cell)
Definition: MESegment.h:49
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:352
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:168
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
const PositionVector & getShape() const
Returns this lane's shape.
Definition: MSLane.h:478
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition: MSLane.h:505
double x() const
Returns the x-position.
Definition: Position.h:55
double y() const
Returns the y-position.
Definition: Position.h:60
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