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