SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-2015 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 <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 #ifdef CHECK_MEMORY_LEAKS
49 #include <foreign/nvwa/debug_new.h>
50 #endif // CHECK_MEMORY_LEAKS
51 
52 
53 // ===========================================================================
54 // method definitions
55 // ===========================================================================
56 void
57 MSFCDExport::write(OutputDevice& of, SUMOTime timestep, bool elevation) {
58  const bool useGeo = OptionsCont::getOptions().getBool("fcd-output.geo");
59  const bool signals = OptionsCont::getOptions().getBool("fcd-output.signals");
60  of.openTag("timestep").writeAttr(SUMO_ATTR_TIME, time2string(timestep));
62  for (MSVehicleControl::constVehIt it = vc.loadedVehBegin(); it != vc.loadedVehEnd(); ++it) {
63  const SUMOVehicle* veh = it->second;
64  const MSVehicle* microVeh = dynamic_cast<const MSVehicle*>(veh);
65  if (veh->isOnRoad()) {
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 != 0) {
83  of.writeAttr(SUMO_ATTR_LANE, microVeh->getLane()->getID());
84  }
86  if (microVeh != 0 && signals) {
87  of.writeAttr("signals", toString(microVeh->getSignals()));
88  }
89  of.closeTag();
90  }
91  }
92  if (MSNet::getInstance()->getPersonControl().hasPersons()) {
93  // write persons
95  const MSEdgeVector& edges = ec.getEdges();
96  for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
97  const std::vector<MSTransportable*>& persons = (*e)->getSortedPersons(timestep);
98  for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
99  MSTransportable* p = *it_p;
100  Position pos = p->getPosition();
101  if (useGeo) {
104  }
106  of.writeAttr(SUMO_ATTR_ID, p->getID());
107  of.writeAttr(SUMO_ATTR_X, pos.x());
108  of.writeAttr(SUMO_ATTR_Y, pos.y());
109  if (elevation) {
110  of.writeAttr(SUMO_ATTR_Z, pos.z());
111  }
115  of.writeAttr(SUMO_ATTR_EDGE, (*e)->getID());
116  of.writeAttr(SUMO_ATTR_SLOPE, (*e)->getLanes()[0]->getShape().slopeDegreeAtOffset(p->getEdgePos()));
117  of.closeTag();
118  }
119  }
120  }
121  if (MSNet::getInstance()->getContainerControl().hasContainers()) {
122  // write containers
124  const std::vector<MSEdge*>& edges = ec.getEdges();
125  for (std::vector<MSEdge*>::const_iterator e = edges.begin(); e != edges.end(); ++e) {
126  const std::vector<MSTransportable*>& containers = (*e)->getSortedContainers(timestep);
127  for (std::vector<MSTransportable*>::const_iterator it_c = containers.begin(); it_c != containers.end(); ++it_c) {
128  MSTransportable* c = *it_c;
129  Position pos = c->getPosition();
130  if (useGeo) {
133  }
135  of.writeAttr(SUMO_ATTR_ID, c->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(c->getEdgePos()));
146  of.closeTag();
147  }
148  }
149  }
150  of.closeTag();
151 }
152 
153 /****************************************************************************/
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:257
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
#define GEO_OUTPUT_ACCURACY
Definition: config.h:16
virtual SUMOReal getPositionOnLane() const =0
Get the vehicle&#39;s position along the lane.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
virtual SUMOReal getAngle() const =0
Get the vehicle&#39;s angle.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:61
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:162
const std::string & getID() const
returns the id of the transportable
virtual SUMOReal getEdgePos() const
Return the position on the edge.
virtual SUMOReal getAngle() const
return the current angle of the container
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:69
static void write(OutputDevice &of, SUMOTime timestep, bool elevation)
Writes the posion and the angle of each vehcile into the given device.
Definition: MSFCDExport.cpp:57
const std::string & getID() const
Returns the id.
Definition: Named.h:60
void setPrecision(unsigned int precision=OUTPUT_ACCURACY)
Sets the precison or resets it to default.
Representation of a vehicle.
Definition: SUMOVehicle.h:65
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:304
SUMOReal z() const
Returns the z-position.
Definition: Position.h:73
Stores edges and lanes, performs moving of vehicle.
Definition: MSEdgeControl.h:74
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:53
virtual SUMOReal getSpeed() const
the current speed of the container
virtual SUMOReal getSpeed() const =0
Returns the vehicle&#39;s current speed.
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
virtual Position getPosition(const SUMOReal offset=0) const =0
Return current position (x/y, cartesian)
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...
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 container.
int getSignals() const
Returns the signals.
Definition: MSVehicle.h:835
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:335
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
virtual SUMOReal getSlope() const =0
Returns the slope of the road at vehicle&#39;s position.
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:331
virtual const std::string & getID() const =0
Get the vehicle&#39;s ID.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
const MSEdgeVector & getEdges() const
Returns loaded edges.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.