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