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-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 /****************************************************************************/
20 // Realises dumping Floating Car Data (FCD) Data
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
36 #include <utils/geom/GeomHelper.h>
37 #include <microsim/MSEdgeControl.h>
38 #include <microsim/MSEdge.h>
39 #include <microsim/MSLane.h>
40 #include <microsim/MSGlobals.h>
41 #include "MSFCDExport.h"
42 #include <microsim/MSNet.h>
43 #include <microsim/MSVehicle.h>
46 #include <microsim/MSContainer.h>
48 
49 
50 // ===========================================================================
51 // method definitions
52 // ===========================================================================
53 void
54 MSFCDExport::write(OutputDevice& of, SUMOTime timestep, bool elevation) {
55  const bool useGeo = OptionsCont::getOptions().getBool("fcd-output.geo");
56  const bool signals = OptionsCont::getOptions().getBool("fcd-output.signals");
57  of.openTag("timestep").writeAttr(SUMO_ATTR_TIME, time2string(timestep));
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  Position pos = veh->getPosition();
64  if (useGeo) {
67  }
69  of.writeAttr(SUMO_ATTR_ID, veh->getID());
70  of.writeAttr(SUMO_ATTR_X, pos.x());
71  of.writeAttr(SUMO_ATTR_Y, pos.y());
72  if (elevation) {
73  of.writeAttr(SUMO_ATTR_Z, pos.z());
74  }
79  if (microVeh != 0) {
80  of.writeAttr(SUMO_ATTR_LANE, microVeh->getLane()->getID());
81  }
83  if (microVeh != 0 && signals) {
84  of.writeAttr("signals", toString(microVeh->getSignals()));
85  }
86  of.closeTag();
87  if (microVeh != 0) {
88  // write persons and containers
89  const std::vector<MSTransportable*>& persons = microVeh->getPersons();
90  for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
91  writeTransportable(of, &microVeh->getLane()->getEdge(), *it_p, SUMO_TAG_PERSON, useGeo, elevation);
92  }
93  const std::vector<MSTransportable*>& containers = microVeh->getContainers();
94  for (std::vector<MSTransportable*>::const_iterator it_c = containers.begin(); it_c != containers.end(); ++it_c) {
95  writeTransportable(of, &microVeh->getLane()->getEdge(), *it_c, SUMO_TAG_CONTAINER, useGeo, elevation);
96  }
97  }
98  }
99  }
101  // write persons
103  const MSEdgeVector& edges = ec.getEdges();
104  for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
105  const std::vector<MSTransportable*>& persons = (*e)->getSortedPersons(timestep);
106  for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
107  writeTransportable(of, *e, *it_p, SUMO_TAG_PERSON, useGeo, elevation);
108  }
109  }
110  }
111  if (MSNet::getInstance()->getContainerControl().hasTransportables()) {
112  // write containers
114  const std::vector<MSEdge*>& edges = ec.getEdges();
115  for (std::vector<MSEdge*>::const_iterator e = edges.begin(); e != edges.end(); ++e) {
116  const std::vector<MSTransportable*>& containers = (*e)->getSortedContainers(timestep);
117  for (std::vector<MSTransportable*>::const_iterator it_c = containers.begin(); it_c != containers.end(); ++it_c) {
118  writeTransportable(of, *e, *it_c, SUMO_TAG_CONTAINER, useGeo, elevation);
119  }
120  }
121  }
122  of.closeTag();
123 }
124 
125 
126 void
127 MSFCDExport::writeTransportable(OutputDevice& of, const MSEdge* e, MSTransportable* p, SumoXMLTag tag, bool useGeo, bool elevation) {
128  Position pos = p->getPosition();
129  if (useGeo) {
132  }
133  of.openTag(tag);
134  of.writeAttr(SUMO_ATTR_ID, p->getID());
135  of.writeAttr(SUMO_ATTR_X, pos.x());
136  of.writeAttr(SUMO_ATTR_Y, pos.y());
137  if (elevation) {
138  of.writeAttr(SUMO_ATTR_Z, pos.z());
139  }
143  of.writeAttr(SUMO_ATTR_EDGE, e->getID());
144  of.writeAttr(SUMO_ATTR_SLOPE, e->getLanes()[0]->getShape().slopeDegreeAtOffset(p->getEdgePos()));
145  of.closeTag();
146 }
147 /****************************************************************************/
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:260
SumoXMLTag
Numbers representing SUMO-XML - element names.
MSEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: MSLane.h:607
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
double z() const
Returns the z-position.
Definition: Position.h:72
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:564
virtual double getEdgePos() const
Return the position on the edge.
double y() const
Returns the y-position.
Definition: Position.h:67
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:59
double x() const
Returns the x-position.
Definition: Position.h:62
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:167
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
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:1231
const std::string & getID() const
Returns the id.
Definition: Named.h:65
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:64
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:54
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:80
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:186
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
Representation of a vehicle.
Definition: SUMOVehicle.h:66
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:768
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
int gPrecisionGeo
Definition: StdDefs.cpp:30
virtual double getAngle() const
return the current angle of the transportable
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:306
Stores edges and lanes, performs moving of vehicle.
Definition: MSEdgeControl.h:73
virtual bool isRemoteControlled() const =0
Returns the information whether the vehicle is fully controlled via TraCI.
const std::string & getID() const
returns the id of the transportable
bool hasTransportables() const
checks whether any transportable waits to finish her plan
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
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.
const std::string & getID() const
Returns the name of the vehicle type.
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:70
bool closeTag()
Closes the most recently opened tag.
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition: MSNet.h:349
long long int SUMOTime
Definition: TraCIDefs.h:51
const std::vector< MSTransportable * > & getPersons() const
retrieve riding persons
Definition: MSVehicle.cpp:4227
The class responsible for building and deletion of vehicles.
const std::vector< MSTransportable * > & getContainers() const
retrieve riding containers
Definition: MSVehicle.cpp:4237
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:77
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.