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 /****************************************************************************/
17 // Base of value-generating classes (detectors)
18 /****************************************************************************/
19 #ifndef MSDetectorFileOutput_h
20 #define MSDetectorFileOutput_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <string>
29 #include <set>
30 
31 #include <utils/common/Named.h>
32 #include <utils/common/SUMOTime.h>
36 #include <microsim/MSVehicleType.h>
38 #include <microsim/MSNet.h>
39 
40 
41 // ===========================================================================
42 // class declarations
43 // ===========================================================================
44 class GUIDetectorWrapper;
45 
46 
47 // ===========================================================================
48 // class definitions
49 // ===========================================================================
54 };
55 
63 class MSDetectorFileOutput : public Named {
64 public:
66  MSDetectorFileOutput(const std::string& id, const std::string& vTypes, const int detectPersons = false) :
67  Named(id),
69  const std::vector<std::string> vt = StringTokenizer(vTypes).getVector();
70  myVehicleTypes.insert(vt.begin(), vt.end());
71  }
72 
74  MSDetectorFileOutput(const std::string& id, const std::set<std::string>& vTypes, const int detectPersons = false)
76  { }
77 
78 
80  virtual ~MSDetectorFileOutput() { }
81 
82 
85 
92  virtual void writeXMLOutput(OutputDevice& dev,
93  SUMOTime startTime, SUMOTime stopTime) = 0;
94 
95 
104  virtual void writeXMLDetectorProlog(OutputDevice& dev) const = 0;
105 
106 
114  virtual void reset() { }
115 
116 
121  virtual void detectorUpdate(const SUMOTime step) {
122  UNUSED_PARAMETER(step);
123  }
124 
125 
132  return 0;
133  }
134 
135 
141  bool vehicleApplies(const SUMOTrafficObject& veh) const {
142  if (veh.isVehicle() == detectPersons()) {
143  return false;
144  } else if (myVehicleTypes.empty() || myVehicleTypes.count(veh.getVehicleType().getOriginalID()) > 0) {
145  return true;
146  } else {
148  for (auto vTypeDist : vTypeDists) {
149  if (myVehicleTypes.count(vTypeDist) > 0) {
150  return true;
151  }
152  }
153  return false;
154  }
155  }
156 
157 
162  bool isTyped() const {
163  return !myVehicleTypes.empty();
164  }
165 
166  inline bool detectPersons() const {
167  return myDetectPersons != 0;
168  }
169 
170 protected:
172  std::set<std::string> myVehicleTypes;
173 
175  const int myDetectPersons;
176 
177 private:
180 
183 
184 
185 };
186 
187 
188 #endif
189 
190 /****************************************************************************/
191 
MSDetectorFileOutput::writeXMLDetectorProlog
virtual void writeXMLDetectorProlog(OutputDevice &dev) const =0
Open the XML-output.
UNUSED_PARAMETER
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:31
SUMOTrafficObject
Representation of a vehicle or person.
Definition: SUMOTrafficObject.h:47
MSDetectorFileOutput::buildDetectorGUIRepresentation
virtual GUIDetectorWrapper * buildDetectorGUIRepresentation()
Builds the graphical representation.
Definition: MSDetectorFileOutput.h:131
SUMOTime.h
MSNet.h
MSDetectorFileOutput
Base of value-generating classes (detectors)
Definition: MSDetectorFileOutput.h:63
Named
Base class for objects which have an id.
Definition: Named.h:56
MSDetectorFileOutput::MSDetectorFileOutput
MSDetectorFileOutput(const std::string &id, const std::string &vTypes, const int detectPersons=false)
Constructor.
Definition: MSDetectorFileOutput.h:66
MSDetectorFileOutput::myVehicleTypes
std::set< std::string > myVehicleTypes
The vehicle types to look for (empty means all)
Definition: MSDetectorFileOutput.h:172
GUIDetectorWrapper
Definition: GUIDetectorWrapper.h:42
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
SUMOTrafficObject::getVehicleType
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.
SUMOTrafficObject::isVehicle
virtual bool isVehicle() const =0
Get the vehicle's ID.
MSDetectorFileOutput::MSDetectorFileOutput
MSDetectorFileOutput(const std::string &id, const std::set< std::string > &vTypes, const int detectPersons=false)
Constructor.
Definition: MSDetectorFileOutput.h:74
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
DU_USER_DEFINED
@ DU_USER_DEFINED
Definition: MSDetectorFileOutput.h:51
MSDetectorFileOutput::myDetectPersons
const int myDetectPersons
Whether pedestrians shall be detected instead of vehicles.
Definition: MSDetectorFileOutput.h:175
MSDetectorFileOutput::isTyped
bool isTyped() const
Checks whether the detector is type specific.
Definition: MSDetectorFileOutput.h:162
MSDetectorFileOutput::operator=
MSDetectorFileOutput & operator=(const MSDetectorFileOutput &)
Invalidated assignment operator.
MSVehicleType.h
MSVehicleType::getOriginalID
const std::string & getOriginalID() const
Returns the id of the original vehicle type if this is a vehicle specific type, the id otherwise.
Definition: MSVehicleType.h:555
MSVehicleControl::getVTypeDistributionMembership
const std::set< std::string > getVTypeDistributionMembership(const std::string &id) const
Return the distribution IDs the vehicle type is a member of.
Definition: MSVehicleControl.cpp:384
Named.h
StringTokenizer
Definition: StringTokenizer.h:61
MSDetectorFileOutput::writeXMLOutput
virtual void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)=0
Write the generated output to the given device.
OutputDevice.h
MSDetectorFileOutput::reset
virtual void reset()
Resets collected values.
Definition: MSDetectorFileOutput.h:114
MSDetectorFileOutput::detectorUpdate
virtual void detectorUpdate(const SUMOTime step)
Updates the detector (computes values)
Definition: MSDetectorFileOutput.h:121
DU_TL_CONTROL
@ DU_TL_CONTROL
Definition: MSDetectorFileOutput.h:53
MSDetectorFileOutput::detectPersons
bool detectPersons() const
Definition: MSDetectorFileOutput.h:166
DetectorUsage
DetectorUsage
Definition: MSDetectorFileOutput.h:50
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
MSDetectorFileOutput::vehicleApplies
bool vehicleApplies(const SUMOTrafficObject &veh) const
Checks whether the detector measures vehicles of the given type.
Definition: MSDetectorFileOutput.h:141
StringTokenizer::getVector
std::vector< std::string > getVector()
return vector of strings
Definition: StringTokenizer.cpp:191
config.h
StringTokenizer.h
SUMOTrafficObject.h
DU_SUMO_INTERNAL
@ DU_SUMO_INTERNAL
Definition: MSDetectorFileOutput.h:52
MSVehicleControl.h
MSNet::getVehicleControl
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:336
MSDetectorFileOutput::~MSDetectorFileOutput
virtual ~MSDetectorFileOutput()
(virtual) destructor
Definition: MSDetectorFileOutput.h:80