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  import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
13  
14  /**
15   * Longitudinal road stripes; simple constructors.
16   * <p>
17   * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
18   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
19   * <p>
20   * $LastChangedDate: 2015-09-03 13:38:01 +0200 (Thu, 03 Sep 2015) $, @version $Revision: 1378 $, by $Author: averbraeck $,
21   * initial version Oct 25, 2014 <br>
22   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
23   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
24   */
25  public class Stripe extends RoadMarkerAlong
26  {
27      /** */
28      private static final long serialVersionUID = 20151025L;
29  
30      /**
31       * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction, with the direction from
32       * the StartNode towards the EndNode as the longitudinal direction.
33       * @param parentLink CrossSectionLink; Cross Section Link to which the element belongs
34       * @param lateralCenterPositionStart Length; the lateral start position compared to the linear geometry of the Cross Section
35       *            Link
36       * @param lateralCenterPositionEnd Length; the lateral start position compared to the linear geometry of the Cross Section
37       *            Link
38       * @param width Length; positioned &lt;i&gt;symmetrically around&lt;/i&gt; the center line given by the
39       *            lateralCenterPosition.
40       * @param fixGradualLateralOffset boolean; true if gradualLateralOffset needs to be fixed
41       * @throws OTSGeometryException when creation of the center line or contour geometry fails
42       * @throws NetworkException when id equal to null or not unique
43       */
44      public Stripe(final CrossSectionLink parentLink, final Length lateralCenterPositionStart,
45              final Length lateralCenterPositionEnd, final Length width, final boolean fixGradualLateralOffset)
46              throws OTSGeometryException, NetworkException
47      {
48          super(parentLink, lateralCenterPositionStart, lateralCenterPositionEnd, width, width, fixGradualLateralOffset);
49      }
50  
51      /**
52       * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction, with the direction from
53       * the StartNode towards the EndNode as the longitudinal direction.
54       * @param parentLink CrossSectionLink; Cross Section Link to which the element belongs
55       * @param lateralCenterPositionStart Length; the lateral start position compared to the linear geometry of the Cross Section
56       *            Link
57       * @param lateralCenterPositionEnd Length; the lateral start position compared to the linear geometry of the Cross Section
58       *            Link
59       * @param width Length; positioned &lt;i&gt;symmetrically around&lt;/i&gt; the center line given by the
60       *            lateralCenterPosition.
61       * @throws OTSGeometryException when creation of the center line or contour geometry fails
62       * @throws NetworkException when id equal to null or not unique
63       */
64      public Stripe(final CrossSectionLink parentLink, final Length lateralCenterPositionStart,
65              final Length lateralCenterPositionEnd, final Length width) throws OTSGeometryException, NetworkException
66      {
67          this(parentLink, lateralCenterPositionStart, lateralCenterPositionEnd, width, false);
68      }
69  
70      /**
71       * Helper constructor that immediately provides permeability for a number of GTU classes.<br>
72       * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction, with the direction from
73       * the StartNode towards the EndNode as the longitudinal direction.
74       * @param parentLink CrossSectionLink; Cross Section Link to which the element belongs
75       * @param lateralCenterPositionStart Length; the lateral start position compared to the linear geometry of the Cross Section
76       *            Link
77       * @param lateralCenterPositionEnd Length; the lateral start position compared to the linear geometry of the Cross Section
78       *            Link
79       * @param width Length; positioned &lt;i&gt;symmetrically around&lt;/i&gt; the center line given by the
80       *            lateralCenterPosition
81       * @param gtuTypes Set&lt;GTUType&gt;; the GTU types for which the permeability is defined
82       * @param permeable Permeable; one of the enums of Stripe.Permeable to define the permeability
83       * @param fixGradualLateralOffset boolean; true if gradualLateralOffset needs to be fixed
84       * @throws OTSGeometryException when creation of the center line or contour geometry fails
85       * @throws NetworkException when id equal to null or not unique
86       */
87      public Stripe(final CrossSectionLink parentLink, final Length lateralCenterPositionStart,
88              final Length lateralCenterPositionEnd, final Length width, final Set<GTUType> gtuTypes, final Permeable permeable,
89              final boolean fixGradualLateralOffset) throws OTSGeometryException, NetworkException
90      {
91          super(parentLink, lateralCenterPositionStart, lateralCenterPositionEnd, width, width, fixGradualLateralOffset);
92          for (GTUType gtuType : gtuTypes)
93          {
94              addPermeability(gtuType, permeable);
95          }
96      }
97  
98      /**
99       * Helper constructor that immediately provides permeability for a number of GTU classes.<br>
100      * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction, with the direction from
101      * the StartNode towards the EndNode as the longitudinal direction.
102      * @param parentLink CrossSectionLink; Cross Section Link to which the element belongs
103      * @param lateralCenterPositionStart Length; the lateral start position compared to the linear geometry of the Cross Section
104      *            Link
105      * @param lateralCenterPositionEnd Length; the lateral start position compared to the linear geometry of the Cross Section
106      *            Link
107      * @param width Length; positioned &lt;i&gt;symmetrically around&lt;/i&gt; the center line given by the
108      *            lateralCenterPosition
109      * @param gtuTypes Set&lt;GTUType&gt;; the GTU types for which the permeability is defined
110      * @param permeable Permeable; one of the enums of Stripe.Permeable to define the permeability
111      * @throws OTSGeometryException when creation of the center line or contour geometry fails
112      * @throws NetworkException when id equal to null or not unique
113      */
114     public Stripe(final CrossSectionLink parentLink, final Length lateralCenterPositionStart,
115             final Length lateralCenterPositionEnd, final Length width, final Set<GTUType> gtuTypes, final Permeable permeable)
116             throws OTSGeometryException, NetworkException
117     {
118         this(parentLink, lateralCenterPositionStart, lateralCenterPositionEnd, width, gtuTypes, permeable, false);
119     }
120 
121     /**
122      * Helper constructor that immediately provides permeability for all GTU classes.<br>
123      * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction, with the direction from
124      * the StartNode towards the EndNode as the longitudinal direction.
125      * @param parentLink CrossSectionLink; Cross Section Link to which the element belongs
126      * @param crossSectionSlices List&lt;CrossSectionSlice&gt;; The offsets and widths at positions along the line, relative to
127      *            the design line of the parent link. If there is just one with and offset, there should just be one element in
128      *            the list with Length = 0. If there are more slices, the last one should be at the length of the design line.
129      *            If not, a NetworkException is thrown.
130      * @param permeable Permeable; one of the enums of Stripe.Permeable to define the permeability
131      * @throws OTSGeometryException when creation of the center line or contour geometry fails
132      * @throws NetworkException when id equal to null or not unique
133      */
134     public Stripe(final CrossSectionLink parentLink, final List<CrossSectionSlice> crossSectionSlices,
135             final Permeable permeable) throws OTSGeometryException, NetworkException
136     {
137         super(parentLink, crossSectionSlices);
138         addPermeability(parentLink.getNetwork().getGtuType(GTUType.DEFAULTS.VEHICLE), permeable);
139         addPermeability(parentLink.getNetwork().getGtuType(GTUType.DEFAULTS.PEDESTRIAN), permeable);
140     }
141 
142     /**
143      * Clone a Stripe for a new network.
144      * @param newParentLink CrossSectionLink; the new link to which the clone belongs
145      * @param newSimulator SimulatorInterface.TimeDoubleUnit; the new simulator for this network
146      * @param cse Stripe; the element to clone from
147      * @throws NetworkException if link already exists in the network, if name of the link is not unique, or if the start node
148      *             or the end node of the link are not registered in the network.
149      */
150     protected Stripe(final CrossSectionLink newParentLink, final SimulatorInterface.TimeDoubleUnit newSimulator,
151             final Stripe cse) throws NetworkException
152     {
153         super(newParentLink, newSimulator, cse);
154     }
155 
156     /**
157      * @param gtuType GTUType; GTU type to add permeability for.
158      * @param permeable Permeable; direction(s) to add compared to the direction of the design line.
159      */
160     public final void addPermeability(final GTUType gtuType, final Permeable permeable)
161     {
162         if (permeable.equals(Permeable.LEFT) || permeable.equals(Permeable.BOTH))
163         {
164             addPermeability(gtuType, LateralDirectionality.LEFT);
165         }
166         if (permeable.equals(Permeable.RIGHT) || permeable.equals(Permeable.BOTH))
167         {
168             addPermeability(gtuType, LateralDirectionality.RIGHT);
169         }
170     }
171 
172     /** The types of permeability of a stripe. */
173     public enum Permeable
174     {
175         /** Permeable in the positive lateral direction compared to the design line direction. */
176         LEFT,
177         /** Permeable in the negative lateral direction compared to the design line direction. */
178         RIGHT,
179         /** Permeable in both directions. */
180         BOTH;
181     }
182 
183     /** {@inheritDoc} */
184     @Override
185     @SuppressWarnings("checkstyle:designforextension")
186     public String toString()
187     {
188         return String.format("Stripe offset %.2fm..%.2fm, width %.2fm..%.2fm", getDesignLineOffsetAtBegin().getSI(),
189                 getDesignLineOffsetAtEnd().getSI(), getBeginWidth().getSI(), getEndWidth().getSI());
190     }
191 
192     /** {@inheritDoc} */
193     @Override
194     @SuppressWarnings("checkstyle:designforextension")
195     public Stripe clone(final CrossSectionLink newParentLink, final SimulatorInterface.TimeDoubleUnit newSimulator)
196             throws NetworkException
197     {
198         return new Stripe(newParentLink, newSimulator, this);
199     }
200 
201 }