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.value.vdouble.scalar.DoubleScalar.Abs;
13 import org.djunits.value.vdouble.scalar.DoubleScalar.Rel;
14 import org.opentrafficsim.core.OTS_SCALAR;
15 import org.opentrafficsim.core.dsol.OTSModelInterface;
16 import org.opentrafficsim.core.dsol.OTSSimTimeDouble;
17 import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
18 import org.opentrafficsim.core.geometry.OTSGeometryException;
19 import org.opentrafficsim.core.geometry.OTSLine3D;
20 import org.opentrafficsim.core.geometry.OTSPoint3D;
21 import org.opentrafficsim.core.network.LongitudinalDirectionality;
22 import org.opentrafficsim.core.network.NetworkException;
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
34
35
36
37
38
39
40
41
42
43 public class TestModel implements OTSModelInterface, OTS_SCALAR
44 {
45
46 private static final long serialVersionUID = 1L;
47
48
49 private OTSSimulatorInterface simulator;
50
51
52 @Override
53 public final void
54 constructModel(final SimulatorInterface<Abs<TimeUnit>, Rel<TimeUnit>, OTSSimTimeDouble> pSimulator)
55 throws SimRuntimeException, RemoteException
56 {
57 this.simulator = (OTSSimulatorInterface) pSimulator;
58
59
60
61 OTSNode n0 = new OTSNode("N0", new OTSPoint3D(-25.0, 0.0));
62 OTSNode n1 = new OTSNode("N1", new OTSPoint3D(0.0, 0.0));
63 CrossSectionLink l01 =
64 new CrossSectionLink("L01", n0, n1, new OTSLine3D(new OTSPoint3D[]{new OTSPoint3D(-25.0, 0.0),
65 new OTSPoint3D(0.0, 0.0)}), LaneKeepingPolicy.KEEP_RIGHT);
66
67 OTSNode n2 = new OTSNode("N2", new OTSPoint3D(25.0, 20.0));
68 CrossSectionLink l12 =
69 new CrossSectionLink("L12", n1, n2, new OTSLine3D(new OTSPoint3D[]{new OTSPoint3D(0.0, 0.0),
70 new OTSPoint3D(25.0, 20.0)}), LaneKeepingPolicy.KEEP_RIGHT);
71
72 OTSNode n3 = new OTSNode("N3", new OTSPoint3D(50.0, 0.0));
73 CrossSectionLink l23 =
74 new CrossSectionLink("L23", n2, n3, new OTSLine3D(new OTSPoint3D[]{new OTSPoint3D(25.0, 20.0),
75 new OTSPoint3D(50.0, 0.0)}), LaneKeepingPolicy.KEEP_RIGHT);
76
77 OTSNode n4 = new OTSNode("N4", new OTSPoint3D(75.0, -20.0));
78 CrossSectionLink l34 =
79 new CrossSectionLink("L34", n3, n4, new OTSLine3D(new OTSPoint3D[]{new OTSPoint3D(50.0, 0.0),
80 new OTSPoint3D(75.0, -20.0)}), LaneKeepingPolicy.KEEP_RIGHT);
81
82 OTSNode n5 = new OTSNode("N5", new OTSPoint3D(100.0, 0.0));
83 CrossSectionLink l45 =
84 new CrossSectionLink("L45", n4, n5, new OTSLine3D(new OTSPoint3D[]{new OTSPoint3D(75.0, -20.0),
85 new OTSPoint3D(100.0, 0.0)}), LaneKeepingPolicy.KEEP_RIGHT);
86
87 OTSNode n6 = new OTSNode("N6", new OTSPoint3D(125.0, 0.0));
88 CrossSectionLink l56 =
89 new CrossSectionLink("L56", n5, n6, new OTSLine3D(new OTSPoint3D[]{new OTSPoint3D(100.0, 0.0),
90 new OTSPoint3D(125.0, 0.0)}), LaneKeepingPolicy.KEEP_RIGHT);
91
92 OTSNode n7 = new OTSNode("N7", new OTSPoint3D(300.0, 0.0));
93 CrossSectionLink l67 =
94 new CrossSectionLink("L67", n6, n7, new OTSLine3D(new OTSPoint3D[]{new OTSPoint3D(125.0, 0.0),
95 new OTSPoint3D(150.0, 0.0), new OTSPoint3D(175.0, 20.0), new OTSPoint3D(200.0, 0.0),
96 new OTSPoint3D(225.0, -20.0), new OTSPoint3D(250.0, 0.0), new OTSPoint3D(300.0, 0.0)}),
97 LaneKeepingPolicy.KEEP_RIGHT);
98
99 try
100 {
101 add2x2Lanes(l01);
102 add2x2Lanes(l12);
103 add2x2Lanes(l23);
104 add2x2Lanes(l34);
105 add2x2Lanes(l45);
106 add2x2Lanes(l56);
107 add2x2Lanes(l67);
108 }
109 catch (NetworkException | OTSGeometryException exception)
110 {
111 exception.printStackTrace();
112 }
113 }
114
115
116
117
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 private void add2x2Lanes(final CrossSectionLink link) throws NetworkException, OTSGeometryException
150 {
151
152
153 Length.Rel m05 = new Length.Rel(0.5, METER);
154 Length.Rel m10 = new Length.Rel(1.0, METER);
155 Length.Rel m35 = new Length.Rel(3.5, METER);
156 Speed.Abs speedLimit = new Speed.Abs(100, KM_PER_HOUR);
157
158 Shoulder sL = new Shoulder(link, "sL", new Length.Rel(9.0, METER), m10, m10);
159
160 Lane laneELL =
161 new NoTrafficLane(link, "ELL", new Length.Rel(8.25, METER), new Length.Rel(8.25, METER), m05, m05);
162 Lane laneL1 =
163 new Lane(link, "L1", new Length.Rel(6.25, METER), new Length.Rel(6.25, METER), m35, m35, null,
164 LongitudinalDirectionality.BACKWARD, speedLimit, new OvertakingConditions.LeftAndRight());
165 Lane laneL2 =
166 new Lane(link, "L2", new Length.Rel(2.75, METER), new Length.Rel(2.75, METER), m35, m35, null,
167 LongitudinalDirectionality.BACKWARD, speedLimit, new OvertakingConditions.LeftAndRight());
168 Lane laneELM =
169 new NoTrafficLane(link, "ELM", new Length.Rel(0.75, METER), new Length.Rel(0.75, METER), m05, m05);
170
171 Shoulder sM = new Shoulder(link, "sM", new Length.Rel(0.0, METER), m10, m10);
172
173 Lane laneERM =
174 new NoTrafficLane(link, "ERM", new Length.Rel(-0.75, METER), new Length.Rel(-0.75, METER), m05, m05);
175 Lane laneR2 =
176 new Lane(link, "R2", new Length.Rel(-2.75, METER), new Length.Rel(-2.75, METER), m35, m35, null,
177 LongitudinalDirectionality.FORWARD, speedLimit, new OvertakingConditions.LeftAndRight());
178 Lane laneR1 =
179 new Lane(link, "R1", new Length.Rel(-6.25, METER), new Length.Rel(-6.25, METER), m35, m35, null,
180 LongitudinalDirectionality.FORWARD, speedLimit, new OvertakingConditions.LeftAndRight());
181 Lane laneERR =
182 new NoTrafficLane(link, "ERR", new Length.Rel(-8.25, METER), new Length.Rel(-8.25, METER), m05, m05);
183
184 Shoulder sR = new Shoulder(link, "sR", new Length.Rel(-9.0, METER), m10, m10);
185
186 try
187 {
188 new LaneAnimation(laneELL, this.simulator, Color.GRAY);
189 new LaneAnimation(laneL1, this.simulator, Color.GRAY);
190 new LaneAnimation(laneL2, this.simulator, Color.GRAY);
191 new LaneAnimation(laneELM, this.simulator, Color.GRAY);
192 new LaneAnimation(laneERM, this.simulator, Color.GRAY);
193 new LaneAnimation(laneR2, this.simulator, Color.GRAY);
194 new LaneAnimation(laneR1, this.simulator, Color.GRAY);
195 new LaneAnimation(laneERR, this.simulator, Color.GRAY);
196
197 new ShoulderAnimation(sL, this.simulator, Color.GREEN);
198 new ShoulderAnimation(sM, this.simulator, Color.GREEN);
199 new ShoulderAnimation(sR, this.simulator, Color.GREEN);
200 }
201 catch (NamingException | RemoteException ne)
202 {
203
204 }
205 }
206
207
208 @Override
209 public final SimulatorInterface<Abs<TimeUnit>, Rel<TimeUnit>, OTSSimTimeDouble> getSimulator()
210 throws RemoteException
211 {
212 return this.simulator;
213 }
214 }