LCOV - code coverage report
Current view: top level - src/netbuild - NBNetBuilder.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 9 9 100.0 %
Date: 2024-05-06 15:32:35 Functions: 0 0 -

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

Generated by: LCOV version 1.14