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.dsol.OTSSimulatorInterface; 8 import org.opentrafficsim.core.geometry.OTSGeometryException; 9 import org.opentrafficsim.core.gtu.GTUType; 10 import org.opentrafficsim.core.network.LateralDirectionality; 11 import org.opentrafficsim.core.network.NetworkException; 12 import org.opentrafficsim.core.network.OTSNetwork; 13 14 /** 15 * Longitudinal road stripes; simple constructors. 16 * <p> 17 * Copyright (c) 2013-2017 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 Cross Section Link to which the element belongs 34 * @param lateralCenterPositionStart the lateral start position compared to the linear geometry of the Cross Section Link 35 * @param lateralCenterPositionEnd the lateral start position compared to the linear geometry of the Cross Section Link 36 * @param width positioned <i>symmetrically around</i> the center line given by the lateralCenterPosition. 37 * @throws OTSGeometryException when creation of the center line or contour geometry fails 38 * @throws NetworkException when id equal to null or not unique 39 */ 40 public Stripe(final CrossSectionLink parentLink, final Length lateralCenterPositionStart, 41 final Length lateralCenterPositionEnd, final Length width) throws OTSGeometryException, NetworkException 42 { 43 super(parentLink, lateralCenterPositionStart, lateralCenterPositionEnd, width, width); 44 } 45 46 /** 47 * Helper constructor that immediately provides permeability for a number of GTU classes.<br> 48 * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction, with the direction from 49 * the StartNode towards the EndNode as the longitudinal direction. 50 * @param parentLink Cross Section Link to which the element belongs 51 * @param lateralCenterPositionStart the lateral start position compared to the linear geometry of the Cross Section Link 52 * @param lateralCenterPositionEnd the lateral start position compared to the linear geometry of the Cross Section Link 53 * @param width positioned <i>symmetrically around</i> the center line given by the lateralCenterPosition 54 * @param gtuTypes the GTU types for which the permeability is defined 55 * @param permeable one of the enums of Stripe.Permeable to define the permeability 56 * @throws OTSGeometryException when creation of the center line or contour geometry fails 57 * @throws NetworkException when id equal to null or not unique 58 */ 59 public Stripe(final CrossSectionLink parentLink, final Length lateralCenterPositionStart, 60 final Length lateralCenterPositionEnd, final Length width, final Set<GTUType> gtuTypes, final Permeable permeable) 61 throws OTSGeometryException, NetworkException 62 { 63 super(parentLink, lateralCenterPositionStart, lateralCenterPositionEnd, width, width); 64 for (GTUType gtuType : gtuTypes) 65 { 66 addPermeability(gtuType, permeable); 67 } 68 } 69 70 /** 71 * Helper constructor that immediately provides permeability for all 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 Cross Section Link to which the element belongs 75 * @param crossSectionSlices The offsets and widths at positions along the line, relative to the design line of the parent 76 * link. If there is just one with and offset, there should just be one element in the list with Length = 0. If 77 * there are more slices, the last one should be at the length of the design line. If not, a NetworkException is 78 * thrown. 79 * @param permeable one of the enums of Stripe.Permeable to define the permeability 80 * @throws OTSGeometryException when creation of the center line or contour geometry fails 81 * @throws NetworkException when id equal to null or not unique 82 */ 83 public Stripe(final CrossSectionLink parentLink, final List<CrossSectionSlice> crossSectionSlices, 84 final Permeable permeable) throws OTSGeometryException, NetworkException 85 { 86 super(parentLink, crossSectionSlices); 87 addPermeability(GTUType.VEHICLE, permeable); 88 addPermeability(GTUType.PEDESTRIAN, permeable); 89 } 90 91 /** 92 * Clone a Stripe for a new network. 93 * @param newParentLink the new link to which the clone belongs 94 * @param newSimulator the new simulator for this network 95 * @param animation whether to (re)create animation or not 96 * @param cse the element to clone from 97 * @throws NetworkException if link already exists in the network, if name of the link is not unique, or if the start node 98 * or the end node of the link are not registered in the network. 99 */ 100 protected Stripe(final CrossSectionLink newParentLink, final OTSSimulatorInterface newSimulator, final boolean animation, 101 final Stripe cse) throws NetworkException 102 { 103 super(newParentLink, newSimulator, animation, cse); 104 105 if (animation) 106 { 107 OTSNetwork.cloneAnimation(cse, this, cse.getParentLink().getSimulator(), newSimulator); 108 } 109 } 110 111 /** 112 * @param gtuType GTU type to add permeability for. 113 * @param 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 OTSSimulatorInterface newSimulator, final boolean animation) 151 throws NetworkException 152 { 153 return new Stripe(newParentLink, newSimulator, animation, this); 154 } 155 156 }