View Javadoc
1   package org.opentrafficsim.road.network.lane;
2   
3   import java.util.List;
4   import java.util.Set;
5   
6   import org.djunits.value.vdouble.scalar.Length;
7   import org.opentrafficsim.core.geometry.OTSGeometryException;
8   import org.opentrafficsim.core.gtu.GTUType;
9   import org.opentrafficsim.core.network.LateralDirectionality;
10  import org.opentrafficsim.core.network.NetworkException;
11  
12  /**
13   * Longitudinal road stripes; simple constructors.
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 class Stripe extends RoadMarkerAlong
24  {
25      /** */
26      private static final long serialVersionUID = 20151025L;
27  
28      /**
29       * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction, with the direction from
30       * the StartNode towards the EndNode as the longitudinal direction.
31       * @param parentLink Cross Section Link to which the element belongs
32       * @param lateralCenterPosition the lateral start position compared to the linear geometry of the Cross Section Link
33       * @param width positioned <i>symmetrically around</i> the center line given by the lateralCenterPosition.
34       * @throws OTSGeometryException when creation of the center line or contour geometry fails
35       * @throws NetworkException when id equal to null or not unique
36       */
37      public Stripe(final CrossSectionLink parentLink, final Length.Rel lateralCenterPosition, final Length.Rel width)
38          throws OTSGeometryException, NetworkException
39      {
40          super(parentLink, lateralCenterPosition, width);
41      }
42  
43      /**
44       * Helper constructor that immediately provides permeability for a number of GTU classes.<br>
45       * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction, with the direction from
46       * the StartNode towards the EndNode as the longitudinal direction.
47       * @param parentLink Cross Section Link to which the element belongs
48       * @param lateralCenterPosition the lateral start position compared to the linear geometry of the Cross Section Link
49       * @param width positioned <i>symmetrically around</i> the center line given by the lateralCenterPosition
50       * @param gtuTypes the GTU types for which the permeability is defined
51       * @param permeable one of the enums of Stripe.Permeable to define the permeability
52       * @throws OTSGeometryException when creation of the center line or contour geometry fails
53       * @throws NetworkException when id equal to null or not unique
54       */
55      public Stripe(final CrossSectionLink parentLink, final Length.Rel lateralCenterPosition, final Length.Rel width,
56          final Set<GTUType> gtuTypes, final Permeable permeable) throws OTSGeometryException, NetworkException
57      {
58          super(parentLink, lateralCenterPosition, width);
59          for (GTUType gtuType : gtuTypes)
60          {
61              addPermeability(gtuType, permeable);
62          }
63      }
64  
65      /**
66       * Helper constructor that immediately provides permeability for all GTU classes.<br>
67       * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction, with the direction from
68       * the StartNode towards the EndNode as the longitudinal direction.
69       * @param parentLink Cross Section Link to which the element belongs
70       * @param crossSectionSlices The offsets and widths at positions along the line, relative to the design line of the parent
71       *            link. If there is just one with and offset, there should just be one element in the list with Length.Rel = 0.
72       *            If there are more slices, the last one should be at the length of the design line. If not, a NetworkException
73       *            is thrown.
74       * @param permeable one of the enums of Stripe.Permeable to define the permeability
75       * @throws OTSGeometryException when creation of the center line or contour geometry fails
76       * @throws NetworkException when id equal to null or not unique
77       */
78      public Stripe(final CrossSectionLink parentLink, final List<CrossSectionSlice> crossSectionSlices,
79          final Permeable permeable) throws OTSGeometryException, NetworkException
80      {
81          super(parentLink, crossSectionSlices);
82          addPermeability(GTUType.ALL, permeable);
83      }
84  
85      /**
86       * @param gtuType GTU type to add permeability for.
87       * @param permeable direction(s) to add compared to the direction of the design line.
88       */
89      public final void addPermeability(final GTUType gtuType, final Permeable permeable)
90      {
91          if (permeable.equals(Permeable.LEFT) || permeable.equals(Permeable.BOTH))
92          {
93              addPermeability(gtuType, LateralDirectionality.LEFT);
94          }
95          if (permeable.equals(Permeable.RIGHT) || permeable.equals(Permeable.BOTH))
96          {
97              addPermeability(gtuType, LateralDirectionality.RIGHT);
98          }
99      }
100 
101     /** The types of permeability of a stripe. */
102     public enum Permeable
103     {
104         /** Permeable in the positive lateral direction compared to the design line direction. */
105         LEFT,
106         /** Permeable in the negative lateral direction compared to the design line direction. */
107         RIGHT,
108         /** Permeable in both directions. */
109         BOTH;
110     }
111 
112     /** {@inheritDoc} */
113     @Override
114     @SuppressWarnings("checkstyle:designforextension")
115     public String toString()
116     {
117         return String.format("Stripe offset %.2fm..%.2fm, width %.2fm..%.2fm", getDesignLineOffsetAtBegin().getSI(),
118             getDesignLineOffsetAtEnd().getSI(), getBeginWidth().getSI(), getEndWidth().getSI());
119     }
120 }