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-2020 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 /****************************************************************************/
21 // Base of value-generating classes (detectors)
22 /****************************************************************************/
23 #pragma once
24 #include <config.h>
25 
26 #include <string>
27 #include <set>
28 
29 #include <utils/common/Named.h>
30 #include <utils/common/SUMOTime.h>
34 #include <microsim/MSVehicleType.h>
36 #include <microsim/MSNet.h>
37 
38 
39 // ===========================================================================
40 // class declarations
41 // ===========================================================================
42 class GUIDetectorWrapper;
43 
44 
45 // ===========================================================================
46 // class definitions
47 // ===========================================================================
52 };
53 
61 class MSDetectorFileOutput : public Named {
62 public:
64  MSDetectorFileOutput(const std::string& id, const std::string& vTypes, const int detectPersons = false) :
65  Named(id),
67  const std::vector<std::string> vt = StringTokenizer(vTypes).getVector();
68  myVehicleTypes.insert(vt.begin(), vt.end());
69  }
70 
72  MSDetectorFileOutput(const std::string& id, const std::set<std::string>& vTypes, const int detectPersons = false)
74  { }
75 
76 
78  virtual ~MSDetectorFileOutput() { }
79 
80 
83 
90  virtual void writeXMLOutput(OutputDevice& dev,
91  SUMOTime startTime, SUMOTime stopTime) = 0;
92 
93 
102  virtual void writeXMLDetectorProlog(OutputDevice& dev) const = 0;
103 
104 
112  virtual void reset() { }
113 
114 
119  virtual void detectorUpdate(const SUMOTime step) {
120  UNUSED_PARAMETER(step);
121  }
122 
123 
130  return 0;
131  }
132 
133 
139  bool vehicleApplies(const SUMOTrafficObject& veh) const {
140  if (veh.isVehicle() == detectPersons()) {
141  return false;
142  } else if (myVehicleTypes.empty() || myVehicleTypes.count(veh.getVehicleType().getOriginalID()) > 0) {
143  return true;
144  } else {
146  for (auto vTypeDist : vTypeDists) {
147  if (myVehicleTypes.count(vTypeDist) > 0) {
148  return true;
149  }
150  }
151  return false;
152  }
153  }
154 
155 
160  bool isTyped() const {
161  return !myVehicleTypes.empty();
162  }
163 
164  const std::set<std::string>& getVehicleTypes() const {
165  return myVehicleTypes;
166  }
167 
168  inline bool detectPersons() const {
169  return myDetectPersons != 0;
170  }
171 
173  virtual void clearState() {};
174 
175 protected:
177  std::set<std::string> myVehicleTypes;
178 
180  const int myDetectPersons;
181 
182 private:
185 
188 
189 
190 };
@ DU_USER_DEFINED
@ DU_SUMO_INTERNAL
@ DU_TL_CONTROL
long long int SUMOTime
Definition: SUMOTime.h:31
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:29
Base of value-generating classes (detectors)
virtual GUIDetectorWrapper * buildDetectorGUIRepresentation()
Builds the graphical representation.
bool isTyped() const
Checks whether the detector is type specific.
MSDetectorFileOutput(const MSDetectorFileOutput &)
Invalidated copy constructor.
virtual void clearState()
Remove all vehicles before quick-loading state.
bool vehicleApplies(const SUMOTrafficObject &veh) const
Checks whether the detector measures vehicles of the given type.
const int myDetectPersons
Whether pedestrians shall be detected instead of vehicles.
virtual void reset()
Resets collected values.
MSDetectorFileOutput(const std::string &id, const std::set< std::string > &vTypes, const int detectPersons=false)
Constructor.
virtual void detectorUpdate(const SUMOTime step)
Updates the detector (computes values)
virtual void writeXMLDetectorProlog(OutputDevice &dev) const =0
Open the XML-output.
MSDetectorFileOutput(const std::string &id, const std::string &vTypes, const int detectPersons=false)
Constructor.
const std::set< std::string > & getVehicleTypes() const
MSDetectorFileOutput & operator=(const MSDetectorFileOutput &)
Invalidated assignment operator.
virtual ~MSDetectorFileOutput()
(virtual) destructor
std::set< std::string > myVehicleTypes
The vehicle types to look for (empty means all)
virtual void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)=0
Write the generated output to the given device.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:171
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:371
const std::set< std::string > getVTypeDistributionMembership(const std::string &id) const
Return the distribution IDs the vehicle type is a member of.
const std::string & getOriginalID() const
Returns the id of the original vehicle type if this is a vehicle specific type, the id otherwise.
Base class for objects which have an id.
Definition: Named.h:53
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:60
Representation of a vehicle, person, or container.
virtual bool isVehicle() const
Whether it is a vehicle.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
std::vector< std::string > getVector()
return vector of strings