Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSDevice_FCD.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2013-2024 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
20// A device which stands as an implementation FCD and which outputs movereminder calls
21/****************************************************************************/
22#include <config.h>
23
24#include <bitset>
31#include <microsim/MSNet.h>
32#include <microsim/MSLane.h>
33#include <microsim/MSEdge.h>
34#include <microsim/MSVehicle.h>
35#include "MSDevice_FCD.h"
36
37
38// ===========================================================================
39// static members
40// ===========================================================================
41std::set<const MSEdge*> MSDevice_FCD::myEdgeFilter;
42std::vector<PositionVector> MSDevice_FCD::myShape4Filters;
47
48// ===========================================================================
49// method definitions
50// ===========================================================================
51// ---------------------------------------------------------------------------
52// static initialisation methods
53// ---------------------------------------------------------------------------
54void
56 oc.addOptionSubTopic("FCD Device");
57 insertDefaultAssignmentOptions("fcd", "FCD Device", oc);
58
59 oc.doRegister("device.fcd.begin", new Option_String("-1"));
60 oc.addDescription("device.fcd.begin", "FCD Device", TL("Recording begin time for FCD-data"));
61
62 oc.doRegister("device.fcd.period", new Option_String("0"));
63 oc.addDescription("device.fcd.period", "FCD Device", TL("Recording period for FCD-data"));
64
65 oc.doRegister("device.fcd.radius", new Option_Float(0));
66 oc.addDescription("device.fcd.radius", "FCD Device", TL("Record objects in a radius around equipped vehicles"));
67}
68
69
70void
71MSDevice_FCD::buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into) {
73 if (equippedByDefaultAssignmentOptions(oc, "fcd", v, oc.isSet("fcd-output"))) {
74 MSDevice_FCD* device = new MSDevice_FCD(v, "fcd_" + v.getID());
75 into.push_back(device);
76 initOnce();
77 }
78}
79
80
81// ---------------------------------------------------------------------------
82// MSDevice_FCD-methods
83// ---------------------------------------------------------------------------
84MSDevice_FCD::MSDevice_FCD(SUMOVehicle& holder, const std::string& id) :
85 MSVehicleDevice(holder, id) {
86}
87
88
91
92
95 SumoXMLAttrMask mask;
96 // set all bits to 1
97 mask.set();
98 // some attributes are not written by default and must be enabled via option fcd-output.attributes
99 // (or with an explicit attribute list)
100 mask.reset(SUMO_ATTR_VEHICLE);
101 mask.reset(SUMO_ATTR_ODOMETER);
102 mask.reset(SUMO_ATTR_SPEED_LAT);
103 mask.reset(SUMO_ATTR_POSITION_LAT);
104 mask.reset(SUMO_ATTR_ARRIVALDELAY);
105 mask.reset(SUMO_ATTR_SEGMENT);
106 mask.reset(SUMO_ATTR_QUEUE);
107 mask.reset(SUMO_ATTR_ENTRYTIME);
108 mask.reset(SUMO_ATTR_EVENTTIME);
109 mask.reset(SUMO_ATTR_BLOCKTIME);
110 return mask;
111}
112
113
114bool
116 // lazily build the shape filter in the case where route file is loaded as an additional file
119 }
120 const MSVehicle* msVeh = dynamic_cast<const MSVehicle*>(veh);
121 for (auto shape : myShape4Filters) {
122 if (shape.around(veh->getPosition()) || ((msVeh != nullptr) && shape.around(msVeh->getBackPosition()))) {
123 return true;
124 }
125 }
126 return false;
127}
128
129
130void
133 if (oc.isSet("fcd-output.filter-shapes")) {
134 const ShapeContainer& loadedShapes = MSNet::getInstance()->getShapeContainer();
135 if (loadedShapes.getPolygons().size() > 0) {
136 for (std::string attrName : oc.getStringVector("fcd-output.filter-shapes")) {
137 if (loadedShapes.getPolygons().get(attrName) == 0) {
138 WRITE_ERRORF(TL("Specified shape '%' for filtering fcd-output could not be found."), attrName);
139 } else {
140 // store the PositionVector, not reference, as traci can manipulate / detete the polygons
141 myShape4Filters.push_back(loadedShapes.getPolygons().get(attrName)->getShape());
142 }
143 }
145 }
146 } else {
148 }
149}
150
151
152void
155 return;
156 }
159 if (oc.isSet("fcd-output.filter-edges.input-file")) {
160 const std::string file = oc.getString("fcd-output.filter-edges.input-file");
161 std::ifstream strm(file.c_str());
162 if (!strm.good()) {
163 throw ProcessError(TLF("Could not load names of edges for filtering fcd-output from '%'.", file));
164 }
165 while (strm.good()) {
166 std::string name;
167 strm >> name;
168 // maybe we're loading an edge-selection
169 if (StringUtils::startsWith(name, "edge:")) {
170 name = name.substr(5);
171 }
172 myEdgeFilter.insert(MSEdge::dictionary(name));
173 }
174 }
175 if (oc.isSet("fcd-output.attributes")) {
176 myWrittenAttributes.reset();
177 for (std::string attrName : oc.getStringVector("fcd-output.attributes")) {
178 if (!SUMOXMLDefinitions::Attrs.hasString(attrName)) {
179 if (attrName == "all") {
181 } else {
182 WRITE_ERRORF(TL("Unknown attribute '%' to write in fcd output."), attrName);
183 }
184 continue;
185 }
186 int attr = SUMOXMLDefinitions::Attrs.get(attrName);
187 myWrittenAttributes.set(attr);
188 }
189 }
190
191 if (oc.isSet("fcd-output.filter-shapes")) {
192 // build the shape filter if it is desired
195 }
196 //std::cout << "mask=" << myWrittenAttributes << " binary=" << std::bitset<64>(myWrittenAttributes) << "\n";
197}
198
199
200void
209
210
211/****************************************************************************/
#define WRITE_ERRORF(...)
Definition MsgHandler.h:305
#define TL(string)
Definition MsgHandler.h:315
#define TLF(string,...)
Definition MsgHandler.h:317
std::bitset< 96 > SumoXMLAttrMask
@ SUMO_ATTR_POSITION_LAT
@ SUMO_ATTR_ODOMETER
@ SUMO_ATTR_QUEUE
@ SUMO_ATTR_ARRIVALDELAY
@ SUMO_ATTR_BLOCKTIME
@ SUMO_ATTR_VEHICLE
@ SUMO_ATTR_EVENTTIME
@ SUMO_ATTR_SEGMENT
@ SUMO_ATTR_SPEED_LAT
@ SUMO_ATTR_ENTRYTIME
A device which collects info on the vehicle trip (mainly on departure and arrival)
static void cleanup()
resets the edge filter
static SumoXMLAttrMask getDefaultMask()
MSDevice_FCD(SUMOVehicle &holder, const std::string &id)
Constructor.
~MSDevice_FCD()
Destructor.
static bool myShapeFilterInitialized
static std::vector< PositionVector > myShape4Filters
polygon spatial filter for FCD output
static SumoXMLAttrMask myWrittenAttributes
bit mask for checking attributes to be written
static std::set< const MSEdge * > myEdgeFilter
edge filter for FCD output
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_FCD-options.
static bool myEdgeFilterInitialized
static bool myShapeFilterDesired
static void initOnce()
initialize edge filter and attribute mask (once)
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
static void buildShapeFilter()
static bool shapeFilter(const SUMOTrafficObject *veh)
checks if in polygon
static void insertDefaultAssignmentOptions(const std::string &deviceName, const std::string &optionsTopic, OptionsCont &oc, const bool isPerson=false)
Adds common command options that allow to assign devices to vehicles.
Definition MSDevice.cpp:155
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, DEVICEHOLDER &v, bool outputOptionSet, const bool isPerson=false)
Determines whether a vehicle should get a certain device.
Definition MSDevice.h:195
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn't already in the dictionary....
Definition MSEdge.cpp:1047
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:186
ShapeContainer & getShapeContainer()
Returns the shapes container.
Definition MSNet.h:501
Abstract in-vehicle device.
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
const Position getBackPosition() const
const std::string & getID() const
Returns the id.
Definition Named.h:74
T get(const std::string &id) const
Retrieves an item.
int size() const
Returns the number of stored items within the container.
A storage for options typed value containers)
Definition OptionsCont.h:89
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
void doRegister(const std::string &name, Option *o)
Adds an option under the given name.
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
static OptionsCont & getOptions()
Retrieves the options.
const PositionVector & getShape() const
Returns the shape of the polygon.
Representation of a vehicle, person, or container.
virtual Position getPosition(const double offset=0) const =0
Return current position (x/y, cartesian)
Representation of a vehicle.
Definition SUMOVehicle.h:62
static SequentialStringBijection Attrs
The names of SUMO-XML attributes for use in netbuild.
int get(const std::string &str) const
Storage for geometrical objects.
const Polygons & getPolygons() const
Returns all polygons.
static bool startsWith(const std::string &str, const std::string prefix)
Checks whether a given string starts with the prefix.