Eclipse SUMO - Simulation of Urban MObility
MSDetectorFileOutput.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-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 /****************************************************************************/
18 // Base of value-generating classes (detectors)
19 /****************************************************************************/
20 #ifndef MSDetectorFileOutput_h
21 #define MSDetectorFileOutput_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #include <config.h>
28 
29 #include <string>
30 #include <set>
31 
32 #include <utils/common/Named.h>
33 #include <utils/common/SUMOTime.h>
37 #include <microsim/MSVehicleType.h>
39 #include <microsim/MSNet.h>
40 
41 
42 // ===========================================================================
43 // class declarations
44 // ===========================================================================
45 class GUIDetectorWrapper;
46 
47 
48 // ===========================================================================
49 // class definitions
50 // ===========================================================================
55 };
56 
64 class MSDetectorFileOutput : public Named {
65 public:
67  MSDetectorFileOutput(const std::string& id, const std::string& vTypes, const int detectPersons = false) :
68  Named(id),
70  const std::vector<std::string> vt = StringTokenizer(vTypes).getVector();
71  myVehicleTypes.insert(vt.begin(), vt.end());
72  }
73 
75  MSDetectorFileOutput(const std::string& id, const std::set<std::string>& vTypes, const int detectPersons = false)
77  { }
78 
79 
81  virtual ~MSDetectorFileOutput() { }
82 
83 
86 
93  virtual void writeXMLOutput(OutputDevice& dev,
94  SUMOTime startTime, SUMOTime stopTime) = 0;
95 
96 
105  virtual void writeXMLDetectorProlog(OutputDevice& dev) const = 0;
106 
107 
115  virtual void reset() { }
116 
117 
122  virtual void detectorUpdate(const SUMOTime step) {
123  UNUSED_PARAMETER(step);
124  }
125 
126 
133  return 0;
134  }
135 
136 
142  bool vehicleApplies(const SUMOTrafficObject& veh) const {
143  if (veh.isVehicle() == detectPersons()) {
144  return false;
145  } else if (myVehicleTypes.empty() || myVehicleTypes.count(veh.getVehicleType().getOriginalID()) > 0) {
146  return true;
147  } else {
149  for (auto vTypeDist : vTypeDists) {
150  if (myVehicleTypes.count(vTypeDist) > 0) {
151  return true;
152  }
153  }
154  return false;
155  }
156  }
157 
158 
163  bool isTyped() const {
164  return !myVehicleTypes.empty();
165  }
166 
167  inline bool detectPersons() const {
168  return myDetectPersons != 0;
169  }
170 
171 protected:
173  std::set<std::string> myVehicleTypes;
174 
176  const int myDetectPersons;
177 
178 private:
181 
184 
185 
186 };
187 
188 
189 #endif
190 
191 /****************************************************************************/
192 
bool vehicleApplies(const SUMOTrafficObject &veh) const
Checks whether the detector measures vehicles of the given type.
const std::string & getOriginalID() const
Returns the id of the original vehicle type if this is a vehicle specific type, the id otherwise...
long long int SUMOTime
Definition: SUMOTime.h:35
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.
virtual bool isVehicle() const =0
Get the vehicle&#39;s ID.
virtual void reset()
Resets collected values.
const std::set< std::string > getVTypeDistributionMembership(const std::string &id) const
Return the distribution IDs the vehicle type is a member of.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:168
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:32
virtual void detectorUpdate(const SUMOTime step)
Updates the detector (computes values)
virtual void writeXMLDetectorProlog(OutputDevice &dev) const =0
Open the XML-output.
MSDetectorFileOutput & operator=(const MSDetectorFileOutput &)
Invalidated assignment operator.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:337
virtual ~MSDetectorFileOutput()
(virtual) destructor
std::set< std::string > myVehicleTypes
The vehicle types to look for (empty means all)
MSDetectorFileOutput(const std::string &id, const std::string &vTypes, const int detectPersons=false)
Constructor.
Base class for objects which have an id.
Definition: Named.h:57
std::vector< std::string > getVector()
return vector of strings
const int myDetectPersons
Whether pedestrians shall be detected instead of vehicles.
bool isTyped() const
Checks whether the detector is type specific.
Representation of a vehicle or person.
MSDetectorFileOutput(const std::string &id, const std::set< std::string > &vTypes, const int detectPersons=false)
Constructor.
virtual void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)=0
Write the generated output to the given device.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
virtual GUIDetectorWrapper * buildDetectorGUIRepresentation()
Builds the graphical representation.
Base of value-generating classes (detectors)