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