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.Network;
22 import org.opentrafficsim.core.network.NetworkException;
23 import org.opentrafficsim.core.network.OTSNetwork;
24 import org.opentrafficsim.core.network.OTSNode;
25 import org.opentrafficsim.road.network.animation.LaneAnimation;
26 import org.opentrafficsim.road.network.animation.ShoulderAnimation;
27 import org.opentrafficsim.road.network.lane.CrossSectionLink;
28 import org.opentrafficsim.road.network.lane.Lane;
29 import org.opentrafficsim.road.network.lane.NoTrafficLane;
30 import org.opentrafficsim.road.network.lane.Shoulder;
31 import org.opentrafficsim.road.network.lane.changing.LaneKeepingPolicy;
32 import org.opentrafficsim.road.network.lane.changing.OvertakingConditions;
33
34 import nl.tudelft.simulation.dsol.SimRuntimeException;
35 import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
36
37
38
39
40
41
42
43
44
45
46
47 public class TestModel implements OTSModelInterface, UNITS
48 {
49
50 private static final long serialVersionUID = 1L;
51
52
53 private OTSSimulatorInterface simulator;
54
55
56 @Override
57 public final void constructModel(final SimulatorInterface<Time, Duration, OTSSimTimeDouble> theSimulator)
58 throws SimRuntimeException, RemoteException
59 {
60 this.simulator = (OTSSimulatorInterface) theSimulator;
61 Network network = new OTSNetwork("geometry test network");
62
63
64
65 try
66 {
67 OTSNode n0 = new OTSNode(network, "N0", new OTSPoint3D(-25.0, 0.0));
68 OTSNode n1 = new OTSNode(network, "N1", new OTSPoint3D(0.0, 0.0));
69 CrossSectionLink l01 = new CrossSectionLink(network, "L01", n0, n1, LinkType.ALL,
70 new OTSLine3D(new OTSPoint3D[] { new OTSPoint3D(-25.0, 0.0), new OTSPoint3D(0.0, 0.0) }),
71 LongitudinalDirectionality.DIR_BOTH, LaneKeepingPolicy.KEEP_RIGHT);
72
73 OTSNode n2 = new OTSNode(network, "N2", new OTSPoint3D(25.0, 20.0));
74 CrossSectionLink l12 = new CrossSectionLink(network, "L12", n1, n2, LinkType.ALL,
75 new OTSLine3D(new OTSPoint3D[] { new OTSPoint3D(0.0, 0.0), new OTSPoint3D(25.0, 20.0) }),
76 LongitudinalDirectionality.DIR_BOTH, LaneKeepingPolicy.KEEP_RIGHT);
77
78 OTSNode n3 = new OTSNode(network, "N3", new OTSPoint3D(50.0, 0.0));
79 CrossSectionLink l23 = new CrossSectionLink(network, "L23", n2, n3, LinkType.ALL,
80 new OTSLine3D(new OTSPoint3D[] { new OTSPoint3D(25.0, 20.0), new OTSPoint3D(50.0, 0.0) }),
81 LongitudinalDirectionality.DIR_BOTH, LaneKeepingPolicy.KEEP_RIGHT);
82
83 OTSNode n4 = new OTSNode(network, "N4", new OTSPoint3D(75.0, -20.0));
84 CrossSectionLink l34 = new CrossSectionLink(network, "L34", n3, n4, LinkType.ALL,
85 new OTSLine3D(new OTSPoint3D[] { new OTSPoint3D(50.0, 0.0), new OTSPoint3D(75.0, -20.0) }),
86 LongitudinalDirectionality.DIR_BOTH, LaneKeepingPolicy.KEEP_RIGHT);
87
88 OTSNode n5 = new OTSNode(network, "N5", new OTSPoint3D(100.0, 0.0));
89 CrossSectionLink l45 = new CrossSectionLink(network, "L45", n4, n5, LinkType.ALL,
90 new OTSLine3D(new OTSPoint3D[] { new OTSPoint3D(75.0, -20.0), new OTSPoint3D(100.0, 0.0) }),
91 LongitudinalDirectionality.DIR_BOTH, LaneKeepingPolicy.KEEP_RIGHT);
92
93 OTSNode n6 = new OTSNode(network, "N6", new OTSPoint3D(125.0, 0.0));
94 CrossSectionLink l56 = new CrossSectionLink(network, "L56", n5, n6, LinkType.ALL,
95 new OTSLine3D(new OTSPoint3D[] { new OTSPoint3D(100.0, 0.0), new OTSPoint3D(125.0, 0.0) }),
96 LongitudinalDirectionality.DIR_BOTH, LaneKeepingPolicy.KEEP_RIGHT);
97
98 OTSNode n7 = new OTSNode(network, "N7", new OTSPoint3D(300.0, 0.0));
99 CrossSectionLink l67 = new CrossSectionLink(network, "L67", n6, n7, LinkType.ALL,
100 new OTSLine3D(new OTSPoint3D[] { new OTSPoint3D(125.0, 0.0), new OTSPoint3D(150.0, 0.0),
101 new OTSPoint3D(175.0, 20.0), new OTSPoint3D(200.0, 0.0), new OTSPoint3D(225.0, -20.0),
102 new OTSPoint3D(250.0, 0.0), new OTSPoint3D(300.0, 0.0) }),
103 LongitudinalDirectionality.DIR_BOTH, LaneKeepingPolicy.KEEP_RIGHT);
104
105 add2x2Lanes(l01);
106 add2x2Lanes(l12);
107 add2x2Lanes(l23);
108 add2x2Lanes(l34);
109 add2x2Lanes(l45);
110 add2x2Lanes(l56);
111 add2x2Lanes(l67);
112 }
113 catch (NetworkException | OTSGeometryException exception)
114 {
115 exception.printStackTrace();
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
150
151
152
153 private void add2x2Lanes(final CrossSectionLink link) throws NetworkException, OTSGeometryException
154 {
155
156
157 Length m05 = new Length(0.5, METER);
158 Length m10 = new Length(1.0, METER);
159 Length m35 = new Length(3.5, METER);
160 Speed speedLimit = new Speed(100, KM_PER_HOUR);
161
162 Shoulder sL = new Shoulder(link, "sL", new Length(9.0, METER), m10);
163
164 Lane laneELL = new NoTrafficLane(link, "ELL", new Length(8.25, METER), new Length(8.25, METER), m05, m05);
165 Lane laneL1 = new Lane(link, "L1", new Length(6.25, METER), new Length(6.25, METER), m35, m35, null,
166 LongitudinalDirectionality.DIR_MINUS, speedLimit, new OvertakingConditions.LeftAndRight());
167 Lane laneL2 = new Lane(link, "L2", new Length(2.75, METER), new Length(2.75, METER), m35, m35, null,
168 LongitudinalDirectionality.DIR_MINUS, speedLimit, new OvertakingConditions.LeftAndRight());
169 Lane laneELM = new NoTrafficLane(link, "ELM", new Length(0.75, METER), new Length(0.75, METER), m05, m05);
170
171 Shoulder sM = new Shoulder(link, "sM", new Length(0.0, METER), m10);
172
173 Lane laneERM = new NoTrafficLane(link, "ERM", new Length(-0.75, METER), new Length(-0.75, METER), m05, m05);
174 Lane laneR2 = new Lane(link, "R2", new Length(-2.75, METER), new Length(-2.75, METER), m35, m35, null,
175 LongitudinalDirectionality.DIR_PLUS, speedLimit, new OvertakingConditions.LeftAndRight());
176 Lane laneR1 = new Lane(link, "R1", new Length(-6.25, METER), new Length(-6.25, METER), m35, m35, null,
177 LongitudinalDirectionality.DIR_PLUS, speedLimit, new OvertakingConditions.LeftAndRight());
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
204 @Override
205 public final SimulatorInterface<Time, Duration, OTSSimTimeDouble> getSimulator() throws RemoteException
206 {
207 return this.simulator;
208 }
209 }