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 /****************************************************************************/
10 /// @file    NBNetBuilder.h
11 /// @author  Daniel Krajzewicz
12 /// @author  Jakob Erdmann
13 /// @author  Sascha Krieg
14 /// @author  Michael Behrisch
15 /// @author  Gregor Laemmel
16 /// @date    Fri, 29.04.2005
17 /// @version $Id$
18 ///
19 // Instance responsible for building networks
20 /****************************************************************************/
21 #ifndef NBNetBuilder_h
22 #define NBNetBuilder_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #include <config.h>
29 
30 #include <string>
31 #include <iostream>
32 #include <vector>
33 #include <set>
34 #include <utils/shapes/ShapeContainer.h>
35 #include "NBEdgeCont.h"
36 #include "NBTypeCont.h"
37 #include "NBNodeCont.h"
38 #include "NBNode.h"
39 #include "NBParking.h"
40 #include "NBTrafficLightLogicCont.h"
41 #include "NBDistrictCont.h"
42 #include "NBPTStopCont.h"
43 #include "NBPTLineCont.h"
44 #include <utils/common/UtilExceptions.h>
45 
46 
47 // ===========================================================================
48 // class declarations
49 // ===========================================================================
50 class OptionsCont;
51 class OutputDevice;
52 class GeoConvHelper;
53 
54 
55 // ===========================================================================
56 // class definitions
57 // ===========================================================================
58 /**
59  * @class NBNetBuilder
60  * @brief Instance responsible for building networks
61  *
62  * The class' - and the netbuild module's - functionality is embedded within the
63  *  compute() method.
64  *
65  * @addtogroup netbuild
66  * @{
67  *
68  * -# Removing self loops
69  *  \n Removes edges which end at the node they start at using NBNodeCont::removeSelfLoops().
70  * -# Joining double connections
71  *  \n Joins edges between same nodes using NBNodeCont::recheckEdges().
72  * -# Finding isolated roads (optional)
73  * -# Removing empty nodes and geometry nodes (optional)
74  *  \n Removed nodes with no incoming/outgoing edges and nodes which can be transformed into
75  *   geometry point using NBNodeCont::removeUnwishedNodes().
76  * -# Removing unwished edges (optional)
77  *  \n If "keep-edges.postload" and "keep-edges.explicit" are set, the edges not within "keep-edges.explicit" are
78  *   removed from the network using NBEdgeCont::removeUnwishedEdges().
79  * -# Rechecking nodes after edge removal (optional)
80  *  \n If any of the edge removing options was set ("keep-edges.explicit", "remove-edges.explicit", "keep-edges.postload",
81  *   "keep-edges.by-vclass", "keep-edges.input-file"), the now orphaned nodes are removed using
82  *   NBNodeCont::removeUnwishedNodes().
83  * -# Splitting geometry edges (optional)
84  *  \n If "geometry.split" is set, edge geometries are converted to nodes using
85  *   NBEdgeCont::splitGeometry().
86  * -# Normalising/transposing node positions
87  *  \n If "offset.disable-normalization", "offset.x", and "offset.y" are not
88  *   set, the road graph's instances are moved to the origin.
89  * -# Guessing and setting on-/off-ramps
90  * -# Guessing and setting TLs
91  * -# Computing turning directions
92  * -# Sorting nodes' edges
93  * -# Guessing and setting roundabouts
94  * -# Computing Approached Edges
95  * -# Computing Approaching Lanes
96  * -# Dividing of Lanes on Approached Lanes
97  * -# Appending Turnarounds (optional)
98  * -# Rechecking of lane endings
99  * -# Computing node shapes
100  * -# Computing edge shapes
101  * -# Computing tls logics
102  * -# Computing node logics
103  * -# Computing traffic light logics
104  *
105  *  @todo Removing unwished edges: Recheck whether this can be done during loading - whether this option/step is really needed.
106  *  @todo Finding isolated roads: Describe
107  *  @bug Removing empty nodes and geometry nodes: Ok, empty nodes should be removed, uh? But this is only done if "geometry.remove" is set.
108  * @}
109  */
110 class NBNetBuilder {
111     friend class GNENet; // for triggering intermediate build steps
112 
113 public:
114     /// @brief Constructor
115     NBNetBuilder();
116 
117     /// @brief Destructor
118     ~NBNetBuilder();
119 
120     /** @brief Initialises the storage by applying given options
121      *
122      * Options, mainly steering the acceptance of edges, are parsed
123      *  and the according internal variables are set.
124      *
125      * @param[in] oc The options container to read options from
126      * @exception ProcessError If something fails (message is included)
127      */
128     void applyOptions(OptionsCont& oc);
129 
130     /** @brief Performs the network building steps
131      *
132      * @param[in] oc Container that contains options for building
133      * @param[in] explicitTurnarounds List of edge ids for which turn-arounds should be added (used by NETEDIT)
134      * @param[in] mayAddOrRemove whether processing steps which cause nodes and edges to be added or removed shall be triggered (used by netedit)
135      * @exception ProcessError (recheck)
136      */
137     void compute(OptionsCont& oc, const std::set<std::string>& explicitTurnarounds = std::set<std::string>(), bool mayAddOrRemove = true);
138 
139     /** @brief Updates the shape for a single Node
140      *
141      * @param[in] oc Container that contains options for building
142      * @param[in] explicitTurnarounds List of edge ids for which turn-arounds should be added (used by NETEDIT)
143      * @param[in] mayAddOrRemove whether processing steps which cause nodes and edges to be added or removed shall be triggered (used by netedit)
144      * @exception ProcessError (recheck)
145      */
146     //void computeSingleNode(NBNode* node, OptionsCont& oc, const std::set<std::string>& explicitTurnarounds = std::set<std::string>(), bool mayAddOrRemove = true);
147 
148     /// @name Retrieval of subcontainers
149     /// @{
150     /// @brief Returns a reference to edge container
getEdgeCont()151     NBEdgeCont& getEdgeCont() {
152         return myEdgeCont;
153     }
154 
155     /// @brief Returns a reference to the node container
getNodeCont()156     NBNodeCont& getNodeCont() {
157         return myNodeCont;
158     }
159 
160     /// @brief Returns a reference to the type container
getTypeCont()161     NBTypeCont& getTypeCont() {
162         return myTypeCont;
163     }
164 
165     /// @brief Returns a reference to the traffic light logics container
getTLLogicCont()166     NBTrafficLightLogicCont& getTLLogicCont() {
167         return myTLLCont;
168     }
169 
170     /// @brief Returns a reference the districts container
getDistrictCont()171     NBDistrictCont& getDistrictCont() {
172         return myDistrictCont;
173     }
174 
175 
176     /// @brief Returns a reference to the pt stop container
getPTStopCont()177     NBPTStopCont& getPTStopCont() {
178         return myPTStopCont;
179     }
180 
181     /// @brief Returns a reference to the pt line container
getPTLineCont()182     NBPTLineCont& getPTLineCont() {
183         return myPTLineCont;
184     }
185     /// @}
186 
getParkingCont()187     NBParkingCont& getParkingCont() {
188         return myParkingCont;
189     }
190 
getShapeCont()191     ShapeContainer& getShapeCont() {
192         return myShapeCont;
193     }
194 
195     /// @brief notify about style of loaded network (Without Crossings)
haveNetworkCrossings()196     bool haveNetworkCrossings() {
197         return myNetworkHaveCrossings;
198     }
199 
200     /// @brief enable crossing in networks
setHaveNetworkCrossings(bool value)201     void setHaveNetworkCrossings(bool value) {
202         myNetworkHaveCrossings = value;
203     }
204 
205     /**
206      * @brief transforms loaded coordinates
207      * handles projections, offsets (using GeoConvHelper) and import of height data (using NBHeightMapper)
208      * @param[in,out] from The coordinate to be transformed
209      * @param[in] includeInBoundary Whether to patch the convex boundary of the GeoConvHelper default instance
210      * @param[in] from_srs The spatial reference system of the input coordinate
211      * @notde These methods are located outside of GeoConvHelper to avoid linker-dependencies on GDAL for libgeom
212      */
213     static bool transformCoordinate(Position& from, bool includeInBoundary = true, GeoConvHelper* from_srs = 0);
214     static bool transformCoordinates(PositionVector& from, bool includeInBoundary = true, GeoConvHelper* from_srs = 0);
215 
216     /// @brief whether netbuilding takes place in the context of NETEDIT
217     static bool runningNetedit();
218 
219 
220 protected:
221     /**
222      * @class by_id_sorter
223      * @brief Sorts nodes by their ids
224      */
225     class by_id_sorter {
226     public:
227         /// @brief constructor
by_id_sorter()228         explicit by_id_sorter() {}
229 
230         /// @brief selection operator
operator()231         int operator()(const NBNode* n1, const NBNode* n2) const {
232             return n1->getID() < n2->getID();
233         }
234     };
235 
236 protected:
237     /// @brief The used container for nodes
238     NBNodeCont myNodeCont;
239 
240     /// @brief The used container for street types
241     NBTypeCont myTypeCont;
242 
243     /// @brief The used container for edges
244     NBEdgeCont myEdgeCont;
245 
246     /// @brief The used container for traffic light logics
247     NBTrafficLightLogicCont myTLLCont;
248 
249     /// @brief The used container for districts
250     NBDistrictCont myDistrictCont;
251 
252     /// @brief The used container for pt stops
253     NBPTStopCont myPTStopCont;
254 
255     /// @brief The used container for pt stops
256     NBPTLineCont myPTLineCont;
257 
258     NBParkingCont myParkingCont;
259 
260     /// @brief container for loaded polygon data
261     ShapeContainer myShapeCont;
262 
263     /// @brief flag to indicate that network has crossings
264     bool myNetworkHaveCrossings;
265 
266 private:
267     /// @brief shift network so its lower left corner is at 0,0
268     void moveToOrigin(GeoConvHelper& geoConvHelper, bool lefthand);
269 
270     /// @brief mirror the network along the X-axis
271     void mirrorX();
272 
273 private:
274     /// @brief invalidated copy constructor
275     NBNetBuilder(const NBNetBuilder& s);
276 
277     /// @brief invalidated assignment operator
278     NBNetBuilder& operator=(const NBNetBuilder& s);
279 };
280 
281 
282 #endif
283 
284 /****************************************************************************/
285 
286