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