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 nl.tudelft.simulation.dsol.SimRuntimeException;
9 import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
10
11 import org.djunits.unit.TimeUnit;
12 import org.djunits.unit.UNITS;
13 import org.djunits.value.vdouble.scalar.DoubleScalar.Abs;
14 import org.djunits.value.vdouble.scalar.DoubleScalar.Rel;
15 import org.djunits.value.vdouble.scalar.Length;
16 import org.djunits.value.vdouble.scalar.Speed;
17 import org.opentrafficsim.core.dsol.OTSModelInterface;
18 import org.opentrafficsim.core.dsol.OTSSimTimeDouble;
19 import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
20 import org.opentrafficsim.core.geometry.OTSGeometryException;
21 import org.opentrafficsim.core.geometry.OTSLine3D;
22 import org.opentrafficsim.core.geometry.OTSPoint3D;
23 import org.opentrafficsim.core.network.LinkType;
24 import org.opentrafficsim.core.network.LongitudinalDirectionality;
25 import org.opentrafficsim.core.network.NetworkException;
26 import org.opentrafficsim.core.network.OTSNode;
27 import org.opentrafficsim.road.network.animation.LaneAnimation;
28 import org.opentrafficsim.road.network.animation.ShoulderAnimation;
29 import org.opentrafficsim.road.network.lane.CrossSectionLink;
30 import org.opentrafficsim.road.network.lane.Lane;
31 import org.opentrafficsim.road.network.lane.NoTrafficLane;
32 import org.opentrafficsim.road.network.lane.Shoulder;
33 import org.opentrafficsim.road.network.lane.changing.LaneKeepingPolicy;
34 import org.opentrafficsim.road.network.lane.changing.OvertakingConditions;
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 @Override
56 public final void
57 constructModel(final SimulatorInterface<Abs<TimeUnit>, Rel<TimeUnit>, OTSSimTimeDouble> pSimulator)
58 throws SimRuntimeException, RemoteException
59 {
60 this.simulator = (OTSSimulatorInterface) pSimulator;
61
62
63
64 try
65 {
66 OTSNode n0 = new OTSNode("N0", new OTSPoint3D(-25.0, 0.0));
67 OTSNode n1 = new OTSNode("N1", new OTSPoint3D(0.0, 0.0));
68 CrossSectionLink l01 =
69 new CrossSectionLink("L01", n0, n1, LinkType.ALL, new OTSLine3D(new OTSPoint3D[]{
70 new OTSPoint3D(-25.0, 0.0), new OTSPoint3D(0.0, 0.0)}), LongitudinalDirectionality.DIR_BOTH,
71 LaneKeepingPolicy.KEEP_RIGHT);
72
73 OTSNode n2 = new OTSNode("N2", new OTSPoint3D(25.0, 20.0));
74 CrossSectionLink l12 =
75 new CrossSectionLink("L12", n1, n2, LinkType.ALL, new OTSLine3D(new OTSPoint3D[]{
76 new OTSPoint3D(0.0, 0.0), new OTSPoint3D(25.0, 20.0)}), LongitudinalDirectionality.DIR_BOTH,
77 LaneKeepingPolicy.KEEP_RIGHT);
78
79 OTSNode n3 = new OTSNode("N3", new OTSPoint3D(50.0, 0.0));
80 CrossSectionLink l23 =
81 new CrossSectionLink("L23", n2, n3, LinkType.ALL, new OTSLine3D(new OTSPoint3D[]{
82 new OTSPoint3D(25.0, 20.0), new OTSPoint3D(50.0, 0.0)}), LongitudinalDirectionality.DIR_BOTH,
83 LaneKeepingPolicy.KEEP_RIGHT);
84
85 OTSNode n4 = new OTSNode("N4", new OTSPoint3D(75.0, -20.0));
86 CrossSectionLink l34 =
87 new CrossSectionLink("L34", n3, n4, LinkType.ALL, new OTSLine3D(new OTSPoint3D[]{
88 new OTSPoint3D(50.0, 0.0), new OTSPoint3D(75.0, -20.0)}), LongitudinalDirectionality.DIR_BOTH,
89 LaneKeepingPolicy.KEEP_RIGHT);
90
91 OTSNode n5 = new OTSNode("N5", new OTSPoint3D(100.0, 0.0));
92 CrossSectionLink l45 =
93 new CrossSectionLink("L45", n4, n5, LinkType.ALL, new OTSLine3D(new OTSPoint3D[]{
94 new OTSPoint3D(75.0, -20.0), new OTSPoint3D(100.0, 0.0)}), LongitudinalDirectionality.DIR_BOTH,
95 LaneKeepingPolicy.KEEP_RIGHT);
96
97 OTSNode n6 = new OTSNode("N6", new OTSPoint3D(125.0, 0.0));
98 CrossSectionLink l56 =
99 new CrossSectionLink("L56", n5, n6, LinkType.ALL, new OTSLine3D(new OTSPoint3D[]{
100 new OTSPoint3D(100.0, 0.0), new OTSPoint3D(125.0, 0.0)}), LongitudinalDirectionality.DIR_BOTH,
101 LaneKeepingPolicy.KEEP_RIGHT);
102
103 OTSNode n7 = new OTSNode("N7", new OTSPoint3D(300.0, 0.0));
104 CrossSectionLink l67 =
105 new CrossSectionLink("L67", n6, n7, LinkType.ALL, new OTSLine3D(new OTSPoint3D[]{
106 new OTSPoint3D(125.0, 0.0), new OTSPoint3D(150.0, 0.0), new OTSPoint3D(175.0, 20.0),
107 new OTSPoint3D(200.0, 0.0), new OTSPoint3D(225.0, -20.0), new OTSPoint3D(250.0, 0.0),
108 new OTSPoint3D(300.0, 0.0)}), LongitudinalDirectionality.DIR_BOTH, LaneKeepingPolicy.KEEP_RIGHT);
109
110 add2x2Lanes(l01);
111 add2x2Lanes(l12);
112 add2x2Lanes(l23);
113 add2x2Lanes(l34);
114 add2x2Lanes(l45);
115 add2x2Lanes(l56);
116 add2x2Lanes(l67);
117 }
118 catch (NetworkException | OTSGeometryException exception)
119 {
120 exception.printStackTrace();
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
156
157
158 private void add2x2Lanes(final CrossSectionLink link) throws NetworkException, OTSGeometryException
159 {
160
161
162 Length.Rel m05 = new Length.Rel(0.5, METER);
163 Length.Rel m10 = new Length.Rel(1.0, METER);
164 Length.Rel m35 = new Length.Rel(3.5, METER);
165 Speed speedLimit = new Speed(100, KM_PER_HOUR);
166
167 Shoulder sL = new Shoulder(link, "sL", new Length.Rel(9.0, METER), m10);
168
169 Lane laneELL =
170 new NoTrafficLane(link, "ELL", new Length.Rel(8.25, METER), new Length.Rel(8.25, METER), m05, m05);
171 Lane laneL1 =
172 new Lane(link, "L1", new Length.Rel(6.25, METER), new Length.Rel(6.25, METER), m35, m35, null,
173 LongitudinalDirectionality.DIR_MINUS, speedLimit, new OvertakingConditions.LeftAndRight());
174 Lane laneL2 =
175 new Lane(link, "L2", new Length.Rel(2.75, METER), new Length.Rel(2.75, METER), m35, m35, null,
176 LongitudinalDirectionality.DIR_MINUS, speedLimit, new OvertakingConditions.LeftAndRight());
177 Lane laneELM =
178 new NoTrafficLane(link, "ELM", new Length.Rel(0.75, METER), new Length.Rel(0.75, METER), m05, m05);
179
180 Shoulder sM = new Shoulder(link, "sM", new Length.Rel(0.0, METER), m10);
181
182 Lane laneERM =
183 new NoTrafficLane(link, "ERM", new Length.Rel(-0.75, METER), new Length.Rel(-0.75, METER), m05, m05);
184 Lane laneR2 =
185 new Lane(link, "R2", new Length.Rel(-2.75, METER), new Length.Rel(-2.75, METER), m35, m35, null,
186 LongitudinalDirectionality.DIR_PLUS, speedLimit, new OvertakingConditions.LeftAndRight());
187 Lane laneR1 =
188 new Lane(link, "R1", new Length.Rel(-6.25, METER), new Length.Rel(-6.25, METER), m35, m35, null,
189 LongitudinalDirectionality.DIR_PLUS, speedLimit, new OvertakingConditions.LeftAndRight());
190 Lane laneERR =
191 new NoTrafficLane(link, "ERR", new Length.Rel(-8.25, METER), new Length.Rel(-8.25, METER), m05, m05);
192
193 Shoulder sR = new Shoulder(link, "sR", new Length.Rel(-9.0, METER), m10);
194
195 try
196 {
197 new LaneAnimation(laneELL, this.simulator, Color.GRAY, false);
198 new LaneAnimation(laneL1, this.simulator, Color.GRAY, false);
199 new LaneAnimation(laneL2, this.simulator, Color.GRAY, false);
200 new LaneAnimation(laneELM, this.simulator, Color.GRAY, false);
201 new LaneAnimation(laneERM, this.simulator, Color.GRAY, false);
202 new LaneAnimation(laneR2, this.simulator, Color.GRAY, false);
203 new LaneAnimation(laneR1, this.simulator, Color.GRAY, false);
204 new LaneAnimation(laneERR, this.simulator, Color.GRAY, false);
205
206 new ShoulderAnimation(sL, this.simulator, Color.GREEN);
207 new ShoulderAnimation(sM, this.simulator, Color.GREEN);
208 new ShoulderAnimation(sR, this.simulator, Color.GREEN);
209 }
210 catch (NamingException | RemoteException ne)
211 {
212
213 }
214 }
215
216
217 @Override
218 public final SimulatorInterface<Abs<TimeUnit>, Rel<TimeUnit>, OTSSimTimeDouble> getSimulator()
219 throws RemoteException
220 {
221 return this.simulator;
222 }
223 }