1 /****************************************************************************/ 2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo 3 // Copyright (C) 2005-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 /****************************************************************************/ 10 /// @file PCPolyContainer.h 11 /// @author Daniel Krajzewicz 12 /// @author Michael Behrisch 13 /// @author Jakob Erdmann 14 /// @date Mon, 05 Dec 2005 15 /// @version $Id$ 16 /// 17 // A storage for loaded polygons and pois 18 /****************************************************************************/ 19 #ifndef PCPolyContainer_h 20 #define PCPolyContainer_h 21 22 23 // =========================================================================== 24 // included modules 25 // =========================================================================== 26 #include <config.h> 27 28 #include <string> 29 #include <map> 30 #include <vector> 31 #include <utils/shapes/ShapeContainer.h> 32 33 34 // =========================================================================== 35 // class declarations 36 // =========================================================================== 37 class Boundary; 38 class SUMOPolygon; 39 class PointOfInterest; 40 class OptionsCont; 41 class OutputDevice; 42 43 44 // =========================================================================== 45 // class definitions 46 // =========================================================================== 47 /** 48 * @class PCPolyContainer 49 * @brief A storage for loaded polygons and pois 50 */ 51 class PCPolyContainer : public ShapeContainer { 52 public: 53 /** @brief Constructor 54 * @param[in] prune Whether added polygons/pois shall be pruned 55 * @param[in] pruningBoundary The pruning boundary (only valid if prune==true) 56 * @param[in] removeByNames Names of objects that shall not be added 57 */ 58 PCPolyContainer(bool prune, const Boundary& pruningBoundary, 59 const std::vector<std::string>& removeByNames); 60 61 62 /// @brief Destructor 63 ~PCPolyContainer(); 64 65 66 /** @brief Adds a polygon to the storage 67 * 68 * If pruning is enabled, "ignorePruning" is false and the polygon lies outside 69 * the pruning boundary, or if the polygon's name is within the names of 70 * objects to discard, the polygon is deleted and false is returned. 71 * 72 * Afterwards it is tested whether a polygon with the same name is already stored. 73 * If so, an error message is printed, the polygon is deleted and false is returned, otherwise true. 74 * 75 * @param[in] poly The polygon to add 76 * @param[in] ignorePruning Whether the polygon shall be kept, even though it would be pruned 77 * @return Whether the polygon could be added 78 */ 79 bool add(SUMOPolygon* poly, bool ignorePruning = false); 80 81 82 /** @brief Adds a poi to the storage 83 * 84 * If pruning is enabled, "ignorePruning" is false and the poi lies outside 85 * the pruning boundary, or if the poi's name is within the names of 86 * objects to discard, the poi is deleted and false is returned. 87 * 88 * Afterwards it is tested whether a poi with the same name is already stored. 89 * If so, an error message is printed, the poi is deleted and false is returned, otherwise true. 90 * 91 * @param[in] poly The poi to add 92 * @param[in] ignorePruning Whether the poi shall be kept, even though it would be pruned 93 * @return Whether the poi could be added 94 */ 95 bool add(PointOfInterest* poi, bool ignorePruning = false); 96 97 98 void addLanePos(const std::string& poiID, const std::string& laneID, double lanePos, double lanePosLat); 99 100 /** @brief Saves the stored polygons and pois into the given file 101 * @param[in] file The name of the file to write stored objects' definitions into 102 * @param[in] useGeo Whether to write output in geo-coordinates 103 * @exception IOError If the file could not be opened 104 */ 105 void save(const std::string& file, bool useGeo); 106 107 /** @brief Saves the stored polygons and pois into the given file in dlrTDP format 108 * @param[in] prefix The prefix of the file to write stored objects' definitions into 109 */ 110 void saveDlrTDP(const std::string& prefix); 111 112 113 /** @brief Retuns a unique id for a given name 114 * 115 * The unique id is generated by having an internal map of ids to running numbers. 116 * The first call to this method will return 0, all subsequent with the same 117 * key will return numbers increased by one at each call. 118 * @param[in] key The key to get a running number for 119 * @return Unique id (running number of calls that used this key) 120 */ 121 int getEnumIDFor(const std::string& key); 122 123 124 private: 125 126 struct LanePos { LanePosLanePos127 LanePos() {} LanePosLanePos128 LanePos(const std::string& _laneID, double _pos, double _posLat) : 129 laneID(_laneID), pos(_pos), posLat(_posLat) {} 130 std::string laneID; 131 double pos; 132 double posLat; 133 }; 134 135 /// @brief An id to pos map for lane pos specs 136 std::map<std::string, LanePos> myLanePosPois; 137 138 /// @brief An id to int map for proper enumeration 139 std::map<std::string, int> myIDEnums; 140 141 /// @brief The boundary that described the rectangle within which an object must be in order to be kept 142 Boundary myPruningBoundary; 143 144 /// @brief Information whether the pruning boundary shall be used 145 bool myDoPrune; 146 147 /// @brief List of names of polygons/pois that shall be removed 148 std::vector<std::string> myRemoveByNames; 149 150 static void writeDlrTDPHeader(OutputDevice& device, const OptionsCont& oc); 151 152 private: 153 /// @brief Invalidated copy constructor 154 PCPolyContainer(const PCPolyContainer& s); 155 156 /// @brief Invalidated assignment operator 157 PCPolyContainer& operator=(const PCPolyContainer& s); 158 159 160 }; 161 162 163 #endif 164 165 /****************************************************************************/ 166 167