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-2019 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 <i>symmetrically around</i> the center line given by the 39 * lateralCenterPosition. 40 * @throws OTSGeometryException when creation of the center line or contour geometry fails 41 * @throws NetworkException when id equal to null or not unique 42 */ 43 public Stripe(final CrossSectionLink parentLink, final Length lateralCenterPositionStart, 44 final Length lateralCenterPositionEnd, final Length width) throws OTSGeometryException, NetworkException 45 { 46 super(parentLink, lateralCenterPositionStart, lateralCenterPositionEnd, width, width); 47 } 48 49 /** 50 * Helper constructor that immediately provides permeability for a number of GTU classes.<br> 51 * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction, with the direction from 52 * the StartNode towards the EndNode as the longitudinal direction. 53 * @param parentLink CrossSectionLink; Cross Section Link to which the element belongs 54 * @param lateralCenterPositionStart Length; the lateral start position compared to the linear geometry of the Cross Section 55 * Link 56 * @param lateralCenterPositionEnd Length; the lateral start position compared to the linear geometry of the Cross Section 57 * Link 58 * @param width Length; positioned <i>symmetrically around</i> the center line given by the 59 * lateralCenterPosition 60 * @param gtuTypes Set<GTUType>; the GTU types for which the permeability is defined 61 * @param permeable Permeable; one of the enums of Stripe.Permeable to define the permeability 62 * @throws OTSGeometryException when creation of the center line or contour geometry fails 63 * @throws NetworkException when id equal to null or not unique 64 */ 65 public Stripe(final CrossSectionLink parentLink, final Length lateralCenterPositionStart, 66 final Length lateralCenterPositionEnd, final Length width, final Set<GTUType> gtuTypes, final Permeable permeable) 67 throws OTSGeometryException, NetworkException 68 { 69 super(parentLink, lateralCenterPositionStart, lateralCenterPositionEnd, width, width); 70 for (GTUType gtuType : gtuTypes) 71 { 72 addPermeability(gtuType, permeable); 73 } 74 } 75 76 /** 77 * Helper constructor that immediately provides permeability for all GTU classes.<br> 78 * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction, with the direction from 79 * the StartNode towards the EndNode as the longitudinal direction. 80 * @param parentLink CrossSectionLink; Cross Section Link to which the element belongs 81 * @param crossSectionSlices List<CrossSectionSlice>; The offsets and widths at positions along the line, relative to 82 * the design line of the parent link. If there is just one with and offset, there should just be one element in 83 * the list with Length = 0. If there are more slices, the last one should be at the length of the design line. 84 * If not, a NetworkException is thrown. 85 * @param permeable Permeable; one of the enums of Stripe.Permeable to define the permeability 86 * @throws OTSGeometryException when creation of the center line or contour geometry fails 87 * @throws NetworkException when id equal to null or not unique 88 */ 89 public Stripe(final CrossSectionLink parentLink, final List<CrossSectionSlice> crossSectionSlices, 90 final Permeable permeable) throws OTSGeometryException, NetworkException 91 { 92 super(parentLink, crossSectionSlices); 93 addPermeability(GTUType.VEHICLE, permeable); 94 addPermeability(GTUType.PEDESTRIAN, permeable); 95 } 96 97 /** 98 * Clone a Stripe for a new network. 99 * @param newParentLink CrossSectionLink; the new link to which the clone belongs 100 * @param newSimulator SimulatorInterface.TimeDoubleUnit; the new simulator for this network 101 * @param cse Stripe; the element to clone from 102 * @throws NetworkException if link already exists in the network, if name of the link is not unique, or if the start node 103 * or the end node of the link are not registered in the network. 104 */ 105 protected Stripe(final CrossSectionLink newParentLink, final SimulatorInterface.TimeDoubleUnit newSimulator, 106 final Stripe cse) throws NetworkException 107 { 108 super(newParentLink, newSimulator, cse); 109 } 110 111 /** 112 * @param gtuType GTUType; GTU type to add permeability for. 113 * @param permeable Permeable; direction(s) to add compared to the direction of the design line. 114 */ 115 public final void addPermeability(final GTUType gtuType, final Permeable permeable) 116 { 117 if (permeable.equals(Permeable.LEFT) || permeable.equals(Permeable.BOTH)) 118 { 119 addPermeability(gtuType, LateralDirectionality.LEFT); 120 } 121 if (permeable.equals(Permeable.RIGHT) || permeable.equals(Permeable.BOTH)) 122 { 123 addPermeability(gtuType, LateralDirectionality.RIGHT); 124 } 125 } 126 127 /** The types of permeability of a stripe. */ 128 public enum Permeable 129 { 130 /** Permeable in the positive lateral direction compared to the design line direction. */ 131 LEFT, 132 /** Permeable in the negative lateral direction compared to the design line direction. */ 133 RIGHT, 134 /** Permeable in both directions. */ 135 BOTH; 136 } 137 138 /** {@inheritDoc} */ 139 @Override 140 @SuppressWarnings("checkstyle:designforextension") 141 public String toString() 142 { 143 return String.format("Stripe offset %.2fm..%.2fm, width %.2fm..%.2fm", getDesignLineOffsetAtBegin().getSI(), 144 getDesignLineOffsetAtEnd().getSI(), getBeginWidth().getSI(), getEndWidth().getSI()); 145 } 146 147 /** {@inheritDoc} */ 148 @Override 149 @SuppressWarnings("checkstyle:designforextension") 150 public Stripe clone(final CrossSectionLink newParentLink, final SimulatorInterface.TimeDoubleUnit newSimulator) 151 throws NetworkException 152 { 153 return new Stripe(newParentLink, newSimulator, this); 154 } 155 156 }