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