SUMO - Simulation of Urban MObility
MSFCDExport.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2012-2018 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 /****************************************************************************/
18 // Realises dumping Floating Car Data (FCD) Data
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
30 #include <utils/geom/GeomHelper.h>
32 #include <microsim/MSEdgeControl.h>
33 #include <microsim/MSEdge.h>
34 #include <microsim/MSLane.h>
35 #include <microsim/MSGlobals.h>
36 #include "MSFCDExport.h"
37 #include <microsim/MSNet.h>
38 #include <microsim/MSVehicle.h>
41 #include <microsim/MSContainer.h>
43 
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
48 void
49 MSFCDExport::write(OutputDevice& of, SUMOTime timestep, bool elevation) {
50  const bool useGeo = OptionsCont::getOptions().getBool("fcd-output.geo");
51  const bool signals = OptionsCont::getOptions().getBool("fcd-output.signals");
52  const SUMOTime period = string2time(OptionsCont::getOptions().getString("device.fcd.period"));
53  if (period > 0 && timestep % period != 0) {
54  return;
55  }
56  of.openTag("timestep").writeAttr(SUMO_ATTR_TIME, time2string(timestep));
58  const bool filter = MSDevice_FCD::getEdgeFilter().size() > 0;
59  for (MSVehicleControl::constVehIt it = vc.loadedVehBegin(); it != vc.loadedVehEnd(); ++it) {
60  const SUMOVehicle* veh = it->second;
61  const MSVehicle* microVeh = dynamic_cast<const MSVehicle*>(veh);
62  if ((veh->isOnRoad() || veh->isParking() || veh->isRemoteControlled())
63  && veh->getDevice(typeid(MSDevice_FCD)) != nullptr
64  // only filter on normal edges
65  && (!filter || MSDevice_FCD::getEdgeFilter().count(veh->getEdge()) > 0)) {
66  Position pos = veh->getPosition();
67  if (useGeo) {
70  }
72  of.writeAttr(SUMO_ATTR_ID, veh->getID());
73  of.writeAttr(SUMO_ATTR_X, pos.x());
74  of.writeAttr(SUMO_ATTR_Y, pos.y());
75  if (elevation) {
76  of.writeAttr(SUMO_ATTR_Z, pos.z());
77  }
82  if (microVeh != nullptr) {
83  of.writeAttr(SUMO_ATTR_LANE, microVeh->getLane()->getID());
84  }
86  if (microVeh != nullptr && signals) {
87  of.writeAttr("signals", toString(microVeh->getSignals()));
88  }
89  of.closeTag();
90  // write persons and containers
91  const MSEdge* edge = microVeh == nullptr ? veh->getEdge() : &veh->getLane()->getEdge();
92 
93  const std::vector<MSTransportable*>& persons = veh->getPersons();
94  for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
95  writeTransportable(of, edge, *it_p, SUMO_TAG_PERSON, useGeo, elevation);
96  }
97  const std::vector<MSTransportable*>& containers = veh->getContainers();
98  for (std::vector<MSTransportable*>::const_iterator it_c = containers.begin(); it_c != containers.end(); ++it_c) {
99  writeTransportable(of, edge, *it_c, SUMO_TAG_CONTAINER, useGeo, elevation);
100  }
101  }
102  }
103  if (MSNet::getInstance()->getPersonControl().hasTransportables()) {
104  // write persons
106  const MSEdgeVector& edges = ec.getEdges();
107  for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
108  if (filter && MSDevice_FCD::getEdgeFilter().count(*e) == 0) {
109  continue;
110  }
111  const std::vector<MSTransportable*>& persons = (*e)->getSortedPersons(timestep);
112  for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
113  writeTransportable(of, *e, *it_p, SUMO_TAG_PERSON, useGeo, elevation);
114  }
115  }
116  }
117  if (MSNet::getInstance()->getContainerControl().hasTransportables()) {
118  // write containers
120  const std::vector<MSEdge*>& edges = ec.getEdges();
121  for (std::vector<MSEdge*>::const_iterator e = edges.begin(); e != edges.end(); ++e) {
122  if (filter && MSDevice_FCD::getEdgeFilter().count(*e) == 0) {
123  continue;
124  }
125  const std::vector<MSTransportable*>& containers = (*e)->getSortedContainers(timestep);
126  for (std::vector<MSTransportable*>::const_iterator it_c = containers.begin(); it_c != containers.end(); ++it_c) {
127  writeTransportable(of, *e, *it_c, SUMO_TAG_CONTAINER, useGeo, elevation);
128  }
129  }
130  }
131  of.closeTag();
132 }
133 
134 
135 void
136 MSFCDExport::writeTransportable(OutputDevice& of, const MSEdge* e, MSTransportable* p, SumoXMLTag tag, bool useGeo, bool elevation) {
137  if (!MSDevice::equippedByParameter(p, "fcd", true)) {
138  return;
139  }
140  Position pos = p->getPosition();
141  if (useGeo) {
144  }
145  of.openTag(tag);
146  of.writeAttr(SUMO_ATTR_ID, p->getID());
147  of.writeAttr(SUMO_ATTR_X, pos.x());
148  of.writeAttr(SUMO_ATTR_Y, pos.y());
149  if (elevation) {
150  of.writeAttr(SUMO_ATTR_Z, pos.z());
151  }
155  of.writeAttr(SUMO_ATTR_EDGE, e->getID());
156  of.writeAttr(SUMO_ATTR_SLOPE, e->getLanes()[0]->getShape().slopeDegreeAtOffset(p->getEdgePos()));
157  of.closeTag();
158 }
159 /****************************************************************************/
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
static const std::set< const MSEdge * > & getEdgeFilter()
Definition: MSDevice_FCD.h:84
SumoXMLTag
Numbers representing SUMO-XML - element names.
MSEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: MSLane.h:640
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79
long long int SUMOTime
Definition: SUMOTime.h:36
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
double z() const
Returns the z-position.
Definition: Position.h:67
virtual const std::vector< MSTransportable * > & getPersons() const =0
retrieve riding persons
virtual MSVehicleDevice * getDevice(const std::type_info &type) const =0
Returns a device of the given type if it exists or 0.
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:565
virtual double getEdgePos() const
Return the position on the edge.
double y() const
Returns the y-position.
Definition: Position.h:62
virtual const MSEdge * getEdge() const =0
Returns the edge the vehicle is currently at.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:65
double x() const
Returns the x-position.
Definition: Position.h:57
virtual MSLane * getLane() const =0
Returns the lane the vehicle is on.
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:162
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:165
virtual double getSlope() const =0
Returns the slope of the road at vehicle&#39;s position.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
int getSignals() const
Returns the signals.
Definition: MSVehicle.h:1246
const std::string & getID() const
Returns the id.
Definition: Named.h:78
static void writeTransportable(OutputDevice &of, const MSEdge *e, MSTransportable *p, SumoXMLTag tag, bool useGeo, bool elevation)
write transportable
virtual double getSpeed() const
the current speed of the transportable
virtual bool isParking() const =0
Returns the information whether the vehicle is parked.
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
static bool equippedByParameter(const MSTransportable *t, const std::string &deviceName, bool outputOptionSet)
Determines whether a transportable should get a certain device.
Definition: MSDevice.cpp:137
static void write(OutputDevice &of, SUMOTime timestep, bool elevation)
Writes the position and the angle of each vehicle into the given device.
Definition: MSFCDExport.cpp:49
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
A road/street connecting two junctions.
Definition: MSEdge.h:75
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:180
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
Representation of a vehicle.
Definition: SUMOVehicle.h:60
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
int gPrecisionGeo
Definition: StdDefs.cpp:28
virtual double getAngle() const
return the current angle of the transportable
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:316
Stores edges and lanes, performs moving of vehicle.
Definition: MSEdgeControl.h:67
virtual bool isRemoteControlled() const =0
Returns the information whether the vehicle is fully controlled via TraCI.
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:42
const std::string & getID() const
returns the id of the transportable
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
virtual const std::vector< MSTransportable * > & getContainers() const =0
retrieve riding containers
trigger: the time of the step
virtual double getAngle() const =0
Get the vehicle&#39;s angle.
virtual Position getPosition() const
Return the Network coordinate of the transportable.
virtual double getPositionOnLane() const =0
Get the vehicle&#39;s position along the lane.
A device which collects info on the vehicle trip (mainly on departure and arrival) ...
Definition: MSDevice_FCD.h:48
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:94
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
virtual Position getPosition(const double offset=0) const =0
Return current position (x/y, cartesian)
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
const MSEdgeVector & getEdges() const
Returns loaded edges.
description of a vehicle
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition: MSNet.h:359
The class responsible for building and deletion of vehicles.
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:71
virtual double getSpeed() const =0
Returns the vehicle&#39;s current speed.
virtual const std::string & getID() const =0
Get the vehicle&#39;s ID.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.