LCOV - code coverage report
Current view: top level - src/netimport - NIImporter_OpenDrive.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 72.0 % 50 36
Test Date: 2024-12-21 15:45:41 Functions: 66.7 % 6 4

            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    NIImporter_OpenDrive.h
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Jakob Erdmann
      17              : /// @author  Michael Behrisch
      18              : /// @author  Mirko Barthauer
      19              : /// @date    Mon, 14.04.2008
      20              : ///
      21              : // Importer for networks stored in openDrive format
      22              : /****************************************************************************/
      23              : #pragma once
      24              : #include <config.h>
      25              : 
      26              : #include <string>
      27              : #include <map>
      28              : #include <utils/xml/GenericSAXHandler.h>
      29              : #include <utils/geom/PositionVector.h>
      30              : 
      31              : 
      32              : // ===========================================================================
      33              : // class declarations
      34              : // ===========================================================================
      35              : class NBNetBuilder;
      36              : class NBEdge;
      37              : class OptionsCont;
      38              : class NBNode;
      39              : class NBNodeCont;
      40              : 
      41              : 
      42              : #define UNSET_CONNECTION 100000
      43              : #define UNSET_LANEVALIDITY 100000
      44              : 
      45              : // ===========================================================================
      46              : // class definitions
      47              : // ===========================================================================
      48              : /**
      49              :  * @class NIImporter_OpenDrive
      50              :  * @brief Importer for networks stored in openDrive format
      51              :  *
      52              :  */
      53              : class NIImporter_OpenDrive : public GenericSAXHandler {
      54              : public:
      55              :     /** @brief Loads content of the optionally given SUMO file
      56              :      *
      57              :      * If the option "opendrive-files" is set, the file stored therein is read and
      58              :      *  the network definition stored therein is stored within the given network
      59              :      *  builder.
      60              :      *
      61              :      * If the option "opendrive-files" is not set, this method simply returns.
      62              :      *
      63              :      * The loading is done by parsing the network definition as an XML file
      64              :      *  using the SAXinterface and handling the incoming data via this class'
      65              :      *  methods.
      66              :      *
      67              :      * @param[in] oc The options to use
      68              :      * @param[in] nb The network builder to fill
      69              :      */
      70              :     static void loadNetwork(const OptionsCont& oc, NBNetBuilder& nb);
      71              : 
      72              : 
      73              : protected:
      74              : 
      75              :     /**
      76              :      * @enum OpenDriveXMLTag
      77              :      * @brief Numbers representing openDrive-XML - element names
      78              :      * @see GenericSAXHandler
      79              :      */
      80              :     enum OpenDriveXMLTag {
      81              :         OPENDRIVE_TAG_NOTHING,
      82              :         OPENDRIVE_TAG_HEADER,
      83              :         OPENDRIVE_TAG_ROAD,
      84              :         OPENDRIVE_TAG_PREDECESSOR,
      85              :         OPENDRIVE_TAG_SUCCESSOR,
      86              :         /// @todo OPENDRIVE_TAG_NEIGHBOR,
      87              :         /// @todo OPENDRIVE_TAG_TYPE,
      88              :         OPENDRIVE_TAG_GEOMETRY,
      89              :         OPENDRIVE_TAG_LINE,
      90              :         OPENDRIVE_TAG_SPIRAL,
      91              :         OPENDRIVE_TAG_ARC,
      92              :         OPENDRIVE_TAG_POLY3,
      93              :         OPENDRIVE_TAG_PARAMPOLY3,
      94              :         OPENDRIVE_TAG_LANESECTION,
      95              :         OPENDRIVE_TAG_LANEOFFSET,
      96              :         OPENDRIVE_TAG_ACCESS,
      97              :         OPENDRIVE_TAG_LEFT,
      98              :         OPENDRIVE_TAG_CENTER,
      99              :         OPENDRIVE_TAG_RIGHT,
     100              :         OPENDRIVE_TAG_LANE,
     101              :         OPENDRIVE_TAG_SIGNAL,
     102              :         OPENDRIVE_TAG_SIGNALREFERENCE,
     103              :         OPENDRIVE_TAG_CONTROLLER,
     104              :         OPENDRIVE_TAG_CONTROL,
     105              :         OPENDRIVE_TAG_VALIDITY,
     106              :         OPENDRIVE_TAG_JUNCTION,
     107              :         OPENDRIVE_TAG_CONNECTION,
     108              :         OPENDRIVE_TAG_LANELINK,
     109              :         OPENDRIVE_TAG_WIDTH,
     110              :         OPENDRIVE_TAG_SPEED,
     111              :         OPENDRIVE_TAG_ELEVATION,
     112              :         OPENDRIVE_TAG_GEOREFERENCE,
     113              :         OPENDRIVE_TAG_OFFSET,
     114              :         OPENDRIVE_TAG_OBJECT,
     115              :         OPENDRIVE_TAG_REPEAT,
     116              :         OPENDRIVE_TAG_INCLUDE
     117              :     };
     118              : 
     119              : 
     120              :     /**
     121              :      * @enum OpenDriveXMLAttr
     122              :      * @brief Numbers representing openDrive-XML - attributes
     123              :      * @see GenericSAXHandler
     124              :      */
     125              :     enum OpenDriveXMLAttr {
     126              :         OPENDRIVE_ATTR_NOTHING,
     127              :         OPENDRIVE_ATTR_REVMAJOR,
     128              :         OPENDRIVE_ATTR_REVMINOR,
     129              :         OPENDRIVE_ATTR_ID,
     130              :         OPENDRIVE_ATTR_LENGTH,
     131              :         OPENDRIVE_ATTR_WIDTH,
     132              :         OPENDRIVE_ATTR_RADIUS,
     133              :         OPENDRIVE_ATTR_DISTANCE,
     134              :         OPENDRIVE_ATTR_TSTART,
     135              :         OPENDRIVE_ATTR_TEND,
     136              :         OPENDRIVE_ATTR_WIDTHSTART,
     137              :         OPENDRIVE_ATTR_WIDTHEND,
     138              :         OPENDRIVE_ATTR_JUNCTION,
     139              :         OPENDRIVE_ATTR_ELEMENTTYPE,
     140              :         OPENDRIVE_ATTR_ELEMENTID,
     141              :         OPENDRIVE_ATTR_CONTACTPOINT,
     142              :         OPENDRIVE_ATTR_S,
     143              :         OPENDRIVE_ATTR_T,
     144              :         OPENDRIVE_ATTR_X,
     145              :         OPENDRIVE_ATTR_Y,
     146              :         OPENDRIVE_ATTR_Z,
     147              :         OPENDRIVE_ATTR_HDG,
     148              :         OPENDRIVE_ATTR_CURVSTART,
     149              :         OPENDRIVE_ATTR_CURVEND,
     150              :         OPENDRIVE_ATTR_CURVATURE,
     151              :         OPENDRIVE_ATTR_A,
     152              :         OPENDRIVE_ATTR_B,
     153              :         OPENDRIVE_ATTR_C,
     154              :         OPENDRIVE_ATTR_D,
     155              :         OPENDRIVE_ATTR_AU,
     156              :         OPENDRIVE_ATTR_BU,
     157              :         OPENDRIVE_ATTR_CU,
     158              :         OPENDRIVE_ATTR_DU,
     159              :         OPENDRIVE_ATTR_AV,
     160              :         OPENDRIVE_ATTR_BV,
     161              :         OPENDRIVE_ATTR_CV,
     162              :         OPENDRIVE_ATTR_DV,
     163              :         OPENDRIVE_ATTR_PRANGE,
     164              :         OPENDRIVE_ATTR_TYPE,
     165              :         OPENDRIVE_ATTR_LEVEL,
     166              :         OPENDRIVE_ATTR_ORIENTATION,
     167              :         OPENDRIVE_ATTR_DYNAMIC,
     168              :         OPENDRIVE_ATTR_INCOMINGROAD,
     169              :         OPENDRIVE_ATTR_CONNECTINGROAD,
     170              :         OPENDRIVE_ATTR_FROM,
     171              :         OPENDRIVE_ATTR_TO,
     172              :         OPENDRIVE_ATTR_FROMLANE,
     173              :         OPENDRIVE_ATTR_TOLANE,
     174              :         OPENDRIVE_ATTR_MAX,
     175              :         OPENDRIVE_ATTR_SOFFSET,
     176              :         OPENDRIVE_ATTR_RULE,
     177              :         OPENDRIVE_ATTR_RESTRICTION,
     178              :         OPENDRIVE_ATTR_NAME,
     179              :         OPENDRIVE_ATTR_UNIT,    // xodr v1.4
     180              :         OPENDRIVE_ATTR_SIGNALID,
     181              :         OPENDRIVE_ATTR_FILE
     182              :     };
     183              : 
     184              : 
     185              :     /** @brief OpenDrive link type enumeration
     186              :      */
     187              :     enum LinkType {
     188              :         OPENDRIVE_LT_SUCCESSOR,
     189              :         OPENDRIVE_LT_PREDECESSOR
     190              :     };
     191              : 
     192              : 
     193              :     /** @brief OpenDrive element type enumeration
     194              :      */
     195              :     enum ElementType {
     196              :         OPENDRIVE_ET_UNKNOWN,
     197              :         OPENDRIVE_ET_ROAD,
     198              :         OPENDRIVE_ET_JUNCTION
     199              :     };
     200              : 
     201              : 
     202              :     /** @brief OpenDrive contact type enumeration
     203              :      */
     204              :     enum ContactPoint {
     205              :         OPENDRIVE_CP_UNKNOWN,
     206              :         OPENDRIVE_CP_START,
     207              :         OPENDRIVE_CP_END
     208              :     };
     209              : 
     210              :     /** @brief OpenDrive geometry type enumeration
     211              :      */
     212              :     enum GeometryType {
     213              :         OPENDRIVE_GT_UNKNOWN,
     214              :         OPENDRIVE_GT_LINE,
     215              :         OPENDRIVE_GT_SPIRAL,
     216              :         OPENDRIVE_GT_ARC,
     217              :         OPENDRIVE_GT_POLY3,
     218              :         OPENDRIVE_GT_PARAMPOLY3 // rev 1.4
     219              :     };
     220              : 
     221              : 
     222              : 
     223              :     /**
     224              :      * @struct OpenDriveLink
     225              :      * @brief Representation of an OpenDrive link
     226              :      */
     227         5702 :     struct OpenDriveLink {
     228              :         /** @brief Constructor
     229              :          * @param[in] linkTypeArg The link type
     230              :          * @param[in] elementIDArg The element id
     231              :          */
     232              :         OpenDriveLink(LinkType linkTypeArg, const std::string& elementIDArg)
     233         1632 :             : linkType(linkTypeArg), elementID(elementIDArg),
     234         1632 :               elementType(OPENDRIVE_ET_UNKNOWN), contactPoint(OPENDRIVE_CP_UNKNOWN) { }
     235              : 
     236              :         LinkType linkType;
     237              :         std::string elementID;
     238              :         ElementType elementType;
     239              :         ContactPoint contactPoint;
     240              :     };
     241              : 
     242              : 
     243              :     /**
     244              :      * @struct OpenDriveGeometry
     245              :      * @brief Representation of an OpenDrive geometry part
     246              :      */
     247         6822 :     struct OpenDriveGeometry {
     248              :         /** @brief Constructor
     249              :          * @param[in] lengthArg The length of this geometry part
     250              :          * @param[in] sArg The offset from the start, counted from the begin
     251              :          * @param[in] xArg x-position at this part's begin
     252              :          * @param[in] yArg y-position at this part's begin
     253              :          * @param[in] hdgArg heading at this part's begin
     254              :          */
     255              :         OpenDriveGeometry(double lengthArg, double sArg, double xArg, double yArg, double hdgArg)
     256         1246 :             : length(lengthArg), s(sArg), x(xArg), y(yArg), hdg(hdgArg),
     257         1246 :               type(OPENDRIVE_GT_UNKNOWN) { }
     258              : 
     259              :         double length;
     260              :         double s;
     261              :         double x;
     262              :         double y;
     263              :         double hdg;
     264              :         GeometryType type;
     265              :         std::vector<double> params;
     266              :     };
     267              : 
     268              :     /**
     269              :      * @struct OpenDriveElevation
     270              :      * @brief Coefficients of an elevation profile (3rd degree polynomial)
     271              :      */
     272              :     struct Poly3 {
     273              :         /** @brief Constructor
     274              :          * @param[in] s The start offset
     275              :          * @param[in] a constant
     276              :          * @param[in] b first order
     277              :          * @param[in] c second order
     278              :          * @param[in] d third order
     279              :          */
     280         2900 :         Poly3(double _s, double _a, double _b, double _c, double _d) :
     281         2900 :             s(_s), a(_a), b(_b), c(_c), d(_d) {}
     282              : 
     283              :         double computeAt(double pos) const {
     284        17741 :             const double ds = pos - s;
     285        17741 :             return a + b * ds + c * ds * ds + d * ds * ds * ds;
     286              :         }
     287              : 
     288              :         double s;
     289              :         double a;
     290              :         double b;
     291              :         double c;
     292              :         double d;
     293              :     };
     294              : 
     295              :     /// LaneOffset has the same fields as Elevation
     296              :     typedef Poly3 OpenDriveElevation;
     297              :     typedef Poly3 OpenDriveLaneOffset;
     298              :     typedef Poly3 OpenDriveWidth;
     299              : 
     300              :     /**
     301              :      * @struct LaneAttributeChange
     302              :      * @brief Attribute set applied at a certain position along a lane
     303              :      */
     304         6328 :     struct LaneAttributeChange {
     305              :         /** @brief Constructor
     306              :          * @param[in] speed The lane speed
     307              :          */
     308          830 :         LaneAttributeChange(double speed) : speed(speed) {}
     309              : 
     310              :         double speed;
     311              :         std::vector<std::string> allowed;
     312              :         std::vector<std::string> denied;
     313              :     };
     314              : 
     315              : 
     316              : 
     317              :     /**
     318              :      * @struct OpenDriveLane
     319              :      * @brief Representation of a lane
     320              :      */
     321              :     struct OpenDriveLane {
     322              :         /** @brief Constructor
     323              :          * @param[in] idArg The OpenDrive id of the lane
     324              :          * @param[in] levelArg The level
     325              :          * @param[in] typeArg type of the lane
     326              :          */
     327         2653 :         OpenDriveLane(int idArg, const std::string& levelArg, const std::string& typeArg) :
     328         5306 :             id(idArg), level(levelArg), type(typeArg), successor(UNSET_CONNECTION), predecessor(UNSET_CONNECTION),
     329         2653 :             speed(0), width(NBEdge::UNSPECIFIED_WIDTH), permission(0) { }
     330              : 
     331              :         /// @brief compute the actual SUMO lane permissions given the lane type as a start solution
     332              :         SVCPermissions computePermission(const NBTypeCont& tc, const std::vector<std::string>& allowed, const std::vector<std::string>& denied) const;
     333              : 
     334              :         int id; //!< The lane's id
     335              :         std::string level; //!< The lane's level (not used)
     336              :         std::string type; //!< The lane's type
     337              :         int successor; //!< The lane's successor lane
     338              :         int predecessor; //!< The lane's predecessor lane
     339              :         std::vector < std::pair<double, LaneAttributeChange> > attributeChanges; //!< List of permission and speed changes
     340              :         double speed; //!< The lane's speed (set in post-processing)
     341              :         double width; //The lane's maximum width
     342              :         SVCPermissions permission; //!< The access permissions (set in post-processing)
     343              :         std::vector<OpenDriveWidth> widthData;
     344              :     };
     345              : 
     346              : 
     347              :     /**
     348              :      * @struct OpenDriveLaneSection
     349              :      * @brief Representation of a lane section
     350              :      */
     351              :     struct OpenDriveLaneSection {
     352              :         /** @brief Constructor
     353              :          * @param[in] sArg The offset from the start, counted from the begin
     354              :          */
     355              :         OpenDriveLaneSection(double sArg);
     356              : 
     357              : 
     358              :         /** @brief Build the mapping from OpenDrive to SUMO lanes
     359              :          *
     360              :          * Not all lanes are converted to SUMO-lanes; the mapping includes only those
     361              :          * which are included in the SUMO network.
     362              :          * @param[in] tc The type container needed to determine whether a lane shall be imported by using the lane's type
     363              :          */
     364              :         void buildLaneMapping(const NBTypeCont& tc);
     365              : 
     366              : 
     367              :         /** @brief Returns the links from the previous to this lane section
     368              :          * @param[in] dir The OpenDrive-direction of drive
     369              :          * @param[in] pre The previous lane section
     370              :          * @return which lane is approached from which lane of the given previous lane section
     371              :          */
     372              :         std::map<int, int> getInnerConnections(OpenDriveXMLTag dir, const OpenDriveLaneSection& prev);
     373              : 
     374              : 
     375              :         bool buildAttributeChanges(const NBTypeCont& tc, std::vector<OpenDriveLaneSection>& newSections);
     376              :         OpenDriveLaneSection buildLaneSection(const NBTypeCont& tc, double startPos);
     377              :         /// @brief The starting offset of this lane section
     378              :         double s;
     379              :         /// @brief The original starting offset of this lane section (differs from s if the section had to be split)
     380              :         double sOrig;
     381              :         /// @brief The length of this lane section
     382              :         double length;
     383              :         /// @brief A mapping from OpenDrive to SUMO-index (the first is signed, the second unsigned)
     384              :         std::map<int, int> laneMap;
     385              :         /// @brief The lanes, sorted by their direction
     386              :         std::map<OpenDriveXMLTag, std::vector<OpenDriveLane> > lanesByDir;
     387              :         /// @brief The id (generic, without the optionally leading '-') of the edge generated for this section
     388              :         std::string sumoID;
     389              :         /// @brief The number of lanes on the right and on the left side, respectively
     390              :         int rightLaneNumber, leftLaneNumber;
     391              :         /// @brief the composite type built from all used lane types
     392              :         std::string rightType;
     393              :         std::string leftType;
     394              :         /// @brief average width of removed inside lanes
     395              :         double discardedInnerWidthLeft;
     396              :         double discardedInnerWidthRight;
     397              :     };
     398              : 
     399              : 
     400              : 
     401              :     /**
     402              :      * @struct OpenDriveSignal
     403              :      * @brief Representation of a signal
     404              :      */
     405              :     struct OpenDriveSignal {
     406              :         /** @brief Constructor
     407              :          * @param[in] idArg The OpenDrive id of the signal
     408              :          * @param[in] typeArg The type of the signal
     409              :          * @param[in] nameArg The type of the signal
     410              :          * @param[in] orientationArg The direction the signal belongs to
     411              :          * @param[in] dynamicArg Whether the signal is dynamic
     412              :          * @param[in] sArg The offset from the start, counted from the begin
     413              :          */
     414           25 :         OpenDriveSignal(const std::string& idArg, const std::string typeArg, const std::string nameArg,
     415           25 :                         int orientationArg, bool dynamicArg, double sArg) :
     416           50 :             id(idArg), type(typeArg), name(nameArg),
     417           25 :             orientation(orientationArg), dynamic(dynamicArg), s(sArg),
     418           25 :             minLane(-UNSET_LANEVALIDITY), maxLane(UNSET_LANEVALIDITY)
     419           25 :         { }
     420              : 
     421              :         /// dummy constructor for use in maps
     422           25 :         OpenDriveSignal() {}
     423              : 
     424              :         std::string id;
     425              :         std::string type;
     426              :         std::string name;
     427              :         int orientation;
     428              :         bool dynamic;
     429              :         double s;
     430              :         /// @brief signal validity range
     431              :         int minLane;
     432              :         int maxLane;
     433              :         /// @brief the controller ID
     434              :         std::string controller;
     435              :     };
     436              : 
     437              : 
     438              :     /**
     439              :      * @struct OpenDriveController
     440              :      * @brief Representation of a signal group
     441              :      */
     442              :     struct OpenDriveController {
     443              :         /** @brief Constructor
     444              :          * @param[in] idArg The OpenDrive id of the signal group
     445              :          * @param[in] nameArg The type of the signal group
     446              :          */
     447         1948 :         OpenDriveController(const std::string& idArg, const std::string nameArg) :
     448         3896 :             id(idArg), name(nameArg) { }
     449              : 
     450              :         /// dummy constructor for use in maps
     451            0 :         OpenDriveController() {}
     452              : 
     453              :         std::string id;
     454              :         std::string name;
     455              :         std::vector<std::string> signalIDs;
     456              :         std::string junction;
     457              :     };
     458              : 
     459              :     /**
     460              :      * @struct Connection
     461              :      * @brief A connection between two roads
     462              :      */
     463              :     struct Connection {
     464              :         std::string fromEdge;
     465              :         std::string toEdge;
     466              :         int fromLane;
     467              :         int toLane;
     468              :         ContactPoint fromCP;
     469              :         ContactPoint toCP;
     470              :         bool all;
     471              :         std::string origID;
     472              :         int origLane;
     473              :         PositionVector shape;
     474              : 
     475              :         std::string getDescription() const {
     476              :             return "Connection from=" + fromEdge + "_" + toString(fromLane)
     477              :                    + " to=" + toEdge + "_" + toString(toLane)
     478              :                    + " fromCP=" + (fromCP == OPENDRIVE_CP_START ? "start" : fromCP == OPENDRIVE_CP_END ? "end" : "unknown")
     479              :                    + " toCP=" + (toCP == OPENDRIVE_CP_START ? "start" : toCP == OPENDRIVE_CP_END ? "end" : "unknown")
     480              :                    + " all=" + toString(all);
     481              :             //+ " origID=" + origID + " origLane=" + toString(origLane);
     482              :         }
     483              :     };
     484              : 
     485              :     /**
     486              :      * @struct Object
     487              :      * @brief A road object (e.g. parkingSpace)
     488              :      */
     489              :     struct OpenDriveObject {
     490              :         std::string type;
     491              :         std::string name;
     492              :         std::string id;
     493              :         double s;
     494              :         double t;
     495              :         double zOffset;
     496              :         double length;
     497              :         double width;
     498              :         double height;
     499              :         double radius;
     500              :         double hdg;
     501              :         double pitch;
     502              :         double roll;
     503              :     };
     504              : 
     505              :     /**
     506              :      * @struct OpenDriveEdge
     507              :      * @brief Representation of an openDrive "link"
     508              :      */
     509              :     struct OpenDriveEdge {
     510          877 :         OpenDriveEdge(const std::string& idArg, const std::string& streetNameArg, const std::string& junctionArg, double lengthArg) :
     511          877 :             id(idArg),
     512          877 :             streetName(streetNameArg),
     513          877 :             junction(junctionArg),
     514          877 :             length(lengthArg),
     515          877 :             from(0),
     516          877 :             to(0) {
     517          877 :             isInner = junction != "" && junction != "-1";
     518          877 :         }
     519              : 
     520              : 
     521              :         /** @brief Returns the edge's priority, regarding the direction
     522              :          *
     523              :          * The priority is determined by evaluating the signs located at the road
     524              :          * @param[in] dir The direction which priority shall be returned
     525              :          * @return The priority of the given direction
     526              :          */
     527              :         int getPriority(OpenDriveXMLTag dir) const;
     528              : 
     529              : 
     530              :         /// @brief The id of the edge
     531              :         std::string id;
     532              :         /// @brief The road name of the edge
     533              :         std::string streetName;
     534              :         /// @brief The id of the junction the edge belongs to
     535              :         std::string junction;
     536              :         /// @brief The length of the edge
     537              :         double length;
     538              :         std::vector<OpenDriveLink> links;
     539              :         std::vector<OpenDriveGeometry> geometries;
     540              :         std::vector<OpenDriveElevation> elevations;
     541              :         std::vector<OpenDriveLaneOffset> offsets;
     542              :         NBNode* from;
     543              :         NBNode* to;
     544              :         PositionVector geom;
     545              :         std::vector<double> laneOffsets;
     546              :         std::vector<OpenDriveLaneSection> laneSections;
     547              :         std::vector<OpenDriveSignal> signals;
     548              :         std::set<Connection> connections;
     549              :         std::vector<OpenDriveObject> objects;
     550              :         bool isInner;
     551              :     };
     552              : 
     553              : 
     554              :     /** @brief A class for sorting lane sections by their s-value */
     555              :     class sections_by_s_sorter {
     556              :     public:
     557              :         /// @brief Constructor
     558              :         explicit sections_by_s_sorter() { }
     559              : 
     560              :         /// @brief Sorting function; compares OpenDriveLaneSection::s
     561              :         int operator()(const OpenDriveLaneSection& ls1, const OpenDriveLaneSection& ls2) {
     562            0 :             return ls1.s < ls2.s;
     563              :         }
     564              :     };
     565              : 
     566              :     /* @brief A class for search in position/attribute change tuple vectors for the given position */
     567              :     class same_position_finder {
     568              :     public:
     569              :         /** @brief constructor */
     570          834 :         explicit same_position_finder(double pos) : myPosition(pos) { }
     571              : 
     572              :         /** @brief the comparing function */
     573              :         bool operator()(const std::pair<double, LaneAttributeChange>& ps) {
     574            8 :             return ps.first == myPosition;
     575              :         }
     576              : 
     577              :     private:
     578              :         /// @brief The position to search for
     579              :         double myPosition;
     580              : 
     581              :     };
     582              : 
     583              : protected:
     584              :     /** @brief Constructor
     585              :      * @param[in] tc The type container used to determine whether a lane shall kept
     586              :      * @param[in] nc The edge map to fill
     587              :      */
     588              :     NIImporter_OpenDrive(const NBTypeCont& tc, std::map<std::string, OpenDriveEdge*>& edges);
     589              : 
     590              : 
     591              :     /// @brief Destructor
     592              :     ~NIImporter_OpenDrive();
     593              : 
     594              : 
     595              : 
     596              :     /// @name inherited from GenericSAXHandler
     597              :     //@{
     598              : 
     599              :     /** @brief Called on the opening of a tag;
     600              :      *
     601              :      * In dependence to the obtained type, an appropriate parsing
     602              :      *  method is called ("addEdge" if an edge encounters, f.e.).
     603              :      *
     604              :      * @param[in] element ID of the currently opened element
     605              :      * @param[in] attrs Attributes within the currently opened element
     606              :      * @exception ProcessError If something fails
     607              :      * @see GenericSAXHandler::myStartElement
     608              :      */
     609              :     void myStartElement(int element, const SUMOSAXAttributes& attrs);
     610              : 
     611              :     /**
     612              :      * @brief Callback method for characters to implement by derived classes
     613              :      *
     614              :      * Called by "endElement" (see there).
     615              :      * @param[in] element The opened element, given as a int
     616              :      * @param[in] chars The complete embedded character string
     617              :      * @exceptions ProcessError These method may throw a ProcessError if something fails
     618              :      */
     619              :     void myCharacters(int element, const std::string& chars);
     620              : 
     621              : 
     622              :     /** @brief Called when a closing tag occurs
     623              :      *
     624              :      * @param[in] element ID of the currently opened element
     625              :      * @exception ProcessError If something fails
     626              :      * @see GenericSAXHandler::myEndElement
     627              :      */
     628              :     void myEndElement(int element);
     629              :     //@}
     630              : 
     631              :     std::map<std::string, OpenDriveSignal>& getSignals() {
     632              :         return mySignals;
     633              :     }
     634              : 
     635              :     std::map<std::string, OpenDriveController>& getControllers() {
     636              :         return myControllers;
     637              :     }
     638              : 
     639              :     std::map<std::string, std::vector<std::string>>& getJunctions2Controllers() {
     640              :         return myJunctions2Controllers;
     641              :     }
     642              : 
     643            0 :     const OpenDriveController& getController(std::string signalID) {
     644            0 :         if (mySignals.find(signalID) != mySignals.end() && myControllers.find(mySignals[signalID].controller) != myControllers.end()) {
     645            0 :             return myControllers[mySignals[signalID].controller];
     646              :         }
     647              :         return myDummyController;
     648              :     }
     649              : 
     650            0 :     int getTLIndexForController(std::string controllerID) {
     651              :         // sort them by their id
     652            0 :         std::string junctionID = myControllers[controllerID].junction;
     653              :         std::vector<std::string> junctionControllers;
     654            0 :         for (auto& it : myControllers) {
     655            0 :             if (it.second.junction == junctionID) {
     656            0 :                 junctionControllers.push_back(it.first);
     657              :             }
     658              :         }
     659            0 :         std::sort(junctionControllers.begin(), junctionControllers.end());
     660            0 :         auto it = std::find(junctionControllers.begin(), junctionControllers.end(), controllerID);
     661            0 :         return (int)(it - junctionControllers.begin());
     662            0 :     }
     663              : 
     664              : 
     665              : private:
     666              :     void addLink(LinkType lt, const std::string& elementType, const std::string& elementID,
     667              :                  const std::string& contactPoint);
     668              :     void addGeometryShape(GeometryType type, const std::vector<double>& vals);
     669              :     static void setEdgeLinks2(OpenDriveEdge& e, const std::map<std::string, OpenDriveEdge*>& edges);
     670              :     static void buildConnectionsToOuter(const Connection& c,
     671              :                                         const std::map<std::string, OpenDriveEdge*>& innerEdges,
     672              :                                         const std::map<std::string, OpenDriveEdge*>& edges,
     673              :                                         const NBTypeCont& tc,
     674              :                                         std::vector<Connection>& into, std::set<Connection>& seen);
     675              :     static bool laneSectionsConnected(OpenDriveEdge* edge, int in, int out);
     676              :     friend bool operator<(const Connection& c1, const Connection& c2);
     677              :     static std::string revertID(const std::string& id);
     678              :     const NBTypeCont& myTypeContainer;
     679              :     OpenDriveEdge myCurrentEdge;
     680              :     OpenDriveController myCurrentController;
     681              : 
     682              :     std::map<std::string, OpenDriveEdge*>& myEdges;
     683              :     std::vector<int> myElementStack;
     684              :     OpenDriveXMLTag myCurrentLaneDirection;
     685              :     std::string myCurrentJunctionID;
     686              :     std::string myCurrentIncomingRoad;
     687              :     std::string myCurrentConnectingRoad;
     688              :     ContactPoint myCurrentContactPoint;
     689              :     bool myConnectionWasEmpty;
     690              :     std::map<std::string, OpenDriveSignal> mySignals;
     691              :     std::map<std::string, OpenDriveController> myControllers;
     692              :     std::map<std::string, std::vector<std::string>> myJunctions2Controllers;
     693              :     Position myOffset;
     694              :     bool myUseCurrentNode;
     695              : 
     696              :     static bool myImportAllTypes;
     697              :     static bool myImportWidths;
     698              :     static double myMinWidth;
     699              :     static bool myImportInternalShapes;
     700              :     static bool myIgnoreMisplacedSignals;
     701              :     static OpenDriveController myDummyController;
     702              : 
     703              : 
     704              : protected:
     705              :     /** @brief Builds a node or returns the already built
     706              :      *
     707              :      * If the node is already known, it is returned. Otherwise, the
     708              :      *  node is built. If the newly built node can not be added to
     709              :      *  the container, a ProcessError is thrown.
     710              :      *  Otherwise this node is returned.
     711              :      *
     712              :      * @param[in] id The id of the node to build/get
     713              :      * @param[in, changed] pos The position of the node to build/get
     714              :      * @param[filled] nc The node container to retrieve/add the node to
     715              :      * @return The retrieved/built node
     716              :      * @exception ProcessError If the node could not be built/retrieved
     717              :      */
     718              :     static NBNode* getOrBuildNode(const std::string& id, const Position& pos, NBNodeCont& nc);
     719              : 
     720              : 
     721              :     static PositionVector geomFromLine(const OpenDriveEdge& e, const OpenDriveGeometry& g, double resolution);
     722              :     static PositionVector geomFromSpiral(const OpenDriveEdge& e, const OpenDriveGeometry& g, double resolution);
     723              :     static PositionVector geomFromArc(const OpenDriveEdge& e, const OpenDriveGeometry& g, double resolution);
     724              :     static PositionVector geomFromPoly(const OpenDriveEdge& e, const OpenDriveGeometry& g, double resolution);
     725              :     static PositionVector geomFromParamPoly(const OpenDriveEdge& e, const OpenDriveGeometry& g, double resolution);
     726              :     static Position calculateStraightEndPoint(double hdg, double length, const Position& start);
     727              :     static void calculateCurveCenter(double* ad_x, double* ad_y, double ad_radius, double ad_hdg);
     728              :     static void calcPointOnCurve(double* ad_x, double* ad_y, double ad_centerX, double ad_centerY,
     729              :                                  double ad_r, double ad_length);
     730              : 
     731              : 
     732              :     /** @brief Computes a polygon representation of each edge's geometry
     733              :      * @param[in] edges The edges which geometries shall be converted
     734              :      */
     735              :     static void computeShapes(std::map<std::string, OpenDriveEdge*>& edges);
     736              : 
     737              :     static bool hasNonLinearElevation(const OpenDriveEdge& e);
     738              : 
     739              :     /// transform Poly3 into a list of offsets, adding intermediate points to geom if needed
     740              :     static std::vector<double> discretizeOffsets(PositionVector& geom, const std::vector<OpenDriveLaneOffset>& offsets, const std::string& id);
     741              : 
     742              :     static void addOffsets(bool left, PositionVector& geom, const std::vector<OpenDriveLaneOffset>& offsets, const std::string& id, std::vector<double>& result);
     743              : 
     744              :     /** @brief Rechecks lane sections of the given edges
     745              :      *
     746              :      *
     747              :      * @param[in] edges The edges which lane sections shall be reviewed
     748              :      */
     749              :     static void revisitLaneSections(const NBTypeCont& tc, std::map<std::string, OpenDriveEdge*>& edges);
     750              : 
     751              :     static void setNodeSecure(NBNodeCont& nc, OpenDriveEdge& e,
     752              :                               const std::string& nodeID, NIImporter_OpenDrive::LinkType lt, std::vector<NodeSet>& joinedNodeIDs);
     753              : 
     754              :     static NBTrafficLightDefinition* getTLSSecure(NBEdge* inEdge, /*const NBEdge::Connection& conn,*/ NBNetBuilder& nb);
     755              : 
     756              : 
     757              :     static std::pair<NBEdge*, NBEdge*> retrieveSignalEdges(NBNetBuilder& nb, const std::string& fromID, const std::string& toID, const std::string& junction);
     758              : 
     759              :     static void splitMinWidths(OpenDriveEdge* e, const NBTypeCont& tc, double minDist);
     760              : 
     761              :     static void findWidthSplit(const NBTypeCont& tc, std::vector<OpenDriveLane>& lanes,
     762              :                                int section, double sectionStart, double sectionEnd,
     763              :                                std::vector<double>& splitPositions);
     764              : 
     765              :     static void sanitizeWidths(OpenDriveEdge* e);
     766              :     static void sanitizeWidths(std::vector<OpenDriveLane>& lanes, double length);
     767              : 
     768              :     static void setStraightConnections(std::vector<OpenDriveLane>& lanes);
     769              :     static void recomputeWidths(OpenDriveLaneSection& sec, double start, double end, double sectionStart, double sectionEnd);
     770              :     static void recomputeWidths(std::vector<OpenDriveLane>& lanes, double start, double end, double sectionStart, double sectionEnd);
     771              :     static void setLaneAttributes(const OpenDriveEdge* e, NBEdge::Lane& sumoLane, const OpenDriveLane& odLane, bool saveOrigIDs, const NBTypeCont& tc);
     772              :     static void writeRoadObjects(const OpenDriveEdge* e);
     773              : 
     774              :     /// The names of openDrive-XML elements (for passing to GenericSAXHandler)
     775              :     static SequentialStringBijection::Entry openDriveTags[];
     776              : 
     777              :     /// The names of openDrive-XML attributes (for passing to GenericSAXHandler)
     778              :     static SequentialStringBijection::Entry openDriveAttrs[];
     779              : 
     780              :     class LaneSorter {
     781              :     public:
     782              :         /// constructor
     783              :         explicit LaneSorter() {}
     784              : 
     785              :         /// comparing operation
     786              :         int operator()(const OpenDriveLane& a, const OpenDriveLane& b) const {
     787              :             // sort from the reference line outwards (desceding order of sumo lane ids)
     788          828 :             return abs(a.id) < abs(b.id);
     789              :         }
     790              : 
     791              :     };
     792              : 
     793              : };
        

Generated by: LCOV version 2.0-1