Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netwrite/NWWriter_OpenDrive.h
169666 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 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 NWWriter_OpenDrive.h
15
/// @author Daniel Krajzewicz
16
/// @date Tue, 04.05.2011
17
///
18
// Exporter writing networks using the openDRIVE format
19
/****************************************************************************/
20
#pragma once
21
#include <config.h>
22
23
#include <utils/common/StringBijection.h>
24
#include <utils/common/SUMOVehicleClass.h>
25
#include <netbuild/NBEdge.h>
26
27
28
// ===========================================================================
29
// class declarations
30
// ===========================================================================
31
class NBNetBuilder;
32
class NBEdge;
33
class OptionsCont;
34
class PositionVector;
35
class OutputDevice;
36
class OutputDevice_String;
37
class ShapeContainer;
38
class PointOfInterest;
39
class SUMOPolygon;
40
41
42
// ===========================================================================
43
// class definitions
44
// ===========================================================================
45
/**
46
* @class NWWriter_OpenDrive
47
* @brief Exporter writing networks using the openDRIVE format
48
*
49
*/
50
class NWWriter_OpenDrive {
51
public:
52
/** @brief Writes the network into a openDRIVE-file
53
*
54
* @param[in] oc The options to use
55
* @param[in] nb The network builder to fill
56
*/
57
static void writeNetwork(const OptionsCont& oc, NBNetBuilder& nb);
58
59
protected:
60
/// @brief signalID -> (lanes, dirs)
61
typedef std::map<std::string, std::pair<std::set<int>, std::set<LinkDirection> > > SignalLanes;
62
63
/// @brief retrieve divider type
64
static std::string getDividerType(const NBEdge* e);
65
66
/// @brief write normal edge to device
67
static void writeNormalEdge(OutputDevice& device, const NBEdge* e,
68
int edgeID, int fromNodeID, int toNodeID,
69
const bool origNames,
70
const double straightThresh,
71
const ShapeContainer& shc,
72
SignalLanes& signalLanes,
73
const std::vector<std::string>& crossings);
74
75
/// @brief write internal edge to device, return next connectionID
76
static int writeInternalEdge(OutputDevice& device, OutputDevice& junctionDevice,
77
const NBEdge* inEdge, int nodeID,
78
int edgeID, int inEdgeID, int outEdgeID,
79
int connectionID,
80
const std::vector<NBEdge::Connection>& parallel,
81
const bool isOuterEdge,
82
const double straightThresh,
83
const std::string& centerMark,
84
SignalLanes& signalLanes);
85
86
static void addPedestrianConnection(const NBEdge* inEdge, const NBEdge* outEdge, std::vector<NBEdge::Connection>& parallel);
87
88
/// @brief write geometry as sequence of lines (sumo style)
89
static double writeGeomLines(const PositionVector& shape, OutputDevice& device, OutputDevice& elevationDevice, double offset = 0);
90
91
/* @brief write geometry as sequence of lines and bezier curves
92
*
93
* @param[in] straightThresh angular changes below threshold are considered to be straight and no curve will be fitted between the segments
94
* @param[out] length Return the total length of the reference line
95
*/
96
static bool writeGeomSmooth(const PositionVector& shape, double speed, OutputDevice& device, OutputDevice& elevationDevice, double straightThresh, double& length);
97
98
/// @brief write geometry as a single bezier curve (paramPoly3)
99
static double writeGeomPP3(OutputDevice& device,
100
OutputDevice& elevationDevice,
101
PositionVector init,
102
double length,
103
double offset = 0);
104
105
static void writeElevationProfile(const PositionVector& shape, OutputDevice& device, const OutputDevice_String& elevationDevice);
106
107
static void writeEmptyCenterLane(OutputDevice& device, const std::string& mark, double markWidth);
108
static int getID(const std::string& origID, StringBijection<int>& map, int& lastID);
109
110
static std::string getLaneType(SVCPermissions permissions);
111
112
/// @brief get the lane border that is closer to the reference line (center line of the edge)
113
static PositionVector getInnerLaneBorder(const NBEdge* edge, int laneIndex = -1, double widthOffset = 0);
114
/// @brief get the lane border that is further away from the reference line (center line of the edge)
115
static PositionVector getOuterLaneBorder(const NBEdge* edge, int laneIndex = -1);
116
117
/// @brief check if the lane geometries are compatible with OpenDRIVE assumptions (colinear stop line)
118
static void checkLaneGeometries(const NBEdge* e);
119
120
/// @brief write road objects referenced as edge parameters
121
static void writeRoadObjects(OutputDevice& device, const NBEdge* e, const ShapeContainer& shc, const std::vector<std::string>& crossings);
122
123
/// @brief write signal record for traffic light
124
static void writeSignals(OutputDevice& device, const NBEdge* e, double length, SignalLanes& signalLanes, const ShapeContainer& shc);
125
126
/// @brief convert sumo lane index to xodr lane index
127
static int s2x(int sumoIndex, int numLanes);
128
129
/// @brief map pois and polygons to the closes edge
130
static void mapmatchRoadObjects(const ShapeContainer& shc, const NBEdgeCont& ec);
131
132
static void writeRoadObjectPOI(OutputDevice& device, const NBEdge* e, const PositionVector& roadShape, const PointOfInterest* poi);
133
134
static void writeRoadObjectPoly(OutputDevice& device, const NBEdge* e, const PositionVector& roadShape, const SUMOPolygon* p);
135
136
struct TrafficSign {
137
std::string country;
138
std::string type;
139
std::string subtype;
140
std::string value;
141
};
142
143
static std::vector<TrafficSign> parseTrafficSign(const std::string& trafficSign, PointOfInterest* poi);
144
static TrafficSign parseTrafficSignId(const std::string& trafficSign);
145
146
// @brief return road postion in s,t coordinates
147
static double getRoadSideOffset(const NBEdge* e);
148
149
150
protected:
151
/// @brief whether a lefthand network is being written
152
static bool lefthand;
153
154
/* @brief whether a the lanes in a lefthand network shall be written to the
155
* left of the reference line (positive indices)
156
* This style is not support by some older programs.
157
* */
158
static bool LHLL;
159
160
// lefthand but lanes written as right lanes
161
static bool LHRL;
162
163
};
164
165