Eclipse SUMO - Simulation of Urban MObility
MSDetectorFileOutput.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2022 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 /****************************************************************************/
22 // Base of value-generating classes (detectors)
23 /****************************************************************************/
24 #include <config.h>
25 
27 #include <microsim/MSVehicleType.h>
32 #include "MSDetectorFileOutput.h"
33 
34 // ===========================================================================
35 // method definitions
36 // ===========================================================================
37 
38 MSDetectorFileOutput::MSDetectorFileOutput(const std::string& id, const std::string& vTypes, const int detectPersons) :
39  Named(id),
40  myDetectPersons(detectPersons) {
41  const std::vector<std::string> vt = StringTokenizer(vTypes).getVector();
42  myVehicleTypes.insert(vt.begin(), vt.end());
43 }
44 
45 MSDetectorFileOutput::MSDetectorFileOutput(const std::string& id, const std::set<std::string>& vTypes, const int detectPersons) :
46  Named(id), myVehicleTypes(vTypes), myDetectPersons(detectPersons)
47 { }
48 
49 bool
51  if (veh.isVehicle() == detectPersons()) {
52  return false;
53  } else if (myVehicleTypes.empty() || myVehicleTypes.count(veh.getVehicleType().getOriginalID()) > 0) {
54  return true;
55  } else {
57  for (auto vTypeDist : vTypeDists) {
58  if (myVehicleTypes.count(vTypeDist) > 0) {
59  return true;
60  }
61  }
62  return false;
63  }
64 }
65 
66 bool
68  //std::cout << getID() << " p=" << p.getID() << " veh=" << Named::getIDSecure(p.getVehicle()) << "\n";
69  if (p.getVehicle() == nullptr) {
70  const int dirCode = dir < 0 ? 2 : dir;
71  //std::cout << " dir=" << dir << " dirCode=" << dirCode << " myDetectPersons=" << myDetectPersons << "\n";
72  if ((dirCode & myDetectPersons) == 0) {
73  // person walking in wrong direction or not walking at all
74  return false;
75  }
76  } else {
77  const SUMOVehicleClass svc = p.getVehicle()->getVClass();
78  int vClassCode;;
79  if ((svc & SVC_PUBLIC_CLASSES) != 0) {
80  vClassCode = (int)PersonMode::PUBLIC;
81  } else if ((svc & SVC_BICYCLE) != 0) {
82  vClassCode = (int)PersonMode::BICYCLE;
83  } else if ((svc & SVC_TAXI) != 0) {
84  vClassCode = (int)PersonMode::TAXI;
85  } else {
86  vClassCode = (int)PersonMode::CAR;
87  }
88  if ((vClassCode & myDetectPersons) == 0) {
89  // person riding in the wrong vehicle
90  return false;
91  }
92  }
93  return true;
94 }
95 
96 
97 
98 /****************************************************************************/
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_BICYCLE
vehicle is a bicycle
@ SVC_PUBLIC_CLASSES
public transport
@ SVC_TAXI
vehicle is a taxi
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.
MSDetectorFileOutput(const std::string &id, const std::string &vTypes, const int detectPersons=false)
Constructor.
bool personApplies(const MSTransportable &p, int dir) const
std::set< std::string > myVehicleTypes
The vehicle types to look for (empty means all)
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:174
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:376
SUMOVehicle * getVehicle() const
The vehicle associated with this transportable.
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:54
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.
virtual SUMOVehicleClass getVClass() const =0
Returns the object's access class.
std::vector< std::string > getVector()
return vector of strings