1 package org.opentrafficsim.road.network.lane; 2 3 import java.util.LinkedHashMap; 4 import java.util.LinkedHashSet; 5 import java.util.List; 6 import java.util.Map; 7 import java.util.Set; 8 import java.util.UUID; 9 10 import org.djunits.value.vdouble.scalar.Length; 11 import org.opentrafficsim.core.dsol.OTSSimulatorInterface; 12 import org.opentrafficsim.core.geometry.OTSGeometryException; 13 import org.opentrafficsim.core.gtu.GTUType; 14 import org.opentrafficsim.core.network.LateralDirectionality; 15 import org.opentrafficsim.core.network.NetworkException; 16 17 /** 18 * <p> 19 * Copyright (c) 2013-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br> 20 * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>. 21 * <p> 22 * $LastChangedDate: 2015-09-03 13:38:01 +0200 (Thu, 03 Sep 2015) $, @version $Revision: 1378 $, by $Author: averbraeck $, 23 * initial version Oct 25, 2014 <br> 24 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a> 25 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a> 26 */ 27 public abstract class RoadMarkerAlong extends CrossSectionElement 28 { 29 /** */ 30 private static final long serialVersionUID = 20141025L; 31 32 /** Lateral permeability per GTU type and direction. */ 33 private final Map<GTUType, Set<LateralDirectionality>> permeabilityMap = new LinkedHashMap<>(); 34 35 /** 36 * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction, with the direction from 37 * the StartNode towards the EndNode as the longitudinal direction. 38 * @param parentLink CrossSectionLink; Cross Section Link to which the element belongs. 39 * @param startCenterPosition Length; the lateral start position compared to the linear geometry of the Cross Section Link 40 * at the start of the road marker. 41 * @param endCenterPosition Length; the lateral end position compared to the linear geometry of the Cross Section Link at 42 * the end of the road marker. 43 * @param beginWidth Length; start width, positioned <i>symmetrically around</i> the lateral start position. 44 * @param endWidth Length; end width, positioned <i>symmetrically around</i> the lateral end position. 45 * @param fixGradualLateralOffset boolean; true if gradualLateralOffset needs to be fixed 46 * @throws OTSGeometryException when creation of the center line or contour geometry fails 47 * @throws NetworkException when id equal to null or not unique 48 */ 49 public RoadMarkerAlong(final CrossSectionLink parentLink, final Length startCenterPosition, final Length endCenterPosition, 50 final Length beginWidth, final Length endWidth, final boolean fixGradualLateralOffset) 51 throws OTSGeometryException, NetworkException 52 { 53 super(parentLink, UUID.randomUUID().toString(), startCenterPosition, endCenterPosition, beginWidth, endWidth, 54 fixGradualLateralOffset); 55 } 56 57 /** 58 * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction, with the direction from 59 * the StartNode towards the EndNode as the longitudinal direction. 60 * @param parentLink CrossSectionLink; Cross Section Link to which the element belongs. 61 * @param startCenterPosition Length; the lateral start position compared to the linear geometry of the Cross Section Link 62 * at the start of the road marker. 63 * @param endCenterPosition Length; the lateral end position compared to the linear geometry of the Cross Section Link at 64 * the end of the road marker. 65 * @param beginWidth Length; start width, positioned <i>symmetrically around</i> the lateral start position. 66 * @param endWidth Length; end width, positioned <i>symmetrically around</i> the lateral end position. 67 * @throws OTSGeometryException when creation of the center line or contour geometry fails 68 * @throws NetworkException when id equal to null or not unique 69 */ 70 public RoadMarkerAlong(final CrossSectionLink parentLink, final Length startCenterPosition, final Length endCenterPosition, 71 final Length beginWidth, final Length endWidth) throws OTSGeometryException, NetworkException 72 { 73 this(parentLink, startCenterPosition, endCenterPosition, beginWidth, endWidth, false); 74 } 75 76 /** 77 * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction, with the direction from 78 * the StartNode towards the EndNode as the longitudinal direction. 79 * @param parentLink CrossSectionLink; Cross Section Link to which the element belongs. 80 * @param lateralCenterPosition Length; the lateral start position compared to the linear geometry of the Cross Section 81 * Link. 82 * @param width Length; start width, positioned <i>symmetrically around</i> the lateral start position. 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 RoadMarkerAlong(final CrossSectionLink parentLink, final Length lateralCenterPosition, final Length width) 87 throws OTSGeometryException, NetworkException 88 { 89 super(parentLink, UUID.randomUUID().toString(), lateralCenterPosition, width); 90 } 91 92 /** 93 * <b>Note:</b> LEFT is seen as a positive lateral direction, RIGHT as a negative lateral direction, with the direction from 94 * the StartNode towards the EndNode as the longitudinal direction. 95 * @param parentLink CrossSectionLink; Cross Section Link to which the element belongs. 96 * @param crossSectionSlices List<CrossSectionSlice>; The offsets and widths at positions along the line, relative to 97 * the design line of the parent link. If there is just one with and offset, there should just be one element in 98 * the list with Length = 0. If there are more slices, the last one should be at the length of the design line. 99 * If not, a NetworkException is thrown. 100 * @throws OTSGeometryException when creation of the center line or contour geometry fails 101 * @throws NetworkException when id equal to null or not unique 102 */ 103 public RoadMarkerAlong(final CrossSectionLink parentLink, final List<CrossSectionSlice> crossSectionSlices) 104 throws OTSGeometryException, NetworkException 105 { 106 super(parentLink, UUID.randomUUID().toString(), crossSectionSlices); 107 } 108 109 /** 110 * Clone a RoadMarkerAlong for a new network. 111 * @param newCrossSectionLink CrossSectionLink; the new link to which the clone belongs 112 * @param newSimulator OTSSimulatorInterface; the new simulator for this network 113 * @param cse RoadMarkerAlong; the element to clone from 114 * @throws NetworkException if link already exists in the network, if name of the link is not unique, or if the start node 115 * or the end node of the link are not registered in the network. 116 */ 117 protected RoadMarkerAlong(final CrossSectionLink newCrossSectionLink, final OTSSimulatorInterface newSimulator, 118 final RoadMarkerAlong cse) throws NetworkException 119 { 120 super(newCrossSectionLink, newSimulator, cse); 121 this.permeabilityMap.putAll(cse.permeabilityMap); 122 } 123 124 /** {@inheritDoc} */ 125 @Override 126 public final double getZ() 127 { 128 return 0.0001; 129 } 130 131 /** 132 * Add lateral permeability for a GTU type in the direction of the design line of the overarching CrossSectionLink. 133 * Therefore, the lateral directionality of one-sided permeability has to be switched for left lanes. This is done because 134 * the CrossSectionLink has no idea in which direction vehicles will be moving. On a 1+1 lane road with overtaking 135 * possibilities, the longitudinal directionality of both lanes will be BOTH. Example: 136 * 137 * <pre> 138 * Suppose the design line runs from left to right. 139 * 140 * ========================= 141 * 142 * LANE 1L (BACKWARD) GTUs are allowed to move to lane 2L 143 * Permeability RIGHT is true, although vehicles will go to the LEFT... 144 * ------------------------- 145 * ========================= 146 * 147 * LANE 2L (BACKWARD) GTUs are NOT allowed to move to lane 1L nor to lane 2R 148 * No permeability defined (empty set) 149 * ========================= 150 * ========================= 151 * 152 * LANE 2R (FORWARD) GTUs are NOT allowed to move to lane 1R nor to lane 2L 153 * No permeability defined (empty set) 154 * ========================= 155 * ------------------------- 156 * 157 * LANE 1R (FORWARD) GTUs are allowed to move to lane 2R 158 * Permeability LEFT is true 159 * ========================= 160 * </pre> 161 * 162 * <b>Note:</b> GTUType.ALL can be used to set permeability for all types of GTU at once. 163 * <p> 164 * @param gtuType GTUType; GTU type to add permeability for. 165 * @param lateralDirection LateralDirectionality; direction to add (LEFT or RIGHT) compared to the direction of the design 166 * line. 167 */ 168 public final void addPermeability(final GTUType gtuType, final LateralDirectionality lateralDirection) 169 { 170 if (!this.permeabilityMap.containsKey(gtuType)) 171 { 172 this.permeabilityMap.put(gtuType, new LinkedHashSet<LateralDirectionality>(2)); 173 } 174 this.permeabilityMap.get(gtuType).add(lateralDirection); 175 } 176 177 /** 178 * @param gtuType GTUType; GTU type to look for. 179 * @param lateralDirection LateralDirectionality; direction to look for (LEFT or RIGHT) compared to the direction of the 180 * design line. 181 * @return whether the road marker is permeable for the GTU type. 182 */ 183 public final boolean isPermeable(final GTUType gtuType, final LateralDirectionality lateralDirection) 184 { 185 for (GTUType testGTUType = gtuType; null != testGTUType; testGTUType = testGTUType.getParent()) 186 { 187 Set<LateralDirectionality> directions = this.permeabilityMap.get(testGTUType); 188 if (null != directions) 189 { 190 return directions.contains(lateralDirection); 191 } 192 } 193 return false; 194 } 195 196 /** 197 * @return permeabilityMap for internal use in (sub)classes. 198 */ 199 protected final Map<GTUType, Set<LateralDirectionality>> getPermeabilityMap() 200 { 201 return this.permeabilityMap; 202 } 203 204 }