1 package org.opentrafficsim.road.network.factory.opendrive;
2
3 import java.io.Serializable;
4
5 import org.djunits.unit.LengthUnit;
6 import org.djunits.value.vdouble.scalar.Length;
7 import org.opentrafficsim.core.network.NetworkException;
8 import org.w3c.dom.NamedNodeMap;
9 import org.w3c.dom.Node;
10 import org.xml.sax.SAXException;
11
12
13
14
15
16
17
18
19
20
21 class ElevationTag implements Serializable
22 {
23
24 private static final long serialVersionUID = 20150723L;
25
26
27 @SuppressWarnings("checkstyle:visibilitymodifier")
28 Length s = null;
29
30
31 @SuppressWarnings("checkstyle:visibilitymodifier")
32 Length a = null;
33
34
35 @SuppressWarnings("checkstyle:visibilitymodifier")
36 Length b = null;
37
38
39 @SuppressWarnings("checkstyle:visibilitymodifier")
40 Length c = null;
41
42
43 @SuppressWarnings("checkstyle:visibilitymodifier")
44 Length d = null;
45
46
47 @SuppressWarnings("checkstyle:visibilitymodifier")
48 Length elevation = null;
49
50
51
52
53
54
55
56
57
58 @SuppressWarnings("checkstyle:needbraces")
59 static ElevationTag parseElevation(final Node node, final OpenDriveNetworkLaneParser parser)
60 throws SAXException, NetworkException
61 {
62 NamedNodeMap attributes = node.getAttributes();
63 ElevationTag elevationTag = new ElevationTag();
64
65 Node s = attributes.getNamedItem("s");
66 if (s == null)
67 throw new SAXException("Geometry: missing attribute s");
68 elevationTag.s = new Length(Double.parseDouble(s.getNodeValue().trim()), LengthUnit.METER);
69
70 Node a = attributes.getNamedItem("a");
71 if (a == null)
72 throw new SAXException("Geometry: missing attribute a");
73 elevationTag.a = new Length(Double.parseDouble(a.getNodeValue().trim()), LengthUnit.METER);
74
75 Node b = attributes.getNamedItem("b");
76 if (b == null)
77 throw new SAXException("Geometry: missing attribute b");
78 elevationTag.b = new Length(Double.parseDouble(b.getNodeValue().trim()), LengthUnit.METER);
79
80 Node c = attributes.getNamedItem("c");
81 if (c == null)
82 throw new SAXException("Geometry: missing attribute c");
83 elevationTag.c = new Length(Double.parseDouble(c.getNodeValue().trim()), LengthUnit.METER);
84
85 Node d = attributes.getNamedItem("d");
86 if (d == null)
87 throw new SAXException("Geometry: missing attribute d");
88 elevationTag.d = new Length(Double.parseDouble(d.getNodeValue().trim()), LengthUnit.METER);
89
90 elevationTag.elevation = new Length(elevationTag.a.plus(elevationTag.b.multiplyBy(elevationTag.s.doubleValue()))
91 .plus(elevationTag.c.multiplyBy(Math.pow(elevationTag.s.doubleValue(), 2)))
92 .plus(elevationTag.d.multiplyBy(Math.pow(elevationTag.s.doubleValue(), 3))));
93
94 return elevationTag;
95 }
96
97
98 @Override
99 public final String toString()
100 {
101 return "ElevationTag [s=" + this.s + ", a=" + this.a + ", b=" + this.b + ", c=" + this.c + ", d=" + this.d
102 + ", elevation=" + this.elevation + "]";
103 }
104 }