RoadMarkerAlong.java

  1. package org.opentrafficsim.road.network.lane;

  2. import java.util.HashMap;
  3. import java.util.HashSet;
  4. import java.util.List;
  5. import java.util.Map;
  6. import java.util.Set;
  7. import java.util.UUID;

  8. import org.djunits.value.vdouble.scalar.Length;
  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.  * <p>
  15.  * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  16.  * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  17.  * <p>
  18.  * $LastChangedDate: 2015-09-03 13:38:01 +0200 (Thu, 03 Sep 2015) $, @version $Revision: 1378 $, by $Author: averbraeck $,
  19.  * initial version Oct 25, 2014 <br>
  20.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  21.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  22.  */
  23. public abstract class RoadMarkerAlong extends CrossSectionElement
  24. {
  25.     /** */
  26.     private static final long serialVersionUID = 20141025L;

  27.     /** Lateral permeability per GTU type and direction. */
  28.     private final Map<GTUType, Set<LateralDirectionality>> permeabilityMap = new HashMap<>();

  29.     /**
  30.      * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction, with the direction from
  31.      * the StartNode towards the EndNode as the longitudinal direction.
  32.      * @param parentLink Cross Section Link to which the element belongs.
  33.      * @param startCenterPosition the lateral start position compared to the linear geometry of the Cross Section Link at the
  34.      *            start of the road marker.
  35.      * @param endCenterPosition the lateral end position compared to the linear geometry of the Cross Section Link at the end of
  36.      *            the road marker.
  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 startCenterPosition,
  43.         final Length.Rel endCenterPosition, final Length.Rel beginWidth, final Length.Rel endWidth)
  44.         throws OTSGeometryException, NetworkException
  45.     {
  46.         super(parentLink, UUID.randomUUID().toString(), startCenterPosition, endCenterPosition, beginWidth, endWidth);
  47.     }

  48.     /**
  49.      * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction, with the direction from
  50.      * the StartNode towards the EndNode as the longitudinal direction.
  51.      * @param parentLink Cross Section Link to which the element belongs.
  52.      * @param lateralCenterPosition the lateral start position compared to the linear geometry of the Cross Section Link.
  53.      * @param width start width, positioned <i>symmetrically around</i> the lateral start position.
  54.      * @throws OTSGeometryException when creation of the center line or contour geometry fails
  55.      * @throws NetworkException when id equal to null or not unique
  56.      */
  57.     public RoadMarkerAlong(final CrossSectionLink parentLink, final Length.Rel lateralCenterPosition,
  58.         final Length.Rel width) throws OTSGeometryException, NetworkException
  59.     {
  60.         super(parentLink, UUID.randomUUID().toString(), lateralCenterPosition, width);
  61.     }

  62.     /**
  63.      * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction, with the direction from
  64.      * the StartNode towards the EndNode as the longitudinal direction.
  65.      * @param parentLink Cross Section Link to which the element belongs.
  66.      * @param crossSectionSlices The offsets and widths at positions along the line, relative to the design line of the parent
  67.      *            link. If there is just one with and offset, there should just be one element in the list with Length.Rel = 0.
  68.      *            If there are more slices, the last one should be at the length of the design line. If not, a NetworkException
  69.      *            is thrown.
  70.      * @throws OTSGeometryException when creation of the center line or contour geometry fails
  71.      * @throws NetworkException when id equal to null or not unique
  72.      */
  73.     public RoadMarkerAlong(final CrossSectionLink parentLink, final List<CrossSectionSlice> crossSectionSlices)
  74.         throws OTSGeometryException, NetworkException
  75.     {
  76.         super(parentLink, UUID.randomUUID().toString(), crossSectionSlices);
  77.     }

  78.     /** {@inheritDoc} */
  79.     @Override
  80.     protected final double getZ()
  81.     {
  82.         return 0.0001;
  83.     }

  84.     /**
  85.      * Add lateral permeability for a GTU type in the direction of the design line of the overarching CrossSectionLink.
  86.      * Therefore, the lateral directionality of one-sided permeability has to be switched for left lanes. This is done because
  87.      * the CrossSectionLink has no idea in which direction vehicles will be moving. On a 1+1 lane road with overtaking
  88.      * possibilities, the longitudinal directionality of both lanes will be BOTH. Example:
  89.      *
  90.      * <pre>
  91.      * Suppose the design line runs from left to right.
  92.      *
  93.      * =========================
  94.      *
  95.      * LANE 1L (BACKWARD)         GTUs are allowed to move to lane 2L
  96.      *                            Permeability RIGHT is true, although vehicles will go to the LEFT...
  97.      * -------------------------  
  98.      * =========================
  99.      *
  100.      * LANE 2L (BACKWARD)         GTUs are NOT allowed to move to lane 1L nor to lane 2R
  101.      *                            No permeability defined (empty set)
  102.      * =========================
  103.      * =========================
  104.      *
  105.      * LANE 2R (FORWARD)          GTUs are NOT allowed to move to lane 1R nor to lane 2L
  106.      *                            No permeability defined (empty set)
  107.      * =========================
  108.      * -------------------------
  109.      *
  110.      * LANE 1R (FORWARD)          GTUs are allowed to move to lane 2R
  111.      *                            Permeability LEFT is true
  112.      * =========================
  113.      * </pre>
  114.      *
  115.      * <b>Note:</b> GTUType.ALL can be used to set permeability for all types of GTU at once.
  116.      * <p>
  117.      * @param gtuType GTU type to add permeability for.
  118.      * @param lateralDirection direction to add (LEFT or RIGHT) compared to the direction of the design line.
  119.      */
  120.     public final void addPermeability(final GTUType gtuType, final LateralDirectionality lateralDirection)
  121.     {
  122.         if (!this.permeabilityMap.containsKey(gtuType))
  123.         {
  124.             this.permeabilityMap.put(gtuType, new HashSet<LateralDirectionality>(2));
  125.         }
  126.         this.permeabilityMap.get(gtuType).add(lateralDirection);
  127.     }

  128.     /**
  129.      * @param gtuType GTU type to look for.
  130.      * @param lateralDirection direction to look for (LEFT or RIGHT) compared to the direction of the design line.
  131.      * @return whether the road marker is permeable for the GTU type.
  132.      */
  133.     public final boolean isPermeable(final GTUType gtuType, final LateralDirectionality lateralDirection)
  134.     {
  135.         if (this.permeabilityMap.containsKey(GTUType.ALL))
  136.         {
  137.             return this.permeabilityMap.get(GTUType.ALL).contains(lateralDirection);
  138.         }
  139.         if (!this.permeabilityMap.containsKey(gtuType))
  140.         {
  141.             return false;
  142.         }
  143.         return this.permeabilityMap.get(gtuType).contains(lateralDirection);
  144.     }

  145. }