View Javadoc
1   package org.opentrafficsim.road.network.lane;
2   
3   import java.util.Set;
4   
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   
10  /**
11   * Longitudinal road stripes.
12   * <p>
13   * Copyright (c) 2013-2015 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      /**
27       * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction, with the direction from
28       * the StartNode towards the EndNode as the longitudinal direction.
29       * @param parentLink Cross Section Link to which the element belongs
30       * @param lateralCenterPosition the lateral start position compared to the linear geometry of the Cross Section Link
31       * @param width positioned <i>symmetrically around</i> the center line given by the lateralCenterPosition.
32       * @throws OTSGeometryException when creation of the center line or contour geometry fails
33       * @throws NetworkException when id equal to null or not unique
34       */
35      public Stripe(final CrossSectionLink parentLink, final Length.Rel lateralCenterPosition, final Length.Rel width)
36          throws OTSGeometryException, NetworkException
37      {
38          super(parentLink, lateralCenterPosition, width, width);
39      }
40  
41      /**
42       * Helper constructor that immediately provides permeability for a number of GTU classes.<br>
43       * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction, with the direction from
44       * the StartNode towards the EndNode as the longitudinal direction.
45       * @param parentLink Cross Section Link to which the element belongs
46       * @param lateralCenterPosition the lateral start position compared to the linear geometry of the Cross Section Link
47       * @param width positioned <i>symmetrically around</i> the center line given by the lateralCenterPosition
48       * @param gtuTypes the GTU types for which the permeability is defined
49       * @param permeable one of the enums of Stripe.Permeable to define the permeability
50       * @throws OTSGeometryException when creation of the center line or contour geometry fails
51       * @throws NetworkException when id equal to null or not unique
52       */
53      public Stripe(final CrossSectionLink parentLink, final Length.Rel lateralCenterPosition, final Length.Rel width,
54          final Set<GTUType> gtuTypes, final Permeable permeable) throws OTSGeometryException, NetworkException
55      {
56          super(parentLink, lateralCenterPosition, width, width);
57          for (GTUType gtuType : gtuTypes)
58          {
59              addPermeability(gtuType, permeable);
60          }
61      }
62  
63      /**
64       * Helper constructor that immediately provides permeability for all 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 Cross Section Link to which the element belongs
68       * @param lateralCenterPosition the lateral start position compared to the linear geometry of the Cross Section Link
69       * @param width positioned <i>symmetrically around</i> the center line given by the lateralCenterPosition
70       * @param permeable one of the enums of Stripe.Permeable to define the permeability
71       * @throws OTSGeometryException when creation of the center line or contour geometry fails
72       * @throws NetworkException when id equal to null or not unique
73       */
74      public Stripe(final CrossSectionLink parentLink, final Length.Rel lateralCenterPosition, final Length.Rel width,
75          final Permeable permeable) throws OTSGeometryException, NetworkException
76      {
77          super(parentLink, lateralCenterPosition, width, width);
78          addPermeability(GTUType.ALL, permeable);
79      }
80  
81      /**
82       * @param gtuType GTU type to add permeability for.
83       * @param permeable direction(s) to add compared to the direction of the design line.
84       */
85      public final void addPermeability(final GTUType gtuType, final Permeable permeable)
86      {
87          if (permeable.equals(Permeable.LEFT) || permeable.equals(Permeable.BOTH))
88          {
89              addPermeability(gtuType, LateralDirectionality.LEFT);
90          }
91          if (permeable.equals(Permeable.RIGHT) || permeable.equals(Permeable.BOTH))
92          {
93              addPermeability(gtuType, LateralDirectionality.RIGHT);
94          }
95      }
96  
97      /** the types of permeability of a stripe. */
98      public enum Permeable
99      {
100         /** Permeable in the positive lateral direction compared to the design line direction. */
101         LEFT,
102         /** Permeable in the negative lateral direction compared to the design line direction. */
103         RIGHT,
104         /** Permeable in both directions. */
105         BOTH;
106     }
107 
108     /** {@inheritDoc} */
109     @Override
110     @SuppressWarnings("checkstyle:designforextension")
111     public String toString()
112     {
113         return String.format("Stripe offset %.2fm..%.2fm, width %.2fm..%.2fm", getDesignLineOffsetAtBegin().getSI(),
114             getDesignLineOffsetAtEnd().getSI(), getBeginWidth().getSI(), getEndWidth().getSI());
115     }
116 }