View Javadoc
1   package org.opentrafficsim.road.network.lane;
2   
3   import java.util.HashMap;
4   import java.util.HashSet;
5   import java.util.Map;
6   import java.util.Set;
7   import java.util.UUID;
8   
9   import org.opentrafficsim.core.geometry.OTSGeometryException;
10  import org.opentrafficsim.core.gtu.GTUType;
11  import org.opentrafficsim.core.network.LateralDirectionality;
12  import org.opentrafficsim.core.network.NetworkException;
13  
14  /**
15   * <p>
16   * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
17   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
18   * <p>
19   * $LastChangedDate: 2015-09-03 13:38:01 +0200 (Thu, 03 Sep 2015) $, @version $Revision: 1378 $, by $Author: averbraeck $,
20   * initial version Oct 25, 2014 <br>
21   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
22   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
23   */
24  public abstract class RoadMarkerAlong extends CrossSectionElement
25  {
26      /** */
27      private static final long serialVersionUID = 20141025L;
28  
29      /** lateral permeability per GTU type and direction. */
30      private final Map<GTUType, Set<LateralDirectionality>> permeabilityMap = new HashMap<>();
31  
32      /**
33       * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction, with the direction from
34       * the StartNode towards the EndNode as the longitudinal direction.
35       * @param parentLink Cross Section Link to which the element belongs.
36       * @param lateralCenterPosition the lateral start position compared to the linear geometry of the Cross Section Link.
37       * @param beginWidth start width, positioned <i>symmetrically around</i> the lateral start position.
38       * @param endWidth end width, positioned <i>symmetrically around</i> the lateral end position.
39       * @throws OTSGeometryException when creation of the center line or contour geometry fails
40       * @throws NetworkException when id equal to null or not unique
41       */
42      public RoadMarkerAlong(final CrossSectionLink parentLink, final Length.Rel lateralCenterPosition,
43          final Length.Rel beginWidth, final Length.Rel endWidth) throws OTSGeometryException, NetworkException
44      {
45          super(parentLink, UUID.randomUUID().toString(), lateralCenterPosition, lateralCenterPosition, beginWidth, endWidth);
46      }
47  
48      /** {@inheritDoc} */
49      @Override
50      protected final double getZ()
51      {
52          return 0.0001;
53      }
54  
55      /**
56       * Add lateral permeability for a GTU type in the direction of the design line of the overarching CrossSectionLink.
57       * Therefore, the lateral directionality of one-sided permeability has to be switched for left lanes. This is done because
58       * the CrossSectionLink has no idea in which direction vehicles will be moving. On a 1+1 lane road with overtaking
59       * possibilities, the longitudinal directionality of both lanes will be BOTH. Example:
60       * 
61       * <pre>
62       * Suppose the design line runs from left to right.
63       * 
64       * =========================
65       * 
66       * LANE 1L (BACKWARD)         GTUs are allowed to move to lane 2L 
67       *                            Permeability RIGHT is true, although vehicles will go to the LEFT...
68       * -------------------------  
69       * =========================
70       * 
71       * LANE 2L (BACKWARD)         GTUs are NOT allowed to move to lane 1L nor to lane 2R
72       *                            No permeability defined (empty set)
73       * =========================
74       * =========================
75       * 
76       * LANE 2R (FORWARD)          GTUs are NOT allowed to move to lane 1R nor to lane 2L
77       *                            No permeability defined (empty set)
78       * =========================
79       * -------------------------
80       * 
81       * LANE 1R (FORWARD)          GTUs are allowed to move to lane 2R
82       *                            Permeability LEFT is true
83       * =========================
84       * </pre>
85       * 
86       * <b>Note:</b> GTUType.ALL can be used to set permeability for all types of GTU at once.
87       * <p>
88       * @param gtuType GTU type to add permeability for.
89       * @param lateralDirection direction to add (LEFT or RIGHT) compared to the direction of the design line.
90       */
91      public final void addPermeability(final GTUType gtuType, final LateralDirectionality lateralDirection)
92      {
93          if (!this.permeabilityMap.containsKey(gtuType))
94          {
95              this.permeabilityMap.put(gtuType, new HashSet<LateralDirectionality>(2));
96          }
97          this.permeabilityMap.get(gtuType).add(lateralDirection);
98      }
99  
100     /**
101      * @param gtuType GTU type to look for.
102      * @param lateralDirection direction to look for (LEFT or RIGHT) compared to the direction of the design line.
103      * @return whether the road marker is permeable for the GTU type.
104      */
105     public final boolean isPermeable(final GTUType gtuType, final LateralDirectionality lateralDirection)
106     {
107         if (this.permeabilityMap.containsKey(GTUType.ALL))
108         {
109             return this.permeabilityMap.get(GTUType.ALL).contains(lateralDirection);
110         }
111         if (!this.permeabilityMap.containsKey(gtuType))
112         {
113             return false;
114         }
115         return this.permeabilityMap.get(gtuType).contains(lateralDirection);
116     }
117 
118 }