1 package org.opentrafficsim.road.network.factory.opendrive;
2
3 import java.io.Serializable;
4 import java.util.UUID;
5
6 import org.djunits.unit.AngleUnit;
7 import org.djunits.unit.LengthUnit;
8 import org.djunits.value.vdouble.scalar.Angle;
9 import org.djunits.value.vdouble.scalar.Direction;
10 import org.djunits.value.vdouble.scalar.Length;
11 import org.opentrafficsim.core.geometry.OTSLine3D;
12 import org.opentrafficsim.core.geometry.OTSPoint3D;
13 import org.opentrafficsim.core.network.Network;
14 import org.opentrafficsim.core.network.NetworkException;
15 import org.opentrafficsim.core.network.OTSNode;
16 import org.w3c.dom.NamedNodeMap;
17 import org.w3c.dom.Node;
18 import org.xml.sax.SAXException;
19
20
21
22
23
24
25
26
27
28
29
30 class GeometryTag implements Serializable
31 {
32
33
34 private static final long serialVersionUID = 20150723L;
35
36
37 @SuppressWarnings("checkstyle:visibilitymodifier")
38 String id = null;
39
40
41 @SuppressWarnings("checkstyle:visibilitymodifier")
42 Length s = null;
43
44
45 @SuppressWarnings("checkstyle:visibilitymodifier")
46 Length x = null;
47
48
49 @SuppressWarnings("checkstyle:visibilitymodifier")
50 Length y = null;
51
52
53 @SuppressWarnings("checkstyle:visibilitymodifier")
54 Length z = null;
55
56
57 @SuppressWarnings("checkstyle:visibilitymodifier")
58 Angle hdg = null;
59
60
61 @SuppressWarnings("checkstyle:visibilitymodifier")
62 Length length = null;
63
64
65 @SuppressWarnings("checkstyle:visibilitymodifier")
66 SpiralTag spiralTag = null;
67
68
69 @SuppressWarnings("checkstyle:visibilitymodifier")
70 ArcTag arcTag = null;
71
72
73 @SuppressWarnings("checkstyle:visibilitymodifier")
74 OTSNode node = null;
75
76 OTSLine3D interLine = null;
77
78
79
80
81
82
83
84
85 @SuppressWarnings("checkstyle:needbraces")
86 static GeometryTag parseGeometry(final Node node, final OpenDriveNetworkLaneParser parser) throws SAXException
87 {
88 NamedNodeMap attributes = node.getAttributes();
89 GeometryTag geometryTag = new GeometryTag();
90
91 Node s = attributes.getNamedItem("s");
92 if (s == null)
93 throw new SAXException("Geometry: missing attribute s");
94 geometryTag.s = new Length(Double.parseDouble(s.getNodeValue().trim()), LengthUnit.METER);
95
96 Node x = attributes.getNamedItem("x");
97 if (x == null)
98 throw new SAXException("Geometry: missing attribute x");
99 geometryTag.x = new Length(Double.parseDouble(x.getNodeValue().trim()), LengthUnit.METER);
100
101 Node y = attributes.getNamedItem("y");
102 if (y == null)
103 throw new SAXException("Geometry: missing attribute y");
104 geometryTag.y = new Length(Double.parseDouble(y.getNodeValue().trim()), LengthUnit.METER);
105
106 Node hdg = attributes.getNamedItem("hdg");
107 if (hdg == null)
108 throw new SAXException("Geometry: missing attribute hdg");
109 geometryTag.hdg = new Angle(Double.parseDouble(hdg.getNodeValue().trim()), AngleUnit.RADIAN);
110
111 Node length = attributes.getNamedItem("length");
112 if (length == null)
113 throw new SAXException("Geometry: missing attribute length");
114 geometryTag.length = new Length(Double.parseDouble(length.getNodeValue().trim()), LengthUnit.METER);
115
116 SpiralTag.parseSpiral(node.getChildNodes(), parser, geometryTag);
117
118 ArcTag.parseArc(node.getChildNodes(), parser, geometryTag);
119
120 return geometryTag;
121 }
122
123
124
125
126
127
128
129 static OTSNode makeOTSNode(final Network network, final GeometryTag geometryTag) throws NetworkException
130 {
131 Direction angle = Direction.ZERO;
132 Angle slope = Angle.ZERO;
133 OTSPoint3D coordinate =
134 new OTSPoint3D(geometryTag.x.doubleValue(), geometryTag.y.doubleValue(), geometryTag.z.doubleValue());
135
136 if (geometryTag.id == null)
137 {
138 geometryTag.id = UUID.randomUUID().toString();
139 }
140
141 OTSNode node = new OTSNode(network, geometryTag.id, coordinate, angle, slope);
142 geometryTag.node = node;
143 return node;
144 }
145
146
147 @Override
148 public final String toString()
149 {
150 return "GeometryTag [id=" + this.id + ", s=" + this.s + ", x=" + this.x + ", y=" + this.y + ", z=" + this.z + ", hdg="
151 + this.hdg + ", length=" + this.length + ", spiralTag=" + this.spiralTag + ", arcTag=" + this.arcTag + ", node="
152 + this.node + ", interLine=" + this.interLine + "]";
153 }
154 }