View Javadoc
1   package org.opentrafficsim.core.network.lane;
2   
3   import java.rmi.RemoteException;
4   import java.util.ArrayList;
5   import java.util.List;
6   
7   import javax.media.j3d.Bounds;
8   
9   import nl.tudelft.simulation.language.d3.BoundingBox;
10  import nl.tudelft.simulation.language.d3.DirectedPoint;
11  
12  import org.opentrafficsim.core.network.geotools.LinkGeotools;
13  import org.opentrafficsim.core.network.geotools.NodeGeotools;
14  import org.opentrafficsim.core.unit.FrequencyUnit;
15  import org.opentrafficsim.core.unit.LengthUnit;
16  import org.opentrafficsim.core.value.vdouble.scalar.DoubleScalar;
17  
18  /**
19   * <p>
20   * Copyright (c) 2013-2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
21   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
22   * <p>
23   * @version Aug 19, 2014 <br>
24   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
25   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
26   * @author <a href="http://www.citg.tudelft.nl">Guus Tamminga</a>
27   * @param <IDL> the ID type of the Link, e.g., String or Integer.
28   * @param <IDN> the ID type of the Node, e.g., String or Integer.
29   */
30  public class CrossSectionLink<IDL, IDN> extends LinkGeotools<IDL, IDN>
31  {
32      /** list of cross-section elements. */
33      private final List<CrossSectionElement> crossSectionElementList = new ArrayList<>();
34  
35      /** */
36      private static final long serialVersionUID = 20141015L;
37  
38      /**
39       * Construction of a link.
40       * @param id the link id.
41       * @param startNode start node (directional).
42       * @param endNode end node (directional).
43       * @param length link length in a length unit.
44       * @param capacity link capacity in vehicles per hour.
45       */
46      public CrossSectionLink(final IDL id, final NodeGeotools<IDN> startNode, final NodeGeotools<IDN> endNode,
47          final DoubleScalar.Rel<LengthUnit> length, final DoubleScalar.Abs<FrequencyUnit> capacity)
48      {
49          super(id, startNode, endNode, length, capacity);
50      }
51  
52      /**
53       * Construction of a link.
54       * @param id the link id.
55       * @param startNode start node (directional).
56       * @param endNode end node (directional).
57       * @param length link length in a length unit.
58       */
59      public CrossSectionLink(final IDL id, final NodeGeotools<IDN> startNode, final NodeGeotools<IDN> endNode,
60          final DoubleScalar.Rel<LengthUnit> length)
61      {
62          super(id, startNode, endNode, length);
63      }
64  
65      /**
66       * Add a cross section element at the end of the list. <br>
67       * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction.
68       * @param cse the cross section element to add.
69       */
70      protected final void addCrossSectionElement(final CrossSectionElement cse)
71      {
72          this.crossSectionElementList.add(cse);
73      }
74  
75      /**
76       * Add a cross section element at specified index in the list.<br>
77       * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction.
78       * @param index the location to insert the element.
79       * @param cse the cross section element to add.
80       */
81      protected final void addCrossSectionElement(final CrossSectionElement cse, final int index)
82      {
83          this.crossSectionElementList.add(index, cse);
84      }
85  
86      /**
87       * @return crossSectionElementList.
88       */
89      public final List<CrossSectionElement> getCrossSectionElementList()
90      {
91          return this.crossSectionElementList;
92      }
93  
94      /** {@inheritDoc} */
95      @Override
96      public final DirectedPoint getLocation() throws RemoteException
97      {
98          return getStartNode().getLocation();
99      }
100 
101     /** {@inheritDoc} */
102     @Override
103     public final Bounds getBounds() throws RemoteException
104     {
105         return new BoundingBox(getEndNode().getLocation().x - getStartNode().getLocation().x, getEndNode().getLocation().y
106             - getStartNode().getLocation().y, getEndNode().getLocation().z - getStartNode().getLocation().z);
107     }
108 
109 }