View Javadoc
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   * <p>
14   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
16   * <p>
17   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
18   * initial version Jul 23, 2015 <br>
19   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
20   */
21  class ElevationTag implements Serializable
22  {
23      /** */
24      private static final long serialVersionUID = 20150723L;
25  
26      /** Start position (s-coordinate). */
27      @SuppressWarnings("checkstyle:visibilitymodifier")
28      Length s = null;
29  
30      /** The a coefficient. */
31      @SuppressWarnings("checkstyle:visibilitymodifier")
32      Length a = null;
33  
34      /** The b coefficient. */
35      @SuppressWarnings("checkstyle:visibilitymodifier")
36      Length b = null;
37  
38      /** The c coefficient. */
39      @SuppressWarnings("checkstyle:visibilitymodifier")
40      Length c = null;
41  
42      /** The d coefficient. */
43      @SuppressWarnings("checkstyle:visibilitymodifier")
44      Length d = null;
45  
46      /** Elevation = a + b*ds + c*ds2 + d*ds3 */
47      @SuppressWarnings("checkstyle:visibilitymodifier")
48      Length elevation = null;
49  
50      /**
51       * Parse the attributes of the road tag. The sub-elements are parsed in separate classes.
52       * @param node Node; the top-level road node
53       * @param parser OpenDriveNetworkLaneParser; the parser with the lists of information
54       * @return the generated RoadTag for further reference
55       * @throws SAXException when parsing of the tag fails
56       * @throws NetworkException when parsing of the tag fails
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      /** {@inheritDoc} */
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 }