Eclipse 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-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 /****************************************************************************/
17 // Realises dumping Floating Car Data (FCD) Data
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
29 #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 <microsim/MSNet.h>
37 #include <microsim/MSVehicle.h>
40 #include <microsim/MSContainer.h>
42 #include "MSFCDExport.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 bool writeDistance = OptionsCont::getOptions().getBool("fcd-output.distance");
53  const SUMOTime period = string2time(OptionsCont::getOptions().getString("device.fcd.period"));
54  const SUMOTime begin = string2time(OptionsCont::getOptions().getString("begin"));
55  if (period > 0 && (timestep - begin) % period != 0) {
56  return;
57  }
58  of.openTag("timestep").writeAttr(SUMO_ATTR_TIME, time2string(timestep));
60  const bool filter = MSDevice_FCD::getEdgeFilter().size() > 0;
61  for (MSVehicleControl::constVehIt it = vc.loadedVehBegin(); it != vc.loadedVehEnd(); ++it) {
62  const SUMOVehicle* veh = it->second;
63  const MSVehicle* microVeh = dynamic_cast<const MSVehicle*>(veh);
64  if ((veh->isOnRoad() || veh->isParking() || veh->isRemoteControlled())
65  && veh->getDevice(typeid(MSDevice_FCD)) != nullptr
66  // only filter on normal edges
67  && (!filter || MSDevice_FCD::getEdgeFilter().count(veh->getEdge()) > 0)) {
68  Position pos = veh->getPosition();
69  if (useGeo) {
72  }
74  of.writeAttr(SUMO_ATTR_ID, veh->getID());
75  of.writeAttr(SUMO_ATTR_X, pos.x());
76  of.writeAttr(SUMO_ATTR_Y, pos.y());
77  if (elevation) {
78  of.writeAttr(SUMO_ATTR_Z, pos.z());
79  }
84  if (microVeh != nullptr) {
85  of.writeAttr(SUMO_ATTR_LANE, microVeh->getLane()->getID());
86  }
88  if (microVeh != nullptr) {
89  if (signals) {
90  of.writeAttr("signals", toString(microVeh->getSignals()));
91  }
92  if (writeDistance) {
93  double distance = microVeh->getEdge()->getDistance();
94  if (microVeh->getLane()->isInternal()) {
95  distance += microVeh->getRoute().getDistanceBetween(0, microVeh->getPositionOnLane(),
96  microVeh->getEdge(), &microVeh->getLane()->getEdge(), true, microVeh->getRoutePosition());
97  } else {
98  distance += microVeh->getPositionOnLane();
99  }
100  // if the kilometrage runs counter to the edge direction edge->getDistance() is negative
101  of.writeAttr("distance", fabs(distance));
102  }
103  }
104  of.closeTag();
105  // write persons and containers
106  const MSEdge* edge = microVeh == nullptr ? veh->getEdge() : &veh->getLane()->getEdge();
107 
108  const std::vector<MSTransportable*>& persons = veh->getPersons();
109  for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
110  writeTransportable(of, edge, *it_p, SUMO_TAG_PERSON, useGeo, elevation);
111  }
112  const std::vector<MSTransportable*>& containers = veh->getContainers();
113  for (std::vector<MSTransportable*>::const_iterator it_c = containers.begin(); it_c != containers.end(); ++it_c) {
114  writeTransportable(of, edge, *it_c, SUMO_TAG_CONTAINER, useGeo, elevation);
115  }
116  }
117  }
118  if (MSNet::getInstance()->getPersonControl().hasTransportables()) {
119  // write persons
121  const MSEdgeVector& edges = ec.getEdges();
122  for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
123  if (filter && MSDevice_FCD::getEdgeFilter().count(*e) == 0) {
124  continue;
125  }
126  const std::vector<MSTransportable*>& persons = (*e)->getSortedPersons(timestep);
127  for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
128  writeTransportable(of, *e, *it_p, SUMO_TAG_PERSON, useGeo, elevation);
129  }
130  }
131  }
132  if (MSNet::getInstance()->getContainerControl().hasTransportables()) {
133  // write containers
135  const std::vector<MSEdge*>& edges = ec.getEdges();
136  for (std::vector<MSEdge*>::const_iterator e = edges.begin(); e != edges.end(); ++e) {
137  if (filter && MSDevice_FCD::getEdgeFilter().count(*e) == 0) {
138  continue;
139  }
140  const std::vector<MSTransportable*>& containers = (*e)->getSortedContainers(timestep);
141  for (std::vector<MSTransportable*>::const_iterator it_c = containers.begin(); it_c != containers.end(); ++it_c) {
142  writeTransportable(of, *e, *it_c, SUMO_TAG_CONTAINER, useGeo, elevation);
143  }
144  }
145  }
146  of.closeTag();
147 }
148 
149 
150 void
151 MSFCDExport::writeTransportable(OutputDevice& of, const MSEdge* e, MSTransportable* p, SumoXMLTag tag, bool useGeo, bool elevation) {
152  if (p->getDevice(typeid(MSTransportableDevice_FCD)) == nullptr) {
153  return;
154  }
155  Position pos = p->getPosition();
156  if (useGeo) {
159  }
160  of.openTag(tag);
161  of.writeAttr(SUMO_ATTR_ID, p->getID());
162  of.writeAttr(SUMO_ATTR_X, pos.x());
163  of.writeAttr(SUMO_ATTR_Y, pos.y());
164  if (elevation) {
165  of.writeAttr(SUMO_ATTR_Z, pos.z());
166  }
170  of.writeAttr(SUMO_ATTR_EDGE, e->getID());
171  of.writeAttr(SUMO_ATTR_SLOPE, e->getLanes()[0]->getShape().slopeDegreeAtOffset(p->getEdgePos()));
172  of.closeTag();
173 }
174 
175 
176 /****************************************************************************/
SUMO_ATTR_TYPE
Definition: SUMOXMLDefinitions.h:381
SUMO_ATTR_ANGLE
Definition: SUMOXMLDefinitions.h:794
SUMOTrafficObject::getPosition
virtual Position getPosition(const double offset=0) const =0
Return current position (x/y, cartesian)
MSVehicleType::getID
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:93
SUMOVehicle::getContainers
virtual const std::vector< MSTransportable * > & getContainers() const =0
retrieve riding containers
SUMOVehicle::getAngle
virtual double getAngle() const =0
Get the vehicle's angle.
MSNet.h
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
MSDevice_FCD::getEdgeFilter
static const std::set< const MSEdge * > & getEdgeFilter()
Definition: MSDevice_FCD.h:84
Position::z
double z() const
Returns the z-position.
Definition: Position.h:66
OptionsCont.h
SUMOTrafficObject::getEdge
virtual const MSEdge * getEdge() const =0
Returns the edge the vehicle is currently at.
SUMOTrafficObject::getVehicleType
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.
SUMOTrafficObject::getID
virtual const std::string & getID() const =0
Get the vehicle's ID.
SUMOVehicle::isRemoteControlled
virtual bool isRemoteControlled() const =0
Returns the information whether the vehicle is fully controlled via TraCI.
SUMO_ATTR_Z
Definition: SUMOXMLDefinitions.h:400
OutputDevice::setPrecision
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
Definition: OutputDevice.cpp:221
SUMO_TAG_PERSON
Definition: SUMOXMLDefinitions.h:295
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
SUMOVehicle
Representation of a vehicle.
Definition: SUMOVehicle.h:60
SUMO_ATTR_EDGE
Definition: SUMOXMLDefinitions.h:423
GeomHelper::naviDegree
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:193
MSBaseVehicle::getRoute
const MSRoute & getRoute() const
Returns the current route.
Definition: MSBaseVehicle.h:115
GeoConvHelper.h
SUMOVehicle::isOnRoad
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
OptionsCont::getBool
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
Definition: OptionsCont.cpp:222
MSFCDExport::write
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
OptionsCont::getOptions
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:57
MSDevice_FCD
A device which collects info on the vehicle trip (mainly on departure and arrival)
Definition: MSDevice_FCD.h:48
MSBaseVehicle::getRoutePosition
int getRoutePosition() const
return index of edge within route
Definition: MSBaseVehicle.cpp:391
SUMO_ATTR_SPEED
Definition: SUMOXMLDefinitions.h:384
SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:378
MSEdge.h
SUMO_ATTR_LANE
Definition: SUMOXMLDefinitions.h:637
MSTransportable
Definition: MSTransportable.h:58
SUMO_TAG_CONTAINER
Definition: SUMOXMLDefinitions.h:316
SumoXMLTag
SumoXMLTag
Numbers representing SUMO-XML - element names.
Definition: SUMOXMLDefinitions.h:41
MSVehicleControl::constVehIt
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
Definition: MSVehicleControl.h:74
gPrecisionGeo
int gPrecisionGeo
Definition: StdDefs.cpp:27
MSFCDExport.h
MSVehicle.h
OutputDevice::closeTag
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
Definition: OutputDevice.cpp:253
MSTransportable::getDevice
MSTransportableDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists or 0.
Definition: MSTransportable.cpp:907
MSBaseVehicle::getEdge
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
Definition: MSBaseVehicle.cpp:181
MSFCDExport::writeTransportable
static void writeTransportable(OutputDevice &of, const MSEdge *e, MSTransportable *p, SumoXMLTag tag, bool useGeo, bool elevation)
write transportable
Definition: MSFCDExport.cpp:151
SUMOVehicle::getPersons
virtual const std::vector< MSTransportable * > & getPersons() const =0
retrieve riding persons
OutputDevice::writeAttr
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:255
MSVehicle::getPositionOnLane
double getPositionOnLane() const
Get the vehicle's position along the lane.
Definition: MSVehicle.h:392
GeoConvHelper::getFinal
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
Definition: GeoConvHelper.h:105
MSTransportableControl.h
MSEdge::getDistance
double getDistance() const
Returns the kilometrage/mileage at the start of the edge.
Definition: MSEdge.h:290
MSVehicleControl::loadedVehEnd
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
Definition: MSVehicleControl.h:185
SUMOVehicle::getDevice
virtual MSVehicleDevice * getDevice(const std::type_info &type) const =0
Returns a device of the given type if it exists or 0.
SUMOVehicle::getLane
virtual MSLane * getLane() const =0
Returns the lane the vehicle is on.
OutputDevice.h
SUMOTrafficObject::getSlope
virtual double getSlope() const =0
Returns the slope of the road at vehicle's position.
GeoConvHelper::cartesian2geo
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
Definition: GeoConvHelper.cpp:293
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
Position::x
double x() const
Returns the x-position.
Definition: Position.h:56
time2string
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:67
MSGlobals.h
SUMO_ATTR_Y
Definition: SUMOXMLDefinitions.h:399
MSVehicle::getSignals
int getSignals() const
Returns the signals.
Definition: MSVehicle.h:1252
MSEdge
A road/street connecting two junctions.
Definition: MSEdge.h:78
MSTransportable::getPosition
Position getPosition(const double) const
Return current position (x/y, cartesian)
Definition: MSTransportable.h:581
MSContainer.h
SUMO_TAG_VEHICLE
description of a vehicle
Definition: SUMOXMLDefinitions.h:119
SUMO_ATTR_TIME
trigger: the time of the step
Definition: SUMOXMLDefinitions.h:676
string2time
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:44
SUMO_ATTR_POSITION
Definition: SUMOXMLDefinitions.h:660
MSTransportable::getEdgePos
virtual double getEdgePos() const
Return the position on the edge.
Definition: MSTransportable.cpp:714
MSPerson.h
MSVehicle::getLane
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:560
MSTransportableDevice_FCD
A device which collects info on the vehicle trip (mainly on departure and arrival)
Definition: MSTransportableDevice_FCD.h:47
MSLane::getEdge
MSEdge & getEdge() const
Returns the lane's edge.
Definition: MSLane.h:669
MSEdgeControl.h
OutputDevice::openTag
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Definition: OutputDevice.cpp:239
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
Position::y
double y() const
Returns the y-position.
Definition: Position.h:61
MSTransportable::getSpeed
virtual double getSpeed() const
the current speed of the transportable
Definition: MSTransportable.cpp:734
MSEdgeVector
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:74
MSTransportable::getID
const std::string & getID() const
returns the id of the transportable
Definition: MSTransportable.cpp:699
MSEdge::getLanes
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:167
config.h
MSVehicleControl
The class responsible for building and deletion of vehicles.
Definition: MSVehicleControl.h:71
MSEdgeControl
Stores edges and lanes, performs moving of vehicle.
Definition: MSEdgeControl.h:74
MSLane::isInternal
bool isInternal() const
Definition: MSLane.cpp:2010
GeomHelper.h
MSDevice_FCD.h
MSVehicleControl::loadedVehBegin
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
Definition: MSVehicleControl.h:177
MSLane.h
SUMOTrafficObject::getPositionOnLane
virtual double getPositionOnLane() const =0
Get the vehicle's position along the lane.
MSTransportableDevice_FCD.h
MSNet::getEdgeControl
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition: MSNet.h:379
MSRoute::getDistanceBetween
double getDistanceBetween(double fromPos, double toPos, const MSEdge *fromEdge, const MSEdge *toEdge, bool includeInternal=true, int routePosition=0) const
Compute the distance between 2 given edges on this route, including the length of internal lanes....
Definition: MSRoute.cpp:278
MSVehicleControl.h
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:76
MSTransportable::getAngle
virtual double getAngle() const
return the current angle of the transportable
Definition: MSTransportable.cpp:724
SUMO_ATTR_X
Definition: SUMOXMLDefinitions.h:398
SUMO_ATTR_SLOPE
Definition: SUMOXMLDefinitions.h:875
MSNet::getVehicleControl
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:336
MSEdgeControl::getEdges
const MSEdgeVector & getEdges() const
Returns loaded edges.
Definition: MSEdgeControl.h:169
SUMOVehicle::isParking
virtual bool isParking() const =0
Returns the information whether the vehicle is parked.
SUMOTrafficObject::getSpeed
virtual double getSpeed() const =0
Returns the vehicle's current speed.
MSVehicle
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79