Stripe.java

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

  2. import java.util.List;
  3. import java.util.Set;

  4. import org.djunits.value.vdouble.scalar.Length;
  5. import org.opentrafficsim.core.geometry.OTSGeometryException;
  6. import org.opentrafficsim.core.gtu.GTUType;
  7. import org.opentrafficsim.core.network.LateralDirectionality;
  8. import org.opentrafficsim.core.network.NetworkException;

  9. import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;

  10. /**
  11.  * Longitudinal road stripes; simple constructors.
  12.  * <p>
  13.  * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  14.  * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  15.  * <p>
  16.  * $LastChangedDate: 2015-09-03 13:38:01 +0200 (Thu, 03 Sep 2015) $, @version $Revision: 1378 $, by $Author: averbraeck $,
  17.  * initial version Oct 25, 2014 <br>
  18.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  19.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  20.  */
  21. public class Stripe extends RoadMarkerAlong
  22. {
  23.     /** */
  24.     private static final long serialVersionUID = 20151025L;

  25.     /**
  26.      * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction, with the direction from
  27.      * the StartNode towards the EndNode as the longitudinal direction.
  28.      * @param parentLink CrossSectionLink; Cross Section Link to which the element belongs
  29.      * @param lateralCenterPositionStart Length; the lateral start position compared to the linear geometry of the Cross Section
  30.      *            Link
  31.      * @param lateralCenterPositionEnd Length; the lateral start position compared to the linear geometry of the Cross Section
  32.      *            Link
  33.      * @param width Length; positioned &lt;i&gt;symmetrically around&lt;/i&gt; the center line given by the
  34.      *            lateralCenterPosition.
  35.      * @param fixGradualLateralOffset boolean; true if gradualLateralOffset needs to be fixed
  36.      * @throws OTSGeometryException when creation of the center line or contour geometry fails
  37.      * @throws NetworkException when id equal to null or not unique
  38.      */
  39.     public Stripe(final CrossSectionLink parentLink, final Length lateralCenterPositionStart,
  40.             final Length lateralCenterPositionEnd, final Length width, final boolean fixGradualLateralOffset)
  41.             throws OTSGeometryException, NetworkException
  42.     {
  43.         super(parentLink, lateralCenterPositionStart, lateralCenterPositionEnd, width, width, fixGradualLateralOffset);
  44.     }

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

  63.     /**
  64.      * Helper constructor that immediately provides permeability for a number of GTU classes.<br>
  65.      * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction, with the direction from
  66.      * the StartNode towards the EndNode as the longitudinal direction.
  67.      * @param parentLink CrossSectionLink; Cross Section Link to which the element belongs
  68.      * @param lateralCenterPositionStart Length; the lateral start position compared to the linear geometry of the Cross Section
  69.      *            Link
  70.      * @param lateralCenterPositionEnd Length; the lateral start position compared to the linear geometry of the Cross Section
  71.      *            Link
  72.      * @param width Length; positioned &lt;i&gt;symmetrically around&lt;/i&gt; the center line given by the
  73.      *            lateralCenterPosition
  74.      * @param gtuTypes Set&lt;GTUType&gt;; the GTU types for which the permeability is defined
  75.      * @param permeable Permeable; one of the enums of Stripe.Permeable to define the permeability
  76.      * @param fixGradualLateralOffset boolean; true if gradualLateralOffset needs to be fixed
  77.      * @throws OTSGeometryException when creation of the center line or contour geometry fails
  78.      * @throws NetworkException when id equal to null or not unique
  79.      */
  80.     public Stripe(final CrossSectionLink parentLink, final Length lateralCenterPositionStart,
  81.             final Length lateralCenterPositionEnd, final Length width, final Set<GTUType> gtuTypes, final Permeable permeable,
  82.             final boolean fixGradualLateralOffset) throws OTSGeometryException, NetworkException
  83.     {
  84.         super(parentLink, lateralCenterPositionStart, lateralCenterPositionEnd, width, width, fixGradualLateralOffset);
  85.         for (GTUType gtuType : gtuTypes)
  86.         {
  87.             addPermeability(gtuType, permeable);
  88.         }
  89.     }

  90.     /**
  91.      * Helper constructor that immediately provides permeability for a number of GTU classes.<br>
  92.      * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction, with the direction from
  93.      * the StartNode towards the EndNode as the longitudinal direction.
  94.      * @param parentLink CrossSectionLink; Cross Section Link to which the element belongs
  95.      * @param lateralCenterPositionStart Length; the lateral start position compared to the linear geometry of the Cross Section
  96.      *            Link
  97.      * @param lateralCenterPositionEnd Length; the lateral start position compared to the linear geometry of the Cross Section
  98.      *            Link
  99.      * @param width Length; positioned &lt;i&gt;symmetrically around&lt;/i&gt; the center line given by the
  100.      *            lateralCenterPosition
  101.      * @param gtuTypes Set&lt;GTUType&gt;; the GTU types for which the permeability is defined
  102.      * @param permeable Permeable; one of the enums of Stripe.Permeable to define the permeability
  103.      * @throws OTSGeometryException when creation of the center line or contour geometry fails
  104.      * @throws NetworkException when id equal to null or not unique
  105.      */
  106.     public Stripe(final CrossSectionLink parentLink, final Length lateralCenterPositionStart,
  107.             final Length lateralCenterPositionEnd, final Length width, final Set<GTUType> gtuTypes, final Permeable permeable)
  108.             throws OTSGeometryException, NetworkException
  109.     {
  110.         this(parentLink, lateralCenterPositionStart, lateralCenterPositionEnd, width, gtuTypes, permeable, false);
  111.     }

  112.     /**
  113.      * Helper constructor that immediately provides permeability for all GTU classes.<br>
  114.      * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction, with the direction from
  115.      * the StartNode towards the EndNode as the longitudinal direction.
  116.      * @param parentLink CrossSectionLink; Cross Section Link to which the element belongs
  117.      * @param crossSectionSlices List&lt;CrossSectionSlice&gt;; The offsets and widths at positions along the line, relative to
  118.      *            the design line of the parent link. If there is just one with and offset, there should just be one element in
  119.      *            the list with Length = 0. If there are more slices, the last one should be at the length of the design line.
  120.      *            If not, a NetworkException is thrown.
  121.      * @param permeable Permeable; one of the enums of Stripe.Permeable to define the permeability
  122.      * @throws OTSGeometryException when creation of the center line or contour geometry fails
  123.      * @throws NetworkException when id equal to null or not unique
  124.      */
  125.     public Stripe(final CrossSectionLink parentLink, final List<CrossSectionSlice> crossSectionSlices,
  126.             final Permeable permeable) throws OTSGeometryException, NetworkException
  127.     {
  128.         super(parentLink, crossSectionSlices);
  129.         addPermeability(parentLink.getNetwork().getGtuType(GTUType.DEFAULTS.VEHICLE), permeable);
  130.         addPermeability(parentLink.getNetwork().getGtuType(GTUType.DEFAULTS.PEDESTRIAN), permeable);
  131.     }

  132.     /**
  133.      * Clone a Stripe for a new network.
  134.      * @param newParentLink CrossSectionLink; the new link to which the clone belongs
  135.      * @param newSimulator SimulatorInterface.TimeDoubleUnit; the new simulator for this network
  136.      * @param cse Stripe; the element to clone from
  137.      * @throws NetworkException if link already exists in the network, if name of the link is not unique, or if the start node
  138.      *             or the end node of the link are not registered in the network.
  139.      */
  140.     protected Stripe(final CrossSectionLink newParentLink, final SimulatorInterface.TimeDoubleUnit newSimulator,
  141.             final Stripe cse) throws NetworkException
  142.     {
  143.         super(newParentLink, newSimulator, cse);
  144.     }

  145.     /**
  146.      * @param gtuType GTUType; GTU type to add permeability for.
  147.      * @param permeable Permeable; direction(s) to add compared to the direction of the design line.
  148.      */
  149.     public final void addPermeability(final GTUType gtuType, final Permeable permeable)
  150.     {
  151.         if (permeable.equals(Permeable.LEFT) || permeable.equals(Permeable.BOTH))
  152.         {
  153.             addPermeability(gtuType, LateralDirectionality.LEFT);
  154.         }
  155.         if (permeable.equals(Permeable.RIGHT) || permeable.equals(Permeable.BOTH))
  156.         {
  157.             addPermeability(gtuType, LateralDirectionality.RIGHT);
  158.         }
  159.     }

  160.     /** The types of permeability of a stripe. */
  161.     public enum Permeable
  162.     {
  163.         /** Permeable in the positive lateral direction compared to the design line direction. */
  164.         LEFT,
  165.         /** Permeable in the negative lateral direction compared to the design line direction. */
  166.         RIGHT,
  167.         /** Permeable in both directions. */
  168.         BOTH;
  169.     }

  170.     /** {@inheritDoc} */
  171.     @Override
  172.     @SuppressWarnings("checkstyle:designforextension")
  173.     public String toString()
  174.     {
  175.         return String.format("Stripe offset %.2fm..%.2fm, width %.2fm..%.2fm", getDesignLineOffsetAtBegin().getSI(),
  176.                 getDesignLineOffsetAtEnd().getSI(), getBeginWidth().getSI(), getEndWidth().getSI());
  177.     }

  178.     /** {@inheritDoc} */
  179.     @Override
  180.     @SuppressWarnings("checkstyle:designforextension")
  181.     public Stripe clone(final CrossSectionLink newParentLink, final SimulatorInterface.TimeDoubleUnit newSimulator)
  182.             throws NetworkException
  183.     {
  184.         return new Stripe(newParentLink, newSimulator, this);
  185.     }

  186. }