SUMO - Simulation of Urban MObility
MSFCDExport.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // Realises dumping Floating Car Data (FCD) Data
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2012-2017 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
37 #include <utils/geom/GeomHelper.h>
38 #include <microsim/MSEdgeControl.h>
39 #include <microsim/MSEdge.h>
40 #include <microsim/MSLane.h>
41 #include <microsim/MSGlobals.h>
42 #include "MSFCDExport.h"
43 #include <microsim/MSNet.h>
44 #include <microsim/MSVehicle.h>
47 #include <microsim/MSContainer.h>
49 
50 
51 // ===========================================================================
52 // method definitions
53 // ===========================================================================
54 void
55 MSFCDExport::write(OutputDevice& of, SUMOTime timestep, bool elevation) {
56  const bool useGeo = OptionsCont::getOptions().getBool("fcd-output.geo");
57  const bool signals = OptionsCont::getOptions().getBool("fcd-output.signals");
58  of.openTag("timestep").writeAttr(SUMO_ATTR_TIME, time2string(timestep));
60  for (MSVehicleControl::constVehIt it = vc.loadedVehBegin(); it != vc.loadedVehEnd(); ++it) {
61  const SUMOVehicle* veh = it->second;
62  const MSVehicle* microVeh = dynamic_cast<const MSVehicle*>(veh);
63  if (veh->isOnRoad() || veh->isParking() || veh->isRemoteControlled()) {
64  Position pos = veh->getPosition();
65  if (useGeo) {
68  }
70  of.writeAttr(SUMO_ATTR_ID, veh->getID());
71  of.writeAttr(SUMO_ATTR_X, pos.x());
72  of.writeAttr(SUMO_ATTR_Y, pos.y());
73  if (elevation) {
74  of.writeAttr(SUMO_ATTR_Z, pos.z());
75  }
80  if (microVeh != 0) {
81  of.writeAttr(SUMO_ATTR_LANE, microVeh->getLane()->getID());
82  }
84  if (microVeh != 0 && signals) {
85  of.writeAttr("signals", toString(microVeh->getSignals()));
86  }
87  of.closeTag();
88  if (microVeh != 0) {
89  // write persons and containers
90  const std::vector<MSTransportable*>& persons = microVeh->getPersons();
91  for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
92  writeTransportable(of, &microVeh->getLane()->getEdge(), *it_p, SUMO_TAG_PERSON, useGeo, elevation);
93  }
94  const std::vector<MSTransportable*>& containers = microVeh->getContainers();
95  for (std::vector<MSTransportable*>::const_iterator it_c = containers.begin(); it_c != containers.end(); ++it_c) {
96  writeTransportable(of, &microVeh->getLane()->getEdge(), *it_c, SUMO_TAG_CONTAINER, useGeo, elevation);
97  }
98  }
99  }
100  }
102  // write persons
104  const MSEdgeVector& edges = ec.getEdges();
105  for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
106  const std::vector<MSTransportable*>& persons = (*e)->getSortedPersons(timestep);
107  for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
108  writeTransportable(of, *e, *it_p, SUMO_TAG_PERSON, useGeo, elevation);
109  }
110  }
111  }
112  if (MSNet::getInstance()->getContainerControl().hasTransportables()) {
113  // write containers
115  const std::vector<MSEdge*>& edges = ec.getEdges();
116  for (std::vector<MSEdge*>::const_iterator e = edges.begin(); e != edges.end(); ++e) {
117  const std::vector<MSTransportable*>& containers = (*e)->getSortedContainers(timestep);
118  for (std::vector<MSTransportable*>::const_iterator it_c = containers.begin(); it_c != containers.end(); ++it_c) {
119  writeTransportable(of, *e, *it_c, SUMO_TAG_CONTAINER, useGeo, elevation);
120  }
121  }
122  }
123  of.closeTag();
124 }
125 
126 
127 void
128 MSFCDExport::writeTransportable(OutputDevice& of, const MSEdge* e, MSTransportable* p, SumoXMLTag tag, bool useGeo, bool elevation) {
129  Position pos = p->getPosition();
130  if (useGeo) {
133  }
134  of.openTag(tag);
135  of.writeAttr(SUMO_ATTR_ID, p->getID());
136  of.writeAttr(SUMO_ATTR_X, pos.x());
137  of.writeAttr(SUMO_ATTR_Y, pos.y());
138  if (elevation) {
139  of.writeAttr(SUMO_ATTR_Z, pos.z());
140  }
144  of.writeAttr(SUMO_ATTR_EDGE, e->getID());
145  of.writeAttr(SUMO_ATTR_SLOPE, e->getLanes()[0]->getShape().slopeDegreeAtOffset(p->getEdgePos()));
146  of.closeTag();
147 }
148 /****************************************************************************/
virtual double getAngle() const =0
Get the vehicle&#39;s angle.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:261
double z() const
Returns the z-position.
Definition: Position.h:73
SumoXMLTag
Numbers representing SUMO-XML - element names.
MSEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: MSLane.h:582
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
virtual double getAngle() const
return the current angle of the transportable
virtual double getEdgePos() const
Return the position on the edge.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
virtual bool isRemoteControlled() const =0
Returns the information whether the vehicle is fully controlled via TraCI.
virtual double getSlope() const =0
Returns the slope of the road at vehicle&#39;s position.
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:168
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
double x() const
Returns the x-position.
Definition: Position.h:63
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:60
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:169
virtual double getPositionOnLane() const =0
Get the vehicle&#39;s position along the lane.
const std::string & getID() const
returns the id of the transportable
static void writeTransportable(OutputDevice &of, const MSEdge *e, MSTransportable *p, SumoXMLTag tag, bool useGeo, bool elevation)
write transportable
virtual Position getPosition(const double offset=0) const =0
Return current position (x/y, cartesian)
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:65
virtual double getSpeed() const
the current speed of the transportable
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:55
const std::string & getID() const
Returns the id.
Definition: Named.h:66
A road/street connecting two junctions.
Definition: MSEdge.h:81
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:187
virtual double getSpeed() const =0
Returns the vehicle&#39;s current speed.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
Representation of a vehicle.
Definition: SUMOVehicle.h:67
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:767
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
int gPrecisionGeo
Definition: StdDefs.cpp:31
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:305
double y() const
Returns the y-position.
Definition: Position.h:68
Stores edges and lanes, performs moving of vehicle.
Definition: MSEdgeControl.h:74
const std::vector< MSTransportable * > & getContainers() const
retrieve riding containers
Definition: MSVehicle.cpp:3724
virtual bool isParking() const =0
Returns the information whether the vehicle is parked.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.
const std::vector< MSTransportable * > & getPersons() const
retrieve riding persons
Definition: MSVehicle.cpp:3714
trigger: the time of the step
bool hasTransportables() const
checks whether any transportable waits to finish her plan
const std::string & getID() const
Returns the name of the vehicle type.
virtual const std::string & getID() const =0
Get the vehicle&#39;s ID.
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
virtual Position getPosition() const
Return the Network coordinate of the transportable.
description of a vehicle
int getSignals() const
Returns the signals.
Definition: MSVehicle.h:1147
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
bool closeTag()
Closes the most recently opened tag.
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition: MSNet.h:348
long long int SUMOTime
Definition: TraCIDefs.h:52
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
The class responsible for building and deletion of vehicles.
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:78
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:499
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
const MSEdgeVector & getEdges() const
Returns loaded edges.