View Javadoc
1   package org.opentrafficsim.demo.geometry;
2   
3   import java.awt.Color;
4   import java.rmi.RemoteException;
5   
6   import javax.naming.NamingException;
7   
8   import org.djunits.unit.UNITS;
9   import org.djunits.value.vdouble.scalar.Length;
10  import org.djunits.value.vdouble.scalar.Speed;
11  import org.opentrafficsim.core.dsol.AbstractOTSModel;
12  import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
13  import org.opentrafficsim.core.geometry.OTSGeometryException;
14  import org.opentrafficsim.core.geometry.OTSLine3D;
15  import org.opentrafficsim.core.geometry.OTSPoint3D;
16  import org.opentrafficsim.core.network.LinkType;
17  import org.opentrafficsim.core.network.NetworkException;
18  import org.opentrafficsim.core.network.OTSNode;
19  import org.opentrafficsim.draw.road.LaneAnimation;
20  import org.opentrafficsim.draw.road.ShoulderAnimation;
21  import org.opentrafficsim.road.network.OTSRoadNetwork;
22  import org.opentrafficsim.road.network.lane.CrossSectionLink;
23  import org.opentrafficsim.road.network.lane.Lane;
24  import org.opentrafficsim.road.network.lane.NoTrafficLane;
25  import org.opentrafficsim.road.network.lane.Shoulder;
26  import org.opentrafficsim.road.network.lane.changing.LaneKeepingPolicy;
27  
28  import nl.tudelft.simulation.dsol.SimRuntimeException;
29  
30  /**
31   * <p>
32   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
33   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
34   * <p>
35   * $LastChangedDate: 2019-03-27 07:42:05 +0100 (Wed, 27 Mar 2019) $, @version $Revision: 5192 $, by $Author: averbraeck $,
36   * initial version ct 17, 2014 <br>
37   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
38   */
39  /** */
40  public class TestModel extends AbstractOTSModel implements UNITS
41  {
42      /**
43       * @param simulator OTSSimulatorInterface; the simulator
44       */
45      public TestModel(final OTSSimulatorInterface simulator)
46      {
47          super(simulator);
48      }
49  
50      /** */
51      private static final long serialVersionUID = 1L;
52  
53      /** the network. */
54      private OTSRoadNetwork network = new OTSRoadNetwork("geometry test network", true);
55  
56      /** {@inheritDoc} */
57      @Override
58      public final void constructModel() throws SimRuntimeException
59      {
60          // create a small graph and a road around it.
61  
62          try
63          {
64              OTSNode n0 = new OTSNode(this.network, "N0", new OTSPoint3D(-25.0, 0.0));
65              OTSNode n1 = new OTSNode(this.network, "N1", new OTSPoint3D(0.0, 0.0));
66              CrossSectionLink l01 =
67                      new CrossSectionLink(this.network, "L01", n0, n1, network.getLinkType(LinkType.DEFAULTS.ROAD),
68                              new OTSLine3D(new OTSPoint3D[] {new OTSPoint3D(-25.0, 0.0), new OTSPoint3D(0.0, 0.0)}),
69                              this.simulator, LaneKeepingPolicy.KEEPRIGHT);
70  
71              OTSNode n2 = new OTSNode(this.network, "N2", new OTSPoint3D(25.0, 20.0));
72              CrossSectionLink l12 =
73                      new CrossSectionLink(this.network, "L12", n1, n2, network.getLinkType(LinkType.DEFAULTS.ROAD),
74                              new OTSLine3D(new OTSPoint3D[] {new OTSPoint3D(0.0, 0.0), new OTSPoint3D(25.0, 20.0)}),
75                              this.simulator, LaneKeepingPolicy.KEEPRIGHT);
76  
77              OTSNode n3 = new OTSNode(this.network, "N3", new OTSPoint3D(50.0, 0.0));
78              CrossSectionLink l23 =
79                      new CrossSectionLink(this.network, "L23", n2, n3, network.getLinkType(LinkType.DEFAULTS.ROAD),
80                              new OTSLine3D(new OTSPoint3D[] {new OTSPoint3D(25.0, 20.0), new OTSPoint3D(50.0, 0.0)}),
81                              this.simulator, LaneKeepingPolicy.KEEPRIGHT);
82  
83              OTSNode n4 = new OTSNode(this.network, "N4", new OTSPoint3D(75.0, -20.0));
84              CrossSectionLink l34 =
85                      new CrossSectionLink(this.network, "L34", n3, n4, network.getLinkType(LinkType.DEFAULTS.ROAD),
86                              new OTSLine3D(new OTSPoint3D[] {new OTSPoint3D(50.0, 0.0), new OTSPoint3D(75.0, -20.0)}),
87                              this.simulator, LaneKeepingPolicy.KEEPRIGHT);
88  
89              OTSNode n5 = new OTSNode(this.network, "N5", new OTSPoint3D(100.0, 0.0));
90              CrossSectionLink l45 =
91                      new CrossSectionLink(this.network, "L45", n4, n5, network.getLinkType(LinkType.DEFAULTS.ROAD),
92                              new OTSLine3D(new OTSPoint3D[] {new OTSPoint3D(75.0, -20.0), new OTSPoint3D(100.0, 0.0)}),
93                              this.simulator, LaneKeepingPolicy.KEEPRIGHT);
94  
95              OTSNode n6 = new OTSNode(this.network, "N6", new OTSPoint3D(125.0, 0.0));
96              CrossSectionLink l56 =
97                      new CrossSectionLink(this.network, "L56", n5, n6, network.getLinkType(LinkType.DEFAULTS.ROAD),
98                              new OTSLine3D(new OTSPoint3D[] {new OTSPoint3D(100.0, 0.0), new OTSPoint3D(125.0, 0.0)}),
99                              this.simulator, LaneKeepingPolicy.KEEPRIGHT);
100 
101             OTSNode n7 = new OTSNode(this.network, "N7", new OTSPoint3D(300.0, 0.0));
102             CrossSectionLink l67 =
103                     new CrossSectionLink(this.network, "L67", n6, n7, network.getLinkType(LinkType.DEFAULTS.ROAD),
104                             new OTSLine3D(new OTSPoint3D[] {new OTSPoint3D(125.0, 0.0), new OTSPoint3D(150.0, 0.0),
105                                     new OTSPoint3D(175.0, 20.0), new OTSPoint3D(200.0, 0.0), new OTSPoint3D(225.0, -20.0),
106                                     new OTSPoint3D(250.0, 0.0), new OTSPoint3D(300.0, 0.0)}),
107                             this.simulator, LaneKeepingPolicy.KEEPRIGHT);
108 
109             add2x2Lanes(l01);
110             add2x2Lanes(l12);
111             add2x2Lanes(l23);
112             add2x2Lanes(l34);
113             add2x2Lanes(l45);
114             add2x2Lanes(l56);
115             add2x2Lanes(l67);
116         }
117         catch (NetworkException | OTSGeometryException exception)
118         {
119             exception.printStackTrace();
120         }
121     }
122 
123     /**
124      * The road is as follows; The design line goes from left to right.
125      * 
126      * <pre>
127      * ----------------------- +9.50
128      * SSSSS Shoulder SL SSSSS +9.00 (width = 1.0)
129      * ----------------------- +8.50
130      * EEEEE Emergency ELL EEE +8.25 (width = 0.5)
131      * ----------------------- +8.00
132      * LLLLL Lane L1 LLLLLLLLL +6.25 (width = 3.5)
133      * ----------------------- +4.50
134      * LLLLL Lane L2 LLLLLLLLL +2.75 (width = 3.5)
135      * ----------------------- +1.00
136      * EEEEE Emergency ELM EEE +0.75 (width = 0.5)
137      * ----------------------- +0.50
138      * SSSSS Shoulder SM SSSSS +0.00 (width = 1.0)
139      * ----------------------- -0.50
140      * EEEEE Emergency ERM EEE -0.75 (width = 0.5)
141      * ----------------------- -1.00
142      * LLLLL Lane R2 LLLLLLLLL -2.75 (width = 3.5)
143      * ----------------------- -4.50
144      * LLLLL Lane R1 LLLLLLLLL -6.25 (width = 3.5)
145      * ----------------------- -8.00
146      * EEEEE Emergency ERR EEE -8.25 (width = 0.5)
147      * ----------------------- -8.50
148      * SSSSS Shoulder SR SSSSS -9.00 (width = 1.0)
149      * ----------------------- -9.50
150      * </pre>
151      *
152      * <br>
153      * @param link CrossSectionLink; link.
154      * @throws NetworkException on network inconsistency
155      * @throws OTSGeometryException on network inconsistency
156      */
157     private void add2x2Lanes(final CrossSectionLink link) throws NetworkException, OTSGeometryException
158     {
159         // four lanes, grass underneath, lines between lane1-2 and lane 2-3, barrier between lane 2-3
160         // lane is 3.5 meters wide. gap between 3-4 is one meter. outside 0.5 meters on both sides
161         Length m05 = new Length(0.5, METER);
162         Length m10 = new Length(1.0, METER);
163         Length m35 = new Length(3.5, METER);
164         Speed speedLimit = new Speed(100, KM_PER_HOUR);
165 
166         Shoulder sL = new Shoulder(link, "sL", new Length(9.0, METER), m10);
167 
168         Lane laneELL = new NoTrafficLane(link, "ELL", new Length(8.25, METER), new Length(8.25, METER), m05, m05);
169         Lane laneL1 = new Lane(link, "L1", new Length(6.25, METER), new Length(6.25, METER), m35, m35, null, speedLimit);
170         Lane laneL2 = new Lane(link, "L2", new Length(2.75, METER), new Length(2.75, METER), m35, m35, null, speedLimit);
171         Lane laneELM = new NoTrafficLane(link, "ELM", new Length(0.75, METER), new Length(0.75, METER), m05, m05);
172 
173         Shoulder sM = new Shoulder(link, "sM", new Length(0.0, METER), m10);
174 
175         Lane laneERM = new NoTrafficLane(link, "ERM", new Length(-0.75, METER), new Length(-0.75, METER), m05, m05);
176         Lane laneR2 = new Lane(link, "R2", new Length(-2.75, METER), new Length(-2.75, METER), m35, m35, null, speedLimit);
177         Lane laneR1 = new Lane(link, "R1", new Length(-6.25, METER), new Length(-6.25, METER), m35, m35, null, speedLimit);
178         Lane laneERR = new NoTrafficLane(link, "ERR", new Length(-8.25, METER), new Length(-8.25, METER), m05, m05);
179 
180         Shoulder sR = new Shoulder(link, "sR", new Length(-9.0, METER), m10);
181 
182         try
183         {
184             new LaneAnimation(laneELL, this.simulator, Color.GRAY, false);
185             new LaneAnimation(laneL1, this.simulator, Color.GRAY, false);
186             new LaneAnimation(laneL2, this.simulator, Color.GRAY, false);
187             new LaneAnimation(laneELM, this.simulator, Color.GRAY, false);
188             new LaneAnimation(laneERM, this.simulator, Color.GRAY, false);
189             new LaneAnimation(laneR2, this.simulator, Color.GRAY, false);
190             new LaneAnimation(laneR1, this.simulator, Color.GRAY, false);
191             new LaneAnimation(laneERR, this.simulator, Color.GRAY, false);
192 
193             new ShoulderAnimation(sL, this.simulator, Color.GREEN);
194             new ShoulderAnimation(sM, this.simulator, Color.GREEN);
195             new ShoulderAnimation(sR, this.simulator, Color.GREEN);
196         }
197         catch (NamingException | RemoteException ne)
198         {
199             //
200         }
201     }
202 
203     /** {@inheritDoc} */
204     @Override
205     public final OTSRoadNetwork getNetwork()
206     {
207         return this.network;
208     }
209 
210 }