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.Duration;
10 import org.djunits.value.vdouble.scalar.Length;
11 import org.djunits.value.vdouble.scalar.Speed;
12 import org.djunits.value.vdouble.scalar.Time;
13 import org.opentrafficsim.core.dsol.OTSModelInterface;
14 import org.opentrafficsim.core.dsol.OTSSimTimeDouble;
15 import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
16 import org.opentrafficsim.core.geometry.OTSGeometryException;
17 import org.opentrafficsim.core.geometry.OTSLine3D;
18 import org.opentrafficsim.core.geometry.OTSPoint3D;
19 import org.opentrafficsim.core.network.LinkType;
20 import org.opentrafficsim.core.network.LongitudinalDirectionality;
21 import org.opentrafficsim.core.network.NetworkException;
22 import org.opentrafficsim.core.network.OTSNetwork;
23 import org.opentrafficsim.core.network.OTSNode;
24 import org.opentrafficsim.road.network.animation.LaneAnimation;
25 import org.opentrafficsim.road.network.animation.ShoulderAnimation;
26 import org.opentrafficsim.road.network.lane.CrossSectionLink;
27 import org.opentrafficsim.road.network.lane.Lane;
28 import org.opentrafficsim.road.network.lane.NoTrafficLane;
29 import org.opentrafficsim.road.network.lane.Shoulder;
30 import org.opentrafficsim.road.network.lane.changing.LaneKeepingPolicy;
31 import org.opentrafficsim.road.network.lane.changing.OvertakingConditions;
32
33 import nl.tudelft.simulation.dsol.SimRuntimeException;
34 import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
35
36
37
38
39
40
41
42
43
44
45
46 public class TestModel implements OTSModelInterface, UNITS
47 {
48
49 private static final long serialVersionUID = 1L;
50
51
52 private OTSSimulatorInterface simulator;
53
54
55 private OTSNetwork network = new OTSNetwork("geometry test network");
56
57
58 @Override
59 public final void constructModel(final SimulatorInterface<Time, Duration, OTSSimTimeDouble> theSimulator)
60 throws SimRuntimeException, RemoteException
61 {
62 this.simulator = (OTSSimulatorInterface) theSimulator;
63
64
65
66
67 try
68 {
69 OTSNode n0 = new OTSNode(this.network, "N0", new OTSPoint3D(-25.0, 0.0));
70 OTSNode n1 = new OTSNode(this.network, "N1", new OTSPoint3D(0.0, 0.0));
71 CrossSectionLink l01 = new CrossSectionLink(this.network, "L01", n0, n1, LinkType.ALL,
72 new OTSLine3D(new OTSPoint3D[] { new OTSPoint3D(-25.0, 0.0), new OTSPoint3D(0.0, 0.0) }), this.simulator,
73 LongitudinalDirectionality.DIR_BOTH, LaneKeepingPolicy.KEEP_RIGHT);
74
75 OTSNode n2 = new OTSNode(this.network, "N2", new OTSPoint3D(25.0, 20.0));
76 CrossSectionLink l12 = new CrossSectionLink(this.network, "L12", n1, n2, LinkType.ALL,
77 new OTSLine3D(new OTSPoint3D[] { new OTSPoint3D(0.0, 0.0), new OTSPoint3D(25.0, 20.0) }), this.simulator,
78 LongitudinalDirectionality.DIR_BOTH, LaneKeepingPolicy.KEEP_RIGHT);
79
80 OTSNode n3 = new OTSNode(this.network, "N3", new OTSPoint3D(50.0, 0.0));
81 CrossSectionLink l23 = new CrossSectionLink(this.network, "L23", n2, n3, LinkType.ALL,
82 new OTSLine3D(new OTSPoint3D[] { new OTSPoint3D(25.0, 20.0), new OTSPoint3D(50.0, 0.0) }), this.simulator,
83 LongitudinalDirectionality.DIR_BOTH, LaneKeepingPolicy.KEEP_RIGHT);
84
85 OTSNode n4 = new OTSNode(this.network, "N4", new OTSPoint3D(75.0, -20.0));
86 CrossSectionLink l34 = new CrossSectionLink(this.network, "L34", n3, n4, LinkType.ALL,
87 new OTSLine3D(new OTSPoint3D[] { new OTSPoint3D(50.0, 0.0), new OTSPoint3D(75.0, -20.0) }), this.simulator,
88 LongitudinalDirectionality.DIR_BOTH, LaneKeepingPolicy.KEEP_RIGHT);
89
90 OTSNode n5 = new OTSNode(this.network, "N5", new OTSPoint3D(100.0, 0.0));
91 CrossSectionLink l45 = new CrossSectionLink(this.network, "L45", n4, n5, LinkType.ALL,
92 new OTSLine3D(new OTSPoint3D[] { new OTSPoint3D(75.0, -20.0), new OTSPoint3D(100.0, 0.0) }), this.simulator,
93 LongitudinalDirectionality.DIR_BOTH, LaneKeepingPolicy.KEEP_RIGHT);
94
95 OTSNode n6 = new OTSNode(this.network, "N6", new OTSPoint3D(125.0, 0.0));
96 CrossSectionLink l56 = new CrossSectionLink(this.network, "L56", n5, n6, LinkType.ALL,
97 new OTSLine3D(new OTSPoint3D[] { new OTSPoint3D(100.0, 0.0), new OTSPoint3D(125.0, 0.0) }), this.simulator,
98 LongitudinalDirectionality.DIR_BOTH, LaneKeepingPolicy.KEEP_RIGHT);
99
100 OTSNode n7 = new OTSNode(this.network, "N7", new OTSPoint3D(300.0, 0.0));
101 CrossSectionLink l67 = new CrossSectionLink(this.network, "L67", n6, n7, LinkType.ALL,
102 new OTSLine3D(new OTSPoint3D[] { new OTSPoint3D(125.0, 0.0), new OTSPoint3D(150.0, 0.0),
103 new OTSPoint3D(175.0, 20.0), new OTSPoint3D(200.0, 0.0), new OTSPoint3D(225.0, -20.0),
104 new OTSPoint3D(250.0, 0.0), new OTSPoint3D(300.0, 0.0) }), this.simulator,
105 LongitudinalDirectionality.DIR_BOTH, LaneKeepingPolicy.KEEP_RIGHT);
106
107 add2x2Lanes(l01);
108 add2x2Lanes(l12);
109 add2x2Lanes(l23);
110 add2x2Lanes(l34);
111 add2x2Lanes(l45);
112 add2x2Lanes(l56);
113 add2x2Lanes(l67);
114 }
115 catch (NetworkException | OTSGeometryException exception)
116 {
117 exception.printStackTrace();
118 }
119 }
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155 private void add2x2Lanes(final CrossSectionLink link) throws NetworkException, OTSGeometryException
156 {
157
158
159 Length m05 = new Length(0.5, METER);
160 Length m10 = new Length(1.0, METER);
161 Length m35 = new Length(3.5, METER);
162 Speed speedLimit = new Speed(100, KM_PER_HOUR);
163
164 Shoulder sL = new Shoulder(link, "sL", new Length(9.0, METER), m10);
165
166 Lane laneELL = new NoTrafficLane(link, "ELL", new Length(8.25, METER), new Length(8.25, METER), m05, m05);
167 Lane laneL1 = new Lane(link, "L1", new Length(6.25, METER), new Length(6.25, METER), m35, m35, null,
168 LongitudinalDirectionality.DIR_MINUS, speedLimit, new OvertakingConditions.LeftAndRight());
169 Lane laneL2 = new Lane(link, "L2", new Length(2.75, METER), new Length(2.75, METER), m35, m35, null,
170 LongitudinalDirectionality.DIR_MINUS, speedLimit, new OvertakingConditions.LeftAndRight());
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,
177 LongitudinalDirectionality.DIR_PLUS, speedLimit, new OvertakingConditions.LeftAndRight());
178 Lane laneR1 = new Lane(link, "R1", new Length(-6.25, METER), new Length(-6.25, METER), m35, m35, null,
179 LongitudinalDirectionality.DIR_PLUS, speedLimit, new OvertakingConditions.LeftAndRight());
180 Lane laneERR = new NoTrafficLane(link, "ERR", new Length(-8.25, METER), new Length(-8.25, METER), m05, m05);
181
182 Shoulder sR = new Shoulder(link, "sR", new Length(-9.0, METER), m10);
183
184 try
185 {
186 new LaneAnimation(laneELL, this.simulator, Color.GRAY, false);
187 new LaneAnimation(laneL1, this.simulator, Color.GRAY, false);
188 new LaneAnimation(laneL2, this.simulator, Color.GRAY, false);
189 new LaneAnimation(laneELM, this.simulator, Color.GRAY, false);
190 new LaneAnimation(laneERM, this.simulator, Color.GRAY, false);
191 new LaneAnimation(laneR2, this.simulator, Color.GRAY, false);
192 new LaneAnimation(laneR1, this.simulator, Color.GRAY, false);
193 new LaneAnimation(laneERR, this.simulator, Color.GRAY, false);
194
195 new ShoulderAnimation(sL, this.simulator, Color.GREEN);
196 new ShoulderAnimation(sM, this.simulator, Color.GREEN);
197 new ShoulderAnimation(sR, this.simulator, Color.GREEN);
198 }
199 catch (NamingException | RemoteException ne)
200 {
201
202 }
203 }
204
205
206 @Override
207 public final SimulatorInterface<Time, Duration, OTSSimTimeDouble> getSimulator() throws RemoteException
208 {
209 return this.simulator;
210 }
211
212
213 @Override
214 public final OTSNetwork getNetwork()
215 {
216 return this.network;
217 }
218
219 }